blob: 0f7fcb3adb187a9399a3c2df7f47636f3eb1e701 [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;
Tyler Gunn65d45c22017-06-05 11:22:26 -070078import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080080import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070081import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080082import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070084import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070085import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080086import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000087import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070088import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070089import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070090import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080091import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080092import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070093import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080094import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070095import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080096import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070097import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080098import android.telephony.ims.aidl.IImsMmTelFeature;
99import android.telephony.ims.aidl.IImsRcsFeature;
100import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700101import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.feature.MmTelFeature;
103import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800104import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800106import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800108import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800109import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800110
Brad Ebinger4c460712018-10-01 10:40:55 -0700111import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700112import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800113import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700114import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700115import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700116import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800117import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700118import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700119import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800121import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800122import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800124import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700125import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100126import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700127import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700130import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800131import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700132import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700133import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700134import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700135import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700136import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700137import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800138import com.android.internal.telephony.SmsApplication;
139import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800140import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800141import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800142import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700143import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800144import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800145import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700146import com.android.internal.telephony.uicc.IccIoResult;
147import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800148import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700149import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800150import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000153import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700154import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800155import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700156import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800157import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700158import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700159import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800160
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700161import java.io.FileDescriptor;
162import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800163import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800165import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800166import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800167import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800168import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800169import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100170import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800171import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800172import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173
174/**
175 * Implementation of the ITelephony interface.
176 */
Santos Cordon117fee72014-05-16 17:56:12 -0700177public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178 private static final String LOG_TAG = "PhoneInterfaceManager";
179 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
180 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182
183 // Message codes used with mMainThreadHandler
184 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700185 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
186 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187 private static final int CMD_OPEN_CHANNEL = 9;
188 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
189 private static final int CMD_CLOSE_CHANNEL = 11;
190 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800191 private static final int CMD_NV_READ_ITEM = 13;
192 private static final int EVENT_NV_READ_ITEM_DONE = 14;
193 private static final int CMD_NV_WRITE_ITEM = 15;
194 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
195 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
196 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700197 private static final int CMD_RESET_MODEM_CONFIG = 19;
198 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800199 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
200 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
201 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
202 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800203 private static final int CMD_SEND_ENVELOPE = 25;
204 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000205 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
206 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700207 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
208 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
209 private static final int CMD_EXCHANGE_SIM_IO = 31;
210 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800211 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
212 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700213 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
214 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700215 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
216 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700217 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
218 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
219 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
220 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700221 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
222 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
223 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
224 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700225 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800226 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
227 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000228 private static final int CMD_SWITCH_SLOTS = 50;
229 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700230 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
231 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
232 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
233 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
234 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
235 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
236 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
237 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700238 private static final int CMD_GET_ALL_CELL_INFO = 60;
239 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
240 private static final int CMD_GET_CELL_LOCATION = 62;
241 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700242 private static final int CMD_MODEM_REBOOT = 64;
243 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700244 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
245 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800246 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
247 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800249 // Parameters of select command.
250 private static final int SELECT_COMMAND = 0xA4;
251 private static final int SELECT_P1 = 0x04;
252 private static final int SELECT_P2 = 0;
253 private static final int SELECT_P3 = 0x10;
254
Pengquan Meng85728fb2018-03-12 16:31:21 -0700255 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
256 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
257 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
258
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259 /** The singleton instance. */
260 private static PhoneInterfaceManager sInstance;
261
Wink Saville3ab207e2014-11-20 13:07:20 -0800262 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800263 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700264 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800265 private AppOpsManager mAppOps;
266 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800267 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800268 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700269 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
Derek Tan97ebb422014-09-05 16:55:38 -0700271 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
272 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800273 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800274 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700275
Micheled3107c52018-12-21 15:00:11 -0800276 // String to store multi SIM allowed
277 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
278
Derek Tan740e1672017-06-27 14:56:27 -0700279 // The AID of ISD-R.
280 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
281
yinxub1bed742017-04-17 11:45:04 -0700282 private NetworkScanRequestTracker mNetworkScanRequestTracker;
283
David Kelly5e06a7f2018-03-12 14:10:59 +0000284 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
285 private static final int MANUFACTURER_CODE_LENGTH = 8;
286
Derek Tan89e89d42014-07-08 17:00:10 -0700287 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700288 * A request object to use for transmitting data to an ICC.
289 */
290 private static final class IccAPDUArgument {
291 public int channel, cla, command, p1, p2, p3;
292 public String data;
293
294 public IccAPDUArgument(int channel, int cla, int command,
295 int p1, int p2, int p3, String data) {
296 this.channel = channel;
297 this.cla = cla;
298 this.command = command;
299 this.p1 = p1;
300 this.p2 = p2;
301 this.p3 = p3;
302 this.data = data;
303 }
304 }
305
306 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700307 * A request object to use for transmitting data to an ICC.
308 */
309 private static final class ManualNetworkSelectionArgument {
310 public OperatorInfo operatorInfo;
311 public boolean persistSelection;
312
313 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
314 this.operatorInfo = operatorInfo;
315 this.persistSelection = persistSelection;
316 }
317 }
318
319 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
321 * request after sending. The main thread will notify the request when it is complete.
322 */
323 private static final class MainThreadRequest {
324 /** The argument to use for the request */
325 public Object argument;
326 /** The result of the request that is run on the main thread */
327 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800328 // The subscriber id that this request applies to. Defaults to
329 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
330 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331
Nathan Harold92bed182018-10-12 18:16:49 -0700332 // In cases where subId is unavailable, the caller needs to specify the phone.
333 public Phone phone;
334
vagdevie435a3e2018-08-15 16:01:53 -0700335 public WorkSource workSource;
336
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 public MainThreadRequest(Object argument) {
338 this.argument = argument;
339 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800340
Nathan Harold92bed182018-10-12 18:16:49 -0700341 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
342 this.argument = argument;
343 if (phone != null) {
344 this.phone = phone;
345 }
346 this.workSource = workSource;
347 }
348
vagdevie435a3e2018-08-15 16:01:53 -0700349 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800350 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800351 if (subId != null) {
352 this.subId = subId;
353 }
vagdevie435a3e2018-08-15 16:01:53 -0700354 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 }
357
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800358 private static final class IncomingThirdPartyCallArgs {
359 public final ComponentName component;
360 public final String callId;
361 public final String callerDisplayName;
362
363 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
364 String callerDisplayName) {
365 this.component = component;
366 this.callId = callId;
367 this.callerDisplayName = callerDisplayName;
368 }
369 }
370
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 /**
372 * A handler that processes messages on the main thread in the phone process. Since many
373 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
374 * inbound binder threads to the main thread in the phone process. The Binder thread
375 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
376 * on, which will be notified when the operation completes and will contain the result of the
377 * request.
378 *
379 * <p>If a MainThreadRequest object is provided in the msg.obj field,
380 * note that request.result must be set to something non-null for the calling thread to
381 * unblock.
382 */
383 private final class MainThreadHandler extends Handler {
384 @Override
385 public void handleMessage(Message msg) {
386 MainThreadRequest request;
387 Message onCompleted;
388 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800389 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700390 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800391 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392
393 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700394 case CMD_HANDLE_USSD_REQUEST: {
395 request = (MainThreadRequest) msg.obj;
396 final Phone phone = getPhoneFromRequest(request);
397 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
398 String ussdRequest = ussdObject.first;
399 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700400
Pengquan Meng0c05b502018-09-06 09:59:22 -0700401 if (!isUssdApiAllowed(request.subId)) {
402 // Carrier does not support use of this API, return failure.
403 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
404 UssdResponse response = new UssdResponse(ussdRequest, null);
405 Bundle returnData = new Bundle();
406 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
407 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700408
Pengquan Meng0c05b502018-09-06 09:59:22 -0700409 request.result = true;
410 notifyRequester(request);
411 return;
412 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700413
Pengquan Meng0c05b502018-09-06 09:59:22 -0700414 try {
415 request.result = phone != null
416 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
417 } catch (CallStateException cse) {
418 request.result = false;
419 }
420 // Wake up the requesting thread
421 notifyRequester(request);
422 break;
pkanwar32d516d2016-10-14 19:37:38 -0700423 }
424
Yorke Lee716f67e2015-06-17 15:39:16 -0700425 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700427 final Phone phone = getPhoneFromRequest(request);
428 request.result = phone != null ?
429 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
430 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700432 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800439 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700440 if (uiccCard == null) {
441 loge("iccTransmitApduLogicalChannel: No UICC");
442 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700443 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700444 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
446 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700447 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 iccArgument.channel, iccArgument.cla, iccArgument.command,
449 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700451 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 break;
453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700455 ar = (AsyncResult) msg.obj;
456 request = (MainThreadRequest) ar.userObj;
457 if (ar.exception == null && ar.result != null) {
458 request.result = ar.result;
459 } else {
460 request.result = new IccIoResult(0x6F, 0, (byte[])null);
461 if (ar.result == null) {
462 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800463 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800465 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 } else {
467 loge("iccTransmitApduLogicalChannel: Unknown exception");
468 }
469 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700470 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700471 break;
472
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
474 request = (MainThreadRequest) msg.obj;
475 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800476 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 if (uiccCard == null) {
478 loge("iccTransmitApduBasicChannel: No UICC");
479 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 } else {
482 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
483 request);
484 uiccCard.iccTransmitApduBasicChannel(
485 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
486 iccArgument.p3, iccArgument.data, onCompleted);
487 }
488 break;
489
490 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
491 ar = (AsyncResult) msg.obj;
492 request = (MainThreadRequest) ar.userObj;
493 if (ar.exception == null && ar.result != null) {
494 request.result = ar.result;
495 } else {
496 request.result = new IccIoResult(0x6F, 0, (byte[])null);
497 if (ar.result == null) {
498 loge("iccTransmitApduBasicChannel: Empty response");
499 } else if (ar.exception instanceof CommandException) {
500 loge("iccTransmitApduBasicChannel: CommandException: " +
501 ar.exception);
502 } else {
503 loge("iccTransmitApduBasicChannel: Unknown exception");
504 }
505 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700506 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 break;
508
509 case CMD_EXCHANGE_SIM_IO:
510 request = (MainThreadRequest) msg.obj;
511 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800512 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 if (uiccCard == null) {
514 loge("iccExchangeSimIO: No UICC");
515 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 } else {
518 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
519 request);
520 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
521 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
522 iccArgument.data, onCompleted);
523 }
524 break;
525
526 case EVENT_EXCHANGE_SIM_IO_DONE:
527 ar = (AsyncResult) msg.obj;
528 request = (MainThreadRequest) ar.userObj;
529 if (ar.exception == null && ar.result != null) {
530 request.result = ar.result;
531 } else {
532 request.result = new IccIoResult(0x6f, 0, (byte[])null);
533 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700534 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 break;
536
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 case CMD_SEND_ENVELOPE:
538 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800539 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 if (uiccCard == null) {
541 loge("sendEnvelopeWithStatus: No UICC");
542 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700543 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700544 } else {
545 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
546 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
547 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 break;
549
550 case EVENT_SEND_ENVELOPE_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800555 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
557 if (ar.result == null) {
558 loge("sendEnvelopeWithStatus: Empty response");
559 } else if (ar.exception instanceof CommandException) {
560 loge("sendEnvelopeWithStatus: CommandException: " +
561 ar.exception);
562 } else {
563 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
564 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700566 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800567 break;
568
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 case CMD_OPEN_CHANNEL:
570 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800571 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800572 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700573 if (uiccCard == null) {
574 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800575 request.result = new IccOpenLogicalChannelResponse(-1,
576 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700577 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700578 } else {
579 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800580 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
581 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 break;
584
585 case EVENT_OPEN_CHANNEL_DONE:
586 ar = (AsyncResult) msg.obj;
587 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 int[] result = (int[]) ar.result;
591 int channelId = result[0];
592 byte[] selectResponse = null;
593 if (result.length > 1) {
594 selectResponse = new byte[result.length - 1];
595 for (int i = 1; i < result.length; ++i) {
596 selectResponse[i - 1] = (byte) result[i];
597 }
598 }
599 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700600 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 if (ar.result == null) {
603 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 if (ar.exception != null) {
606 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
607 }
608
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700610 if (ar.exception instanceof CommandException) {
611 CommandException.Error error =
612 ((CommandException) (ar.exception)).getCommandError();
613 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700614 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700615 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700616 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 }
618 }
619 openChannelResp = new IccOpenLogicalChannelResponse(
620 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700622 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 break;
625
626 case CMD_CLOSE_CHANNEL:
627 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800628 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 if (uiccCard == null) {
630 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900631 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 } else {
634 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
635 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
636 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
639 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800640 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
641 break;
642
643 case CMD_NV_READ_ITEM:
644 request = (MainThreadRequest) msg.obj;
645 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800646 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
647 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800648 break;
649
650 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 ar = (AsyncResult) msg.obj;
652 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800653 if (ar.exception == null && ar.result != null) {
654 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800656 request.result = "";
657 if (ar.result == null) {
658 loge("nvReadItem: Empty response");
659 } else if (ar.exception instanceof CommandException) {
660 loge("nvReadItem: CommandException: " +
661 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800663 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 }
665 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 break;
668
Jake Hambye994d462014-02-03 13:10:13 -0800669 case CMD_NV_WRITE_ITEM:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
672 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800673 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700674 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800675 break;
676
677 case EVENT_NV_WRITE_ITEM_DONE:
678 handleNullReturnEvent(msg, "nvWriteItem");
679 break;
680
681 case CMD_NV_WRITE_CDMA_PRL:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800684 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800685 break;
686
687 case EVENT_NV_WRITE_CDMA_PRL_DONE:
688 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
689 break;
690
chen xu1cc0abe2018-10-26 17:39:23 -0700691 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800692 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700693 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800694 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800695 break;
696
chen xu1cc0abe2018-10-26 17:39:23 -0700697 case EVENT_RESET_MODEM_CONFIG_DONE:
698 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 case CMD_GET_PREFERRED_NETWORK_TYPE:
702 request = (MainThreadRequest) msg.obj;
703 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700704 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800705 break;
706
707 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
708 ar = (AsyncResult) msg.obj;
709 request = (MainThreadRequest) ar.userObj;
710 if (ar.exception == null && ar.result != null) {
711 request.result = ar.result; // Integer
712 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800713 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 if (ar.result == null) {
715 loge("getPreferredNetworkType: Empty response");
716 } else if (ar.exception instanceof CommandException) {
717 loge("getPreferredNetworkType: CommandException: " +
718 ar.exception);
719 } else {
720 loge("getPreferredNetworkType: Unknown exception");
721 }
722 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700723 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 break;
725
726 case CMD_SET_PREFERRED_NETWORK_TYPE:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
729 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700730 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
734 handleNullReturnEvent(msg, "setPreferredNetworkType");
735 break;
736
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000737 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
738 request = (MainThreadRequest)msg.obj;
739 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800740 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000741 break;
742
743 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
744 ar = (AsyncResult)msg.obj;
745 request = (MainThreadRequest)ar.userObj;
746 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700747 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000748 break;
749
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800750 case CMD_SET_VOICEMAIL_NUMBER:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
753 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800754 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
755 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800756 break;
757
758 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
759 handleNullReturnEvent(msg, "setVoicemailNumber");
760 break;
761
Stuart Scott54788802015-03-30 13:18:01 -0700762 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
765 request);
766 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
767 break;
768
769 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
770 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
771 break;
772
Shishir Agrawal302c8692015-06-19 13:49:39 -0700773 case CMD_PERFORM_NETWORK_SCAN:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
776 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
777 break;
778
779 case EVENT_PERFORM_NETWORK_SCAN_DONE:
780 ar = (AsyncResult) msg.obj;
781 request = (MainThreadRequest) ar.userObj;
782 CellNetworkScanResult cellScanResult;
783 if (ar.exception == null && ar.result != null) {
784 cellScanResult = new CellNetworkScanResult(
785 CellNetworkScanResult.STATUS_SUCCESS,
786 (List<OperatorInfo>) ar.result);
787 } else {
788 if (ar.result == null) {
789 loge("getCellNetworkScanResults: Empty response");
790 }
791 if (ar.exception != null) {
792 loge("getCellNetworkScanResults: Exception: " + ar.exception);
793 }
794 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
795 if (ar.exception instanceof CommandException) {
796 CommandException.Error error =
797 ((CommandException) (ar.exception)).getCommandError();
798 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
799 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
800 } else if (error == CommandException.Error.GENERIC_FAILURE) {
801 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
802 }
803 }
804 cellScanResult = new CellNetworkScanResult(errorCode, null);
805 }
806 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700807 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700808 break;
809
810 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
811 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700812 ManualNetworkSelectionArgument selArg =
813 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700814 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
815 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700816 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
817 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 break;
819
820 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700821 ar = (AsyncResult) msg.obj;
822 request = (MainThreadRequest) ar.userObj;
823 if (ar.exception == null) {
824 request.result = true;
825 } else {
826 request.result = false;
827 loge("setNetworkSelectionModeManual " + ar.exception);
828 }
829 notifyRequester(request);
830 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 break;
832
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700833 case CMD_GET_MODEM_ACTIVITY_INFO:
834 request = (MainThreadRequest) msg.obj;
835 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800836 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700837 break;
838
839 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
840 ar = (AsyncResult) msg.obj;
841 request = (MainThreadRequest) ar.userObj;
842 if (ar.exception == null && ar.result != null) {
843 request.result = ar.result;
844 } else {
845 if (ar.result == null) {
846 loge("queryModemActivityInfo: Empty response");
847 } else if (ar.exception instanceof CommandException) {
848 loge("queryModemActivityInfo: CommandException: " +
849 ar.exception);
850 } else {
851 loge("queryModemActivityInfo: Unknown exception");
852 }
853 }
Amit Mahajand4766222016-01-28 15:28:28 -0800854 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
855 if (request.result == null) {
856 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
857 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700858 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700859 break;
860
Meng Wang1a7c35a2016-05-05 20:56:15 -0700861 case CMD_SET_ALLOWED_CARRIERS:
862 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800863 CarrierRestrictionRules argument =
864 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700865 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800866 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700867 break;
868
869 case EVENT_SET_ALLOWED_CARRIERS_DONE:
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null && ar.result != null) {
873 request.result = ar.result;
874 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800875 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
876 if (ar.exception instanceof CommandException) {
877 loge("setAllowedCarriers: CommandException: " + ar.exception);
878 CommandException.Error error =
879 ((CommandException) (ar.exception)).getCommandError();
880 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
881 request.result =
882 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
883 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 } else {
885 loge("setAllowedCarriers: Unknown exception");
886 }
887 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700888 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 break;
890
891 case CMD_GET_ALLOWED_CARRIERS:
892 request = (MainThreadRequest) msg.obj;
893 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800894 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 break;
896
897 case EVENT_GET_ALLOWED_CARRIERS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800903 request.result = new IllegalStateException(
904 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700905 if (ar.result == null) {
906 loge("getAllowedCarriers: Empty response");
907 } else if (ar.exception instanceof CommandException) {
908 loge("getAllowedCarriers: CommandException: " +
909 ar.exception);
910 } else {
911 loge("getAllowedCarriers: Unknown exception");
912 }
913 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700914 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700915 break;
916
Nathan Haroldb3014052017-01-25 15:57:32 -0800917 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
918 ar = (AsyncResult) msg.obj;
919 request = (MainThreadRequest) ar.userObj;
920 if (ar.exception == null && ar.result != null) {
921 request.result = ar.result;
922 } else {
923 request.result = new IllegalArgumentException(
924 "Failed to retrieve Forbidden Plmns");
925 if (ar.result == null) {
926 loge("getForbiddenPlmns: Empty response");
927 } else {
928 loge("getForbiddenPlmns: Unknown exception");
929 }
930 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700931 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800932 break;
933
934 case CMD_GET_FORBIDDEN_PLMNS:
935 request = (MainThreadRequest) msg.obj;
936 uiccCard = getUiccCardFromRequest(request);
937 if (uiccCard == null) {
938 loge("getForbiddenPlmns() UiccCard is null");
939 request.result = new IllegalArgumentException(
940 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700941 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800942 break;
943 }
944 Integer appType = (Integer) request.argument;
945 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
946 if (uiccApp == null) {
947 loge("getForbiddenPlmns() no app with specified type -- "
948 + appType);
949 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700950 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800951 break;
952 } else {
953 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
954 + " specified type -- " + appType);
955 }
956 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
957 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
958 onCompleted);
959 break;
960
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000961 case CMD_SWITCH_SLOTS:
962 request = (MainThreadRequest) msg.obj;
963 int[] physicalSlots = (int[]) request.argument;
964 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
965 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
966 break;
967
968 case EVENT_SWITCH_SLOTS_DONE:
969 ar = (AsyncResult) msg.obj;
970 request = (MainThreadRequest) ar.userObj;
971 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700972 notifyRequester(request);
973 break;
974 case CMD_GET_NETWORK_SELECTION_MODE:
975 request = (MainThreadRequest) msg.obj;
976 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
977 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
978 break;
979
980 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 if (ar.exception != null) {
984 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
985 } else {
986 int mode = ((int[]) ar.result)[0];
987 if (mode == 0) {
988 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
989 } else {
990 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
991 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000992 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700993 notifyRequester(request);
994 break;
995 case CMD_GET_CDMA_ROAMING_MODE:
996 request = (MainThreadRequest) msg.obj;
997 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
998 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
999 break;
1000 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1001 ar = (AsyncResult) msg.obj;
1002 request = (MainThreadRequest) ar.userObj;
1003 if (ar.exception != null) {
1004 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1005 } else {
1006 request.result = ((int[]) ar.result)[0];
1007 }
1008 notifyRequester(request);
1009 break;
1010 case CMD_SET_CDMA_ROAMING_MODE:
1011 request = (MainThreadRequest) msg.obj;
1012 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1013 int mode = (int) request.argument;
1014 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1015 break;
1016 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 request.result = ar.exception == null;
1020 notifyRequester(request);
1021 break;
1022 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1025 int subscriptionMode = (int) request.argument;
1026 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1027 break;
1028 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 request.result = ar.exception == null;
1032 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001033 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001034 case CMD_GET_ALL_CELL_INFO:
1035 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001036 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001037 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001038 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001039 case EVENT_GET_ALL_CELL_INFO_DONE:
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001042 // If a timeout occurs, the response will be null
1043 request.result = (ar.exception == null && ar.result != null)
1044 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001045 synchronized (request) {
1046 request.notifyAll();
1047 }
1048 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001049 case CMD_REQUEST_CELL_INFO_UPDATE:
1050 request = (MainThreadRequest) msg.obj;
1051 request.phone.requestCellInfoUpdate(request.workSource,
1052 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1053 break;
1054 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1058 try {
1059 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001061 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1062 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001063 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001065 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001066 } else {
1067 // use the result as returned
1068 cb.onCellInfo((List<CellInfo>) ar.result);
1069 }
1070 } catch (RemoteException re) {
1071 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1072 }
1073 break;
1074 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001075 request = (MainThreadRequest) msg.obj;
1076 WorkSource ws = (WorkSource) request.argument;
1077 Phone phone = getPhoneFromRequest(request);
1078 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1079 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001081 ar = (AsyncResult) msg.obj;
1082 request = (MainThreadRequest) ar.userObj;
1083 if (ar.exception == null) {
1084 request.result = ar.result;
1085 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001086 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001087 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1088 ? new CdmaCellLocation() : new GsmCellLocation();
1089 }
1090
1091 synchronized (request) {
1092 request.notifyAll();
1093 }
1094 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001095 case CMD_MODEM_REBOOT:
1096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001098 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001099 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001100 case EVENT_CMD_MODEM_REBOOT_DONE:
1101 handleNullReturnEvent(msg, "rebootModem");
1102 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001103 case CMD_REQUEST_ENABLE_MODEM:
1104 request = (MainThreadRequest) msg.obj;
1105 boolean enable = (boolean) request.argument;
1106 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001107 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001108 PhoneConfigurationManager.getInstance()
1109 .enablePhone(request.phone, enable, onCompleted);
1110 break;
1111 case EVENT_ENABLE_MODEM_DONE:
1112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
1114 request.result = (ar.exception == null);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001115 //update the cache as modem status has changed
1116 mPhoneConfigurationManager.addToPhoneStatusCache(
1117 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001118 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001119 notifyRequester(request);
1120 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001121 default:
1122 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1123 break;
1124 }
1125 }
Jake Hambye994d462014-02-03 13:10:13 -08001126
Pengquan Meng0c05b502018-09-06 09:59:22 -07001127 private void notifyRequester(MainThreadRequest request) {
1128 synchronized (request) {
1129 request.notifyAll();
1130 }
1131 }
1132
Jake Hambye994d462014-02-03 13:10:13 -08001133 private void handleNullReturnEvent(Message msg, String command) {
1134 AsyncResult ar = (AsyncResult) msg.obj;
1135 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1136 if (ar.exception == null) {
1137 request.result = true;
1138 } else {
1139 request.result = false;
1140 if (ar.exception instanceof CommandException) {
1141 loge(command + ": CommandException: " + ar.exception);
1142 } else {
1143 loge(command + ": Unknown exception");
1144 }
1145 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001146 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 }
1149
1150 /**
1151 * Posts the specified command to be executed on the main thread,
1152 * waits for the request to complete, and returns the result.
1153 * @see #sendRequestAsync
1154 */
1155 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001156 return sendRequest(
1157 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001158 }
1159
1160 /**
1161 * Posts the specified command to be executed on the main thread,
1162 * waits for the request to complete, and returns the result.
1163 * @see #sendRequestAsync
1164 */
1165 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1166 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001167 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001168 }
1169
1170 /**
1171 * Posts the specified command to be executed on the main thread,
1172 * waits for the request to complete, and returns the result.
1173 * @see #sendRequestAsync
1174 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001175 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001176 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001177 }
1178
1179 /**
1180 * Posts the specified command to be executed on the main thread,
1181 * waits for the request to complete, and returns the result.
1182 * @see #sendRequestAsync
1183 */
Nathan Harold92bed182018-10-12 18:16:49 -07001184 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1185 return sendRequest(command, argument, subId, null, workSource);
1186 }
1187
1188 /**
1189 * Posts the specified command to be executed on the main thread,
1190 * waits for the request to complete, and returns the result.
1191 * @see #sendRequestAsync
1192 */
1193 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1194 return sendRequest(
1195 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1196 }
1197
1198 /**
1199 * Posts the specified command to be executed on the main thread,
1200 * waits for the request to complete, and returns the result.
1201 * @see #sendRequestAsync
1202 */
1203 private Object sendRequest(
1204 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1206 throw new RuntimeException("This method will deadlock if called from the main thread.");
1207 }
1208
Nathan Harold92bed182018-10-12 18:16:49 -07001209 MainThreadRequest request = null;
1210 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1211 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1212 } else if (phone != null) {
1213 request = new MainThreadRequest(argument, phone, workSource);
1214 } else {
1215 request = new MainThreadRequest(argument, subId, workSource);
1216 }
1217
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 Message msg = mMainThreadHandler.obtainMessage(command, request);
1219 msg.sendToTarget();
1220
1221 // Wait for the request to complete
1222 synchronized (request) {
1223 while (request.result == null) {
1224 try {
1225 request.wait();
1226 } catch (InterruptedException e) {
1227 // Do nothing, go back and wait until the request is complete
1228 }
1229 }
1230 }
1231 return request.result;
1232 }
1233
1234 /**
1235 * Asynchronous ("fire and forget") version of sendRequest():
1236 * Posts the specified command to be executed on the main thread, and
1237 * returns immediately.
1238 * @see #sendRequest
1239 */
1240 private void sendRequestAsync(int command) {
1241 mMainThreadHandler.sendEmptyMessage(command);
1242 }
1243
1244 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001245 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001246 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001247 */
1248 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001249 sendRequestAsync(command, argument, null, null);
1250 }
1251
1252 /**
1253 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1254 * @see {@link #sendRequest(int,Object)}
1255 */
1256 private void sendRequestAsync(
1257 int command, Object argument, Phone phone, WorkSource workSource) {
1258 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001259 Message msg = mMainThreadHandler.obtainMessage(command, request);
1260 msg.sendToTarget();
1261 }
1262
1263 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 * Initialize the singleton PhoneInterfaceManager instance.
1265 * This is only done once, at startup, from PhoneApp.onCreate().
1266 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001267 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 synchronized (PhoneInterfaceManager.class) {
1269 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001270 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271 } else {
1272 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1273 }
1274 return sInstance;
1275 }
1276 }
1277
1278 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001279 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001282 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1284 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001285 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001286 mTelephonySharedPreferences =
1287 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001288 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001289 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001290
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001291 publish();
1292 }
1293
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001294 private Phone getDefaultPhone() {
1295 Phone thePhone = getPhone(getDefaultSubscription());
1296 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1297 }
1298
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299 private void publish() {
1300 if (DBG) log("publish: " + this);
1301
1302 ServiceManager.addService("phone", this);
1303 }
1304
Stuart Scott584921c2015-01-15 17:10:34 -08001305 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001306 if (request.phone != null) {
1307 return request.phone;
1308 } else {
1309 return getPhoneFromSubId(request.subId);
1310 }
1311 }
1312
1313 private Phone getPhoneFromSubId(int subId) {
1314 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1315 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001316 }
1317
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001318 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1319 Phone phone = getPhoneFromRequest(request);
1320 return phone == null ? null :
1321 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1322 }
1323
Wink Saville36469e72014-06-11 15:17:00 -07001324 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001325 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001326 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328
1329 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001330 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001331 }
1332
Wink Savilleb564aae2014-10-23 10:18:09 -07001333 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 if (DBG) log("dial: " + number);
1335 // No permission check needed here: This is just a wrapper around the
1336 // ACTION_DIAL intent, which is available to any app since it puts up
1337 // the UI before it does anything.
1338
Malcolm Chend965c8b2018-02-28 15:00:40 -08001339 final long identity = Binder.clearCallingIdentity();
1340 try {
1341 String url = createTelUrl(number);
1342 if (url == null) {
1343 return;
1344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001345
Malcolm Chend965c8b2018-02-28 15:00:40 -08001346 // PENDING: should we just silently fail if phone is offhook or ringing?
1347 PhoneConstants.State state = mCM.getState(subId);
1348 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1349 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1350 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1351 mApp.startActivity(intent);
1352 }
1353 } finally {
1354 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001355 }
1356 }
1357
1358 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001359 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001360 }
1361
Wink Savilleb564aae2014-10-23 10:18:09 -07001362 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 if (DBG) log("call: " + number);
1364
1365 // This is just a wrapper around the ACTION_CALL intent, but we still
1366 // need to do a permission check since we're calling startActivity()
1367 // from the context of the phone app.
1368 enforceCallPermission();
1369
1370 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1371 != AppOpsManager.MODE_ALLOWED) {
1372 return;
1373 }
1374
Malcolm Chend965c8b2018-02-28 15:00:40 -08001375 final long identity = Binder.clearCallingIdentity();
1376 try {
1377 String url = createTelUrl(number);
1378 if (url == null) {
1379 return;
1380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381
Malcolm Chend965c8b2018-02-28 15:00:40 -08001382 boolean isValid = false;
1383 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1384 if (slist != null) {
1385 for (SubscriptionInfo subInfoRecord : slist) {
1386 if (subInfoRecord.getSubscriptionId() == subId) {
1387 isValid = true;
1388 break;
1389 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001390 }
Wink Saville08874612014-08-31 19:19:58 -07001391 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001392 if (!isValid) {
1393 return;
1394 }
Wink Saville08874612014-08-31 19:19:58 -07001395
Malcolm Chend965c8b2018-02-28 15:00:40 -08001396 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1397 intent.putExtra(SUBSCRIPTION_KEY, subId);
1398 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1399 mApp.startActivity(intent);
1400 } finally {
1401 Binder.restoreCallingIdentity(identity);
1402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 }
1404
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001406 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001407 }
1408
Wink Savilleb564aae2014-10-23 10:18:09 -07001409 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001410 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001411 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1412 }
1413
1414 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001415 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001416 }
1417
Wink Savilleb564aae2014-10-23 10:18:09 -07001418 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001419 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001420 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1421 }
1422
1423 /** {@hide} */
1424 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001425 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001426 }
1427
Wink Savilleb564aae2014-10-23 10:18:09 -07001428 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001430
1431 final long identity = Binder.clearCallingIdentity();
1432 try {
1433 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1434 checkSimPin.start();
1435 return checkSimPin.unlockSim(null, pin);
1436 } finally {
1437 Binder.restoreCallingIdentity(identity);
1438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439 }
1440
Wink Saville9de0f752013-10-22 19:04:03 -07001441 /** {@hide} */
1442 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001443 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001444 }
1445
Wink Savilleb564aae2014-10-23 10:18:09 -07001446 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001448
1449 final long identity = Binder.clearCallingIdentity();
1450 try {
1451 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1452 checkSimPuk.start();
1453 return checkSimPuk.unlockSim(puk, pin);
1454 } finally {
1455 Binder.restoreCallingIdentity(identity);
1456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 }
1458
1459 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001460 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 * a synchronous one.
1462 */
1463 private static class UnlockSim extends Thread {
1464
1465 private final IccCard mSimCard;
1466
1467 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001468 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1469 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470
1471 // For replies from SimCard interface
1472 private Handler mHandler;
1473
1474 // For async handler to identify request type
1475 private static final int SUPPLY_PIN_COMPLETE = 100;
1476
1477 public UnlockSim(IccCard simCard) {
1478 mSimCard = simCard;
1479 }
1480
1481 @Override
1482 public void run() {
1483 Looper.prepare();
1484 synchronized (UnlockSim.this) {
1485 mHandler = new Handler() {
1486 @Override
1487 public void handleMessage(Message msg) {
1488 AsyncResult ar = (AsyncResult) msg.obj;
1489 switch (msg.what) {
1490 case SUPPLY_PIN_COMPLETE:
1491 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1492 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001493 mRetryCount = msg.arg1;
1494 if (ar.exception != null) {
1495 if (ar.exception instanceof CommandException &&
1496 ((CommandException)(ar.exception)).getCommandError()
1497 == CommandException.Error.PASSWORD_INCORRECT) {
1498 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1499 } else {
1500 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1501 }
1502 } else {
1503 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 mDone = true;
1506 UnlockSim.this.notifyAll();
1507 }
1508 break;
1509 }
1510 }
1511 };
1512 UnlockSim.this.notifyAll();
1513 }
1514 Looper.loop();
1515 }
1516
1517 /*
1518 * Use PIN or PUK to unlock SIM card
1519 *
1520 * If PUK is null, unlock SIM card with PIN
1521 *
1522 * If PUK is not null, unlock SIM card with PUK and set PIN code
1523 */
Wink Saville9de0f752013-10-22 19:04:03 -07001524 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525
1526 while (mHandler == null) {
1527 try {
1528 wait();
1529 } catch (InterruptedException e) {
1530 Thread.currentThread().interrupt();
1531 }
1532 }
1533 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1534
1535 if (puk == null) {
1536 mSimCard.supplyPin(pin, callback);
1537 } else {
1538 mSimCard.supplyPuk(puk, pin, callback);
1539 }
1540
1541 while (!mDone) {
1542 try {
1543 Log.d(LOG_TAG, "wait for done");
1544 wait();
1545 } catch (InterruptedException e) {
1546 // Restore the interrupted status
1547 Thread.currentThread().interrupt();
1548 }
1549 }
1550 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001551 int[] resultArray = new int[2];
1552 resultArray[0] = mResult;
1553 resultArray[1] = mRetryCount;
1554 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 }
1556 }
1557
1558 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001559 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001560
1561 }
1562
Wink Savilleb564aae2014-10-23 10:18:09 -07001563 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 // No permission check needed here: this call is harmless, and it's
1565 // needed for the ServiceState.requestStateUpdate() call (which is
1566 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001567 final long identity = Binder.clearCallingIdentity();
1568 try {
1569 final Phone phone = getPhone(subId);
1570 if (phone != null) {
1571 phone.updateServiceLocation();
1572 }
1573 } finally {
1574 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001576 }
1577
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001578 @Override
1579 public boolean isRadioOn(String callingPackage) {
1580 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001581 }
1582
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001583 @Override
1584 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001586 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001587 return false;
1588 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001589
1590 final long identity = Binder.clearCallingIdentity();
1591 try {
1592 return isRadioOnForSubscriber(subId);
1593 } finally {
1594 Binder.restoreCallingIdentity(identity);
1595 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001596 }
1597
1598 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001599 final long identity = Binder.clearCallingIdentity();
1600 try {
1601 final Phone phone = getPhone(subId);
1602 if (phone != null) {
1603 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1604 } else {
1605 return false;
1606 }
1607 } finally {
1608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 }
1611
1612 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001613 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 }
Wink Saville36469e72014-06-11 15:17:00 -07001615
Wink Savilleb564aae2014-10-23 10:18:09 -07001616 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001618
1619 final long identity = Binder.clearCallingIdentity();
1620 try {
1621 final Phone phone = getPhone(subId);
1622 if (phone != null) {
1623 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1624 }
1625 } finally {
1626 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001627 }
Wink Saville36469e72014-06-11 15:17:00 -07001628 }
1629
1630 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001631 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001632 }
1633
Wink Savilleb564aae2014-10-23 10:18:09 -07001634 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001635 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001636
1637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 final Phone phone = getPhone(subId);
1640 if (phone == null) {
1641 return false;
1642 }
1643 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1644 toggleRadioOnOffForSubscriber(subId);
1645 }
1646 return true;
1647 } finally {
1648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
Wink Saville36469e72014-06-11 15:17:00 -07001651
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001652 public boolean needMobileRadioShutdown() {
1653 /*
1654 * If any of the Radios are available, it will need to be
1655 * shutdown. So return true if any Radio is available.
1656 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001657 final long identity = Binder.clearCallingIdentity();
1658 try {
1659 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1660 Phone phone = PhoneFactory.getPhone(i);
1661 if (phone != null && phone.isRadioAvailable()) return true;
1662 }
1663 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1664 return false;
1665 } finally {
1666 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001667 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001668 }
1669
Malcolm Chend965c8b2018-02-28 15:00:40 -08001670 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001671 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001672 enforceModifyPermission();
1673
1674 final long identity = Binder.clearCallingIdentity();
1675 try {
1676 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1677 logv("Shutting down Phone " + i);
1678 shutdownRadioUsingPhoneId(i);
1679 }
1680 } finally {
1681 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001682 }
1683 }
1684
1685 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001686 Phone phone = PhoneFactory.getPhone(phoneId);
1687 if (phone != null && phone.isRadioAvailable()) {
1688 phone.shutdownRadio();
1689 }
1690 }
1691
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001693 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001694
1695 final long identity = Binder.clearCallingIdentity();
1696 try {
1697 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1698 if (defaultPhone != null) {
1699 defaultPhone.setRadioPower(turnOn);
1700 return true;
1701 } else {
1702 loge("There's no default phone.");
1703 return false;
1704 }
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001707 }
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
1709
Wink Savilleb564aae2014-10-23 10:18:09 -07001710 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001712
1713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 final Phone phone = getPhone(subId);
1716 if (phone != null) {
1717 phone.setRadioPower(turnOn);
1718 return true;
1719 } else {
1720 return false;
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
Wink Saville36469e72014-06-11 15:17:00 -07001727 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 public boolean enableDataConnectivity() {
1730 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001731
1732 final long identity = Binder.clearCallingIdentity();
1733 try {
1734 int subId = mSubscriptionController.getDefaultDataSubId();
1735 final Phone phone = getPhone(subId);
1736 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001737 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001738 return true;
1739 } else {
1740 return false;
1741 }
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
Wink Saville36469e72014-06-11 15:17:00 -07001747 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 public boolean disableDataConnectivity() {
1750 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001751
1752 final long identity = Binder.clearCallingIdentity();
1753 try {
1754 int subId = mSubscriptionController.getDefaultDataSubId();
1755 final Phone phone = getPhone(subId);
1756 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001757 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001758 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
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001768 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 final Phone phone = getPhone(subId);
1772 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001773 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001774 } else {
1775 return false;
1776 }
1777 } finally {
1778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 }
1781
1782 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001783 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001784 }
1785
pkanwarae03a6b2016-11-06 20:37:09 -08001786 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001787 enforceCallPermission();
1788
1789 final long identity = Binder.clearCallingIdentity();
1790 try {
1791 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1792 return;
1793 }
1794 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1795 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1796 } finally {
1797 Binder.restoreCallingIdentity(identity);
1798 }
pkanwar32d516d2016-10-14 19:37:38 -07001799 };
1800
Wink Savilleb564aae2014-10-23 10:18:09 -07001801 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001803
1804 final long identity = Binder.clearCallingIdentity();
1805 try {
1806 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1807 return false;
1808 }
1809 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1810 } finally {
1811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001816 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001817 }
1818
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001819 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 Phone phone = PhoneFactory.getPhone(slotIndex);
1823 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1824 PhoneConstantConversions.convertCallState(phone.getState());
1825 } finally {
1826 Binder.restoreCallingIdentity(identity);
1827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
Sanket Padawe356d7632015-06-22 14:03:32 -07001830 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001832 final long identity = Binder.clearCallingIdentity();
1833 try {
1834 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1835 if (phone != null) {
1836 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1837 } else {
1838 return PhoneConstantConversions.convertDataState(
1839 PhoneConstants.DataState.DISCONNECTED);
1840 }
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 }
1845
Sanket Padawe356d7632015-06-22 14:03:32 -07001846 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1851 if (phone != null) {
1852 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1853 } else {
1854 return TelephonyManager.DATA_ACTIVITY_NONE;
1855 }
1856 } finally {
1857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 }
1860
1861 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001862 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001863 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001864 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001865
1866 LocationAccessPolicy.LocationPermissionResult locationResult =
1867 LocationAccessPolicy.checkLocationPermission(mApp,
1868 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1869 .setCallingPackage(callingPackage)
1870 .setCallingPid(Binder.getCallingPid())
1871 .setCallingUid(Binder.getCallingUid())
1872 .setMethod("getCellLocation")
1873 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1874 .build());
1875 switch (locationResult) {
1876 case DENIED_HARD:
1877 throw new SecurityException("Not allowed to access cell location");
1878 case DENIED_SOFT:
1879 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 }
1881
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001882 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001883 final long identity = Binder.clearCallingIdentity();
1884 try {
1885 if (DBG_LOC) log("getCellLocation: is active user");
1886 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001887 int subId = mSubscriptionController.getDefaultDataSubId();
1888 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1889 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001890 return data;
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
Svetoslav64fad262015-04-14 14:35:21 -07001894 }
1895
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001897 public String getNetworkCountryIsoForPhone(int phoneId) {
1898 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1899 // registered cell info, so return a NULL country instead.
1900 final long identity = Binder.clearCallingIdentity();
1901 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001902 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1903 // Get default phone in this case.
1904 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1905 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001906 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001907 // Todo: fix this when we can get the actual cellular network info when the device
1908 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001909 if (TelephonyManager.NETWORK_TYPE_IWLAN
1910 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1911 return "";
1912 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001913 Phone phone = PhoneFactory.getPhone(phoneId);
1914 if (phone != null) {
1915 ServiceStateTracker sst = phone.getServiceStateTracker();
1916 if (sst != null) {
1917 LocaleTracker lt = sst.getLocaleTracker();
1918 if (lt != null) {
1919 return lt.getCurrentCountry();
1920 }
1921 }
1922 }
1923 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001924 } finally {
1925 Binder.restoreCallingIdentity(identity);
1926 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001927 }
1928
1929 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001931 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001932 }
1933
Sanket Padawe356d7632015-06-22 14:03:32 -07001934 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001935 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 mApp.enforceCallingOrSelfPermission(
1937 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001938
1939 final long identity = Binder.clearCallingIdentity();
1940 try {
1941 final Phone phone = getPhone(subId);
1942 if (phone != null) {
1943 phone.enableLocationUpdates();
1944 }
1945 } finally {
1946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 }
1949
1950 @Override
1951 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001952 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001956 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 mApp.enforceCallingOrSelfPermission(
1958 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001959
1960 final long identity = Binder.clearCallingIdentity();
1961 try {
1962 final Phone phone = getPhone(subId);
1963 if (phone != null) {
1964 phone.disableLocationUpdates();
1965 }
1966 } finally {
1967 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
1970
Nathan Harold31d7ff32018-10-15 20:20:30 -07001971 /**
1972 * Returns the target SDK version number for a given package name.
1973 *
1974 * @return target SDK if the package is found or INT_MAX.
1975 */
1976 private int getTargetSdk(String packageName) {
1977 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001978 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1979 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001980 if (ai != null) return ai.targetSdkVersion;
1981 } catch (PackageManager.NameNotFoundException unexpected) {
1982 }
1983 return Integer.MAX_VALUE;
1984 }
1985
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001986 @Override
1987 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001988 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1989 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001990 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1991 throw new SecurityException(
1992 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1993 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001994
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1996 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1997 return null;
1998 }
Svetoslav64fad262015-04-14 14:35:21 -07001999
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002000 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001
Nathan Haroldf180aac2018-06-01 18:43:55 -07002002 List<CellInfo> info = getAllCellInfo(callingPackage);
2003 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004
Nathan Haroldf180aac2018-06-01 18:43:55 -07002005 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2006 for (CellInfo ci : info) {
2007 if (ci instanceof CellInfoGsm) {
2008 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2009 } else if (ci instanceof CellInfoWcdma) {
2010 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002013 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002014 }
2015
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002016 private List<CellInfo> getCachedCellInfo() {
2017 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2018 for (Phone phone : PhoneFactory.getPhones()) {
2019 List<CellInfo> info = phone.getAllCellInfo();
2020 if (info != null) cellInfos.addAll(info);
2021 }
2022 return cellInfos;
2023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002024
2025 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002026 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002027 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002028 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002029
2030 LocationAccessPolicy.LocationPermissionResult locationResult =
2031 LocationAccessPolicy.checkLocationPermission(mApp,
2032 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2033 .setCallingPackage(callingPackage)
2034 .setCallingPid(Binder.getCallingPid())
2035 .setCallingUid(Binder.getCallingUid())
2036 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002037 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002038 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2039 .build());
2040 switch (locationResult) {
2041 case DENIED_HARD:
2042 throw new SecurityException("Not allowed to access cell info");
2043 case DENIED_SOFT:
2044 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 }
2046
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002047 final int targetSdk = getTargetSdk(callingPackage);
2048 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2049 return getCachedCellInfo();
2050 }
2051
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002052 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002053 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002054 final long identity = Binder.clearCallingIdentity();
2055 try {
2056 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2057 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002058 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002059 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002060 if (info != null) cellInfos.addAll(info);
2061 }
2062 return cellInfos;
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 }
2066 }
2067
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002068 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002069 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2070 requestCellInfoUpdateInternal(
2071 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2072 }
2073
2074 @Override
2075 public void requestCellInfoUpdateWithWorkSource(
2076 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2077 enforceModifyPermission();
2078 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2079 }
2080
2081 private void requestCellInfoUpdateInternal(
2082 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002083 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002084 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002085
2086 LocationAccessPolicy.LocationPermissionResult locationResult =
2087 LocationAccessPolicy.checkLocationPermission(mApp,
2088 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2089 .setCallingPackage(callingPackage)
2090 .setCallingPid(Binder.getCallingPid())
2091 .setCallingUid(Binder.getCallingUid())
2092 .setMethod("requestCellInfoUpdate")
2093 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2094 .build());
2095 switch (locationResult) {
2096 case DENIED_HARD:
2097 throw new SecurityException("Not allowed to access cell info");
2098 case DENIED_SOFT:
2099 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002100 }
2101
2102 final Phone phone = getPhone(subId);
2103 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2104
2105 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2106 }
2107
2108 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002110 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002112
2113 final long identity = Binder.clearCallingIdentity();
2114 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002115 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002116 } finally {
2117 Binder.restoreCallingIdentity(identity);
2118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 }
2120
Shishir Agrawala9f32182016-04-12 12:00:16 -07002121 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002122 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002123 Phone phone = PhoneFactory.getPhone(slotIndex);
2124 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002125 return null;
2126 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002127 int subId = phone.getSubId();
2128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2129 mApp, subId, callingPackage, "getImeiForSlot")) {
2130 return null;
2131 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002132
2133 final long identity = Binder.clearCallingIdentity();
2134 try {
2135 return phone.getImei();
2136 } finally {
2137 Binder.restoreCallingIdentity(identity);
2138 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002139 }
2140
2141 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002142 public String getTypeAllocationCodeForSlot(int slotIndex) {
2143 Phone phone = PhoneFactory.getPhone(slotIndex);
2144 String tac = null;
2145 if (phone != null) {
2146 String imei = phone.getImei();
2147 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2148 }
2149 return tac;
2150 }
2151
2152 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002153 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002154 Phone phone = PhoneFactory.getPhone(slotIndex);
2155 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002156 return null;
2157 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002158
Jeff Davidson913390f2018-02-23 17:11:49 -08002159 int subId = phone.getSubId();
2160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2161 mApp, subId, callingPackage, "getMeidForSlot")) {
2162 return null;
2163 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002164
2165 final long identity = Binder.clearCallingIdentity();
2166 try {
2167 return phone.getMeid();
2168 } finally {
2169 Binder.restoreCallingIdentity(identity);
2170 }
Jack Yu2af8d712017-03-15 17:14:14 -07002171 }
2172
2173 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002174 public String getManufacturerCodeForSlot(int slotIndex) {
2175 Phone phone = PhoneFactory.getPhone(slotIndex);
2176 String manufacturerCode = null;
2177 if (phone != null) {
2178 String meid = phone.getMeid();
2179 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2180 }
2181 return manufacturerCode;
2182 }
2183
2184 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002185 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002186 Phone phone = PhoneFactory.getPhone(slotIndex);
2187 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002188 return null;
2189 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002190 int subId = phone.getSubId();
2191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2192 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2193 return null;
2194 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002195
2196 final long identity = Binder.clearCallingIdentity();
2197 try {
2198 return phone.getDeviceSvn();
2199 } finally {
2200 Binder.restoreCallingIdentity(identity);
2201 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002202 }
2203
fionaxu43304da2017-11-27 22:51:16 -08002204 @Override
2205 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 final Phone phone = getPhone(subId);
2209 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2210 } finally {
2211 Binder.restoreCallingIdentity(identity);
2212 }
fionaxu43304da2017-11-27 22:51:16 -08002213 }
2214
2215 @Override
2216 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002217 final long identity = Binder.clearCallingIdentity();
2218 try {
2219 final Phone phone = getPhone(subId);
2220 return phone == null ? null : phone.getCarrierName();
2221 } finally {
2222 Binder.restoreCallingIdentity(identity);
2223 }
fionaxu43304da2017-11-27 22:51:16 -08002224 }
2225
calvinpaneed9ae82018-11-01 19:43:06 +08002226 @Override
chen xua31f22b2019-03-06 15:28:50 -08002227 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 final Phone phone = getPhone(subId);
2231 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002232 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002233 } finally {
2234 Binder.restoreCallingIdentity(identity);
2235 }
2236 }
2237
2238 @Override
chen xua31f22b2019-03-06 15:28:50 -08002239 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002240 final long identity = Binder.clearCallingIdentity();
2241 try {
2242 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002243 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002244 } finally {
2245 Binder.restoreCallingIdentity(identity);
2246 }
2247 }
2248
chen xu02581692018-11-11 19:03:44 -08002249 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002250 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2251 if (!isSubscriptionMccMnc) {
2252 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2253 }
chen xu02581692018-11-11 19:03:44 -08002254 final Phone phone = PhoneFactory.getPhone(slotIndex);
2255 if (phone == null) {
2256 return TelephonyManager.UNKNOWN_CARRIER_ID;
2257 }
2258 final long identity = Binder.clearCallingIdentity();
2259 try {
2260 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2261 } finally {
2262 Binder.restoreCallingIdentity(identity);
2263 }
2264 }
2265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 //
2267 // Internal helper methods.
2268 //
2269
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002270 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2272 *
2273 * @throws SecurityException if the caller does not have the required permission
2274 */
2275 private void enforceModifyPermission() {
2276 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2277 }
2278
2279 /**
2280 * Make sure the caller has the CALL_PHONE permission.
2281 *
2282 * @throws SecurityException if the caller does not have the required permission
2283 */
2284 private void enforceCallPermission() {
2285 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2286 }
2287
Stuart Scott8eef64f2015-04-08 15:13:54 -07002288 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002289 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002290 "ConnectivityService");
2291 }
2292
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 private String createTelUrl(String number) {
2294 if (TextUtils.isEmpty(number)) {
2295 return null;
2296 }
2297
Jake Hambye994d462014-02-03 13:10:13 -08002298 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 }
2300
Ihab Awadf9e92732013-12-05 18:02:52 -08002301 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2303 }
2304
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002305 private static void logv(String msg) {
2306 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2307 }
2308
Ihab Awadf9e92732013-12-05 18:02:52 -08002309 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2311 }
2312
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002313 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002315 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002319 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002320 final long identity = Binder.clearCallingIdentity();
2321 try {
2322 final Phone phone = PhoneFactory.getPhone(slotIndex);
2323 if (phone == null) {
2324 return PhoneConstants.PHONE_TYPE_NONE;
2325 } else {
2326 return phone.getPhoneType();
2327 }
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 }
2332
2333 /**
2334 * Returns the CDMA ERI icon index to display
2335 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002336 @Override
2337 public int getCdmaEriIconIndex(String callingPackage) {
2338 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002339 }
2340
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002342 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002344 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002345 return -1;
2346 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
2351 if (phone != null) {
2352 return phone.getCdmaEriIconIndex();
2353 } else {
2354 return -1;
2355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
2361 /**
2362 * Returns the CDMA ERI icon mode,
2363 * 0 - ON
2364 * 1 - FLASHING
2365 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002366 @Override
2367 public int getCdmaEriIconMode(String callingPackage) {
2368 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002369 }
2370
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002372 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002374 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002375 return -1;
2376 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 final Phone phone = getPhone(subId);
2381 if (phone != null) {
2382 return phone.getCdmaEriIconMode();
2383 } else {
2384 return -1;
2385 }
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 }
2390
2391 /**
2392 * Returns the CDMA ERI text,
2393 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002394 @Override
2395 public String getCdmaEriText(String callingPackage) {
2396 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002397 }
2398
Sanket Padawe356d7632015-06-22 14:03:32 -07002399 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002400 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002402 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002403 return null;
2404 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002405
2406 final long identity = Binder.clearCallingIdentity();
2407 try {
2408 final Phone phone = getPhone(subId);
2409 if (phone != null) {
2410 return phone.getCdmaEriText();
2411 } else {
2412 return null;
2413 }
2414 } finally {
2415 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 }
2418
2419 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002420 * Returns the CDMA MDN.
2421 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002422 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002423 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2425 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002426
2427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002430 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002431 return phone.getLine1Number();
2432 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002433 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002434 return null;
2435 }
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002438 }
2439 }
2440
2441 /**
2442 * Returns the CDMA MIN.
2443 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002444 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002445 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2447 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002448
2449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 final Phone phone = getPhone(subId);
2452 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2453 return phone.getCdmaMin();
2454 } else {
2455 return null;
2456 }
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002459 }
2460 }
2461
Hall Liud892bec2018-11-30 14:51:45 -08002462 @Override
2463 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2464 INumberVerificationCallback callback, String callingPackage) {
2465 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2466 != PERMISSION_GRANTED) {
2467 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2468 }
2469 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2470
2471 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2472 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2473 throw new SecurityException("Calling package must be configured in the device config");
2474 }
2475
2476 if (range == null) {
2477 throw new NullPointerException("Range must be non-null");
2478 }
2479
2480 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002481 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002482
2483 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2484 }
2485
Junda Liuca05d5d2014-08-14 22:36:34 -07002486 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 * Returns true if CDMA provisioning needs to run.
2488 */
2489 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002490 final long identity = Binder.clearCallingIdentity();
2491 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002492 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002493 } finally {
2494 Binder.restoreCallingIdentity(identity);
2495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 }
2497
2498 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002499 * Sets the voice mail number of a given subId.
2500 */
2501 @Override
2502 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002503 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002504
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2508 new Pair<String, String>(alphaTag, number), new Integer(subId));
2509 return success;
2510 } finally {
2511 Binder.restoreCallingIdentity(identity);
2512 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002513 }
2514
Ta-wei Yen87c49842016-05-13 21:19:52 -07002515 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002516 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2517 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002518 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002519 if (!TextUtils.equals(callingPackage, systemDialer)) {
2520 throw new SecurityException("caller must be system dialer");
2521 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002522
2523 final long identity = Binder.clearCallingIdentity();
2524 try {
2525 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2526 if (phoneAccountHandle == null) {
2527 return null;
2528 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002529 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002530 } finally {
2531 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002532 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002533 }
2534
2535 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002536 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002537 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002539 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002540 return null;
2541 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002542
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002543 final long identity = Binder.clearCallingIdentity();
2544 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002545 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002546 } finally {
2547 Binder.restoreCallingIdentity(identity);
2548 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002549 }
2550
2551 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002552 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2553 VisualVoicemailSmsFilterSettings settings) {
2554 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002555
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002559 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002560 } finally {
2561 Binder.restoreCallingIdentity(identity);
2562 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002563 }
2564
2565 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002566 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2567 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002572 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002573 } finally {
2574 Binder.restoreCallingIdentity(identity);
2575 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002576 }
2577
2578 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002579 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2580 String callingPackage, int subId) {
2581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002582
2583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002586 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002587 } finally {
2588 Binder.restoreCallingIdentity(identity);
2589 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002590 }
2591
2592 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002593 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002594 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002599 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002600 } finally {
2601 Binder.restoreCallingIdentity(identity);
2602 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002603 }
2604
2605 @Override
2606 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2607 String number, int port, String text, PendingIntent sentIntent) {
2608 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002609 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002610 enforceSendSmsPermission();
2611 // Make the calls as the phone process.
2612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2615 if (port == 0) {
2616 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2617 sentIntent, null, false);
2618 } else {
2619 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2620 smsManager.sendDataMessageWithSelfPermissions(number, null,
2621 (short) port, data, sentIntent, null);
2622 }
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
2625 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002626 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002627 /**
fionaxu0152e512016-11-14 13:36:14 -08002628 * Sets the voice activation state of a given subId.
2629 */
2630 @Override
2631 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2633 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 final Phone phone = getPhone(subId);
2638 if (phone != null) {
2639 phone.setVoiceActivationState(activationState);
2640 } else {
2641 loge("setVoiceActivationState fails with invalid subId: " + subId);
2642 }
2643 } finally {
2644 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002645 }
2646 }
2647
2648 /**
2649 * Sets the data activation state of a given subId.
2650 */
2651 @Override
2652 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2654 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 final Phone phone = getPhone(subId);
2659 if (phone != null) {
2660 phone.setDataActivationState(activationState);
2661 } else {
2662 loge("setVoiceActivationState fails with invalid subId: " + subId);
2663 }
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002666 }
2667 }
2668
2669 /**
2670 * Returns the voice activation state of a given subId.
2671 */
2672 @Override
2673 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002674 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002675
fionaxu0152e512016-11-14 13:36:14 -08002676 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002677 final long identity = Binder.clearCallingIdentity();
2678 try {
2679 if (phone != null) {
2680 return phone.getVoiceActivationState();
2681 } else {
2682 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2683 }
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002686 }
2687 }
2688
2689 /**
2690 * Returns the data activation state of a given subId.
2691 */
2692 @Override
2693 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002694 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002695
fionaxu0152e512016-11-14 13:36:14 -08002696 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 if (phone != null) {
2700 return phone.getDataActivationState();
2701 } else {
2702 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002706 }
2707 }
2708
2709 /**
Wink Saville36469e72014-06-11 15:17:00 -07002710 * Returns the unread count of voicemails for a subId
2711 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002712 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002713 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2715 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2716 return 0;
2717 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 final Phone phone = getPhone(subId);
2721 if (phone != null) {
2722 return phone.getVoiceMessageCount();
2723 } else {
2724 return 0;
2725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 }
2730
2731 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002732 * returns true, if the device is in a state where both voice and data
2733 * are supported simultaneously. This can change based on location or network condition.
2734 */
2735 @Override
2736 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002737 final long identity = Binder.clearCallingIdentity();
2738 try {
2739 final Phone phone = getPhone(subId);
2740 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2741 } finally {
2742 Binder.restoreCallingIdentity(identity);
2743 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002744 }
2745
2746 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002747 * Send the dialer code if called from the current default dialer or the caller has
2748 * carrier privilege.
2749 * @param inputCode The dialer code to send
2750 */
2751 @Override
2752 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002753 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002755 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2756 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002757 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002758 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2759 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002760 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002764 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002765 } finally {
2766 Binder.restoreCallingIdentity(identity);
2767 }
fionaxu235cc5e2017-03-06 22:25:57 -08002768 }
2769
2770 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002771 * Returns the data network type.
2772 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002773 *
2774 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2775 */
2776 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002777 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 final Phone phone = getPhone(getDefaultSubscription());
2781 if (phone != null) {
2782 return phone.getServiceState().getDataNetworkType();
2783 } else {
2784 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2785 }
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002788 }
Wink Saville36469e72014-06-11 15:17:00 -07002789 }
2790
Pengquan Meng0c05b502018-09-06 09:59:22 -07002791 @Override
2792 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002793 if (!isActiveSubscription(subId)) {
2794 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2795 }
2796
Pengquan Meng0c05b502018-09-06 09:59:22 -07002797 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2798 }
2799
Brad Ebinger4c460712018-10-01 10:40:55 -07002800 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002801 public boolean isInEmergencySmsMode() {
2802 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 for (Phone phone : PhoneFactory.getPhones()) {
2806 if (phone.isInEmergencySmsMode()) {
2807 return true;
2808 }
2809 }
2810 } finally {
2811 Binder.restoreCallingIdentity(identity);
2812 }
2813 return false;
2814 }
2815
2816 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002817 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2818 throws RemoteException {
2819 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002820 final long token = Binder.clearCallingIdentity();
2821 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002823 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002824 .addRegistrationCallbackForSubscription(c, subId);
2825 } finally {
2826 Binder.restoreCallingIdentity(token);
2827 }
2828 }
2829
2830 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002831 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2832 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002833 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2834 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2835 }
2836 Binder.withCleanCallingIdentity(() -> {
2837 try {
2838 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002839 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002840 .removeRegistrationCallbackForSubscription(c, subId);
2841 } catch (IllegalArgumentException e) {
2842 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2843 + "is inactive, ignoring unregister.");
2844 // If the subscription is no longer active, just return, since the callback
2845 // will already have been removed internally.
2846 }
2847 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002848 }
2849
2850 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002851 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2852 throws RemoteException {
2853 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2855 final long token = Binder.clearCallingIdentity();
2856 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002857 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002858 .addCapabilitiesCallbackForSubscription(c, subId);
2859 } finally {
2860 Binder.restoreCallingIdentity(token);
2861 }
2862 }
2863
2864 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002865 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2866 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002867
2868 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2869 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2870 }
2871 Binder.withCleanCallingIdentity(() -> {
2872 try {
2873 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002874 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002875 .removeCapabilitiesCallbackForSubscription(c, subId);
2876 } catch (IllegalArgumentException e) {
2877 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2878 + "is inactive, ignoring unregister.");
2879 // If the subscription is no longer active, just return, since the callback
2880 // will already have been removed internally.
2881 }
2882 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002883 }
2884
2885 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002886 public boolean isCapable(int subId, int capability, int regTech) {
2887 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2889 final long token = Binder.clearCallingIdentity();
2890 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002891 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002892 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2893 } catch (ImsException e) {
2894 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2895 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002896 } catch (IllegalArgumentException e) {
2897 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2898 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002899 } finally {
2900 Binder.restoreCallingIdentity(token);
2901 }
2902 }
2903
2904 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002905 public boolean isAvailable(int subId, int capability, int regTech) {
2906 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002907 final long token = Binder.clearCallingIdentity();
2908 try {
2909 Phone phone = getPhone(subId);
2910 if (phone == null) return false;
2911 return phone.isImsCapabilityAvailable(capability, regTech);
2912 } finally {
2913 Binder.restoreCallingIdentity(token);
2914 }
2915 }
2916
2917 @Override
2918 public boolean isAdvancedCallingSettingEnabled(int subId) {
2919 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2921 final long token = Binder.clearCallingIdentity();
2922 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002923 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002924 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2925 } finally {
2926 Binder.restoreCallingIdentity(token);
2927 }
2928 }
2929
2930 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002931 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002933 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002937 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002938 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
2941 }
2942 }
2943
2944 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002945 public boolean isVtSettingEnabled(int subId) {
2946 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002950 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002951 getSlotIndexOrException(subId)).isVtEnabledByUser();
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
2954 }
2955 }
2956
2957 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002958 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002960 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002964 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
2968 }
2969
2970 @Override
2971 public boolean isVoWiFiSettingEnabled(int subId) {
2972 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2973 final long identity = Binder.clearCallingIdentity();
2974 try {
2975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002976 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002977 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
2983 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002984 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002986 "setVoWiFiSettingEnabled");
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 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
2994 }
2995
2996 @Override
2997 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2998 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003002 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003003 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
3007 }
3008
3009 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003010 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003012 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003013 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 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003017 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
3021 }
3022
3023 @Override
3024 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3026 "setVoWiFiNonPersistent");
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003030 boolean isRoaming = TelephonyManager.from(
3031 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003032 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003033 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 @Override
3040 public int getVoWiFiModeSetting(int subId) {
3041 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003045 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003046 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
3050 }
3051
3052 @Override
3053 public void setVoWiFiModeSetting(int subId, int mode) {
3054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3055 "setVoWiFiModeSetting");
3056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003059 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003060 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3061 } finally {
3062 Binder.restoreCallingIdentity(identity);
3063 }
3064 }
3065
3066 @Override
3067 public int getVoWiFiRoamingModeSetting(int subId) {
3068 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003072 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003073 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3074 } finally {
3075 Binder.restoreCallingIdentity(identity);
3076 }
3077 }
3078
3079 @Override
3080 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3082 "setVoWiFiRoamingModeSetting");
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003086 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003087 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
3091 }
3092
3093 @Override
3094 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3096 "setRttCapabilityEnabled");
3097 final long identity = Binder.clearCallingIdentity();
3098 try {
3099 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003100 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003101 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
3105 }
3106
3107 @Override
3108 public boolean isTtyOverVolteEnabled(int subId) {
3109 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003113 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003114 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
3117 }
3118 }
3119
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003120 @Override
3121 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3122 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
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, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003127 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
3131 }
3132
3133 @Override
3134 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3135 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3136 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003137 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3138 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3139 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003140 try {
3141 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003142 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003143 .removeProvisioningCallbackForSubscription(callback, subId);
3144 } catch (IllegalArgumentException e) {
3145 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3146 + "is inactive, ignoring unregister.");
3147 // If the subscription is no longer active, just return, since the callback will already
3148 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003149 } finally {
3150 Binder.restoreCallingIdentity(identity);
3151 }
3152 }
3153
3154 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003155 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3156 boolean isProvisioned) {
3157 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3158 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3159 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3160 }
3161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3162 "setProvisioningStatusForCapability");
3163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3166 Phone phone = getPhone(subId);
3167 if (phone == null) {
3168 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3169 + subId);
3170 return;
3171 }
3172 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3173 return;
3174 }
3175
3176 // this capability requires provisioning, route to the correct API.
3177 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3178 switch (capability) {
3179 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3180 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3181 ims.setVolteProvisioned(isProvisioned);
3182 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3183 ims.setWfcProvisioned(isProvisioned);
3184 }
3185 break;
3186 }
3187 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3188 // There is currently no difference in VT provisioning type.
3189 ims.setVtProvisioned(isProvisioned);
3190 break;
3191 }
3192 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3193 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3194 // change the capability of the feature instead if needed.
3195 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3196 == isProvisioned) {
3197 // No change in provisioning.
3198 return;
3199 }
3200 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3201 try {
3202 ims.changeMmTelCapability(capability, tech, isProvisioned);
3203 } catch (ImsException e) {
3204 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3205 + ", Exception" + e.getMessage());
3206 }
3207 break;
3208 }
3209 default: {
3210 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3211 + capability + "', which does not require provisioning.");
3212 }
3213 }
3214
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
3218 }
3219
3220 @Override
3221 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3222 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3223 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3224 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3225 }
3226 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3230 Phone phone = getPhone(subId);
3231 if (phone == null) {
3232 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3233 + subId);
3234 // We will fail with "true" as the provisioning status because this is the default
3235 // if we do not require provisioning.
3236 return true;
3237 }
3238
3239 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3240 return true;
3241 }
3242
3243 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3244 switch (capability) {
3245 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3246 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3247 return ims.isVolteProvisionedOnDevice();
3248 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3249 return ims.isWfcProvisionedOnDevice();
3250 }
3251 // This should never happen, since we are checking tech above to make sure it
3252 // is either LTE or IWLAN.
3253 throw new IllegalArgumentException("Invalid radio technology for voice "
3254 + "capability.");
3255 }
3256 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3257 // There is currently no difference in VT provisioning type.
3258 return ims.isVtProvisionedOnDevice();
3259 }
3260 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3261 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3262 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3263 }
3264 default: {
3265 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3266 + capability + "', which does not require provisioning.");
3267 }
3268 }
3269
3270 } finally {
3271 Binder.restoreCallingIdentity(identity);
3272 }
3273 }
3274
3275 @Override
3276 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3277 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3278 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3279 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3280 }
3281 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3282 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3283 return (provisionedBits & capability) > 0;
3284 }
3285
3286 @Override
3287 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3288 boolean isProvisioned) {
3289 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3290 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3291 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3292 }
3293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3294 "setProvisioningStatusForCapability");
3295 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3296 // If the current provisioning status for capability already matches isProvisioned,
3297 // do nothing.
3298 if (((provisionedBits & capability) > 0) == isProvisioned) {
3299 return;
3300 }
3301 if (isProvisioned) {
3302 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3303 } else {
3304 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3305 }
3306 }
3307
3308 /**
3309 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3310 * technology. The bitfield should mirror the bitfield defined by
3311 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3312 */
3313 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3314 String key = getMmTelProvisioningKey(subId, tech);
3315 // Default is no capabilities are provisioned.
3316 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3317 }
3318
3319 /**
3320 * Sets the MmTel capability provisioning bitfield (defined by
3321 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3322 * technology specified.
3323 *
3324 * Note: This is a synchronous command and should not be called on UI thread.
3325 */
3326 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3327 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3328 String key = getMmTelProvisioningKey(subId, tech);
3329 editor.putInt(key, newField);
3330 editor.commit();
3331 }
3332
3333 private static String getMmTelProvisioningKey(int subId, int tech) {
3334 // resulting key is provision_ims_mmtel_{subId}_{tech}
3335 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3336 }
3337
3338 /**
3339 * Query CarrierConfig to see if the specified capability requires provisioning for the
3340 * carrier associated with the subscription id.
3341 */
3342 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3343 int capability) {
3344 CarrierConfigManager configManager = new CarrierConfigManager(context);
3345 PersistableBundle c = configManager.getConfigForSubId(subId);
3346 boolean requireUtProvisioning = c.getBoolean(
3347 // By default, this config is true (even if there is no SIM). We also check to make
3348 // sure the subscription needs provisioning here, so we do not need to check for
3349 // the no-SIM case, where we would normally shortcut this to false.
3350 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3351 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3352 false);
3353 boolean requireVoiceVtProvisioning = c.getBoolean(
3354 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3355
3356 // First check to make sure that the capability requires provisioning.
3357 switch (capability) {
3358 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3359 // intentional fallthrough
3360 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3361 if (requireVoiceVtProvisioning) {
3362 // Voice and Video requires provisioning
3363 return true;
3364 }
3365 break;
3366 }
3367 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3368 if (requireUtProvisioning) {
3369 // UT requires provisioning
3370 return true;
3371 }
3372 break;
3373 }
3374 }
3375 return false;
3376 }
3377
3378 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003379 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003380 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3381 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3382 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003383 enforceReadPrivilegedPermission("getImsProvisioningInt");
3384 final long identity = Binder.clearCallingIdentity();
3385 try {
3386 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003387 int slotId = getSlotIndex(subId);
3388 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3389 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3390 + subId + "' for key:" + key);
3391 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3392 }
3393 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003394 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003395 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3396 + subId + "' for key:" + key);
3397 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
3401 }
3402
3403 @Override
3404 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003405 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3406 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3407 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003408 enforceReadPrivilegedPermission("getImsProvisioningString");
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003412 int slotId = getSlotIndex(subId);
3413 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3414 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3415 + subId + "' for key:" + key);
3416 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3417 }
3418 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003419 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003420 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3421 + subId + "' for key:" + key);
3422 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
3426 }
3427
3428 @Override
3429 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003430 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3431 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3432 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3434 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003438 int slotId = getSlotIndex(subId);
3439 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3440 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3441 + subId + "' for key:" + key);
3442 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3443 }
3444 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003445 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003446 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3447 + "' for key:" + key);
3448 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 } finally {
3450 Binder.restoreCallingIdentity(identity);
3451 }
3452 }
3453
3454 @Override
3455 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003456 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3457 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3458 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3460 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003464 int slotId = getSlotIndex(subId);
3465 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3466 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3467 + subId + "' for key:" + key);
3468 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3469 }
3470 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003471 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003472 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3473 + "' for key:" + key);
3474 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003475 } finally {
3476 Binder.restoreCallingIdentity(identity);
3477 }
3478 }
3479
Brad Ebinger4c460712018-10-01 10:40:55 -07003480 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3481 int slotId = SubscriptionManager.getSlotIndex(subId);
3482 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003483 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003484 }
3485 return slotId;
3486 }
3487
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003488 private int getSlotIndex(int subId) {
3489 int slotId = SubscriptionManager.getSlotIndex(subId);
3490 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3491 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3492 }
3493 return slotId;
3494 }
3495
Wink Saville36469e72014-06-11 15:17:00 -07003496 /**
3497 * Returns the network type for a subId
3498 */
3499 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003500 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003501 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003502 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003503 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3504 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003505
Malcolm Chend965c8b2018-02-28 15:00:40 -08003506 final long identity = Binder.clearCallingIdentity();
3507 try {
3508 final Phone phone = getPhone(subId);
3509 if (phone != null) {
3510 return phone.getServiceState().getDataNetworkType();
3511 } else {
3512 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3513 }
3514 } finally {
3515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003517 }
3518
3519 /**
3520 * Returns the data network type
3521 */
3522 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003523 public int getDataNetworkType(String callingPackage) {
3524 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003525 }
3526
3527 /**
3528 * Returns the data network type for a subId
3529 */
3530 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003531 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003533 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003534 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3535 }
3536
Malcolm Chend965c8b2018-02-28 15:00:40 -08003537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 final Phone phone = getPhone(subId);
3540 if (phone != null) {
3541 return phone.getServiceState().getDataNetworkType();
3542 } else {
3543 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3544 }
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003548 }
3549
3550 /**
Wink Saville36469e72014-06-11 15:17:00 -07003551 * Returns the Voice network type for a subId
3552 */
3553 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003554 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003556 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003557 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3558 }
3559
Malcolm Chend965c8b2018-02-28 15:00:40 -08003560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 final Phone phone = getPhone(subId);
3563 if (phone != null) {
3564 return phone.getServiceState().getVoiceNetworkType();
3565 } else {
3566 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3567 }
3568 } finally {
3569 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003571 }
3572
3573 /**
3574 * @return true if a ICC card is present
3575 */
3576 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003577 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003578 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3579 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003580 }
3581
3582 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003583 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003584 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003585 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003586 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 final Phone phone = PhoneFactory.getPhone(slotIndex);
3590 if (phone != null) {
3591 return phone.getIccCard().hasIccCard();
3592 } else {
3593 return false;
3594 }
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003598 }
3599
3600 /**
3601 * Return if the current radio is LTE on CDMA. This
3602 * is a tri-state return value as for a period of time
3603 * the mode may be unknown.
3604 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003605 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003606 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003607 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003608 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003609 @Override
3610 public int getLteOnCdmaMode(String callingPackage) {
3611 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003612 }
3613
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003615 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003617 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003618 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3619 }
3620
Malcolm Chend965c8b2018-02-28 15:00:40 -08003621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 final Phone phone = getPhone(subId);
3624 if (phone == null) {
3625 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3626 } else {
3627 return phone.getLteOnCdmaMode();
3628 }
3629 } finally {
3630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003631 }
Wink Saville36469e72014-06-11 15:17:00 -07003632 }
3633
Wink Saville36469e72014-06-11 15:17:00 -07003634 /**
3635 * {@hide}
3636 * Returns Default subId, 0 in the case of single standby.
3637 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003638 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003639 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003640 }
3641
Shishir Agrawala9f32182016-04-12 12:00:16 -07003642 private int getSlotForDefaultSubscription() {
3643 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3644 }
3645
Wink Savilleb564aae2014-10-23 10:18:09 -07003646 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003647 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003649
Pengquan Meng466e2482018-09-21 15:54:48 -07003650 private boolean isActiveSubscription(int subId) {
3651 return mSubscriptionController.isActiveSubId(subId);
3652 }
3653
Ihab Awadf2177b72013-11-25 13:33:23 -08003654 /**
3655 * @see android.telephony.TelephonyManager.WifiCallingChoices
3656 */
3657 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003658 final long identity = Binder.clearCallingIdentity();
3659 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003660 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003661 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3662 getWhenToMakeWifiCallsDefaultPreference());
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003666 }
3667
3668 /**
3669 * @see android.telephony.TelephonyManager.WifiCallingChoices
3670 */
3671 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003675 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003676 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003680 }
3681
Sailesh Nepald1e68152013-12-12 19:08:02 -08003682 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003683 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003684 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003685 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003686
Jordan Liu73b078d2019-02-28 12:03:40 -08003687 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3688 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3689 if (phoneId == -1) {
3690 throw new IllegalArgumentException("Given slot index: " + slotIndex
3691 + " does not correspond to an active phone");
3692 }
3693 return PhoneFactory.getPhone(phoneId);
3694 }
3695
Shishir Agrawal566b7612013-10-28 14:41:00 -07003696 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003697 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3698 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3700 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003701 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003702 if (DBG) {
3703 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3704 }
3705 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3706 p2);
3707 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003708
Jordan Liu73b078d2019-02-28 12:03:40 -08003709
3710 @Override
3711 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3712 int slotIndex, String callingPackage, String aid, int p2) {
3713 enforceModifyPermission();
3714 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3715 if (DBG) {
3716 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3717 }
3718 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3719 callingPackage, aid, p2);
3720 }
3721
3722 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3723 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 if (TextUtils.equals(ISDR_AID, aid)) {
3727 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003728 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3729 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003730 if (bestComponent == null
3731 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3732 loge("The calling package is not allowed to access ISD-R.");
3733 throw new SecurityException(
3734 "The calling package is not allowed to access ISD-R.");
3735 }
Derek Tan740e1672017-06-27 14:56:27 -07003736 }
Derek Tan740e1672017-06-27 14:56:27 -07003737
Malcolm Chend965c8b2018-02-28 15:00:40 -08003738 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003739 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3740 null /* workSource */);
3741 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003742 return response;
3743 } finally {
3744 Binder.restoreCallingIdentity(identity);
3745 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003746 }
3747
3748 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003749 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3751 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003752 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3753 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3754 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003755
Jordan Liu73b078d2019-02-28 12:03:40 -08003756 @Override
3757 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3758 enforceModifyPermission();
3759 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3760 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3761 channel);
3762 }
3763
3764 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003765 final long identity = Binder.clearCallingIdentity();
3766 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003767 if (channel < 0) {
3768 return false;
3769 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003770 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3771 null /* workSource */);
3772 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003773 return success;
3774 } finally {
3775 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003776 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003777 }
3778
3779 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003780 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003781 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3783 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003784 if (DBG) {
3785 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3786 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3787 + p3 + " data=" + data);
3788 }
3789 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3790 command, p1, p2, p3, data);
3791 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003792
Jordan Liu73b078d2019-02-28 12:03:40 -08003793 @Override
3794 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3795 int command, int p1, int p2, int p3, String data) {
3796 enforceModifyPermission();
3797 if (DBG) {
3798 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3799 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3800 + p3 + " data=" + data);
3801 }
3802 return iccTransmitApduLogicalChannelWithPermission(
3803 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3804 data);
3805 }
3806
3807 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3808 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003811 if (channel < 0) {
3812 return "";
3813 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003814
Malcolm Chend965c8b2018-02-28 15:00:40 -08003815 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003816 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3817 null /* workSource */);
3818 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003819
Malcolm Chend965c8b2018-02-28 15:00:40 -08003820 // Append the returned status code to the end of the response payload.
3821 String s = Integer.toHexString(
3822 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3823 if (response.payload != null) {
3824 s = IccUtils.bytesToHexString(response.payload) + s;
3825 }
3826 return s;
3827 } finally {
3828 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003829 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003830 }
Jake Hambye994d462014-02-03 13:10:13 -08003831
Evan Charltonc66da362014-05-16 14:06:40 -07003832 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003833 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3834 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3836 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003837 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003838 if (DBG) {
3839 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3840 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3841 }
3842 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3843 cla, command, p1, p2, p3, data);
3844 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003845
Jordan Liu73b078d2019-02-28 12:03:40 -08003846 @Override
3847 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3848 int command, int p1, int p2, int p3, String data) {
3849 enforceModifyPermission();
3850 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3851 if (DBG) {
3852 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3853 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3854 + " data=" + data);
3855 }
3856
3857 return iccTransmitApduBasicChannelWithPermission(
3858 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3859 p2, p3, data);
3860 }
3861
3862 // open APDU basic channel assuming the caller has sufficient permissions
3863 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3864 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3868 && TextUtils.equals(ISDR_AID, data)) {
3869 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003870 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3871 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003872 if (bestComponent == null
3873 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3874 loge("The calling package is not allowed to select ISD-R.");
3875 throw new SecurityException(
3876 "The calling package is not allowed to select ISD-R.");
3877 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003878 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003879
Malcolm Chend965c8b2018-02-28 15:00:40 -08003880 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003881 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3882 null /* workSource */);
3883 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003884
Malcolm Chend965c8b2018-02-28 15:00:40 -08003885 // Append the returned status code to the end of the response payload.
3886 String s = Integer.toHexString(
3887 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3888 if (response.payload != null) {
3889 s = IccUtils.bytesToHexString(response.payload) + s;
3890 }
3891 return s;
3892 } finally {
3893 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003894 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003895 }
3896
3897 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003898 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003899 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3901 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003902
Malcolm Chend965c8b2018-02-28 15:00:40 -08003903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 if (DBG) {
3906 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3907 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3908 }
3909
3910 IccIoResult response =
3911 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3912 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3913 subId);
3914
3915 if (DBG) {
3916 log("Exchange SIM_IO [R]" + response);
3917 }
3918
3919 byte[] result = null;
3920 int length = 2;
3921 if (response.payload != null) {
3922 length = 2 + response.payload.length;
3923 result = new byte[length];
3924 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3925 } else {
3926 result = new byte[length];
3927 }
3928
3929 result[length - 1] = (byte) response.sw2;
3930 result[length - 2] = (byte) response.sw1;
3931 return result;
3932 } finally {
3933 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003934 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003935 }
3936
Nathan Haroldb3014052017-01-25 15:57:32 -08003937 /**
3938 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3939 * on a particular subscription
3940 */
sqianb6e41952018-03-12 14:54:01 -07003941 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3943 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3944 return null;
3945 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003946
3947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 if (appType != TelephonyManager.APPTYPE_USIM
3950 && appType != TelephonyManager.APPTYPE_SIM) {
3951 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3952 return null;
3953 }
3954 Object response = sendRequest(
3955 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3956 if (response instanceof String[]) {
3957 return (String[]) response;
3958 }
3959 // Response is an Exception of some kind,
3960 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003961 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003962 } finally {
3963 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003964 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003965 }
3966
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003967 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003968 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3970 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003971
Malcolm Chend965c8b2018-02-28 15:00:40 -08003972 final long identity = Binder.clearCallingIdentity();
3973 try {
3974 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3975 if (response.payload == null) {
3976 return "";
3977 }
Evan Charltonc66da362014-05-16 14:06:40 -07003978
Malcolm Chend965c8b2018-02-28 15:00:40 -08003979 // Append the returned status code to the end of the response payload.
3980 String s = Integer.toHexString(
3981 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3982 s = IccUtils.bytesToHexString(response.payload) + s;
3983 return s;
3984 } finally {
3985 Binder.restoreCallingIdentity(identity);
3986 }
Evan Charltonc66da362014-05-16 14:06:40 -07003987 }
3988
Jake Hambye994d462014-02-03 13:10:13 -08003989 /**
3990 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3991 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3992 *
3993 * @param itemID the ID of the item to read
3994 * @return the NV item as a String, or null on error.
3995 */
3996 @Override
3997 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003998 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4000 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004001
4002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004005 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004006 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4007 return value;
4008 } finally {
4009 Binder.restoreCallingIdentity(identity);
4010 }
Jake Hambye994d462014-02-03 13:10:13 -08004011 }
4012
4013 /**
4014 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4015 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4016 *
4017 * @param itemID the ID of the item to read
4018 * @param itemValue the value to write, as a String
4019 * @return true on success; false on any failure
4020 */
4021 @Override
4022 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004023 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4025 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004026
4027 final long identity = Binder.clearCallingIdentity();
4028 try {
4029 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4030 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004031 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004032 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4033 return success;
4034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
Jake Hambye994d462014-02-03 13:10:13 -08004037 }
4038
4039 /**
4040 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4041 * Used for device configuration by some CDMA operators.
4042 *
4043 * @param preferredRoamingList byte array containing the new PRL
4044 * @return true on success; false on any failure
4045 */
4046 @Override
4047 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4049 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004050
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4054 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4055 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4056 return success;
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
Jake Hambye994d462014-02-03 13:10:13 -08004060 }
4061
4062 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004063 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004064 * Used for device configuration by some CDMA operators.
4065 *
chen xu1cc0abe2018-10-26 17:39:23 -07004066 * @param slotIndex - device slot.
4067 *
Jake Hambye994d462014-02-03 13:10:13 -08004068 * @return true on success; false on any failure
4069 */
4070 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004071 public boolean resetModemConfig(int slotIndex) {
4072 Phone phone = PhoneFactory.getPhone(slotIndex);
4073 if (phone != null) {
4074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4075 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004076
chen xu1cc0abe2018-10-26 17:39:23 -07004077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4080 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4081 return success;
4082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004085 }
chen xu1cc0abe2018-10-26 17:39:23 -07004086 return false;
4087 }
4088
4089 /**
4090 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4091 *
4092 * @param slotIndex - device slot.
4093 *
4094 * @return true on success; false on any failure
4095 */
4096 @Override
4097 public boolean rebootModem(int slotIndex) {
4098 Phone phone = PhoneFactory.getPhone(slotIndex);
4099 if (phone != null) {
4100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4101 mApp, phone.getSubId(), "rebootModem");
4102
4103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4106 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4107 return success;
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
4111 }
4112 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004113 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004114
Svet Ganovb320e182015-04-16 12:30:10 -07004115 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004116 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004118 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004119 return new String[0];
4120 }
4121
Malcolm Chend965c8b2018-02-28 15:00:40 -08004122 final long identity = Binder.clearCallingIdentity();
4123 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004124 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
Wink Saville36469e72014-06-11 15:17:00 -07004128 }
4129
Brad Ebinger51f743a2017-01-23 13:50:20 -08004130 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004131 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4132 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004133 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004134 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004135 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004136
4137 final long identity = Binder.clearCallingIdentity();
4138 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004139 ImsResolver resolver = PhoneFactory.getImsResolver();
4140 if (resolver == null) {
4141 // may happen if the device does not support IMS.
4142 return;
4143 }
4144 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004148 }
4149
4150 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004151 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4152 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004153 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004154 public void disableIms(int slotId) {
4155 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004156
4157 final long identity = Binder.clearCallingIdentity();
4158 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004159 ImsResolver resolver = PhoneFactory.getImsResolver();
4160 if (resolver == null) {
4161 // may happen if the device does not support IMS.
4162 return;
4163 }
4164 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004168 }
4169
4170 /**
4171 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4172 * feature or {@link null} if the service is not available. If the feature is available, the
4173 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4174 */
4175 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004176 IImsServiceFeatureCallback callback) {
4177 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004178
4179 final long identity = Binder.clearCallingIdentity();
4180 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004181 ImsResolver resolver = PhoneFactory.getImsResolver();
4182 if (resolver == null) {
4183 // may happen if the device does not support IMS.
4184 return null;
4185 }
4186 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004187 } finally {
4188 Binder.restoreCallingIdentity(identity);
4189 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004190 }
4191
4192 /**
4193 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4194 * feature during emergency calling or {@link null} if the service is not available. If the
4195 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4196 * listener for feature updates.
4197 */
4198 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4199 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004200
4201 final long identity = Binder.clearCallingIdentity();
4202 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004203 ImsResolver resolver = PhoneFactory.getImsResolver();
4204 if (resolver == null) {
4205 // may happen if the device does not support IMS.
4206 return null;
4207 }
4208 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004212 }
4213
Brad Ebinger5f64b052017-12-14 14:26:15 -08004214 /**
4215 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004216 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004217 */
4218 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4219 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004220
4221 final long identity = Binder.clearCallingIdentity();
4222 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004223 ImsResolver resolver = PhoneFactory.getImsResolver();
4224 if (resolver == null) {
4225 // may happen if the device does not support IMS.
4226 return null;
4227 }
4228 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004229 } finally {
4230 Binder.restoreCallingIdentity(identity);
4231 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004232 }
4233
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004234 /**
4235 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004236 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004237 */
4238 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4239 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004240
4241 final long identity = Binder.clearCallingIdentity();
4242 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004243 ImsResolver resolver = PhoneFactory.getImsResolver();
4244 if (resolver == null) {
4245 // may happen if the device does not support IMS.
4246 return null;
4247 }
4248 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
4251 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004252 }
4253
Brad Ebinger884c07b2018-02-15 16:17:40 -08004254 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004255 * Sets the ImsService Package Name that Telephony will bind to.
4256 *
4257 * @param slotId the slot ID that the ImsService should bind for.
4258 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4259 * ImsService is the device default ImsService.
4260 * @param packageName The package name of the application that contains the ImsService to bind
4261 * to.
4262 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4263 * @hide
4264 */
4265 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004266 int[] subIds = SubscriptionManager.getSubId(slotId);
4267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4268 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4269 "setImsService");
4270
Malcolm Chend965c8b2018-02-28 15:00:40 -08004271 final long identity = Binder.clearCallingIdentity();
4272 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004273 ImsResolver resolver = PhoneFactory.getImsResolver();
4274 if (resolver == null) {
4275 // may happen if the device does not support IMS.
4276 return false;
4277 }
4278 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4279 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004283 }
4284
4285 /**
4286 * Return the ImsService configuration.
4287 *
4288 * @param slotId The slot that the ImsService is associated with.
4289 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4290 * the device default.
4291 * @return the package name of the ImsService configuration.
4292 */
4293 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004294 int[] subIds = SubscriptionManager.getSubId(slotId);
4295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4296 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4297 "getImsService");
4298
Malcolm Chend965c8b2018-02-28 15:00:40 -08004299 final long identity = Binder.clearCallingIdentity();
4300 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004301 ImsResolver resolver = PhoneFactory.getImsResolver();
4302 if (resolver == null) {
4303 // may happen if the device does not support IMS.
4304 return "";
4305 }
4306 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004310 }
4311
Wink Saville36469e72014-06-11 15:17:00 -07004312 public void setImsRegistrationState(boolean registered) {
4313 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004314
4315 final long identity = Binder.clearCallingIdentity();
4316 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004317 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
Wink Saville36469e72014-06-11 15:17:00 -07004321 }
4322
4323 /**
Stuart Scott54788802015-03-30 13:18:01 -07004324 * Set the network selection mode to automatic.
4325 *
4326 */
4327 @Override
4328 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4330 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004331
Pengquan Meng466e2482018-09-21 15:54:48 -07004332 if (!isActiveSubscription(subId)) {
4333 return;
4334 }
4335
Malcolm Chend965c8b2018-02-28 15:00:40 -08004336 final long identity = Binder.clearCallingIdentity();
4337 try {
4338 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4339 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
Stuart Scott54788802015-03-30 13:18:01 -07004343 }
4344
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004345 /**
4346 * Ask the radio to connect to the input network and change selection mode to manual.
4347 *
4348 * @param subId the id of the subscription.
4349 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4350 * the operator to attach to.
4351 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4352 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4353 * normal network selection next time.
4354 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004355 */
4356 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004357 public boolean setNetworkSelectionModeManual(
4358 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4360 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004361
4362 if (!isActiveSubscription(subId)) {
4363 return false;
4364 }
4365
Malcolm Chend965c8b2018-02-28 15:00:40 -08004366 final long identity = Binder.clearCallingIdentity();
4367 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004368 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004369 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004370 if (DBG) {
4371 log("setNetworkSelectionModeManual: subId: " + subId
4372 + " operator: " + operatorInfo);
4373 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004374 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4375 } finally {
4376 Binder.restoreCallingIdentity(identity);
4377 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004378 }
4379
4380 /**
4381 * Scans for available networks.
4382 */
4383 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004384 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4386 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004387 LocationAccessPolicy.LocationPermissionResult locationResult =
4388 LocationAccessPolicy.checkLocationPermission(mApp,
4389 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4390 .setCallingPackage(callingPackage)
4391 .setCallingPid(Binder.getCallingPid())
4392 .setCallingUid(Binder.getCallingUid())
4393 .setMethod("getCellNetworkScanResults")
4394 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4395 .build());
4396 switch (locationResult) {
4397 case DENIED_HARD:
4398 throw new SecurityException("Not allowed to access scan results -- location");
4399 case DENIED_SOFT:
4400 return null;
4401 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004402
Pengquan Meng0c05b502018-09-06 09:59:22 -07004403 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004404 try {
4405 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004406 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004407 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004408 } finally {
4409 Binder.restoreCallingIdentity(identity);
4410 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004411 }
4412
4413 /**
yinxub1bed742017-04-17 11:45:04 -07004414 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004415 *
yinxub1bed742017-04-17 11:45:04 -07004416 * @param subId id of the subscription
4417 * @param request contains the radio access networks with bands/channels to scan
4418 * @param messenger callback messenger for scan results or errors
4419 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004420 * @return the id of the requested scan which can be used to stop the scan.
4421 */
4422 @Override
4423 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004424 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4426 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004427
Hall Liuf19c44f2018-11-27 14:38:17 -08004428 LocationAccessPolicy.LocationPermissionResult locationResult =
4429 LocationAccessPolicy.checkLocationPermission(mApp,
4430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4431 .setCallingPackage(callingPackage)
4432 .setCallingPid(Binder.getCallingPid())
4433 .setCallingUid(Binder.getCallingUid())
4434 .setMethod("requestNetworkScan")
4435 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4436 .build());
4437 switch (locationResult) {
4438 case DENIED_HARD:
4439 throw new SecurityException("Not allowed to request network scan -- location");
4440 case DENIED_SOFT:
4441 return -1;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004442 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004443
4444 return mNetworkScanRequestTracker.startNetworkScan(
4445 request, messenger, binder, getPhone(subId),
4446 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004447 }
4448
4449 /**
4450 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004451 *
4452 * @param subId id of the subscription
4453 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004454 */
4455 @Override
4456 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4458 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004459
4460 final long identity = Binder.clearCallingIdentity();
4461 try {
4462 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
yinxu504e1392017-04-12 16:03:22 -07004466 }
4467
4468 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004469 * Get the calculated preferred network type.
4470 * Used for debugging incorrect network type.
4471 *
4472 * @return the preferred network type, defined in RILConstants.java.
4473 */
4474 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004475 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004476 final Phone defaultPhone = getDefaultPhone();
4477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4478 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004479 return RILConstants.PREFERRED_NETWORK_MODE;
4480 }
4481
Malcolm Chend965c8b2018-02-28 15:00:40 -08004482 final long identity = Binder.clearCallingIdentity();
4483 try {
4484 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004485 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
Junda Liu84d15a22014-07-02 11:21:04 -07004489 }
4490
4491 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004492 * Get the preferred network type.
4493 * Used for device configuration by some CDMA operators.
4494 *
4495 * @return the preferred network type, defined in RILConstants.java.
4496 */
4497 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004498 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004499 TelephonyPermissions
4500 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4501 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004502
4503 final long identity = Binder.clearCallingIdentity();
4504 try {
4505 if (DBG) log("getPreferredNetworkType");
4506 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4507 int networkType = (result != null ? result[0] : -1);
4508 if (DBG) log("getPreferredNetworkType: " + networkType);
4509 return networkType;
4510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004513 }
4514
4515 /**
4516 * Set the preferred network type.
4517 * Used for device configuration by some CDMA operators.
4518 *
4519 * @param networkType the preferred network type, defined in RILConstants.java.
4520 * @return true on success; false on any failure.
4521 */
4522 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004523 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4525 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004526
4527 final long identity = Binder.clearCallingIdentity();
4528 try {
4529 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4530 Boolean success = (Boolean) sendRequest(
4531 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4532 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4533 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004534 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004535 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4536 }
4537 return success;
4538 } finally {
4539 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004540 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004541 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004542
4543 /**
Miaoa84611c2019-03-15 09:21:10 +08004544 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004545 *
Miaoa84611c2019-03-15 09:21:10 +08004546 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004547 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004548 * @hide
4549 */
4550 @Override
Miaoa84611c2019-03-15 09:21:10 +08004551 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004552 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004553 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004554 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004555 try {
Miaoa84611c2019-03-15 09:21:10 +08004556 if (phone != null) {
4557 return phone.hasMatchedTetherApnSetting();
4558 } else {
4559 return false;
4560 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004561 } finally {
4562 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004563 }
Junda Liu475951f2014-11-07 16:45:03 -08004564 }
4565
4566 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004567 * Set mobile data enabled
4568 * Used by the user through settings etc to turn on/off mobile data
4569 *
4570 * @param enable {@code true} turn turn data on, else {@code false}
4571 */
4572 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004573 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4575 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004576
4577 final long identity = Binder.clearCallingIdentity();
4578 try {
4579 int phoneId = mSubscriptionController.getPhoneId(subId);
4580 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4581 Phone phone = PhoneFactory.getPhone(phoneId);
4582 if (phone != null) {
4583 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004584 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004585 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004586 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004587 }
4588 } finally {
4589 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004590 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004591 }
4592
4593 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004594 * Get the user enabled state of Mobile Data.
4595 *
4596 * TODO: remove and use isUserDataEnabled.
4597 * This can't be removed now because some vendor codes
4598 * calls through ITelephony directly while they should
4599 * use TelephonyManager.
4600 *
4601 * @return true on enabled
4602 */
4603 @Override
4604 public boolean getDataEnabled(int subId) {
4605 return isUserDataEnabled(subId);
4606 }
4607
4608 /**
4609 * Get whether mobile data is enabled per user setting.
4610 *
4611 * There are other factors deciding whether mobile data is actually enabled, but they are
4612 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004613 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004614 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004615 *
4616 * @return {@code true} if data is enabled else {@code false}
4617 */
4618 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004619 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004620 try {
4621 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4622 null);
4623 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4625 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004626 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004627
4628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 int phoneId = mSubscriptionController.getPhoneId(subId);
4631 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4632 Phone phone = PhoneFactory.getPhone(phoneId);
4633 if (phone != null) {
4634 boolean retVal = phone.isUserDataEnabled();
4635 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4636 return retVal;
4637 } else {
4638 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4639 return false;
4640 }
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004643 }
4644 }
4645
4646 /**
4647 * Get whether mobile data is enabled.
4648 *
4649 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4650 * whether mobile data is actually enabled.
4651 *
4652 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4653 *
4654 * @return {@code true} if data is enabled else {@code false}
4655 */
4656 @Override
4657 public boolean isDataEnabled(int subId) {
4658 try {
4659 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4660 null);
4661 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4663 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004664 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004665
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
4668 int phoneId = mSubscriptionController.getPhoneId(subId);
4669 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4670 Phone phone = PhoneFactory.getPhone(phoneId);
4671 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004672 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004673 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4674 return retVal;
4675 } else {
4676 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4677 return false;
4678 }
4679 } finally {
4680 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004681 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004682 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004683
4684 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004685 public int getCarrierPrivilegeStatus(int subId) {
4686 final Phone phone = getPhone(subId);
4687 if (phone == null) {
4688 loge("getCarrierPrivilegeStatus: Invalid subId");
4689 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4690 }
4691 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004692 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004693 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004694 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4695 }
4696 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004697 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004698 }
Junda Liu29340342014-07-10 15:23:27 -07004699
4700 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004701 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4702 final Phone phone = getPhone(subId);
4703 if (phone == null) {
4704 loge("getCarrierPrivilegeStatus: Invalid subId");
4705 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4706 }
4707 UiccProfile profile =
4708 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4709 if (profile == null) {
4710 loge("getCarrierPrivilegeStatus: No UICC");
4711 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4712 }
4713 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4714 }
4715
4716 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004717 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004718 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004719 if (TextUtils.isEmpty(pkgName))
4720 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004721 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004722 if (card == null) {
4723 loge("checkCarrierPrivilegesForPackage: No UICC");
4724 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4725 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004726 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4727 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004728 }
4729
4730 @Override
4731 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004732 if (TextUtils.isEmpty(pkgName))
4733 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004734 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4735 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4736 UiccCard card = UiccController.getInstance().getUiccCard(i);
4737 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004738 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004739 continue;
4740 }
4741
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004742 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004743 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4744 break;
4745 }
4746 }
4747
4748 return result;
Junda Liu29340342014-07-10 15:23:27 -07004749 }
Derek Tan89e89d42014-07-08 17:00:10 -07004750
4751 @Override
Junda Liue64de782015-04-16 17:19:16 -07004752 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4753 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4754 loge("phoneId " + phoneId + " is not valid.");
4755 return null;
4756 }
4757 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004758 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004759 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004760 return null ;
4761 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004762 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004763 }
4764
Amith Yamasani6e118872016-02-19 12:53:51 -08004765 @Override
4766 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004767 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004768 List<String> privilegedPackages = new ArrayList<>();
4769 List<PackageInfo> packages = null;
4770 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4771 UiccCard card = UiccController.getInstance().getUiccCard(i);
4772 if (card == null) {
4773 // No UICC in that slot.
4774 continue;
4775 }
4776 if (card.hasCarrierPrivilegeRules()) {
4777 if (packages == null) {
4778 // Only check packages in user 0 for now
4779 packages = pm.getInstalledPackagesAsUser(
4780 PackageManager.MATCH_DISABLED_COMPONENTS
4781 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4782 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4783 }
4784 for (int p = packages.size() - 1; p >= 0; p--) {
4785 PackageInfo pkgInfo = packages.get(p);
4786 if (pkgInfo != null && pkgInfo.packageName != null
4787 && card.getCarrierPrivilegeStatus(pkgInfo)
4788 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4789 privilegedPackages.add(pkgInfo.packageName);
4790 }
4791 }
4792 }
4793 }
4794 return privilegedPackages;
4795 }
4796
Wink Savilleb564aae2014-10-23 10:18:09 -07004797 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004798 final Phone phone = getPhone(subId);
4799 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004800 if (card == null) {
4801 loge("getIccId: No UICC");
4802 return null;
4803 }
4804 String iccId = card.getIccId();
4805 if (TextUtils.isEmpty(iccId)) {
4806 loge("getIccId: ICC ID is null or empty.");
4807 return null;
4808 }
4809 return iccId;
4810 }
4811
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004812 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004813 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4814 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004815 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4816 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004817
Malcolm Chend965c8b2018-02-28 15:00:40 -08004818 final long identity = Binder.clearCallingIdentity();
4819 try {
4820 final String iccId = getIccId(subId);
4821 final Phone phone = getPhone(subId);
4822 if (phone == null) {
4823 return false;
4824 }
4825 final String subscriberId = phone.getSubscriberId();
4826
4827 if (DBG_MERGE) {
4828 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4829 + subscriberId + " to " + number);
4830 }
4831
4832 if (TextUtils.isEmpty(iccId)) {
4833 return false;
4834 }
4835
4836 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4837
4838 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4839 if (alphaTag == null) {
4840 editor.remove(alphaTagPrefKey);
4841 } else {
4842 editor.putString(alphaTagPrefKey, alphaTag);
4843 }
4844
4845 // Record both the line number and IMSI for this ICCID, since we need to
4846 // track all merged IMSIs based on line number
4847 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4848 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4849 if (number == null) {
4850 editor.remove(numberPrefKey);
4851 editor.remove(subscriberPrefKey);
4852 } else {
4853 editor.putString(numberPrefKey, number);
4854 editor.putString(subscriberPrefKey, subscriberId);
4855 }
4856
4857 editor.commit();
4858 return true;
4859 } finally {
4860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004861 }
Derek Tan7226c842014-07-02 17:42:23 -07004862 }
4863
4864 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004865 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004866 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004867 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004868 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004869 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004870 return null;
4871 }
Derek Tan97ebb422014-09-05 16:55:38 -07004872
Malcolm Chend965c8b2018-02-28 15:00:40 -08004873 final long identity = Binder.clearCallingIdentity();
4874 try {
4875 String iccId = getIccId(subId);
4876 if (iccId != null) {
4877 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4878 if (DBG_MERGE) {
4879 log("getLine1NumberForDisplay returning "
4880 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4881 }
4882 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004883 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004884 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4885 return null;
4886 } finally {
4887 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004888 }
Derek Tan7226c842014-07-02 17:42:23 -07004889 }
4890
4891 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004892 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004894 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004895 return null;
4896 }
Derek Tan97ebb422014-09-05 16:55:38 -07004897
Malcolm Chend965c8b2018-02-28 15:00:40 -08004898 final long identity = Binder.clearCallingIdentity();
4899 try {
4900 String iccId = getIccId(subId);
4901 if (iccId != null) {
4902 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4903 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4904 }
4905 return null;
4906 } finally {
4907 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004908 }
Derek Tan7226c842014-07-02 17:42:23 -07004909 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004910
4911 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004912 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004913 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4914 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004916 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4917 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004918 return null;
4919 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004920
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004921 final long identity = Binder.clearCallingIdentity();
4922 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004923 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004924 final TelephonyManager tele = TelephonyManager.from(context);
4925 final SubscriptionManager sub = SubscriptionManager.from(context);
4926
4927 // Figure out what subscribers are currently active
4928 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4929 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4930 // the process, where TelephonyManager was instantiated.
4931 // Otherwise AppOps check will fail.
4932
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004933 final int[] subIds = sub.getActiveSubscriptionIdList();
4934 for (int subId : subIds) {
4935 activeSubscriberIds.add(tele.getSubscriberId(subId));
4936 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004937
4938 // First pass, find a number override for an active subscriber
4939 String mergeNumber = null;
4940 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4941 for (String key : prefs.keySet()) {
4942 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4943 final String subscriberId = (String) prefs.get(key);
4944 if (activeSubscriberIds.contains(subscriberId)) {
4945 final String iccId = key.substring(
4946 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4947 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4948 mergeNumber = (String) prefs.get(numberKey);
4949 if (DBG_MERGE) {
4950 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4951 + " for active subscriber " + subscriberId);
4952 }
4953 if (!TextUtils.isEmpty(mergeNumber)) {
4954 break;
4955 }
4956 }
4957 }
4958 }
4959
4960 // Shortcut when no active merged subscribers
4961 if (TextUtils.isEmpty(mergeNumber)) {
4962 return null;
4963 }
4964
4965 // Second pass, find all subscribers under that line override
4966 final ArraySet<String> result = new ArraySet<>();
4967 for (String key : prefs.keySet()) {
4968 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4969 final String number = (String) prefs.get(key);
4970 if (mergeNumber.equals(number)) {
4971 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4972 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4973 final String subscriberId = (String) prefs.get(subscriberKey);
4974 if (!TextUtils.isEmpty(subscriberId)) {
4975 result.add(subscriberId);
4976 }
4977 }
4978 }
4979 }
4980
4981 final String[] resultArray = result.toArray(new String[result.size()]);
4982 Arrays.sort(resultArray);
4983 if (DBG_MERGE) {
4984 Slog.d(LOG_TAG,
4985 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4986 }
4987 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004988 } finally {
4989 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004990 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004991 }
4992
4993 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004994 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004995 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4996 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004997
4998 final long identity = Binder.clearCallingIdentity();
4999 try {
5000 final Phone phone = getPhone(subId);
5001 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005005 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005006
5007 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005008 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005009 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5010 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005011 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005012
5013 final long identity = Binder.clearCallingIdentity();
5014 try {
5015 final Phone phone = getPhone(subId);
5016 if (phone == null) {
5017 return false;
5018 }
5019 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5020 cdmaNonRoamingList);
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005023 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005024 }
5025
5026 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005027 @Deprecated
5028 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5029 enforceModifyPermission();
5030
5031 int returnValue = 0;
5032 try {
vagdevie435a3e2018-08-15 16:01:53 -07005033 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005034 if(result.exception == null) {
5035 if (result.result != null) {
5036 byte[] responseData = (byte[])(result.result);
5037 if(responseData.length > oemResp.length) {
5038 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5039 responseData.length + "bytes. Buffer Size is " +
5040 oemResp.length + "bytes.");
5041 }
5042 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5043 returnValue = responseData.length;
5044 }
5045 } else {
5046 CommandException ex = (CommandException) result.exception;
5047 returnValue = ex.getCommandError().ordinal();
5048 if(returnValue > 0) returnValue *= -1;
5049 }
5050 } catch (RuntimeException e) {
5051 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5052 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5053 if(returnValue > 0) returnValue *= -1;
5054 }
5055
5056 return returnValue;
5057 }
5058
5059 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005060 public void setRadioCapability(RadioAccessFamily[] rafs) {
5061 try {
5062 ProxyController.getInstance().setRadioCapability(rafs);
5063 } catch (RuntimeException e) {
5064 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5065 }
5066 }
5067
5068 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005069 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005070 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005071 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005072 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005073 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005074 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005075 final long identity = Binder.clearCallingIdentity();
5076 try {
chen xufeeed752018-10-26 14:17:57 -07005077 TelephonyPermissions
5078 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5079 mApp, phone.getSubId(), "getRadioAccessFamily");
5080 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005081 } finally {
5082 Binder.restoreCallingIdentity(identity);
5083 }
chen xufeeed752018-10-26 14:17:57 -07005084 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005085 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005086
5087 @Override
5088 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005089 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005090 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005091
5092 final long identity = Binder.clearCallingIdentity();
5093 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005094 ImsManager.getInstance(defaultPhone.getContext(),
5095 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005096 } finally {
5097 Binder.restoreCallingIdentity(identity);
5098 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005099 }
5100
5101 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005102 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005103 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005104 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005105 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005106 return false;
5107 }
Svet Ganovb320e182015-04-16 12:30:10 -07005108
Malcolm Chend965c8b2018-02-28 15:00:40 -08005109 final long identity = Binder.clearCallingIdentity();
5110 try {
5111 // Check the user preference and the system-level IMS setting. Even if the user has
5112 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5113 // In the long run, we may instead need to check if there exists a connection service
5114 // which can support video calling.
5115 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005116 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005117 return imsManager.isVtEnabledByPlatform()
5118 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5119 && imsManager.isVtEnabledByUser();
5120 } finally {
5121 Binder.restoreCallingIdentity(identity);
5122 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005123 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005124
Andrew Leea1239f22015-03-02 17:44:07 -08005125 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005126 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5128 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5129 return false;
5130 }
5131
5132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 CarrierConfigManager configManager =
5135 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005136 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005137 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
5140 }
Andrew Leea1239f22015-03-02 17:44:07 -08005141 }
5142
5143 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005144 public boolean isWorldPhone(int subId, String callingPackage) {
5145 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5146 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5147 return false;
5148 }
5149
5150 final long identity = Binder.clearCallingIdentity();
5151 try {
5152 CarrierConfigManager configManager =
5153 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005154 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005155 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
5158 }
Andrew Leea1239f22015-03-02 17:44:07 -08005159 }
5160
Andrew Lee9431b832015-03-09 18:46:45 -07005161 @Override
5162 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005163 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005164 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005165 }
5166
5167 @Override
5168 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005169 final long identity = Binder.clearCallingIdentity();
5170 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005171 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
Andrew Lee9431b832015-03-09 18:46:45 -07005175 }
5176
Hall Liuf6668912018-10-31 17:05:23 -07005177 /**
5178 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5179 * support for the feature and device firmware support.
5180 *
5181 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5182 */
5183 @Override
5184 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005186 final Phone phone = getPhone(subscriptionId);
5187 if (phone == null) {
5188 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5189 return false;
5190 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005191 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005192 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005193 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5194 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005195 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005196 return isCarrierSupported && isDeviceSupported;
5197 } finally {
5198 Binder.restoreCallingIdentity(identity);
5199 }
Hall Liu98187582018-01-22 19:15:32 -08005200 }
5201
Hall Liuf6668912018-10-31 17:05:23 -07005202 /**
5203 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5204 * both also support RTT.
5205 */
5206 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005207 final long identity = Binder.clearCallingIdentity();
5208 try {
Hall Liuf6668912018-10-31 17:05:23 -07005209 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005210 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005211 } finally {
5212 Binder.restoreCallingIdentity(identity);
5213 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005214 }
5215
Sanket Padawe7310cc72015-01-14 09:53:20 -08005216 /**
5217 * Returns the unique device ID of phone, for example, the IMEI for
5218 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5219 *
5220 * <p>Requires Permission:
5221 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5222 */
5223 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005224 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005225 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005226 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005227 return null;
5228 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005229 int subId = phone.getSubId();
5230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5231 mApp, subId, callingPackage, "getDeviceId")) {
5232 return null;
5233 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005234
5235 final long identity = Binder.clearCallingIdentity();
5236 try {
5237 return phone.getDeviceId();
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
5240 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005241 }
5242
Ping Sunc67b7c22016-03-02 19:16:45 +08005243 /**
5244 * {@hide}
5245 * Returns the IMS Registration Status on a particular subid
5246 *
5247 * @param subId
5248 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005249 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005250 Phone phone = getPhone(subId);
5251 if (phone != null) {
5252 return phone.isImsRegistered();
5253 } else {
5254 return false;
5255 }
5256 }
5257
Santos Cordon7a1885b2015-02-03 11:15:19 -08005258 @Override
5259 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005260 final long identity = Binder.clearCallingIdentity();
5261 try {
5262 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
5265 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005266 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005267
Tyler Gunn327a9722019-04-03 15:28:53 -07005268 @Override
5269 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 Phone phone = getPhone(subscriptionId);
5273 if (phone == null) {
5274 return null;
5275 }
5276 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
5280 }
5281
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005282 /**
5283 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005284 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005285 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
5288 Phone phone = getPhone(subId);
5289 if (phone != null) {
5290 return phone.isWifiCallingEnabled();
5291 } else {
5292 return false;
5293 }
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005296 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005297 }
5298
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005299 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005300 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005301 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005302 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005303 final long identity = Binder.clearCallingIdentity();
5304 try {
5305 Phone phone = getPhone(subId);
5306 if (phone != null) {
5307 return phone.isVideoEnabled();
5308 } else {
5309 return false;
5310 }
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005313 }
5314 }
5315
5316 /**
5317 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5318 * defined in {@link ImsRegistrationImplBase}.
5319 */
5320 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005321 final long identity = Binder.clearCallingIdentity();
5322 try {
5323 Phone phone = getPhone(subId);
5324 if (phone != null) {
5325 return phone.getImsRegistrationTech();
5326 } else {
5327 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5328 }
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005331 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005332 }
5333
Stuart Scott8eef64f2015-04-08 15:13:54 -07005334 @Override
5335 public void factoryReset(int subId) {
5336 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005337 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5338 return;
5339 }
5340
Svet Ganovcc087f82015-05-12 20:35:54 -07005341 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005342
Svet Ganovcc087f82015-05-12 20:35:54 -07005343 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005344 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5345 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005346 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005347 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005348 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005349 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5350 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005351 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005352 // There has been issues when Sms raw table somehow stores orphan
5353 // fragments. They lead to garbled message when new fragments come
5354 // in and combined with those stale ones. In case this happens again,
5355 // user can reset all network settings which will clean up this table.
5356 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005357 } finally {
5358 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005359 }
5360 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005361
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005362 private void cleanUpSmsRawTable(Context context) {
5363 ContentResolver resolver = context.getContentResolver();
5364 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5365 resolver.delete(uri, null, null);
5366 }
5367
Narayan Kamath1c496c22015-04-16 14:40:19 +01005368 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005369 public String getSimLocaleForSubscriber(int subId) {
5370 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5371 final Phone phone = getPhone(subId);
5372 if (phone == null) {
5373 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005374 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005375 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005376 final long identity = Binder.clearCallingIdentity();
5377 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005378 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5379 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005380 // Try and fetch the locale from the carrier properties or from the SIM language
5381 // preferences (EF-PL and EF-LI)...
5382 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005383 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005384 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5385 if (localeFromDefaultSim != null) {
5386 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5387 if (DBG) log("Using locale from subId: " + subId + " locale: "
5388 + localeFromDefaultSim);
5389 return localeFromDefaultSim.toLanguageTag();
5390 } else {
5391 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005392 }
5393 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005394
Malcolm Chend965c8b2018-02-28 15:00:40 -08005395 // The SIM language preferences only store a language (e.g. fr = French), not an
5396 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5397 // the SIM and carrier preferences does not include a country we add the country
5398 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005399 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005400 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005401 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005402 return mccLocale.toLanguageTag();
5403 }
5404
5405 if (DBG) log("No locale found - returning null");
5406 return null;
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
5409 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005410 }
5411
5412 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005413 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005414 }
5415
Malcolm Chend965c8b2018-02-28 15:00:40 -08005416 /**
5417 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5418 */
5419 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005420 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005421 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005422
Chenjie Yu1ba97252018-01-11 18:16:20 -08005423 private final ModemActivityInfo mLastModemActivityInfo =
5424 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5425
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005426 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005427 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5428 * representing the state of the modem.
5429 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005430 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5431 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005432 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005433 */
5434 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005435 public void requestModemActivityInfo(ResultReceiver result) {
5436 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005437 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005438
5439 final long identity = Binder.clearCallingIdentity();
5440 try {
5441 ModemActivityInfo ret = null;
5442 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005443 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5444 CMD_GET_MODEM_ACTIVITY_INFO,
5445 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005446 if (isModemActivityInfoValid(info)) {
5447 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5448 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5449 mergedTxTimeMs[i] =
5450 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5451 }
5452 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5453 mLastModemActivityInfo.setSleepTimeMillis(
5454 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5455 mLastModemActivityInfo.setIdleTimeMillis(
5456 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5457 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5458 mLastModemActivityInfo.setRxTimeMillis(
5459 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5460 mLastModemActivityInfo.setEnergyUsed(
5461 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005462 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005463 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5464 mLastModemActivityInfo.getSleepTimeMillis(),
5465 mLastModemActivityInfo.getIdleTimeMillis(),
5466 mLastModemActivityInfo.getTxTimeMillis(),
5467 mLastModemActivityInfo.getRxTimeMillis(),
5468 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005469 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005470 Bundle bundle = new Bundle();
5471 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5472 result.send(0, bundle);
5473 } finally {
5474 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005475 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005476 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005477
Siddharth Rayf5d29552018-06-17 15:02:38 -07005478 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5479 // less than total activity duration.
5480 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5481 if (info == null) {
5482 return false;
5483 }
5484 int activityDurationMs =
5485 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5486 int totalTxTimeMs = 0;
5487 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5488 totalTxTimeMs += info.getTxTimeMillis()[i];
5489 }
5490 return (info.isValid()
5491 && (info.getSleepTimeMillis() <= activityDurationMs)
5492 && (info.getIdleTimeMillis() <= activityDurationMs)
5493 && (info.getRxTimeMillis() <= activityDurationMs)
5494 && (totalTxTimeMs <= activityDurationMs));
5495 }
5496
Jack Yu85bd38a2015-11-09 11:34:32 -08005497 /**
5498 * {@hide}
5499 * Returns the service state information on specified subscription.
5500 */
5501 @Override
5502 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005504 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005505 return null;
5506 }
5507
Hall Liuf19c44f2018-11-27 14:38:17 -08005508 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5509 LocationAccessPolicy.checkLocationPermission(mApp,
5510 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5511 .setCallingPackage(callingPackage)
5512 .setCallingPid(Binder.getCallingPid())
5513 .setCallingUid(Binder.getCallingUid())
5514 .setMethod("getServiceStateForSubscriber")
5515 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5516 .build());
5517
5518 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5519 LocationAccessPolicy.checkLocationPermission(mApp,
5520 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5521 .setCallingPackage(callingPackage)
5522 .setCallingPid(Binder.getCallingPid())
5523 .setCallingUid(Binder.getCallingUid())
5524 .setMethod("getServiceStateForSubscriber")
5525 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5526 .build());
5527 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5528 boolean hasFinePermission =
5529 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5530 boolean hasCoarsePermission =
5531 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5532
Malcolm Chend965c8b2018-02-28 15:00:40 -08005533 final long identity = Binder.clearCallingIdentity();
5534 try {
5535 final Phone phone = getPhone(subId);
5536 if (phone == null) {
5537 return null;
5538 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005539
Hall Liuf19c44f2018-11-27 14:38:17 -08005540 ServiceState ss = phone.getServiceState();
5541
5542 // Scrub out the location info in ServiceState depending on what level of access
5543 // the caller has.
5544 if (hasFinePermission) return ss;
5545 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5546 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005547 } finally {
5548 Binder.restoreCallingIdentity(identity);
5549 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005550 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005551
5552 /**
5553 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5554 *
5555 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5556 * voicemail ringtone.
5557 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5558 * PhoneAccount.
5559 */
5560 @Override
5561 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5565 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005566 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005567 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005568
Malcolm Chend965c8b2018-02-28 15:00:40 -08005569 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005573 }
5574
5575 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005576 * Sets the per-account voicemail ringtone.
5577 *
5578 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5579 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5580 *
5581 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5582 * voicemail ringtone.
5583 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5584 * PhoneAccount.
5585 */
5586 @Override
5587 public void setVoicemailRingtoneUri(String callingPackage,
5588 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005589 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5591 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005592 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5594 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5595 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005596 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005597
5598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5601 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005602 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005603 }
5604 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005607 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005608 }
5609
5610 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005611 * Returns whether vibration is set for voicemail notification in Phone settings.
5612 *
5613 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5614 * voicemail vibration setting.
5615 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5616 */
5617 @Override
5618 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5622 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005623 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005624 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005625
Malcolm Chend965c8b2018-02-28 15:00:40 -08005626 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005630 }
5631
Youhan Wange64578a2016-05-02 15:32:42 -07005632 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005633 * Sets the per-account voicemail vibration.
5634 *
5635 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5636 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5637 *
5638 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5639 * voicemail vibration setting.
5640 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5641 * specific PhoneAccount.
5642 */
5643 @Override
5644 public void setVoicemailVibrationEnabled(String callingPackage,
5645 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005646 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005647 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5648 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005649 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5651 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5652 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005653 }
5654
Malcolm Chend965c8b2018-02-28 15:00:40 -08005655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5658 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005659 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005660 }
5661 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5662 } finally {
5663 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005664 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005665 }
5666
5667 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005668 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5669 *
5670 * @throws SecurityException if the caller does not have the required permission
5671 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005672 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005673 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005674 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005675 }
5676
5677 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005678 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5679 * permission.
5680 *
5681 * @throws SecurityException if the caller does not have the required permission
5682 */
5683 private void enforceSendSmsPermission() {
5684 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5685 }
5686
5687 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005688 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005689 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005690 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005691 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005692 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005696 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005697 if (componentName == null) {
5698 throw new SecurityException(
5699 "Caller not current active visual voicemail package[null]");
5700 }
5701 String vvmPackage = componentName.getPackageName();
5702 if (!callingPackage.equals(vvmPackage)) {
5703 throw new SecurityException("Caller not current active visual voicemail package["
5704 + vvmPackage + "]");
5705 }
5706 } finally {
5707 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005708 }
5709 }
5710
5711 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005712 * Return the application ID for the app type.
5713 *
5714 * @param subId the subscription ID that this request applies to.
5715 * @param appType the uicc app type.
5716 * @return Application ID for specificied app type, or null if no uicc.
5717 */
5718 @Override
5719 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005720 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005721 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005722
5723 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005724 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005725 if (phone == null) {
5726 return null;
5727 }
5728 String aid = null;
5729 try {
5730 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5731 .getApplicationByType(appType).getAid();
5732 } catch (Exception e) {
5733 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5734 }
5735 return aid;
5736 } finally {
5737 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005738 }
Youhan Wange64578a2016-05-02 15:32:42 -07005739 }
5740
Youhan Wang4001d252016-05-11 10:29:41 -07005741 /**
5742 * Return the Electronic Serial Number.
5743 *
5744 * @param subId the subscription ID that this request applies to.
5745 * @return ESN or null if error.
5746 */
5747 @Override
5748 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005749 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005750 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005751
5752 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005753 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005754 if (phone == null) {
5755 return null;
5756 }
5757 String esn = null;
5758 try {
5759 esn = phone.getEsn();
5760 } catch (Exception e) {
5761 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5762 }
5763 return esn;
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005766 }
Youhan Wang4001d252016-05-11 10:29:41 -07005767 }
5768
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005769 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005770 * Return the Preferred Roaming List Version.
5771 *
5772 * @param subId the subscription ID that this request applies to.
5773 * @return PRLVersion or null if error.
5774 */
5775 @Override
5776 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005777 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005778 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005779
5780 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005781 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005782 if (phone == null) {
5783 return null;
5784 }
5785 String cdmaPrlVersion = null;
5786 try {
5787 cdmaPrlVersion = phone.getCdmaPrlVersion();
5788 } catch (Exception e) {
5789 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5790 }
5791 return cdmaPrlVersion;
5792 } finally {
5793 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005794 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005795 }
5796
5797 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005798 * Get snapshot of Telephony histograms
5799 * @return List of Telephony histograms
5800 * @hide
5801 */
5802 @Override
5803 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5805 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005806
5807 final long identity = Binder.clearCallingIdentity();
5808 try {
5809 return RIL.getTelephonyRILTimingHistograms();
5810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005813 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005814
5815 /**
5816 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005817 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5818 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005819 * Require system privileges. In the future we may add this to carrier APIs.
5820 *
Michele Berionne0963c862018-11-27 18:57:59 -08005821 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005822 */
5823 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005824 @TelephonyManager.SetCarrierRestrictionResult
5825 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005826 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005827 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005828
Michele Berionne0963c862018-11-27 18:57:59 -08005829 if (carrierRestrictionRules == null) {
5830 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005831 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005832
Malcolm Chend965c8b2018-02-28 15:00:40 -08005833 final long identity = Binder.clearCallingIdentity();
5834 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005835 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005836 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005840 }
5841
5842 /**
5843 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005844 * Get the allowed carrier list and the excluded carrier list, including the priority between
5845 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005846 * Require system privileges. In the future we may add this to carrier APIs.
5847 *
Michele Berionne0963c862018-11-27 18:57:59 -08005848 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005849 */
5850 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005851 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005852 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005853 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005854
5855 final long identity = Binder.clearCallingIdentity();
5856 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005857 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5858 if (response instanceof CarrierRestrictionRules) {
5859 return (CarrierRestrictionRules) response;
5860 }
5861 // Response is an Exception of some kind,
5862 // which is signalled to the user as a NULL retval
5863 return null;
5864 } catch (Exception e) {
5865 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5866 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005867 } finally {
5868 Binder.restoreCallingIdentity(identity);
5869 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005870 }
5871
fionaxu59545b42016-05-25 15:53:37 -07005872 /**
5873 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5874 * @param subId the subscription ID that this action applies to.
5875 * @param enabled control enable or disable metered apns.
5876 * {@hide}
5877 */
5878 @Override
5879 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5880 enforceModifyPermission();
5881 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005882
5883 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005884 if (phone == null) {
5885 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5886 return;
5887 }
5888 try {
5889 phone.carrierActionSetMeteredApnsEnabled(enabled);
5890 } catch (Exception e) {
5891 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005892 } finally {
5893 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005894 }
5895 }
5896
5897 /**
5898 * Action set from carrier signalling broadcast receivers to enable/disable radio
5899 * @param subId the subscription ID that this action applies to.
5900 * @param enabled control enable or disable radio.
5901 * {@hide}
5902 */
5903 @Override
5904 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5905 enforceModifyPermission();
5906 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005907
5908 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005909 if (phone == null) {
5910 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5911 return;
5912 }
5913 try {
5914 phone.carrierActionSetRadioEnabled(enabled);
5915 } catch (Exception e) {
5916 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005917 } finally {
5918 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005919 }
5920 }
5921
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005922 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005923 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5924 * network status based on which carrier apps could apply actions accordingly,
5925 * enable/disable default url handler for example.
5926 *
5927 * @param subId the subscription ID that this action applies to.
5928 * @param report control start/stop reporting the default network status.
5929 * {@hide}
5930 */
5931 @Override
5932 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5933 enforceModifyPermission();
5934 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005935
5936 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005937 if (phone == null) {
5938 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5939 return;
5940 }
5941 try {
5942 phone.carrierActionReportDefaultNetworkStatus(report);
5943 } catch (Exception e) {
5944 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005945 } finally {
5946 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005947 }
5948 }
5949
5950 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005951 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5952 * bug report is being generated.
5953 */
5954 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005955 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005956 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5957 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005958 writer.println("Permission Denial: can't dump Phone from pid="
5959 + Binder.getCallingPid()
5960 + ", uid=" + Binder.getCallingUid()
5961 + "without permission "
5962 + android.Manifest.permission.DUMP);
5963 return;
5964 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005965 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005966 }
Jack Yueb89b242016-06-22 13:27:47 -07005967
Brad Ebingerdac2f002018-04-03 15:17:52 -07005968 @Override
5969 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5970 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5971 throws RemoteException {
5972 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5973 }
5974
Jack Yueb89b242016-06-22 13:27:47 -07005975 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005976 * Get aggregated video call data usage since boot.
5977 *
5978 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5979 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005980 * {@hide}
5981 */
5982 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005983 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005984 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5985 null);
5986
Malcolm Chend965c8b2018-02-28 15:00:40 -08005987 final long identity = Binder.clearCallingIdentity();
5988 try {
5989 // NetworkStatsService keeps tracking the active network interface and identity. It
5990 // records the delta with the corresponding network identity.
5991 // We just return the total video call data usage snapshot since boot.
5992 Phone phone = getPhone(subId);
5993 if (phone != null) {
5994 return phone.getVtDataUsage(perUidStats);
5995 }
5996 return null;
5997 } finally {
5998 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005999 }
Jack Yueb89b242016-06-22 13:27:47 -07006000 }
Jack Yu75ab2952016-07-08 14:29:33 -07006001
6002 /**
6003 * Policy control of data connection. Usually used when data limit is passed.
6004 * @param enabled True if enabling the data, otherwise disabling.
6005 * @param subId Subscription index
6006 * {@hide}
6007 */
6008 @Override
6009 public void setPolicyDataEnabled(boolean enabled, int subId) {
6010 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006011
6012 final long identity = Binder.clearCallingIdentity();
6013 try {
6014 Phone phone = getPhone(subId);
6015 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006016 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006017 }
6018 } finally {
6019 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006020 }
6021 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006022
6023 /**
6024 * Get Client request stats
6025 * @return List of Client Request Stats
6026 * @hide
6027 */
6028 @Override
6029 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006031 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006032 return null;
6033 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006034 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006035
Malcolm Chend965c8b2018-02-28 15:00:40 -08006036 final long identity = Binder.clearCallingIdentity();
6037 try {
6038 if (phone != null) {
6039 return phone.getClientRequestStats();
6040 }
6041
6042 return null;
6043 } finally {
6044 Binder.restoreCallingIdentity(identity);
6045 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006046 }
6047
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006048 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006049 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006050 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006051 }
Jack Yueb4124c2017-02-16 15:32:43 -08006052
6053 /**
Grace Chen70990072017-03-24 17:21:30 -07006054 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006055 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006056 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006057 * @param state State of SIM (power down, power up, pass through)
6058 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6059 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6060 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006061 *
6062 **/
6063 @Override
Grace Chen70990072017-03-24 17:21:30 -07006064 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006065 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006066 Phone phone = PhoneFactory.getPhone(slotIndex);
6067
vagdevie435a3e2018-08-15 16:01:53 -07006068 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6069
Malcolm Chend965c8b2018-02-28 15:00:40 -08006070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006073 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006074 }
6075 } finally {
6076 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006077 }
6078 }
Shuo Qiandd210312017-04-12 22:11:33 +00006079
Tyler Gunn65d45c22017-06-05 11:22:26 -07006080 private boolean isUssdApiAllowed(int subId) {
6081 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006082 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006083 if (configManager == null) {
6084 return false;
6085 }
6086 PersistableBundle pb = configManager.getConfigForSubId(subId);
6087 if (pb == null) {
6088 return false;
6089 }
6090 return pb.getBoolean(
6091 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6092 }
6093
Shuo Qiandd210312017-04-12 22:11:33 +00006094 /**
6095 * Check if phone is in emergency callback mode
6096 * @return true if phone is in emergency callback mode
6097 * @param subId sub id
6098 */
goneil9c5f4872017-12-05 14:07:56 -08006099 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006100 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006101 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006102 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006103
6104 final long identity = Binder.clearCallingIdentity();
6105 try {
6106 if (phone != null) {
6107 return phone.isInEcm();
6108 } else {
6109 return false;
6110 }
6111 } finally {
6112 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006113 }
6114 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006115
6116 /**
6117 * Get the current signal strength information for the given subscription.
6118 * Because this information is not updated when the device is in a low power state
6119 * it should not be relied-upon to be current.
6120 * @param subId Subscription index
6121 * @return the most recent cached signal strength info from the modem
6122 */
6123 @Override
6124 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006125 final long identity = Binder.clearCallingIdentity();
6126 try {
6127 Phone p = getPhone(subId);
6128 if (p == null) {
6129 return null;
6130 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006131
Malcolm Chend965c8b2018-02-28 15:00:40 -08006132 return p.getSignalStrength();
6133 } finally {
6134 Binder.restoreCallingIdentity(identity);
6135 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006136 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006137
Pengquan Meng9140aec2018-08-22 14:49:57 -07006138 /**
chen xu907e5a22018-10-11 13:21:04 -07006139 * Get the current modem radio state for the given slot.
6140 * @param slotIndex slot index.
6141 * @param callingPackage the name of the package making the call.
6142 * @return the current radio power state from the modem
6143 */
6144 @Override
6145 public int getRadioPowerState(int slotIndex, String callingPackage) {
6146 Phone phone = PhoneFactory.getPhone(slotIndex);
6147 if (phone != null) {
6148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6149 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6150 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6151 }
6152
6153 final long identity = Binder.clearCallingIdentity();
6154 try {
6155 return phone.getRadioPowerState();
6156 } finally {
6157 Binder.restoreCallingIdentity(identity);
6158 }
6159 }
6160 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6161 }
6162
6163 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006164 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6165 *
6166 * <p>Requires one of the following permissions:
6167 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6168 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6169 * privileges.
6170 *
6171 * @param subId subscription id
6172 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6173 * {@code false}.
6174 */
6175 @Override
6176 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006177 boolean isEnabled = false;
6178 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006179 try {
6180 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07006181 null /* message */);
6182 Phone phone = getPhone(subId);
6183 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006184 } catch (Exception e) {
6185 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6186 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006187 } finally {
6188 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006189 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006190 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006191 }
6192
6193
6194 /**
6195 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6196 *
6197 * <p> Requires permission:
6198 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6199 * privileges.
6200 *
6201 * @param subId subscription id
6202 * @param isEnabled {@code true} means enable, {@code false} means disable.
6203 */
6204 @Override
6205 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006206 final long identity = Binder.clearCallingIdentity();
6207 try {
6208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6209 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07006210
Pengquan Meng0c05b502018-09-06 09:59:22 -07006211 Phone phone = getPhone(subId);
6212 if (phone != null) {
6213 phone.setDataRoamingEnabled(isEnabled);
6214 }
6215 } finally {
6216 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006217 }
6218 }
6219
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006220 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006221 public boolean isManualNetworkSelectionAllowed(int subId) {
6222 boolean isAllowed = true;
6223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6226 mApp, subId, "isManualNetworkSelectionAllowed");
6227 Phone phone = getPhone(subId);
6228 if (phone != null) {
6229 isAllowed = phone.isCspPlmnEnabled();
6230 }
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
6234 return isAllowed;
6235 }
6236
6237 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006238 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006239 try {
6240 enforceReadPrivilegedPermission("getUiccCardsInfo");
6241 } catch (SecurityException e) {
6242 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6243 // has carrier privileges on an active UICC
6244 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6245 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6246 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6247 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006248 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006249
6250 final long identity = Binder.clearCallingIdentity();
6251 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006252 UiccController uiccController = UiccController.getInstance();
6253 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6254
6255 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6256 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6257 // Remove private info if the caller doesn't have access
6258 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6259 for (UiccCardInfo cardInfo : cardInfos) {
6260 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6261 UiccProfile profile = card.getUiccProfile();
6262 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6263 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6264 filteredInfos.add(cardInfo.getUnprivileged());
6265 } else {
6266 filteredInfos.add(cardInfo);
6267 }
6268 }
6269 return filteredInfos;
6270 }
6271 return cardInfos;
6272 } catch (PackageManager.NameNotFoundException e) {
6273 // This should not happen since we pass the package info in from TelephonyManager
6274 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006275 } finally {
6276 Binder.restoreCallingIdentity(identity);
6277 }
6278 }
6279
6280 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006281 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006282 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006283
Malcolm Chend965c8b2018-02-28 15:00:40 -08006284 final long identity = Binder.clearCallingIdentity();
6285 try {
6286 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6287 if (slots == null) {
6288 Rlog.i(LOG_TAG, "slots is null.");
6289 return null;
6290 }
6291
6292 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6293 for (int i = 0; i < slots.length; i++) {
6294 UiccSlot slot = slots[i];
6295 if (slot == null) {
6296 continue;
6297 }
6298
6299 String cardId;
6300 UiccCard card = slot.getUiccCard();
6301 if (card != null) {
6302 cardId = card.getCardId();
6303 } else {
6304 cardId = slot.getIccId();
6305 }
6306
6307 int cardState = 0;
6308 switch (slot.getCardState()) {
6309 case CARDSTATE_ABSENT:
6310 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6311 break;
6312 case CARDSTATE_PRESENT:
6313 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6314 break;
6315 case CARDSTATE_ERROR:
6316 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6317 break;
6318 case CARDSTATE_RESTRICTED:
6319 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6320 break;
6321 default:
6322 break;
6323
6324 }
6325
6326 infos[i] = new UiccSlotInfo(
6327 slot.isActive(),
6328 slot.isEuicc(),
6329 cardId,
6330 cardState,
6331 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006332 slot.isExtendedApduSupported(),
6333 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006334 }
6335 return infos;
6336 } finally {
6337 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006338 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006339 }
6340
6341 @Override
6342 public boolean switchSlots(int[] physicalSlots) {
6343 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006344
6345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
6350 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006351 }
Jack Yu4c988042018-02-27 15:30:01 -08006352
6353 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006354 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 return UiccController.getInstance().getCardIdForDefaultEuicc();
6358 } finally {
6359 Binder.restoreCallingIdentity(identity);
6360 }
6361 }
6362
6363 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006364 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6365 enforceModifyPermission();
6366 final Phone phone = getPhone(subId);
6367 if (phone == null) {
6368 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6369 return;
6370 }
6371
Malcolm Chend965c8b2018-02-28 15:00:40 -08006372 final long identity = Binder.clearCallingIdentity();
6373 try {
6374 phone.setRadioIndicationUpdateMode(filters, mode);
6375 } finally {
6376 Binder.restoreCallingIdentity(identity);
6377 }
Jack Yu4c988042018-02-27 15:30:01 -08006378 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006379
6380 /**
goneil47ffb6e2018-04-06 15:40:58 -07006381 * A test API to reload the UICC profile.
6382 *
6383 * <p>Requires that the calling app has permission
6384 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6385 * @hide
6386 */
6387 @Override
6388 public void refreshUiccProfile(int subId) {
6389 enforceModifyPermission();
6390
6391 final long identity = Binder.clearCallingIdentity();
6392 try {
6393 Phone phone = getPhone(subId);
6394 if (phone == null) {
6395 return;
6396 }
6397 UiccCard uiccCard = phone.getUiccCard();
6398 if (uiccCard == null) {
6399 return;
6400 }
6401 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6402 if (uiccProfile == null) {
6403 return;
6404 }
6405 uiccProfile.refresh();
6406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
6409 }
6410
6411 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006412 * Returns false if the mobile data is disabled by default, otherwise return true.
6413 */
6414 private boolean getDefaultDataEnabled() {
6415 return "true".equalsIgnoreCase(
6416 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6417 }
6418
6419 /**
6420 * Returns true if the data roaming is enabled by default, i.e the system property
6421 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6422 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6423 */
6424 private boolean getDefaultDataRoamingEnabled(int subId) {
6425 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006426 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006427 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6428 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6429 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6430 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6431 return isDataRoamingEnabled;
6432 }
6433
6434 /**
6435 * Returns the default network type for the given {@code subId}, if the default network type is
6436 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6437 */
6438 private int getDefaultNetworkType(int subId) {
6439 return Integer.parseInt(
6440 TelephonyManager.getTelephonyProperty(
6441 mSubscriptionController.getPhoneId(subId),
6442 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6443 String.valueOf(Phone.PREFERRED_NT_MODE)));
6444 }
fionaxua13278b2018-03-21 00:08:13 -07006445
6446 @Override
6447 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6448 gid1, String gid2, String plmn, String spn) {
6449 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006450
6451 final long identity = Binder.clearCallingIdentity();
6452 try {
6453 final Phone phone = getPhone(subId);
6454 if (phone == null) {
6455 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6456 return;
6457 }
6458 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6459 } finally {
6460 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006461 }
fionaxua13278b2018-03-21 00:08:13 -07006462 }
6463
6464 @Override
6465 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006466 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006467
6468 final long identity = Binder.clearCallingIdentity();
6469 try {
6470 final Phone phone = getPhone(subId);
6471 if (phone == null) {
6472 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6473 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6474 }
6475 return phone.getCarrierIdListVersion();
6476 } finally {
6477 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006478 }
fionaxua13278b2018-03-21 00:08:13 -07006479 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006480
6481 @Override
6482 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6484 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6485 return -1;
6486 }
6487
6488 final long identity = Binder.clearCallingIdentity();
6489 try {
6490 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6491 } finally {
6492 Binder.restoreCallingIdentity(identity);
6493 }
6494 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006495
6496 @Override
6497 public int getCdmaRoamingMode(int subId) {
6498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6499 mApp, subId, "getCdmaRoamingMode");
6500
6501 final long identity = Binder.clearCallingIdentity();
6502 try {
6503 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6504 } finally {
6505 Binder.restoreCallingIdentity(identity);
6506 }
6507 }
6508
6509 @Override
6510 public boolean setCdmaRoamingMode(int subId, int mode) {
6511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6512 mApp, subId, "setCdmaRoamingMode");
6513
6514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6517 } finally {
6518 Binder.restoreCallingIdentity(identity);
6519 }
6520 }
6521
6522 @Override
6523 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6525 mApp, subId, "setCdmaSubscriptionMode");
6526
6527 final long identity = Binder.clearCallingIdentity();
6528 try {
6529 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6530 } finally {
6531 Binder.restoreCallingIdentity(identity);
6532 }
6533 }
chen xu7ee67862018-10-30 22:27:10 -07006534
sqian2fff4a32018-11-05 14:18:37 -08006535 private void ensureUserRunning(int userId) {
6536 if (!mUserManager.isUserRunning(userId)) {
6537 throw new IllegalStateException("User " + userId + " does not exist or not running");
6538 }
6539 }
6540
6541 /**
6542 * Returns a list of SMS apps on a given user.
6543 *
6544 * Only the shell user (UID 2000 or 0) can call it.
6545 * Target user must be running.
6546 */
6547 @Override
6548 public String[] getSmsApps(int userId) {
6549 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6550 ensureUserRunning(userId);
6551
6552 final Collection<SmsApplicationData> apps =
6553 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6554
6555 String[] ret = new String[apps.size()];
6556 int i = 0;
6557 for (SmsApplicationData app : apps) {
6558 ret[i++] = app.mPackageName;
6559 }
6560 return ret;
6561 }
6562
6563 /**
6564 * Returns the default SMS app package name on a given user.
6565 *
6566 * Only the shell user (UID 2000 or 0) can call it.
6567 * Target user must be running.
6568 */
6569 @Override
6570 public String getDefaultSmsApp(int userId) {
6571 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6572 ensureUserRunning(userId);
6573
6574 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6575 /* updateIfNeeded= */ true, userId);
6576 return cn == null ? null : cn.getPackageName();
6577 }
6578
6579 /**
6580 * Set a package as the default SMS app on a given user.
6581 *
6582 * Only the shell user (UID 2000 or 0) can call it.
6583 * Target user must be running.
6584 */
6585 @Override
6586 public void setDefaultSmsApp(int userId, String packageName) {
6587 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6588 ensureUserRunning(userId);
6589
6590 boolean found = false;
6591 for (String pkg : getSmsApps(userId)) {
6592 if (TextUtils.equals(packageName, pkg)) {
6593 found = true;
6594 break;
6595 }
6596 }
6597 if (!found) {
6598 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6599 }
6600
6601 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6602 }
6603
chen xu7ee67862018-10-30 22:27:10 -07006604 @Override
sqian65eefe12019-02-22 15:55:18 -08006605 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006606 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006608 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006609 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6610 }
6611 final long identity = Binder.clearCallingIdentity();
6612 try {
sqian991b35e2018-12-12 16:48:18 -08006613 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6614 for (Phone phone: PhoneFactory.getPhones()) {
6615 if (phone.getEmergencyNumberTracker() != null
6616 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6617 emergencyNumberListInternal.put(
6618 phone.getSubId(),
6619 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6620 }
sqian03bca152018-12-05 18:48:28 -08006621 }
sqian991b35e2018-12-12 16:48:18 -08006622 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
sqian04b86072018-11-07 14:02:21 -08006626 }
6627
6628 @Override
sqian65eefe12019-02-22 15:55:18 -08006629 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006630 final Phone defaultPhone = getDefaultPhone();
6631 if (!exactMatch) {
6632 TelephonyPermissions
6633 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006634 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006635 }
6636 final long identity = Binder.clearCallingIdentity();
6637 try {
sqian991b35e2018-12-12 16:48:18 -08006638 for (Phone phone: PhoneFactory.getPhones()) {
6639 if (phone.getEmergencyNumberTracker() != null
6640 && phone.getEmergencyNumberTracker() != null) {
6641 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6642 number, exactMatch)) {
6643 return true;
sqian03bca152018-12-05 18:48:28 -08006644 }
6645 }
sqian03bca152018-12-05 18:48:28 -08006646 }
6647 return false;
6648 } finally {
6649 Binder.restoreCallingIdentity(identity);
6650 }
6651 }
6652
sqian9d4df8b2019-01-15 18:32:07 -08006653 /**
6654 * Update emergency number list for test mode.
6655 */
6656 @Override
6657 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6658 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6659 "updateEmergencyNumberListTestMode");
6660
6661 final long identity = Binder.clearCallingIdentity();
6662 try {
6663 for (Phone phone: PhoneFactory.getPhones()) {
6664 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6665 if (tracker != null) {
6666 tracker.executeEmergencyNumberTestModeCommand(action, num);
6667 }
6668 }
6669 } finally {
6670 Binder.restoreCallingIdentity(identity);
6671 }
6672 }
6673
6674 /**
6675 * Get the full emergency number list for test mode.
6676 */
6677 @Override
6678 public List<String> getEmergencyNumberListTestMode() {
6679 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6680 "getEmergencyNumberListTestMode");
6681
6682 final long identity = Binder.clearCallingIdentity();
6683 try {
6684 Set<String> emergencyNumbers = new HashSet<>();
6685 for (Phone phone: PhoneFactory.getPhones()) {
6686 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6687 if (tracker != null) {
6688 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6689 emergencyNumbers.add(num.getNumber());
6690 }
6691 }
6692 }
6693 return new ArrayList<>(emergencyNumbers);
6694 } finally {
6695 Binder.restoreCallingIdentity(identity);
6696 }
6697 }
6698
sqian04b86072018-11-07 14:02:21 -08006699 @Override
chen xu7ee67862018-10-30 22:27:10 -07006700 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6701 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6702 Phone phone = getPhone(subId);
6703 if (phone == null) {
6704 return null;
6705 }
6706 final long identity = Binder.clearCallingIdentity();
6707 try {
6708 UiccProfile profile = UiccController.getInstance()
6709 .getUiccProfileForPhone(phone.getPhoneId());
6710 if (profile != null) {
6711 return profile.getCertsFromCarrierPrivilegeAccessRules();
6712 }
6713 } finally {
6714 Binder.restoreCallingIdentity(identity);
6715 }
6716 return null;
6717 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006718
6719 /**
6720 * Enable or disable a modem stack.
6721 */
6722 @Override
6723 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6724 enforceModifyPermission();
6725
6726 final long identity = Binder.clearCallingIdentity();
6727 try {
6728 Phone phone = PhoneFactory.getPhone(slotIndex);
6729 if (phone == null) {
6730 return false;
6731 } else {
6732 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6733 }
6734 } finally {
6735 Binder.restoreCallingIdentity(identity);
6736 }
6737 }
Micheled3107c52018-12-21 15:00:11 -08006738
6739 @Override
Michele2fb0f222019-03-19 14:58:42 -07006740 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006741 enforceModifyPermission();
6742
6743 final long identity = Binder.clearCallingIdentity();
6744 try {
6745 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006746 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006747 .commit();
6748 } finally {
6749 Binder.restoreCallingIdentity(identity);
6750 }
6751 }
6752
6753 @Override
Michele2fb0f222019-03-19 14:58:42 -07006754 @TelephonyManager.IsMultiSimSupportedResult
6755 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006757 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6758 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006759 }
Micheled3107c52018-12-21 15:00:11 -08006760
6761 final long identity = Binder.clearCallingIdentity();
6762 try {
Michele2fb0f222019-03-19 14:58:42 -07006763 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006764 } finally {
6765 Binder.restoreCallingIdentity(identity);
6766 }
6767 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006768
Michele2fb0f222019-03-19 14:58:42 -07006769 @TelephonyManager.IsMultiSimSupportedResult
6770 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006771 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6772 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6773 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006774 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6775 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006776 }
6777 // Check if the hardware supports multisim functionality. If usage of multisim is not
6778 // supported by the modem, indicate that it is restricted.
6779 PhoneCapability staticCapability =
6780 mPhoneConfigurationManager.getStaticPhoneCapability();
6781 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006782 loge("isMultiSimSupportedInternal: no static configuration available");
6783 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006784 }
6785 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006786 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6787 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006788 }
6789 // Check if support of multiple SIMs is restricted by carrier
6790 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006791 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006792 }
6793
Michele2fb0f222019-03-19 14:58:42 -07006794 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006795 }
6796
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006797 /**
6798 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006799 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6800 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6801 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006802 * @param numOfSims number of active sims we want to switch to
6803 */
6804 @Override
6805 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006806 if (numOfSims == 1) {
6807 enforceModifyPermission();
6808 } else {
6809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6810 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6811 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006812 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006813
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006814 try {
Michele30b57b22019-03-01 12:01:14 -08006815 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006816 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006817 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6818 return;
6819 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006820 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6821 } finally {
6822 Binder.restoreCallingIdentity(identity);
6823 }
6824 }
6825
6826 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006827 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006828 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006829 */
6830 @Override
6831 public boolean isRebootRequiredForModemConfigChange() {
6832 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6833 final long identity = Binder.clearCallingIdentity();
6834 try {
6835 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6836 } finally {
6837 Binder.restoreCallingIdentity(identity);
6838 }
6839 }
6840
Pengquan Meng92d253b2019-02-06 11:12:53 -08006841 private void updateModemStateMetrics() {
6842 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6843 // TODO: check the state for each modem if the api is ready.
6844 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6845 }
6846
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006847 @Override
6848 public int[] getSlotsMapping() {
6849 enforceReadPrivilegedPermission("getSlotsMapping");
6850
6851 final long identity = Binder.clearCallingIdentity();
6852 try {
6853 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6854 // All logical slots should have a mapping to a physical slot.
6855 int[] logicalSlotsMapping = new int[phoneCount];
6856 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6857 for (int i = 0; i < slotInfos.length; i++) {
6858 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6859 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6860 }
6861 }
6862 return logicalSlotsMapping;
6863 } finally {
6864 Binder.restoreCallingIdentity(identity);
6865 }
6866 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006867
6868 /**
6869 * Get the IRadio HAL Version
6870 */
6871 @Override
6872 public int getRadioHalVersion() {
6873 Phone phone = getDefaultPhone();
6874 if (phone == null) return -1;
6875 HalVersion hv = phone.getHalVersion();
6876 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6877 return hv.major * 100 + hv.minor;
6878 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006879}