blob: 02738c2dfbe9d7c1acee53adcbc7c753d03d50c8 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080038import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Bundle;
40import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Looper;
43import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070045import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080046import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070047import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070049import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070050import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070052import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070053import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070054import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080055import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080060import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070062import android.telephony.CellInfoGsm;
63import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070064import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070066import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070067import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080068import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070069import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080070import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070071import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080072import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070073import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070074import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080076import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070077import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080078import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080079import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070080import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070081import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080082import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000083import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070084import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070085import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070086import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080087import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080088import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070089import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080090import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070091import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080092import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070093import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080094import android.telephony.ims.aidl.IImsMmTelFeature;
95import android.telephony.ims.aidl.IImsRcsFeature;
96import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070097import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080098import android.telephony.ims.feature.MmTelFeature;
99import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800100import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800102import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800104import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800105import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800106
Brad Ebinger4c460712018-10-01 10:40:55 -0700107import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700108import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800109import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700110import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700111import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700112import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800113import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700114import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700115import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800117import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800118import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800120import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700121import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100122import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700123import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700124import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700126import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800127import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700128import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700129import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700130import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700131import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700132import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700133import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800134import com.android.internal.telephony.SmsApplication;
135import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800136import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800137import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800138import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700139import com.android.internal.telephony.euicc.EuiccConnector;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800140import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.uicc.IccIoResult;
142import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800143import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700144import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800145import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700146import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800147import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000148import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700149import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800150import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700151import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800152import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700153import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700154import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800155
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700156import java.io.FileDescriptor;
157import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800158import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800160import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800161import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800162import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800163import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800164import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100165import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800166import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800167import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168
169/**
170 * Implementation of the ITelephony interface.
171 */
Santos Cordon117fee72014-05-16 17:56:12 -0700172public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173 private static final String LOG_TAG = "PhoneInterfaceManager";
174 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
175 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800176 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177
178 // Message codes used with mMainThreadHandler
179 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700180 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
181 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182 private static final int CMD_OPEN_CHANNEL = 9;
183 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
184 private static final int CMD_CLOSE_CHANNEL = 11;
185 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800186 private static final int CMD_NV_READ_ITEM = 13;
187 private static final int EVENT_NV_READ_ITEM_DONE = 14;
188 private static final int CMD_NV_WRITE_ITEM = 15;
189 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
190 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
191 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700192 private static final int CMD_RESET_MODEM_CONFIG = 19;
193 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800194 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
195 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
196 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
197 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800198 private static final int CMD_SEND_ENVELOPE = 25;
199 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000200 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
201 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700202 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
203 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
204 private static final int CMD_EXCHANGE_SIM_IO = 31;
205 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800206 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
207 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700208 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
209 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700210 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
211 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700212 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
213 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
214 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
215 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700216 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
217 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
218 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
219 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700220 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800221 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
222 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000223 private static final int CMD_SWITCH_SLOTS = 50;
224 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700225 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
226 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
227 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
228 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
229 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
230 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
231 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
232 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700233 private static final int CMD_GET_ALL_CELL_INFO = 60;
234 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
235 private static final int CMD_GET_CELL_LOCATION = 62;
236 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700237 private static final int CMD_MODEM_REBOOT = 64;
238 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700239 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
240 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800241 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
242 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800244 // Parameters of select command.
245 private static final int SELECT_COMMAND = 0xA4;
246 private static final int SELECT_P1 = 0x04;
247 private static final int SELECT_P2 = 0;
248 private static final int SELECT_P3 = 0x10;
249
Pengquan Meng85728fb2018-03-12 16:31:21 -0700250 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
251 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
252 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
253
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254 /** The singleton instance. */
255 private static PhoneInterfaceManager sInstance;
256
Wink Saville3ab207e2014-11-20 13:07:20 -0800257 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800258 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700259 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800260 private AppOpsManager mAppOps;
261 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800262 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800263 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700264 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
Derek Tan97ebb422014-09-05 16:55:38 -0700266 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
267 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800268 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800269 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700270
Micheled3107c52018-12-21 15:00:11 -0800271 // String to store multi SIM allowed
272 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
273
Derek Tan740e1672017-06-27 14:56:27 -0700274 // The AID of ISD-R.
275 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
276
yinxub1bed742017-04-17 11:45:04 -0700277 private NetworkScanRequestTracker mNetworkScanRequestTracker;
278
David Kelly5e06a7f2018-03-12 14:10:59 +0000279 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
280 private static final int MANUFACTURER_CODE_LENGTH = 8;
281
Derek Tan89e89d42014-07-08 17:00:10 -0700282 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700283 * A request object to use for transmitting data to an ICC.
284 */
285 private static final class IccAPDUArgument {
286 public int channel, cla, command, p1, p2, p3;
287 public String data;
288
289 public IccAPDUArgument(int channel, int cla, int command,
290 int p1, int p2, int p3, String data) {
291 this.channel = channel;
292 this.cla = cla;
293 this.command = command;
294 this.p1 = p1;
295 this.p2 = p2;
296 this.p3 = p3;
297 this.data = data;
298 }
299 }
300
301 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700302 * A request object to use for transmitting data to an ICC.
303 */
304 private static final class ManualNetworkSelectionArgument {
305 public OperatorInfo operatorInfo;
306 public boolean persistSelection;
307
308 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
309 this.operatorInfo = operatorInfo;
310 this.persistSelection = persistSelection;
311 }
312 }
313
314 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
316 * request after sending. The main thread will notify the request when it is complete.
317 */
318 private static final class MainThreadRequest {
319 /** The argument to use for the request */
320 public Object argument;
321 /** The result of the request that is run on the main thread */
322 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800323 // The subscriber id that this request applies to. Defaults to
324 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
325 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700326
Nathan Harold92bed182018-10-12 18:16:49 -0700327 // In cases where subId is unavailable, the caller needs to specify the phone.
328 public Phone phone;
329
vagdevie435a3e2018-08-15 16:01:53 -0700330 public WorkSource workSource;
331
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 public MainThreadRequest(Object argument) {
333 this.argument = argument;
334 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800335
Nathan Harold92bed182018-10-12 18:16:49 -0700336 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
337 this.argument = argument;
338 if (phone != null) {
339 this.phone = phone;
340 }
341 this.workSource = workSource;
342 }
343
vagdevie435a3e2018-08-15 16:01:53 -0700344 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800345 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800346 if (subId != null) {
347 this.subId = subId;
348 }
vagdevie435a3e2018-08-15 16:01:53 -0700349 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 }
352
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800353 private static final class IncomingThirdPartyCallArgs {
354 public final ComponentName component;
355 public final String callId;
356 public final String callerDisplayName;
357
358 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
359 String callerDisplayName) {
360 this.component = component;
361 this.callId = callId;
362 this.callerDisplayName = callerDisplayName;
363 }
364 }
365
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 /**
367 * A handler that processes messages on the main thread in the phone process. Since many
368 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
369 * inbound binder threads to the main thread in the phone process. The Binder thread
370 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
371 * on, which will be notified when the operation completes and will contain the result of the
372 * request.
373 *
374 * <p>If a MainThreadRequest object is provided in the msg.obj field,
375 * note that request.result must be set to something non-null for the calling thread to
376 * unblock.
377 */
378 private final class MainThreadHandler extends Handler {
379 @Override
380 public void handleMessage(Message msg) {
381 MainThreadRequest request;
382 Message onCompleted;
383 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800384 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700385 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800386 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387
388 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700389 case CMD_HANDLE_USSD_REQUEST: {
390 request = (MainThreadRequest) msg.obj;
391 final Phone phone = getPhoneFromRequest(request);
392 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
393 String ussdRequest = ussdObject.first;
394 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700395
Pengquan Meng0c05b502018-09-06 09:59:22 -0700396 if (!isUssdApiAllowed(request.subId)) {
397 // Carrier does not support use of this API, return failure.
398 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
399 UssdResponse response = new UssdResponse(ussdRequest, null);
400 Bundle returnData = new Bundle();
401 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
402 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700403
Pengquan Meng0c05b502018-09-06 09:59:22 -0700404 request.result = true;
405 notifyRequester(request);
406 return;
407 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700408
Pengquan Meng0c05b502018-09-06 09:59:22 -0700409 try {
410 request.result = phone != null
411 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
412 } catch (CallStateException cse) {
413 request.result = false;
414 }
415 // Wake up the requesting thread
416 notifyRequester(request);
417 break;
pkanwar32d516d2016-10-14 19:37:38 -0700418 }
419
Yorke Lee716f67e2015-06-17 15:39:16 -0700420 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700422 final Phone phone = getPhoneFromRequest(request);
423 request.result = phone != null ?
424 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
425 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700427 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800434 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700435 if (uiccCard == null) {
436 loge("iccTransmitApduLogicalChannel: No UICC");
437 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700438 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
441 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700442 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 iccArgument.channel, iccArgument.cla, iccArgument.command,
444 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700446 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 break;
448
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 ar = (AsyncResult) msg.obj;
451 request = (MainThreadRequest) ar.userObj;
452 if (ar.exception == null && ar.result != null) {
453 request.result = ar.result;
454 } else {
455 request.result = new IccIoResult(0x6F, 0, (byte[])null);
456 if (ar.result == null) {
457 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800458 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800460 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 } else {
462 loge("iccTransmitApduLogicalChannel: Unknown exception");
463 }
464 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700465 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 break;
467
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
469 request = (MainThreadRequest) msg.obj;
470 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800471 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 if (uiccCard == null) {
473 loge("iccTransmitApduBasicChannel: No UICC");
474 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700475 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 } else {
477 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
478 request);
479 uiccCard.iccTransmitApduBasicChannel(
480 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
481 iccArgument.p3, iccArgument.data, onCompleted);
482 }
483 break;
484
485 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
486 ar = (AsyncResult) msg.obj;
487 request = (MainThreadRequest) ar.userObj;
488 if (ar.exception == null && ar.result != null) {
489 request.result = ar.result;
490 } else {
491 request.result = new IccIoResult(0x6F, 0, (byte[])null);
492 if (ar.result == null) {
493 loge("iccTransmitApduBasicChannel: Empty response");
494 } else if (ar.exception instanceof CommandException) {
495 loge("iccTransmitApduBasicChannel: CommandException: " +
496 ar.exception);
497 } else {
498 loge("iccTransmitApduBasicChannel: Unknown exception");
499 }
500 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700501 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 break;
503
504 case CMD_EXCHANGE_SIM_IO:
505 request = (MainThreadRequest) msg.obj;
506 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800507 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 if (uiccCard == null) {
509 loge("iccExchangeSimIO: No UICC");
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700511 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 } else {
513 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
514 request);
515 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
516 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
517 iccArgument.data, onCompleted);
518 }
519 break;
520
521 case EVENT_EXCHANGE_SIM_IO_DONE:
522 ar = (AsyncResult) msg.obj;
523 request = (MainThreadRequest) ar.userObj;
524 if (ar.exception == null && ar.result != null) {
525 request.result = ar.result;
526 } else {
527 request.result = new IccIoResult(0x6f, 0, (byte[])null);
528 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 break;
531
Derek Tan4d5e5c12014-02-04 11:54:58 -0800532 case CMD_SEND_ENVELOPE:
533 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700535 if (uiccCard == null) {
536 loge("sendEnvelopeWithStatus: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 } else {
540 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
541 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
542 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 break;
544
545 case EVENT_SEND_ENVELOPE_DONE:
546 ar = (AsyncResult) msg.obj;
547 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700548 if (ar.exception == null && ar.result != null) {
549 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
552 if (ar.result == null) {
553 loge("sendEnvelopeWithStatus: Empty response");
554 } else if (ar.exception instanceof CommandException) {
555 loge("sendEnvelopeWithStatus: CommandException: " +
556 ar.exception);
557 } else {
558 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
559 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700561 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800562 break;
563
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 case CMD_OPEN_CHANNEL:
565 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800566 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800567 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 if (uiccCard == null) {
569 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800570 request.result = new IccOpenLogicalChannelResponse(-1,
571 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700572 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700573 } else {
574 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800575 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
576 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 break;
579
580 case EVENT_OPEN_CHANNEL_DONE:
581 ar = (AsyncResult) msg.obj;
582 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 int[] result = (int[]) ar.result;
586 int channelId = result[0];
587 byte[] selectResponse = null;
588 if (result.length > 1) {
589 selectResponse = new byte[result.length - 1];
590 for (int i = 1; i < result.length; ++i) {
591 selectResponse[i - 1] = (byte) result[i];
592 }
593 }
594 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 if (ar.result == null) {
598 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 if (ar.exception != null) {
601 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
602 }
603
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700604 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700605 if (ar.exception instanceof CommandException) {
606 CommandException.Error error =
607 ((CommandException) (ar.exception)).getCommandError();
608 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700610 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 }
613 }
614 openChannelResp = new IccOpenLogicalChannelResponse(
615 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700617 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 break;
620
621 case CMD_CLOSE_CHANNEL:
622 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800623 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 if (uiccCard == null) {
625 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900626 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 } else {
629 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
630 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
631 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 break;
633
634 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800635 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
636 break;
637
638 case CMD_NV_READ_ITEM:
639 request = (MainThreadRequest) msg.obj;
640 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800641 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
642 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800643 break;
644
645 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800648 if (ar.exception == null && ar.result != null) {
649 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800651 request.result = "";
652 if (ar.result == null) {
653 loge("nvReadItem: Empty response");
654 } else if (ar.exception instanceof CommandException) {
655 loge("nvReadItem: CommandException: " +
656 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800658 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 }
660 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700661 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 break;
663
Jake Hambye994d462014-02-03 13:10:13 -0800664 case CMD_NV_WRITE_ITEM:
665 request = (MainThreadRequest) msg.obj;
666 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
667 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800668 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700669 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800670 break;
671
672 case EVENT_NV_WRITE_ITEM_DONE:
673 handleNullReturnEvent(msg, "nvWriteItem");
674 break;
675
676 case CMD_NV_WRITE_CDMA_PRL:
677 request = (MainThreadRequest) msg.obj;
678 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800679 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800680 break;
681
682 case EVENT_NV_WRITE_CDMA_PRL_DONE:
683 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
684 break;
685
chen xu1cc0abe2018-10-26 17:39:23 -0700686 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800687 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700688 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800689 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800690 break;
691
chen xu1cc0abe2018-10-26 17:39:23 -0700692 case EVENT_RESET_MODEM_CONFIG_DONE:
693 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800694 break;
695
Jake Hamby7c27be32014-03-03 13:25:59 -0800696 case CMD_GET_PREFERRED_NETWORK_TYPE:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700699 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 break;
701
702 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
703 ar = (AsyncResult) msg.obj;
704 request = (MainThreadRequest) ar.userObj;
705 if (ar.exception == null && ar.result != null) {
706 request.result = ar.result; // Integer
707 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800708 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800709 if (ar.result == null) {
710 loge("getPreferredNetworkType: Empty response");
711 } else if (ar.exception instanceof CommandException) {
712 loge("getPreferredNetworkType: CommandException: " +
713 ar.exception);
714 } else {
715 loge("getPreferredNetworkType: Unknown exception");
716 }
717 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700718 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800719 break;
720
721 case CMD_SET_PREFERRED_NETWORK_TYPE:
722 request = (MainThreadRequest) msg.obj;
723 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
724 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700725 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 break;
727
728 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
729 handleNullReturnEvent(msg, "setPreferredNetworkType");
730 break;
731
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000732 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
733 request = (MainThreadRequest)msg.obj;
734 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800735 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000736 break;
737
738 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
739 ar = (AsyncResult)msg.obj;
740 request = (MainThreadRequest)ar.userObj;
741 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700742 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000743 break;
744
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800745 case CMD_SET_VOICEMAIL_NUMBER:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
748 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800749 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
750 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800751 break;
752
753 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
754 handleNullReturnEvent(msg, "setVoicemailNumber");
755 break;
756
Stuart Scott54788802015-03-30 13:18:01 -0700757 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
758 request = (MainThreadRequest) msg.obj;
759 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
760 request);
761 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
762 break;
763
764 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
765 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
766 break;
767
Shishir Agrawal302c8692015-06-19 13:49:39 -0700768 case CMD_PERFORM_NETWORK_SCAN:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
771 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
772 break;
773
774 case EVENT_PERFORM_NETWORK_SCAN_DONE:
775 ar = (AsyncResult) msg.obj;
776 request = (MainThreadRequest) ar.userObj;
777 CellNetworkScanResult cellScanResult;
778 if (ar.exception == null && ar.result != null) {
779 cellScanResult = new CellNetworkScanResult(
780 CellNetworkScanResult.STATUS_SUCCESS,
781 (List<OperatorInfo>) ar.result);
782 } else {
783 if (ar.result == null) {
784 loge("getCellNetworkScanResults: Empty response");
785 }
786 if (ar.exception != null) {
787 loge("getCellNetworkScanResults: Exception: " + ar.exception);
788 }
789 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
790 if (ar.exception instanceof CommandException) {
791 CommandException.Error error =
792 ((CommandException) (ar.exception)).getCommandError();
793 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
794 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
795 } else if (error == CommandException.Error.GENERIC_FAILURE) {
796 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
797 }
798 }
799 cellScanResult = new CellNetworkScanResult(errorCode, null);
800 }
801 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700802 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700803 break;
804
805 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
806 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700807 ManualNetworkSelectionArgument selArg =
808 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700809 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
810 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700811 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
812 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700813 break;
814
815 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700816 ar = (AsyncResult) msg.obj;
817 request = (MainThreadRequest) ar.userObj;
818 if (ar.exception == null) {
819 request.result = true;
820 } else {
821 request.result = false;
822 loge("setNetworkSelectionModeManual " + ar.exception);
823 }
824 notifyRequester(request);
825 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700826 break;
827
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700828 case CMD_GET_MODEM_ACTIVITY_INFO:
829 request = (MainThreadRequest) msg.obj;
830 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800831 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700832 break;
833
834 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result;
839 } else {
840 if (ar.result == null) {
841 loge("queryModemActivityInfo: Empty response");
842 } else if (ar.exception instanceof CommandException) {
843 loge("queryModemActivityInfo: CommandException: " +
844 ar.exception);
845 } else {
846 loge("queryModemActivityInfo: Unknown exception");
847 }
848 }
Amit Mahajand4766222016-01-28 15:28:28 -0800849 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
850 if (request.result == null) {
851 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
852 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700853 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700854 break;
855
Meng Wang1a7c35a2016-05-05 20:56:15 -0700856 case CMD_SET_ALLOWED_CARRIERS:
857 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800858 CarrierRestrictionRules argument =
859 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700860 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800861 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700862 break;
863
864 case EVENT_SET_ALLOWED_CARRIERS_DONE:
865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
867 if (ar.exception == null && ar.result != null) {
868 request.result = ar.result;
869 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800870 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
871 if (ar.exception instanceof CommandException) {
872 loge("setAllowedCarriers: CommandException: " + ar.exception);
873 CommandException.Error error =
874 ((CommandException) (ar.exception)).getCommandError();
875 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
876 request.result =
877 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
878 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 } else {
880 loge("setAllowedCarriers: Unknown exception");
881 }
882 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700883 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 break;
885
886 case CMD_GET_ALLOWED_CARRIERS:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800889 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 break;
891
892 case EVENT_GET_ALLOWED_CARRIERS_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result;
897 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800898 request.result = new IllegalStateException(
899 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700900 if (ar.result == null) {
901 loge("getAllowedCarriers: Empty response");
902 } else if (ar.exception instanceof CommandException) {
903 loge("getAllowedCarriers: CommandException: " +
904 ar.exception);
905 } else {
906 loge("getAllowedCarriers: Unknown exception");
907 }
908 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700909 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 break;
911
Nathan Haroldb3014052017-01-25 15:57:32 -0800912 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
915 if (ar.exception == null && ar.result != null) {
916 request.result = ar.result;
917 } else {
918 request.result = new IllegalArgumentException(
919 "Failed to retrieve Forbidden Plmns");
920 if (ar.result == null) {
921 loge("getForbiddenPlmns: Empty response");
922 } else {
923 loge("getForbiddenPlmns: Unknown exception");
924 }
925 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700926 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800927 break;
928
929 case CMD_GET_FORBIDDEN_PLMNS:
930 request = (MainThreadRequest) msg.obj;
931 uiccCard = getUiccCardFromRequest(request);
932 if (uiccCard == null) {
933 loge("getForbiddenPlmns() UiccCard is null");
934 request.result = new IllegalArgumentException(
935 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700936 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800937 break;
938 }
939 Integer appType = (Integer) request.argument;
940 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
941 if (uiccApp == null) {
942 loge("getForbiddenPlmns() no app with specified type -- "
943 + appType);
944 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700945 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800946 break;
947 } else {
948 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
949 + " specified type -- " + appType);
950 }
951 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
952 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
953 onCompleted);
954 break;
955
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000956 case CMD_SWITCH_SLOTS:
957 request = (MainThreadRequest) msg.obj;
958 int[] physicalSlots = (int[]) request.argument;
959 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
960 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
961 break;
962
963 case EVENT_SWITCH_SLOTS_DONE:
964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
966 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700967 notifyRequester(request);
968 break;
969 case CMD_GET_NETWORK_SELECTION_MODE:
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
972 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
973 break;
974
975 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
976 ar = (AsyncResult) msg.obj;
977 request = (MainThreadRequest) ar.userObj;
978 if (ar.exception != null) {
979 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
980 } else {
981 int mode = ((int[]) ar.result)[0];
982 if (mode == 0) {
983 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
984 } else {
985 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
986 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000987 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700988 notifyRequester(request);
989 break;
990 case CMD_GET_CDMA_ROAMING_MODE:
991 request = (MainThreadRequest) msg.obj;
992 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
993 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
994 break;
995 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 if (ar.exception != null) {
999 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1000 } else {
1001 request.result = ((int[]) ar.result)[0];
1002 }
1003 notifyRequester(request);
1004 break;
1005 case CMD_SET_CDMA_ROAMING_MODE:
1006 request = (MainThreadRequest) msg.obj;
1007 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1008 int mode = (int) request.argument;
1009 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1010 break;
1011 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1012 ar = (AsyncResult) msg.obj;
1013 request = (MainThreadRequest) ar.userObj;
1014 request.result = ar.exception == null;
1015 notifyRequester(request);
1016 break;
1017 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1018 request = (MainThreadRequest) msg.obj;
1019 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1020 int subscriptionMode = (int) request.argument;
1021 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1022 break;
1023 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1024 ar = (AsyncResult) msg.obj;
1025 request = (MainThreadRequest) ar.userObj;
1026 request.result = ar.exception == null;
1027 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001028 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001029 case CMD_GET_ALL_CELL_INFO:
1030 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001031 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001032 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001033 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001034 case EVENT_GET_ALL_CELL_INFO_DONE:
1035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001037 // If a timeout occurs, the response will be null
1038 request.result = (ar.exception == null && ar.result != null)
1039 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001040 synchronized (request) {
1041 request.notifyAll();
1042 }
1043 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001044 case CMD_REQUEST_CELL_INFO_UPDATE:
1045 request = (MainThreadRequest) msg.obj;
1046 request.phone.requestCellInfoUpdate(request.workSource,
1047 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1048 break;
1049 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1050 ar = (AsyncResult) msg.obj;
1051 request = (MainThreadRequest) ar.userObj;
1052 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1053 try {
1054 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001055 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001056 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1057 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001058 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001059 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001060 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 } else {
1062 // use the result as returned
1063 cb.onCellInfo((List<CellInfo>) ar.result);
1064 }
1065 } catch (RemoteException re) {
1066 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1067 }
1068 break;
1069 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001070 request = (MainThreadRequest) msg.obj;
1071 WorkSource ws = (WorkSource) request.argument;
1072 Phone phone = getPhoneFromRequest(request);
1073 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1074 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001076 ar = (AsyncResult) msg.obj;
1077 request = (MainThreadRequest) ar.userObj;
1078 if (ar.exception == null) {
1079 request.result = ar.result;
1080 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001082 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1083 ? new CdmaCellLocation() : new GsmCellLocation();
1084 }
1085
1086 synchronized (request) {
1087 request.notifyAll();
1088 }
1089 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001090 case CMD_MODEM_REBOOT:
1091 request = (MainThreadRequest) msg.obj;
1092 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001093 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001094 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001095 case EVENT_CMD_MODEM_REBOOT_DONE:
1096 handleNullReturnEvent(msg, "rebootModem");
1097 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001098 case CMD_REQUEST_ENABLE_MODEM:
1099 request = (MainThreadRequest) msg.obj;
1100 boolean enable = (boolean) request.argument;
1101 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1102 PhoneConfigurationManager.getInstance()
1103 .enablePhone(request.phone, enable, onCompleted);
1104 break;
1105 case EVENT_ENABLE_MODEM_DONE:
1106 ar = (AsyncResult) msg.obj;
1107 request = (MainThreadRequest) ar.userObj;
1108 request.result = (ar.exception == null);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001109 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001110 notifyRequester(request);
1111 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001112 default:
1113 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1114 break;
1115 }
1116 }
Jake Hambye994d462014-02-03 13:10:13 -08001117
Pengquan Meng0c05b502018-09-06 09:59:22 -07001118 private void notifyRequester(MainThreadRequest request) {
1119 synchronized (request) {
1120 request.notifyAll();
1121 }
1122 }
1123
Jake Hambye994d462014-02-03 13:10:13 -08001124 private void handleNullReturnEvent(Message msg, String command) {
1125 AsyncResult ar = (AsyncResult) msg.obj;
1126 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1127 if (ar.exception == null) {
1128 request.result = true;
1129 } else {
1130 request.result = false;
1131 if (ar.exception instanceof CommandException) {
1132 loge(command + ": CommandException: " + ar.exception);
1133 } else {
1134 loge(command + ": Unknown exception");
1135 }
1136 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001137 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 }
1140
1141 /**
1142 * Posts the specified command to be executed on the main thread,
1143 * waits for the request to complete, and returns the result.
1144 * @see #sendRequestAsync
1145 */
1146 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001147 return sendRequest(
1148 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001149 }
1150
1151 /**
1152 * Posts the specified command to be executed on the main thread,
1153 * waits for the request to complete, and returns the result.
1154 * @see #sendRequestAsync
1155 */
1156 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1157 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001158 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001159 }
1160
1161 /**
1162 * Posts the specified command to be executed on the main thread,
1163 * waits for the request to complete, and returns the result.
1164 * @see #sendRequestAsync
1165 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001166 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001167 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -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 */
Nathan Harold92bed182018-10-12 18:16:49 -07001175 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1176 return sendRequest(command, argument, subId, null, workSource);
1177 }
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 */
1184 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1185 return sendRequest(
1186 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1187 }
1188
1189 /**
1190 * Posts the specified command to be executed on the main thread,
1191 * waits for the request to complete, and returns the result.
1192 * @see #sendRequestAsync
1193 */
1194 private Object sendRequest(
1195 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1197 throw new RuntimeException("This method will deadlock if called from the main thread.");
1198 }
1199
Nathan Harold92bed182018-10-12 18:16:49 -07001200 MainThreadRequest request = null;
1201 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1202 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1203 } else if (phone != null) {
1204 request = new MainThreadRequest(argument, phone, workSource);
1205 } else {
1206 request = new MainThreadRequest(argument, subId, workSource);
1207 }
1208
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001209 Message msg = mMainThreadHandler.obtainMessage(command, request);
1210 msg.sendToTarget();
1211
1212 // Wait for the request to complete
1213 synchronized (request) {
1214 while (request.result == null) {
1215 try {
1216 request.wait();
1217 } catch (InterruptedException e) {
1218 // Do nothing, go back and wait until the request is complete
1219 }
1220 }
1221 }
1222 return request.result;
1223 }
1224
1225 /**
1226 * Asynchronous ("fire and forget") version of sendRequest():
1227 * Posts the specified command to be executed on the main thread, and
1228 * returns immediately.
1229 * @see #sendRequest
1230 */
1231 private void sendRequestAsync(int command) {
1232 mMainThreadHandler.sendEmptyMessage(command);
1233 }
1234
1235 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001236 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001237 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001238 */
1239 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001240 sendRequestAsync(command, argument, null, null);
1241 }
1242
1243 /**
1244 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1245 * @see {@link #sendRequest(int,Object)}
1246 */
1247 private void sendRequestAsync(
1248 int command, Object argument, Phone phone, WorkSource workSource) {
1249 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001250 Message msg = mMainThreadHandler.obtainMessage(command, request);
1251 msg.sendToTarget();
1252 }
1253
1254 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 * Initialize the singleton PhoneInterfaceManager instance.
1256 * This is only done once, at startup, from PhoneApp.onCreate().
1257 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001258 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 synchronized (PhoneInterfaceManager.class) {
1260 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001261 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 } else {
1263 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1264 }
1265 return sInstance;
1266 }
1267 }
1268
1269 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001270 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001273 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1275 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001276 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001277 mTelephonySharedPreferences =
1278 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001279 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001280 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001281
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 publish();
1283 }
1284
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001285 private Phone getDefaultPhone() {
1286 Phone thePhone = getPhone(getDefaultSubscription());
1287 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1288 }
1289
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 private void publish() {
1291 if (DBG) log("publish: " + this);
1292
1293 ServiceManager.addService("phone", this);
1294 }
1295
Stuart Scott584921c2015-01-15 17:10:34 -08001296 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001297 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001298 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001299 }
1300
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001301 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1302 Phone phone = getPhoneFromRequest(request);
1303 return phone == null ? null :
1304 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1305 }
1306
Wink Saville36469e72014-06-11 15:17:00 -07001307 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001308 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001309 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311
1312 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001313 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Wink Savilleb564aae2014-10-23 10:18:09 -07001316 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 if (DBG) log("dial: " + number);
1318 // No permission check needed here: This is just a wrapper around the
1319 // ACTION_DIAL intent, which is available to any app since it puts up
1320 // the UI before it does anything.
1321
Malcolm Chend965c8b2018-02-28 15:00:40 -08001322 final long identity = Binder.clearCallingIdentity();
1323 try {
1324 String url = createTelUrl(number);
1325 if (url == null) {
1326 return;
1327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328
Malcolm Chend965c8b2018-02-28 15:00:40 -08001329 // PENDING: should we just silently fail if phone is offhook or ringing?
1330 PhoneConstants.State state = mCM.getState(subId);
1331 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1332 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1333 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1334 mApp.startActivity(intent);
1335 }
1336 } finally {
1337 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001338 }
1339 }
1340
1341 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001342 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001343 }
1344
Wink Savilleb564aae2014-10-23 10:18:09 -07001345 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001346 if (DBG) log("call: " + number);
1347
1348 // This is just a wrapper around the ACTION_CALL intent, but we still
1349 // need to do a permission check since we're calling startActivity()
1350 // from the context of the phone app.
1351 enforceCallPermission();
1352
1353 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1354 != AppOpsManager.MODE_ALLOWED) {
1355 return;
1356 }
1357
Malcolm Chend965c8b2018-02-28 15:00:40 -08001358 final long identity = Binder.clearCallingIdentity();
1359 try {
1360 String url = createTelUrl(number);
1361 if (url == null) {
1362 return;
1363 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364
Malcolm Chend965c8b2018-02-28 15:00:40 -08001365 boolean isValid = false;
1366 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1367 if (slist != null) {
1368 for (SubscriptionInfo subInfoRecord : slist) {
1369 if (subInfoRecord.getSubscriptionId() == subId) {
1370 isValid = true;
1371 break;
1372 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001373 }
Wink Saville08874612014-08-31 19:19:58 -07001374 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001375 if (!isValid) {
1376 return;
1377 }
Wink Saville08874612014-08-31 19:19:58 -07001378
Malcolm Chend965c8b2018-02-28 15:00:40 -08001379 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1380 intent.putExtra(SUBSCRIPTION_KEY, subId);
1381 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1382 mApp.startActivity(intent);
1383 } finally {
1384 Binder.restoreCallingIdentity(identity);
1385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 }
1387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001389 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001390 }
1391
Wink Savilleb564aae2014-10-23 10:18:09 -07001392 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001393 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001394 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1395 }
1396
1397 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001399 }
1400
Wink Savilleb564aae2014-10-23 10:18:09 -07001401 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001402 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001403 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1404 }
1405
1406 /** {@hide} */
1407 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001408 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001409 }
1410
Wink Savilleb564aae2014-10-23 10:18:09 -07001411 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001413
1414 final long identity = Binder.clearCallingIdentity();
1415 try {
1416 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1417 checkSimPin.start();
1418 return checkSimPin.unlockSim(null, pin);
1419 } finally {
1420 Binder.restoreCallingIdentity(identity);
1421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001422 }
1423
Wink Saville9de0f752013-10-22 19:04:03 -07001424 /** {@hide} */
1425 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001426 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001427 }
1428
Wink Savilleb564aae2014-10-23 10:18:09 -07001429 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001431
1432 final long identity = Binder.clearCallingIdentity();
1433 try {
1434 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1435 checkSimPuk.start();
1436 return checkSimPuk.unlockSim(puk, pin);
1437 } finally {
1438 Binder.restoreCallingIdentity(identity);
1439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 }
1441
1442 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001443 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001444 * a synchronous one.
1445 */
1446 private static class UnlockSim extends Thread {
1447
1448 private final IccCard mSimCard;
1449
1450 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001451 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1452 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453
1454 // For replies from SimCard interface
1455 private Handler mHandler;
1456
1457 // For async handler to identify request type
1458 private static final int SUPPLY_PIN_COMPLETE = 100;
1459
1460 public UnlockSim(IccCard simCard) {
1461 mSimCard = simCard;
1462 }
1463
1464 @Override
1465 public void run() {
1466 Looper.prepare();
1467 synchronized (UnlockSim.this) {
1468 mHandler = new Handler() {
1469 @Override
1470 public void handleMessage(Message msg) {
1471 AsyncResult ar = (AsyncResult) msg.obj;
1472 switch (msg.what) {
1473 case SUPPLY_PIN_COMPLETE:
1474 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1475 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001476 mRetryCount = msg.arg1;
1477 if (ar.exception != null) {
1478 if (ar.exception instanceof CommandException &&
1479 ((CommandException)(ar.exception)).getCommandError()
1480 == CommandException.Error.PASSWORD_INCORRECT) {
1481 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1482 } else {
1483 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1484 }
1485 } else {
1486 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 mDone = true;
1489 UnlockSim.this.notifyAll();
1490 }
1491 break;
1492 }
1493 }
1494 };
1495 UnlockSim.this.notifyAll();
1496 }
1497 Looper.loop();
1498 }
1499
1500 /*
1501 * Use PIN or PUK to unlock SIM card
1502 *
1503 * If PUK is null, unlock SIM card with PIN
1504 *
1505 * If PUK is not null, unlock SIM card with PUK and set PIN code
1506 */
Wink Saville9de0f752013-10-22 19:04:03 -07001507 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508
1509 while (mHandler == null) {
1510 try {
1511 wait();
1512 } catch (InterruptedException e) {
1513 Thread.currentThread().interrupt();
1514 }
1515 }
1516 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1517
1518 if (puk == null) {
1519 mSimCard.supplyPin(pin, callback);
1520 } else {
1521 mSimCard.supplyPuk(puk, pin, callback);
1522 }
1523
1524 while (!mDone) {
1525 try {
1526 Log.d(LOG_TAG, "wait for done");
1527 wait();
1528 } catch (InterruptedException e) {
1529 // Restore the interrupted status
1530 Thread.currentThread().interrupt();
1531 }
1532 }
1533 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001534 int[] resultArray = new int[2];
1535 resultArray[0] = mResult;
1536 resultArray[1] = mRetryCount;
1537 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001538 }
1539 }
1540
1541 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001542 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001543
1544 }
1545
Wink Savilleb564aae2014-10-23 10:18:09 -07001546 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 // No permission check needed here: this call is harmless, and it's
1548 // needed for the ServiceState.requestStateUpdate() call (which is
1549 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001550 final long identity = Binder.clearCallingIdentity();
1551 try {
1552 final Phone phone = getPhone(subId);
1553 if (phone != null) {
1554 phone.updateServiceLocation();
1555 }
1556 } finally {
1557 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 }
1560
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001561 @Override
1562 public boolean isRadioOn(String callingPackage) {
1563 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001564 }
1565
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001566 @Override
1567 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001569 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001570 return false;
1571 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001572
1573 final long identity = Binder.clearCallingIdentity();
1574 try {
1575 return isRadioOnForSubscriber(subId);
1576 } finally {
1577 Binder.restoreCallingIdentity(identity);
1578 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001579 }
1580
1581 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001582 final long identity = Binder.clearCallingIdentity();
1583 try {
1584 final Phone phone = getPhone(subId);
1585 if (phone != null) {
1586 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1587 } else {
1588 return false;
1589 }
1590 } finally {
1591 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 }
1594
1595 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001596 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 }
Wink Saville36469e72014-06-11 15:17:00 -07001598
Wink Savilleb564aae2014-10-23 10:18:09 -07001599 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001601
1602 final long identity = Binder.clearCallingIdentity();
1603 try {
1604 final Phone phone = getPhone(subId);
1605 if (phone != null) {
1606 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1607 }
1608 } finally {
1609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 }
Wink Saville36469e72014-06-11 15:17:00 -07001611 }
1612
1613 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001614 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001615 }
1616
Wink Savilleb564aae2014-10-23 10:18:09 -07001617 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001618 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001619
1620 final long identity = Binder.clearCallingIdentity();
1621 try {
1622 final Phone phone = getPhone(subId);
1623 if (phone == null) {
1624 return false;
1625 }
1626 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1627 toggleRadioOnOffForSubscriber(subId);
1628 }
1629 return true;
1630 } finally {
1631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 }
Wink Saville36469e72014-06-11 15:17:00 -07001634
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001635 public boolean needMobileRadioShutdown() {
1636 /*
1637 * If any of the Radios are available, it will need to be
1638 * shutdown. So return true if any Radio is available.
1639 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001640 final long identity = Binder.clearCallingIdentity();
1641 try {
1642 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1643 Phone phone = PhoneFactory.getPhone(i);
1644 if (phone != null && phone.isRadioAvailable()) return true;
1645 }
1646 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1647 return false;
1648 } finally {
1649 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001650 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001651 }
1652
Malcolm Chend965c8b2018-02-28 15:00:40 -08001653 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001654 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001655 enforceModifyPermission();
1656
1657 final long identity = Binder.clearCallingIdentity();
1658 try {
1659 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1660 logv("Shutting down Phone " + i);
1661 shutdownRadioUsingPhoneId(i);
1662 }
1663 } finally {
1664 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001665 }
1666 }
1667
1668 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001669 Phone phone = PhoneFactory.getPhone(phoneId);
1670 if (phone != null && phone.isRadioAvailable()) {
1671 phone.shutdownRadio();
1672 }
1673 }
1674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001676 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001677
1678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1681 if (defaultPhone != null) {
1682 defaultPhone.setRadioPower(turnOn);
1683 return true;
1684 } else {
1685 loge("There's no default phone.");
1686 return false;
1687 }
1688 } finally {
1689 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001690 }
Wink Saville36469e72014-06-11 15:17:00 -07001691 }
1692
Wink Savilleb564aae2014-10-23 10:18:09 -07001693 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001695
1696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 final Phone phone = getPhone(subId);
1699 if (phone != null) {
1700 phone.setRadioPower(turnOn);
1701 return true;
1702 } else {
1703 return false;
1704 }
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 }
1709
Wink Saville36469e72014-06-11 15:17:00 -07001710 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001711 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 public boolean enableDataConnectivity() {
1713 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001714
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 int subId = mSubscriptionController.getDefaultDataSubId();
1718 final Phone phone = getPhone(subId);
1719 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001720 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001721 return true;
1722 } else {
1723 return false;
1724 }
1725 } finally {
1726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 }
1729
Wink Saville36469e72014-06-11 15:17:00 -07001730 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001731 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 public boolean disableDataConnectivity() {
1733 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001734
1735 final long identity = Binder.clearCallingIdentity();
1736 try {
1737 int subId = mSubscriptionController.getDefaultDataSubId();
1738 final Phone phone = getPhone(subId);
1739 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001740 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001741 return true;
1742 } else {
1743 return false;
1744 }
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
1749
Sanket Padawe356d7632015-06-22 14:03:32 -07001750 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001751 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001752 final long identity = Binder.clearCallingIdentity();
1753 try {
1754 final Phone phone = getPhone(subId);
1755 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001756 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001757 } else {
1758 return false;
1759 }
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
1764
1765 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001766 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
1768
pkanwarae03a6b2016-11-06 20:37:09 -08001769 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001770 enforceCallPermission();
1771
1772 final long identity = Binder.clearCallingIdentity();
1773 try {
1774 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1775 return;
1776 }
1777 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1778 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1779 } finally {
1780 Binder.restoreCallingIdentity(identity);
1781 }
pkanwar32d516d2016-10-14 19:37:38 -07001782 };
1783
Wink Savilleb564aae2014-10-23 10:18:09 -07001784 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001786
1787 final long identity = Binder.clearCallingIdentity();
1788 try {
1789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1790 return false;
1791 }
1792 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1793 } finally {
1794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 }
1797
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001799 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001800 }
1801
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001802 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 Phone phone = PhoneFactory.getPhone(slotIndex);
1806 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1807 PhoneConstantConversions.convertCallState(phone.getState());
1808 } finally {
1809 Binder.restoreCallingIdentity(identity);
1810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
1812
Sanket Padawe356d7632015-06-22 14:03:32 -07001813 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1818 if (phone != null) {
1819 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1820 } else {
1821 return PhoneConstantConversions.convertDataState(
1822 PhoneConstants.DataState.DISCONNECTED);
1823 }
1824 } finally {
1825 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 }
1828
Sanket Padawe356d7632015-06-22 14:03:32 -07001829 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001831 final long identity = Binder.clearCallingIdentity();
1832 try {
1833 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1834 if (phone != null) {
1835 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1836 } else {
1837 return TelephonyManager.DATA_ACTIVITY_NONE;
1838 }
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 }
1843
1844 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001845 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001846 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001847 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001848
1849 LocationAccessPolicy.LocationPermissionResult locationResult =
1850 LocationAccessPolicy.checkLocationPermission(mApp,
1851 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1852 .setCallingPackage(callingPackage)
1853 .setCallingPid(Binder.getCallingPid())
1854 .setCallingUid(Binder.getCallingUid())
1855 .setMethod("getCellLocation")
1856 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1857 .build());
1858 switch (locationResult) {
1859 case DENIED_HARD:
1860 throw new SecurityException("Not allowed to access cell location");
1861 case DENIED_SOFT:
1862 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 }
1864
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001865 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001866 final long identity = Binder.clearCallingIdentity();
1867 try {
1868 if (DBG_LOC) log("getCellLocation: is active user");
1869 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001870 int subId = mSubscriptionController.getDefaultDataSubId();
1871 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1872 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001873 return data;
1874 } finally {
1875 Binder.restoreCallingIdentity(identity);
1876 }
Svetoslav64fad262015-04-14 14:35:21 -07001877 }
1878
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001880 public String getNetworkCountryIsoForPhone(int phoneId) {
1881 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1882 // registered cell info, so return a NULL country instead.
1883 final long identity = Binder.clearCallingIdentity();
1884 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001885 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1886 // Get default phone in this case.
1887 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1888 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001889 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001890 // Todo: fix this when we can get the actual cellular network info when the device
1891 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001892 if (TelephonyManager.NETWORK_TYPE_IWLAN
1893 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1894 return "";
1895 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001896 Phone phone = PhoneFactory.getPhone(phoneId);
1897 if (phone != null) {
1898 ServiceStateTracker sst = phone.getServiceStateTracker();
1899 if (sst != null) {
1900 LocaleTracker lt = sst.getLocaleTracker();
1901 if (lt != null) {
1902 return lt.getCurrentCountry();
1903 }
1904 }
1905 }
1906 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001907 } finally {
1908 Binder.restoreCallingIdentity(identity);
1909 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001910 }
1911
1912 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001914 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001915 }
1916
Sanket Padawe356d7632015-06-22 14:03:32 -07001917 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001918 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 mApp.enforceCallingOrSelfPermission(
1920 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001921
1922 final long identity = Binder.clearCallingIdentity();
1923 try {
1924 final Phone phone = getPhone(subId);
1925 if (phone != null) {
1926 phone.enableLocationUpdates();
1927 }
1928 } finally {
1929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 }
1932
1933 @Override
1934 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001935 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001936 }
1937
Sanket Padawe356d7632015-06-22 14:03:32 -07001938 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001939 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 mApp.enforceCallingOrSelfPermission(
1941 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001942
1943 final long identity = Binder.clearCallingIdentity();
1944 try {
1945 final Phone phone = getPhone(subId);
1946 if (phone != null) {
1947 phone.disableLocationUpdates();
1948 }
1949 } finally {
1950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
Nathan Harold31d7ff32018-10-15 20:20:30 -07001954 /**
1955 * Returns the target SDK version number for a given package name.
1956 *
1957 * @return target SDK if the package is found or INT_MAX.
1958 */
1959 private int getTargetSdk(String packageName) {
1960 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001961 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1962 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001963 if (ai != null) return ai.targetSdkVersion;
1964 } catch (PackageManager.NameNotFoundException unexpected) {
1965 }
1966 return Integer.MAX_VALUE;
1967 }
1968
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 @Override
1970 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001971 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1972 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001973 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1974 throw new SecurityException(
1975 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1976 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001977
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1979 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1980 return null;
1981 }
Svetoslav64fad262015-04-14 14:35:21 -07001982
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001983 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984
Nathan Haroldf180aac2018-06-01 18:43:55 -07001985 List<CellInfo> info = getAllCellInfo(callingPackage);
1986 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987
Nathan Haroldf180aac2018-06-01 18:43:55 -07001988 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1989 for (CellInfo ci : info) {
1990 if (ci instanceof CellInfoGsm) {
1991 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1992 } else if (ci instanceof CellInfoWcdma) {
1993 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001996 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001999 private List<CellInfo> getCachedCellInfo() {
2000 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2001 for (Phone phone : PhoneFactory.getPhones()) {
2002 List<CellInfo> info = phone.getAllCellInfo();
2003 if (info != null) cellInfos.addAll(info);
2004 }
2005 return cellInfos;
2006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007
2008 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002009 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002010 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002011 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002012
2013 LocationAccessPolicy.LocationPermissionResult locationResult =
2014 LocationAccessPolicy.checkLocationPermission(mApp,
2015 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2016 .setCallingPackage(callingPackage)
2017 .setCallingPid(Binder.getCallingPid())
2018 .setCallingUid(Binder.getCallingUid())
2019 .setMethod("getAllCellInfo")
2020 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2021 .build());
2022 switch (locationResult) {
2023 case DENIED_HARD:
2024 throw new SecurityException("Not allowed to access cell info");
2025 case DENIED_SOFT:
2026 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 }
2028
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002029 final int targetSdk = getTargetSdk(callingPackage);
2030 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2031 return getCachedCellInfo();
2032 }
2033
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002034 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002035 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002036 final long identity = Binder.clearCallingIdentity();
2037 try {
2038 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2039 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002040 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002041 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002042 if (info != null) cellInfos.addAll(info);
2043 }
2044 return cellInfos;
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 }
2048 }
2049
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002050 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002051 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2052 requestCellInfoUpdateInternal(
2053 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2054 }
2055
2056 @Override
2057 public void requestCellInfoUpdateWithWorkSource(
2058 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2059 enforceModifyPermission();
2060 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2061 }
2062
2063 private void requestCellInfoUpdateInternal(
2064 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002065 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002066 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002067
2068 LocationAccessPolicy.LocationPermissionResult locationResult =
2069 LocationAccessPolicy.checkLocationPermission(mApp,
2070 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2071 .setCallingPackage(callingPackage)
2072 .setCallingPid(Binder.getCallingPid())
2073 .setCallingUid(Binder.getCallingUid())
2074 .setMethod("requestCellInfoUpdate")
2075 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2076 .build());
2077 switch (locationResult) {
2078 case DENIED_HARD:
2079 throw new SecurityException("Not allowed to access cell info");
2080 case DENIED_SOFT:
2081 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002082 }
2083
2084 final Phone phone = getPhone(subId);
2085 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2086
2087 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2088 }
2089
2090 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002092 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002093 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002094
2095 final long identity = Binder.clearCallingIdentity();
2096 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002097 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002098 } finally {
2099 Binder.restoreCallingIdentity(identity);
2100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 }
2102
Shishir Agrawala9f32182016-04-12 12:00:16 -07002103 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002104 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002105 Phone phone = PhoneFactory.getPhone(slotIndex);
2106 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002107 return null;
2108 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002109 int subId = phone.getSubId();
2110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2111 mApp, subId, callingPackage, "getImeiForSlot")) {
2112 return null;
2113 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002114
2115 final long identity = Binder.clearCallingIdentity();
2116 try {
2117 return phone.getImei();
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002121 }
2122
2123 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002124 public String getTypeAllocationCodeForSlot(int slotIndex) {
2125 Phone phone = PhoneFactory.getPhone(slotIndex);
2126 String tac = null;
2127 if (phone != null) {
2128 String imei = phone.getImei();
2129 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2130 }
2131 return tac;
2132 }
2133
2134 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002135 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002136 Phone phone = PhoneFactory.getPhone(slotIndex);
2137 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002138 return null;
2139 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002140
Jeff Davidson913390f2018-02-23 17:11:49 -08002141 int subId = phone.getSubId();
2142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2143 mApp, subId, callingPackage, "getMeidForSlot")) {
2144 return null;
2145 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002146
2147 final long identity = Binder.clearCallingIdentity();
2148 try {
2149 return phone.getMeid();
2150 } finally {
2151 Binder.restoreCallingIdentity(identity);
2152 }
Jack Yu2af8d712017-03-15 17:14:14 -07002153 }
2154
2155 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002156 public String getManufacturerCodeForSlot(int slotIndex) {
2157 Phone phone = PhoneFactory.getPhone(slotIndex);
2158 String manufacturerCode = null;
2159 if (phone != null) {
2160 String meid = phone.getMeid();
2161 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2162 }
2163 return manufacturerCode;
2164 }
2165
2166 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002167 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002168 Phone phone = PhoneFactory.getPhone(slotIndex);
2169 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002170 return null;
2171 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002172 int subId = phone.getSubId();
2173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2174 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2175 return null;
2176 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002177
2178 final long identity = Binder.clearCallingIdentity();
2179 try {
2180 return phone.getDeviceSvn();
2181 } finally {
2182 Binder.restoreCallingIdentity(identity);
2183 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002184 }
2185
fionaxu43304da2017-11-27 22:51:16 -08002186 @Override
2187 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002188 final long identity = Binder.clearCallingIdentity();
2189 try {
2190 final Phone phone = getPhone(subId);
2191 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2192 } finally {
2193 Binder.restoreCallingIdentity(identity);
2194 }
fionaxu43304da2017-11-27 22:51:16 -08002195 }
2196
2197 @Override
2198 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002199 final long identity = Binder.clearCallingIdentity();
2200 try {
2201 final Phone phone = getPhone(subId);
2202 return phone == null ? null : phone.getCarrierName();
2203 } finally {
2204 Binder.restoreCallingIdentity(identity);
2205 }
fionaxu43304da2017-11-27 22:51:16 -08002206 }
2207
calvinpaneed9ae82018-11-01 19:43:06 +08002208 @Override
chen xuc93cc282018-11-04 17:17:00 -08002209 public int getSubscriptionPreciseCarrierId(int subId) {
2210 final long identity = Binder.clearCallingIdentity();
2211 try {
2212 final Phone phone = getPhone(subId);
2213 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2214 : phone.getPreciseCarrierId();
2215 } finally {
2216 Binder.restoreCallingIdentity(identity);
2217 }
2218 }
2219
2220 @Override
2221 public String getSubscriptionPreciseCarrierName(int subId) {
2222 final long identity = Binder.clearCallingIdentity();
2223 try {
2224 final Phone phone = getPhone(subId);
2225 return phone == null ? null : phone.getPreciseCarrierName();
2226 } finally {
2227 Binder.restoreCallingIdentity(identity);
2228 }
2229 }
2230
chen xu02581692018-11-11 19:03:44 -08002231 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002232 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2233 if (!isSubscriptionMccMnc) {
2234 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2235 }
chen xu02581692018-11-11 19:03:44 -08002236 final Phone phone = PhoneFactory.getPhone(slotIndex);
2237 if (phone == null) {
2238 return TelephonyManager.UNKNOWN_CARRIER_ID;
2239 }
2240 final long identity = Binder.clearCallingIdentity();
2241 try {
2242 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2243 } finally {
2244 Binder.restoreCallingIdentity(identity);
2245 }
2246 }
2247
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 //
2249 // Internal helper methods.
2250 //
2251
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002252 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2254 *
2255 * @throws SecurityException if the caller does not have the required permission
2256 */
2257 private void enforceModifyPermission() {
2258 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2259 }
2260
2261 /**
2262 * Make sure the caller has the CALL_PHONE permission.
2263 *
2264 * @throws SecurityException if the caller does not have the required permission
2265 */
2266 private void enforceCallPermission() {
2267 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2268 }
2269
Stuart Scott8eef64f2015-04-08 15:13:54 -07002270 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002271 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002272 "ConnectivityService");
2273 }
2274
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 private String createTelUrl(String number) {
2276 if (TextUtils.isEmpty(number)) {
2277 return null;
2278 }
2279
Jake Hambye994d462014-02-03 13:10:13 -08002280 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
Ihab Awadf9e92732013-12-05 18:02:52 -08002283 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2285 }
2286
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002287 private static void logv(String msg) {
2288 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2289 }
2290
Ihab Awadf9e92732013-12-05 18:02:52 -08002291 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2293 }
2294
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002295 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002297 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002298 }
2299
Sanket Padawe356d7632015-06-22 14:03:32 -07002300 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002301 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002302 final long identity = Binder.clearCallingIdentity();
2303 try {
2304 final Phone phone = PhoneFactory.getPhone(slotIndex);
2305 if (phone == null) {
2306 return PhoneConstants.PHONE_TYPE_NONE;
2307 } else {
2308 return phone.getPhoneType();
2309 }
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
2315 /**
2316 * Returns the CDMA ERI icon index to display
2317 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002318 @Override
2319 public int getCdmaEriIconIndex(String callingPackage) {
2320 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002321 }
2322
Sanket Padawe356d7632015-06-22 14:03:32 -07002323 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002324 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002326 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002327 return -1;
2328 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002329
2330 final long identity = Binder.clearCallingIdentity();
2331 try {
2332 final Phone phone = getPhone(subId);
2333 if (phone != null) {
2334 return phone.getCdmaEriIconIndex();
2335 } else {
2336 return -1;
2337 }
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 }
2342
2343 /**
2344 * Returns the CDMA ERI icon mode,
2345 * 0 - ON
2346 * 1 - FLASHING
2347 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002348 @Override
2349 public int getCdmaEriIconMode(String callingPackage) {
2350 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002351 }
2352
Sanket Padawe356d7632015-06-22 14:03:32 -07002353 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002354 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002356 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002357 return -1;
2358 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002359
2360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 final Phone phone = getPhone(subId);
2363 if (phone != null) {
2364 return phone.getCdmaEriIconMode();
2365 } else {
2366 return -1;
2367 }
2368 } finally {
2369 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
2373 /**
2374 * Returns the CDMA ERI text,
2375 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002376 @Override
2377 public String getCdmaEriText(String callingPackage) {
2378 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002379 }
2380
Sanket Padawe356d7632015-06-22 14:03:32 -07002381 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002382 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002384 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002385 return null;
2386 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 if (phone != null) {
2392 return phone.getCdmaEriText();
2393 } else {
2394 return null;
2395 }
2396 } finally {
2397 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 }
2400
2401 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002402 * Returns the CDMA MDN.
2403 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002404 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002405 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2407 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002408
2409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002412 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002413 return phone.getLine1Number();
2414 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002415 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002416 return null;
2417 }
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002420 }
2421 }
2422
2423 /**
2424 * Returns the CDMA MIN.
2425 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002426 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002427 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2429 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002430
2431 final long identity = Binder.clearCallingIdentity();
2432 try {
2433 final Phone phone = getPhone(subId);
2434 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2435 return phone.getCdmaMin();
2436 } else {
2437 return null;
2438 }
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002441 }
2442 }
2443
Hall Liud892bec2018-11-30 14:51:45 -08002444 @Override
2445 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2446 INumberVerificationCallback callback, String callingPackage) {
2447 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2448 != PERMISSION_GRANTED) {
2449 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2450 }
2451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2452
2453 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2454 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2455 throw new SecurityException("Calling package must be configured in the device config");
2456 }
2457
2458 if (range == null) {
2459 throw new NullPointerException("Range must be non-null");
2460 }
2461
2462 timeoutMillis = Math.min(timeoutMillis,
2463 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2464
2465 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2466 }
2467
Junda Liuca05d5d2014-08-14 22:36:34 -07002468 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 * Returns true if CDMA provisioning needs to run.
2470 */
2471 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002472 final long identity = Binder.clearCallingIdentity();
2473 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002474 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002475 } finally {
2476 Binder.restoreCallingIdentity(identity);
2477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 }
2479
2480 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002481 * Sets the voice mail number of a given subId.
2482 */
2483 @Override
2484 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002485 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002486
2487 final long identity = Binder.clearCallingIdentity();
2488 try {
2489 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2490 new Pair<String, String>(alphaTag, number), new Integer(subId));
2491 return success;
2492 } finally {
2493 Binder.restoreCallingIdentity(identity);
2494 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002495 }
2496
Ta-wei Yen87c49842016-05-13 21:19:52 -07002497 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002498 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002500 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002501 if (!TextUtils.equals(callingPackage, systemDialer)) {
2502 throw new SecurityException("caller must be system dialer");
2503 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002504
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2508 if (phoneAccountHandle == null) {
2509 return null;
2510 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002511 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002512 } finally {
2513 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002514 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002515 }
2516
2517 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002518 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002519 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002521 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002522 return null;
2523 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002524
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002525 final long identity = Binder.clearCallingIdentity();
2526 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002527 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002528 } finally {
2529 Binder.restoreCallingIdentity(identity);
2530 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002531 }
2532
2533 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002534 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2535 VisualVoicemailSmsFilterSettings settings) {
2536 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002537
2538 final long identity = Binder.clearCallingIdentity();
2539 try {
2540 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002541 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002545 }
2546
2547 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002548 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2549 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002550
2551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002554 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002555 } finally {
2556 Binder.restoreCallingIdentity(identity);
2557 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002558 }
2559
2560 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002561 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2562 String callingPackage, int subId) {
2563 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002568 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002569 } finally {
2570 Binder.restoreCallingIdentity(identity);
2571 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002572 }
2573
2574 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002575 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002576 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002577
2578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002581 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002582 } finally {
2583 Binder.restoreCallingIdentity(identity);
2584 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002585 }
2586
2587 @Override
2588 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2589 String number, int port, String text, PendingIntent sentIntent) {
2590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002591 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002592 enforceSendSmsPermission();
2593 // Make the calls as the phone process.
2594 final long identity = Binder.clearCallingIdentity();
2595 try {
2596 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2597 if (port == 0) {
2598 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2599 sentIntent, null, false);
2600 } else {
2601 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2602 smsManager.sendDataMessageWithSelfPermissions(number, null,
2603 (short) port, data, sentIntent, null);
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
2607 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002608 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002609 /**
fionaxu0152e512016-11-14 13:36:14 -08002610 * Sets the voice activation state of a given subId.
2611 */
2612 @Override
2613 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2615 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002616
2617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 final Phone phone = getPhone(subId);
2620 if (phone != null) {
2621 phone.setVoiceActivationState(activationState);
2622 } else {
2623 loge("setVoiceActivationState fails with invalid subId: " + subId);
2624 }
2625 } finally {
2626 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002627 }
2628 }
2629
2630 /**
2631 * Sets the data activation state of a given subId.
2632 */
2633 @Override
2634 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2636 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002637
2638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 final Phone phone = getPhone(subId);
2641 if (phone != null) {
2642 phone.setDataActivationState(activationState);
2643 } else {
2644 loge("setVoiceActivationState fails with invalid subId: " + subId);
2645 }
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002648 }
2649 }
2650
2651 /**
2652 * Returns the voice activation state of a given subId.
2653 */
2654 @Override
2655 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002656 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002657
fionaxu0152e512016-11-14 13:36:14 -08002658 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 if (phone != null) {
2662 return phone.getVoiceActivationState();
2663 } else {
2664 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2665 }
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002668 }
2669 }
2670
2671 /**
2672 * Returns the data activation state of a given subId.
2673 */
2674 @Override
2675 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002676 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002677
fionaxu0152e512016-11-14 13:36:14 -08002678 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 if (phone != null) {
2682 return phone.getDataActivationState();
2683 } else {
2684 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2685 }
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002688 }
2689 }
2690
2691 /**
Wink Saville36469e72014-06-11 15:17:00 -07002692 * Returns the unread count of voicemails for a subId
2693 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002695 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2697 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2698 return 0;
2699 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 final Phone phone = getPhone(subId);
2703 if (phone != null) {
2704 return phone.getVoiceMessageCount();
2705 } else {
2706 return 0;
2707 }
2708 } finally {
2709 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002710 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002711 }
2712
2713 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002714 * returns true, if the device is in a state where both voice and data
2715 * are supported simultaneously. This can change based on location or network condition.
2716 */
2717 @Override
2718 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 final Phone phone = getPhone(subId);
2722 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
2725 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002726 }
2727
2728 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002729 * Send the dialer code if called from the current default dialer or the caller has
2730 * carrier privilege.
2731 * @param inputCode The dialer code to send
2732 */
2733 @Override
2734 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002735 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002737 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2738 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002739 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002740 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2741 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002742 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002743
2744 final long identity = Binder.clearCallingIdentity();
2745 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002746 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002747 } finally {
2748 Binder.restoreCallingIdentity(identity);
2749 }
fionaxu235cc5e2017-03-06 22:25:57 -08002750 }
2751
2752 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002753 * Returns the data network type.
2754 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 *
2756 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2757 */
2758 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002759 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 final Phone phone = getPhone(getDefaultSubscription());
2763 if (phone != null) {
2764 return phone.getServiceState().getDataNetworkType();
2765 } else {
2766 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2767 }
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002770 }
Wink Saville36469e72014-06-11 15:17:00 -07002771 }
2772
Pengquan Meng0c05b502018-09-06 09:59:22 -07002773 @Override
2774 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002775 if (!isActiveSubscription(subId)) {
2776 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2777 }
2778
Pengquan Meng0c05b502018-09-06 09:59:22 -07002779 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2780 }
2781
Brad Ebinger4c460712018-10-01 10:40:55 -07002782 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002783 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2784 throws RemoteException {
2785 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002786 final long token = Binder.clearCallingIdentity();
2787 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002788 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002789 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002790 .addRegistrationCallbackForSubscription(c, subId);
2791 } finally {
2792 Binder.restoreCallingIdentity(token);
2793 }
2794 }
2795
2796 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002797 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2798 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002799 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2800 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2801 }
2802 Binder.withCleanCallingIdentity(() -> {
2803 try {
2804 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002805 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002806 .removeRegistrationCallbackForSubscription(c, subId);
2807 } catch (IllegalArgumentException e) {
2808 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2809 + "is inactive, ignoring unregister.");
2810 // If the subscription is no longer active, just return, since the callback
2811 // will already have been removed internally.
2812 }
2813 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002814 }
2815
2816 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002817 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2818 throws RemoteException {
2819 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002820 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2821 final long token = Binder.clearCallingIdentity();
2822 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002823 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002824 .addCapabilitiesCallbackForSubscription(c, subId);
2825 } finally {
2826 Binder.restoreCallingIdentity(token);
2827 }
2828 }
2829
2830 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002831 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2832 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002833
2834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2835 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2836 }
2837 Binder.withCleanCallingIdentity(() -> {
2838 try {
2839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002840 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002841 .removeCapabilitiesCallbackForSubscription(c, subId);
2842 } catch (IllegalArgumentException e) {
2843 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2844 + "is inactive, ignoring unregister.");
2845 // If the subscription is no longer active, just return, since the callback
2846 // will already have been removed internally.
2847 }
2848 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002849 }
2850
2851 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002852 public boolean isCapable(int subId, int capability, int regTech) {
2853 enforceReadPrivilegedPermission("isCapable");
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 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002858 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2859 } catch (ImsException e) {
2860 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2861 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002862 } catch (IllegalArgumentException e) {
2863 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2864 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002865 } finally {
2866 Binder.restoreCallingIdentity(token);
2867 }
2868 }
2869
2870 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002871 public boolean isAvailable(int subId, int capability, int regTech) {
2872 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002873 final long token = Binder.clearCallingIdentity();
2874 try {
2875 Phone phone = getPhone(subId);
2876 if (phone == null) return false;
2877 return phone.isImsCapabilityAvailable(capability, regTech);
2878 } finally {
2879 Binder.restoreCallingIdentity(token);
2880 }
2881 }
2882
2883 @Override
2884 public boolean isAdvancedCallingSettingEnabled(int subId) {
2885 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2886 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2887 final long token = Binder.clearCallingIdentity();
2888 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002889 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002890 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2891 } finally {
2892 Binder.restoreCallingIdentity(token);
2893 }
2894 }
2895
2896 @Override
2897 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2899 "setAdvancedCallingSetting");
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002903 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002904 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
2908 }
2909
2910 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002911 public boolean isVtSettingEnabled(int subId) {
2912 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002916 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002917 getSlotIndexOrException(subId)).isVtEnabledByUser();
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
2920 }
2921 }
2922
2923 @Override
2924 public void setVtSetting(int subId, boolean isEnabled) {
2925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2926 "setVtSetting");
2927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002930 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
2934 }
2935
2936 @Override
2937 public boolean isVoWiFiSettingEnabled(int subId) {
2938 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002942 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002943 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
2947 }
2948
2949 @Override
2950 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2952 "setVoWiFiSetting");
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002956 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002957 } finally {
2958 Binder.restoreCallingIdentity(identity);
2959 }
2960 }
2961
2962 @Override
2963 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2964 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002968 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002969 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
2972 }
2973 }
2974
2975 @Override
2976 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2978 "setVoWiFiRoamingSetting");
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002982 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002983 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
2987 }
2988
2989 @Override
2990 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2992 "setVoWiFiNonPersistent");
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002996 boolean isRoaming = TelephonyManager.from(
2997 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002998 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08002999 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
3003 }
3004
3005 @Override
3006 public int getVoWiFiModeSetting(int subId) {
3007 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003011 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003012 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
3015 }
3016 }
3017
3018 @Override
3019 public void setVoWiFiModeSetting(int subId, int mode) {
3020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3021 "setVoWiFiModeSetting");
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003025 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003026 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
3029 }
3030 }
3031
3032 @Override
3033 public int getVoWiFiRoamingModeSetting(int subId) {
3034 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003038 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003039 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3040 } finally {
3041 Binder.restoreCallingIdentity(identity);
3042 }
3043 }
3044
3045 @Override
3046 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3048 "setVoWiFiRoamingModeSetting");
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003052 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003053 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
3057 }
3058
3059 @Override
3060 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3062 "setRttCapabilityEnabled");
3063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003066 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003067 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
3071 }
3072
3073 @Override
3074 public boolean isTtyOverVolteEnabled(int subId) {
3075 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003079 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003080 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
3084 }
3085
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003086 @Override
3087 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3088 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003092 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003093 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003094 } finally {
3095 Binder.restoreCallingIdentity(identity);
3096 }
3097 }
3098
3099 @Override
3100 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3101 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3102 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003103 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3104 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3105 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003106 try {
3107 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003108 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003109 .removeProvisioningCallbackForSubscription(callback, subId);
3110 } catch (IllegalArgumentException e) {
3111 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3112 + "is inactive, ignoring unregister.");
3113 // If the subscription is no longer active, just return, since the callback will already
3114 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003115 } finally {
3116 Binder.restoreCallingIdentity(identity);
3117 }
3118 }
3119
3120 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003121 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3122 boolean isProvisioned) {
3123 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3124 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3125 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3126 }
3127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3128 "setProvisioningStatusForCapability");
3129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3132 Phone phone = getPhone(subId);
3133 if (phone == null) {
3134 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3135 + subId);
3136 return;
3137 }
3138 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3139 return;
3140 }
3141
3142 // this capability requires provisioning, route to the correct API.
3143 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3144 switch (capability) {
3145 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3146 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3147 ims.setVolteProvisioned(isProvisioned);
3148 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3149 ims.setWfcProvisioned(isProvisioned);
3150 }
3151 break;
3152 }
3153 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3154 // There is currently no difference in VT provisioning type.
3155 ims.setVtProvisioned(isProvisioned);
3156 break;
3157 }
3158 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3159 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3160 // change the capability of the feature instead if needed.
3161 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3162 == isProvisioned) {
3163 // No change in provisioning.
3164 return;
3165 }
3166 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3167 try {
3168 ims.changeMmTelCapability(capability, tech, isProvisioned);
3169 } catch (ImsException e) {
3170 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3171 + ", Exception" + e.getMessage());
3172 }
3173 break;
3174 }
3175 default: {
3176 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3177 + capability + "', which does not require provisioning.");
3178 }
3179 }
3180
3181 } finally {
3182 Binder.restoreCallingIdentity(identity);
3183 }
3184 }
3185
3186 @Override
3187 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3188 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3189 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3190 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3191 }
3192 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3196 Phone phone = getPhone(subId);
3197 if (phone == null) {
3198 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3199 + subId);
3200 // We will fail with "true" as the provisioning status because this is the default
3201 // if we do not require provisioning.
3202 return true;
3203 }
3204
3205 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3206 return true;
3207 }
3208
3209 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3210 switch (capability) {
3211 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3212 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3213 return ims.isVolteProvisionedOnDevice();
3214 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3215 return ims.isWfcProvisionedOnDevice();
3216 }
3217 // This should never happen, since we are checking tech above to make sure it
3218 // is either LTE or IWLAN.
3219 throw new IllegalArgumentException("Invalid radio technology for voice "
3220 + "capability.");
3221 }
3222 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3223 // There is currently no difference in VT provisioning type.
3224 return ims.isVtProvisionedOnDevice();
3225 }
3226 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3227 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3228 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3229 }
3230 default: {
3231 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3232 + capability + "', which does not require provisioning.");
3233 }
3234 }
3235
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
3239 }
3240
3241 @Override
3242 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3243 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3244 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3245 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3246 }
3247 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3248 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3249 return (provisionedBits & capability) > 0;
3250 }
3251
3252 @Override
3253 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3254 boolean isProvisioned) {
3255 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3256 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3257 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3258 }
3259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3260 "setProvisioningStatusForCapability");
3261 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3262 // If the current provisioning status for capability already matches isProvisioned,
3263 // do nothing.
3264 if (((provisionedBits & capability) > 0) == isProvisioned) {
3265 return;
3266 }
3267 if (isProvisioned) {
3268 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3269 } else {
3270 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3271 }
3272 }
3273
3274 /**
3275 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3276 * technology. The bitfield should mirror the bitfield defined by
3277 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3278 */
3279 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3280 String key = getMmTelProvisioningKey(subId, tech);
3281 // Default is no capabilities are provisioned.
3282 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3283 }
3284
3285 /**
3286 * Sets the MmTel capability provisioning bitfield (defined by
3287 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3288 * technology specified.
3289 *
3290 * Note: This is a synchronous command and should not be called on UI thread.
3291 */
3292 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3293 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3294 String key = getMmTelProvisioningKey(subId, tech);
3295 editor.putInt(key, newField);
3296 editor.commit();
3297 }
3298
3299 private static String getMmTelProvisioningKey(int subId, int tech) {
3300 // resulting key is provision_ims_mmtel_{subId}_{tech}
3301 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3302 }
3303
3304 /**
3305 * Query CarrierConfig to see if the specified capability requires provisioning for the
3306 * carrier associated with the subscription id.
3307 */
3308 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3309 int capability) {
3310 CarrierConfigManager configManager = new CarrierConfigManager(context);
3311 PersistableBundle c = configManager.getConfigForSubId(subId);
3312 boolean requireUtProvisioning = c.getBoolean(
3313 // By default, this config is true (even if there is no SIM). We also check to make
3314 // sure the subscription needs provisioning here, so we do not need to check for
3315 // the no-SIM case, where we would normally shortcut this to false.
3316 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3317 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3318 false);
3319 boolean requireVoiceVtProvisioning = c.getBoolean(
3320 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3321
3322 // First check to make sure that the capability requires provisioning.
3323 switch (capability) {
3324 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3325 // intentional fallthrough
3326 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3327 if (requireVoiceVtProvisioning) {
3328 // Voice and Video requires provisioning
3329 return true;
3330 }
3331 break;
3332 }
3333 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3334 if (requireUtProvisioning) {
3335 // UT requires provisioning
3336 return true;
3337 }
3338 break;
3339 }
3340 }
3341 return false;
3342 }
3343
3344 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003345 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003346 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3347 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3348 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003349 enforceReadPrivilegedPermission("getImsProvisioningInt");
3350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003353 int slotId = getSlotIndex(subId);
3354 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3355 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3356 + subId + "' for key:" + key);
3357 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3358 }
3359 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003360 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003361 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3362 + subId + "' for key:" + key);
3363 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003364 } finally {
3365 Binder.restoreCallingIdentity(identity);
3366 }
3367 }
3368
3369 @Override
3370 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003371 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3372 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3373 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003374 enforceReadPrivilegedPermission("getImsProvisioningString");
3375 final long identity = Binder.clearCallingIdentity();
3376 try {
3377 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003378 int slotId = getSlotIndex(subId);
3379 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3380 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3381 + subId + "' for key:" + key);
3382 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3383 }
3384 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003385 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003386 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3387 + subId + "' for key:" + key);
3388 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003389 } finally {
3390 Binder.restoreCallingIdentity(identity);
3391 }
3392 }
3393
3394 @Override
3395 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003396 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3397 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3398 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3400 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003404 int slotId = getSlotIndex(subId);
3405 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3406 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3407 + subId + "' for key:" + key);
3408 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3409 }
3410 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003411 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003412 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3413 + "' for key:" + key);
3414 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
3418 }
3419
3420 @Override
3421 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003422 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3423 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3424 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3426 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003430 int slotId = getSlotIndex(subId);
3431 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3432 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3433 + subId + "' for key:" + key);
3434 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3435 }
3436 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003437 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003438 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3439 + "' for key:" + key);
3440 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003441 } finally {
3442 Binder.restoreCallingIdentity(identity);
3443 }
3444 }
3445
Brad Ebinger4c460712018-10-01 10:40:55 -07003446 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3447 int slotId = SubscriptionManager.getSlotIndex(subId);
3448 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003449 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003450 }
3451 return slotId;
3452 }
3453
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003454 private int getSlotIndex(int subId) {
3455 int slotId = SubscriptionManager.getSlotIndex(subId);
3456 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3457 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3458 }
3459 return slotId;
3460 }
3461
Wink Saville36469e72014-06-11 15:17:00 -07003462 /**
3463 * Returns the network type for a subId
3464 */
3465 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003466 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003468 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003469 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3470 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003471
Malcolm Chend965c8b2018-02-28 15:00:40 -08003472 final long identity = Binder.clearCallingIdentity();
3473 try {
3474 final Phone phone = getPhone(subId);
3475 if (phone != null) {
3476 return phone.getServiceState().getDataNetworkType();
3477 } else {
3478 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3479 }
3480 } finally {
3481 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483 }
3484
3485 /**
3486 * Returns the data network type
3487 */
3488 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003489 public int getDataNetworkType(String callingPackage) {
3490 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003491 }
3492
3493 /**
3494 * Returns the data network type for a subId
3495 */
3496 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003497 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003499 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003500 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3501 }
3502
Malcolm Chend965c8b2018-02-28 15:00:40 -08003503 final long identity = Binder.clearCallingIdentity();
3504 try {
3505 final Phone phone = getPhone(subId);
3506 if (phone != null) {
3507 return phone.getServiceState().getDataNetworkType();
3508 } else {
3509 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3510 }
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003514 }
3515
3516 /**
Wink Saville36469e72014-06-11 15:17:00 -07003517 * Returns the Voice network type for a subId
3518 */
3519 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003520 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003522 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003523 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3524 }
3525
Malcolm Chend965c8b2018-02-28 15:00:40 -08003526 final long identity = Binder.clearCallingIdentity();
3527 try {
3528 final Phone phone = getPhone(subId);
3529 if (phone != null) {
3530 return phone.getServiceState().getVoiceNetworkType();
3531 } else {
3532 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3533 }
3534 } finally {
3535 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003536 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003537 }
3538
3539 /**
3540 * @return true if a ICC card is present
3541 */
3542 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003543 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003544 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3545 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003546 }
3547
3548 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003549 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003550 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003551 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003552 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 final Phone phone = PhoneFactory.getPhone(slotIndex);
3556 if (phone != null) {
3557 return phone.getIccCard().hasIccCard();
3558 } else {
3559 return false;
3560 }
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003564 }
3565
3566 /**
3567 * Return if the current radio is LTE on CDMA. This
3568 * is a tri-state return value as for a period of time
3569 * the mode may be unknown.
3570 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003571 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003572 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003573 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003575 @Override
3576 public int getLteOnCdmaMode(String callingPackage) {
3577 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003578 }
3579
Sanket Padawe356d7632015-06-22 14:03:32 -07003580 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003581 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003583 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003584 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3585 }
3586
Malcolm Chend965c8b2018-02-28 15:00:40 -08003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 final Phone phone = getPhone(subId);
3590 if (phone == null) {
3591 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3592 } else {
3593 return phone.getLteOnCdmaMode();
3594 }
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003597 }
Wink Saville36469e72014-06-11 15:17:00 -07003598 }
3599
Wink Saville36469e72014-06-11 15:17:00 -07003600 /**
3601 * {@hide}
3602 * Returns Default subId, 0 in the case of single standby.
3603 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003604 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003605 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003606 }
3607
Shishir Agrawala9f32182016-04-12 12:00:16 -07003608 private int getSlotForDefaultSubscription() {
3609 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3610 }
3611
Wink Savilleb564aae2014-10-23 10:18:09 -07003612 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003613 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003614 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003615
Pengquan Meng466e2482018-09-21 15:54:48 -07003616 private boolean isActiveSubscription(int subId) {
3617 return mSubscriptionController.isActiveSubId(subId);
3618 }
3619
Ihab Awadf2177b72013-11-25 13:33:23 -08003620 /**
3621 * @see android.telephony.TelephonyManager.WifiCallingChoices
3622 */
3623 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003624 final long identity = Binder.clearCallingIdentity();
3625 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003626 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003627 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3628 getWhenToMakeWifiCallsDefaultPreference());
3629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003632 }
3633
3634 /**
3635 * @see android.telephony.TelephonyManager.WifiCallingChoices
3636 */
3637 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003641 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003642 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003646 }
3647
Sailesh Nepald1e68152013-12-12 19:08:02 -08003648 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003649 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003650 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003651 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003652
Shishir Agrawal566b7612013-10-28 14:41:00 -07003653 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003654 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3655 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3657 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003659
Malcolm Chend965c8b2018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 if (TextUtils.equals(ISDR_AID, aid)) {
3663 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003664 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3665 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003666 if (bestComponent == null
3667 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3668 loge("The calling package is not allowed to access ISD-R.");
3669 throw new SecurityException(
3670 "The calling package is not allowed to access ISD-R.");
3671 }
Derek Tan740e1672017-06-27 14:56:27 -07003672 }
Derek Tan740e1672017-06-27 14:56:27 -07003673
Malcolm Chend965c8b2018-02-28 15:00:40 -08003674 if (DBG) {
3675 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3676 }
3677 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3678 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3679 if (DBG) log("iccOpenLogicalChannel: " + response);
3680 return response;
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
3683 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003684 }
3685
3686 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003687 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3689 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003690
Malcolm Chend965c8b2018-02-28 15:00:40 -08003691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3694 if (channel < 0) {
3695 return false;
3696 }
3697 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3698 if (DBG) log("iccCloseLogicalChannel: " + success);
3699 return success;
3700 } finally {
3701 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003702 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003703 }
3704
3705 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003706 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003707 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3709 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003710
Malcolm Chend965c8b2018-02-28 15:00:40 -08003711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 if (DBG) {
3714 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3715 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3716 + p3 + " data=" + data);
3717 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003718
Malcolm Chend965c8b2018-02-28 15:00:40 -08003719 if (channel < 0) {
3720 return "";
3721 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003722
Malcolm Chend965c8b2018-02-28 15:00:40 -08003723 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3724 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3725 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003726
Malcolm Chend965c8b2018-02-28 15:00:40 -08003727 // Append the returned status code to the end of the response payload.
3728 String s = Integer.toHexString(
3729 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3730 if (response.payload != null) {
3731 s = IccUtils.bytesToHexString(response.payload) + s;
3732 }
3733 return s;
3734 } finally {
3735 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003736 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003737 }
Jake Hambye994d462014-02-03 13:10:13 -08003738
Evan Charltonc66da362014-05-16 14:06:40 -07003739 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003740 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3741 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3743 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003744 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003745
Malcolm Chend965c8b2018-02-28 15:00:40 -08003746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3749 && TextUtils.equals(ISDR_AID, data)) {
3750 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003751 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3752 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003753 if (bestComponent == null
3754 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3755 loge("The calling package is not allowed to select ISD-R.");
3756 throw new SecurityException(
3757 "The calling package is not allowed to select ISD-R.");
3758 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003759 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003760
Malcolm Chend965c8b2018-02-28 15:00:40 -08003761 if (DBG) {
3762 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3763 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3764 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003765
Malcolm Chend965c8b2018-02-28 15:00:40 -08003766 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3767 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3768 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003769
Malcolm Chend965c8b2018-02-28 15:00:40 -08003770 // Append the returned status code to the end of the response payload.
3771 String s = Integer.toHexString(
3772 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3773 if (response.payload != null) {
3774 s = IccUtils.bytesToHexString(response.payload) + s;
3775 }
3776 return s;
3777 } finally {
3778 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003779 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003780 }
3781
3782 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003783 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003784 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3786 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003787
Malcolm Chend965c8b2018-02-28 15:00:40 -08003788 final long identity = Binder.clearCallingIdentity();
3789 try {
3790 if (DBG) {
3791 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3792 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3793 }
3794
3795 IccIoResult response =
3796 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3797 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3798 subId);
3799
3800 if (DBG) {
3801 log("Exchange SIM_IO [R]" + response);
3802 }
3803
3804 byte[] result = null;
3805 int length = 2;
3806 if (response.payload != null) {
3807 length = 2 + response.payload.length;
3808 result = new byte[length];
3809 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3810 } else {
3811 result = new byte[length];
3812 }
3813
3814 result[length - 1] = (byte) response.sw2;
3815 result[length - 2] = (byte) response.sw1;
3816 return result;
3817 } finally {
3818 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003819 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003820 }
3821
Nathan Haroldb3014052017-01-25 15:57:32 -08003822 /**
3823 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3824 * on a particular subscription
3825 */
sqianb6e41952018-03-12 14:54:01 -07003826 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3828 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3829 return null;
3830 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003831
3832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 if (appType != TelephonyManager.APPTYPE_USIM
3835 && appType != TelephonyManager.APPTYPE_SIM) {
3836 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3837 return null;
3838 }
3839 Object response = sendRequest(
3840 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3841 if (response instanceof String[]) {
3842 return (String[]) response;
3843 }
3844 // Response is an Exception of some kind,
3845 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003846 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003847 } finally {
3848 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003849 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003850 }
3851
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003852 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003853 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3855 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003856
Malcolm Chend965c8b2018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3860 if (response.payload == null) {
3861 return "";
3862 }
Evan Charltonc66da362014-05-16 14:06:40 -07003863
Malcolm Chend965c8b2018-02-28 15:00:40 -08003864 // Append the returned status code to the end of the response payload.
3865 String s = Integer.toHexString(
3866 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3867 s = IccUtils.bytesToHexString(response.payload) + s;
3868 return s;
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
3871 }
Evan Charltonc66da362014-05-16 14:06:40 -07003872 }
3873
Jake Hambye994d462014-02-03 13:10:13 -08003874 /**
3875 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3876 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3877 *
3878 * @param itemID the ID of the item to read
3879 * @return the NV item as a String, or null on error.
3880 */
3881 @Override
3882 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003883 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3885 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003886
3887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003890 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003891 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3892 return value;
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
3895 }
Jake Hambye994d462014-02-03 13:10:13 -08003896 }
3897
3898 /**
3899 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3900 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3901 *
3902 * @param itemID the ID of the item to read
3903 * @param itemValue the value to write, as a String
3904 * @return true on success; false on any failure
3905 */
3906 @Override
3907 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003908 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3910 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003911
3912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3915 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003916 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003917 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3918 return success;
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
3921 }
Jake Hambye994d462014-02-03 13:10:13 -08003922 }
3923
3924 /**
3925 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3926 * Used for device configuration by some CDMA operators.
3927 *
3928 * @param preferredRoamingList byte array containing the new PRL
3929 * @return true on success; false on any failure
3930 */
3931 @Override
3932 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3934 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003935
3936 final long identity = Binder.clearCallingIdentity();
3937 try {
3938 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3939 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3940 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3941 return success;
3942 } finally {
3943 Binder.restoreCallingIdentity(identity);
3944 }
Jake Hambye994d462014-02-03 13:10:13 -08003945 }
3946
3947 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003948 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003949 * Used for device configuration by some CDMA operators.
3950 *
chen xu1cc0abe2018-10-26 17:39:23 -07003951 * @param slotIndex - device slot.
3952 *
Jake Hambye994d462014-02-03 13:10:13 -08003953 * @return true on success; false on any failure
3954 */
3955 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003956 public boolean resetModemConfig(int slotIndex) {
3957 Phone phone = PhoneFactory.getPhone(slotIndex);
3958 if (phone != null) {
3959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3960 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003961
chen xu1cc0abe2018-10-26 17:39:23 -07003962 final long identity = Binder.clearCallingIdentity();
3963 try {
3964 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3965 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3966 return success;
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
3969 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003970 }
chen xu1cc0abe2018-10-26 17:39:23 -07003971 return false;
3972 }
3973
3974 /**
3975 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3976 *
3977 * @param slotIndex - device slot.
3978 *
3979 * @return true on success; false on any failure
3980 */
3981 @Override
3982 public boolean rebootModem(int slotIndex) {
3983 Phone phone = PhoneFactory.getPhone(slotIndex);
3984 if (phone != null) {
3985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3986 mApp, phone.getSubId(), "rebootModem");
3987
3988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3991 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3992 return success;
3993 } finally {
3994 Binder.restoreCallingIdentity(identity);
3995 }
3996 }
3997 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003998 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003999
Svet Ganovb320e182015-04-16 12:30:10 -07004000 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004001 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004003 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004004 return new String[0];
4005 }
4006
Malcolm Chend965c8b2018-02-28 15:00:40 -08004007 final long identity = Binder.clearCallingIdentity();
4008 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004009 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
Wink Saville36469e72014-06-11 15:17:00 -07004013 }
4014
Brad Ebinger51f743a2017-01-23 13:50:20 -08004015 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004016 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4017 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004018 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004019 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004020 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 PhoneFactory.getImsResolver().enableIms(slotId);
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004028 }
4029
4030 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004031 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4032 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004033 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004034 public void disableIms(int slotId) {
4035 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004036
4037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 PhoneFactory.getImsResolver().disableIms(slotId);
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004043 }
4044
4045 /**
4046 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4047 * feature or {@link null} if the service is not available. If the feature is available, the
4048 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4049 */
4050 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004051 IImsServiceFeatureCallback callback) {
4052 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004053
4054 final long identity = Binder.clearCallingIdentity();
4055 try {
4056 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004060 }
4061
4062 /**
4063 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4064 * feature during emergency calling or {@link null} if the service is not available. If the
4065 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4066 * listener for feature updates.
4067 */
4068 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4069 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004070
4071 final long identity = Binder.clearCallingIdentity();
4072 try {
4073 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004077 }
4078
Brad Ebinger5f64b052017-12-14 14:26:15 -08004079 /**
4080 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4081 * specified.
4082 */
4083 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4084 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004085
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
4091 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004092 }
4093
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004094 /**
4095 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4096 * specified.
4097 */
4098 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4099 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004100
4101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004107 }
4108
Brad Ebinger884c07b2018-02-15 16:17:40 -08004109 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004110 * Sets the ImsService Package Name that Telephony will bind to.
4111 *
4112 * @param slotId the slot ID that the ImsService should bind for.
4113 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4114 * ImsService is the device default ImsService.
4115 * @param packageName The package name of the application that contains the ImsService to bind
4116 * to.
4117 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4118 * @hide
4119 */
4120 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004121 int[] subIds = SubscriptionManager.getSubId(slotId);
4122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4123 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4124 "setImsService");
4125
Malcolm Chend965c8b2018-02-28 15:00:40 -08004126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4129 isCarrierImsService, packageName);
4130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004133 }
4134
4135 /**
4136 * Return the ImsService configuration.
4137 *
4138 * @param slotId The slot that the ImsService is associated with.
4139 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4140 * the device default.
4141 * @return the package name of the ImsService configuration.
4142 */
4143 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004144 int[] subIds = SubscriptionManager.getSubId(slotId);
4145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4146 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4147 "getImsService");
4148
Malcolm Chend965c8b2018-02-28 15:00:40 -08004149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4152 isCarrierImsService);
4153 } finally {
4154 Binder.restoreCallingIdentity(identity);
4155 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004156 }
4157
Wink Saville36469e72014-06-11 15:17:00 -07004158 public void setImsRegistrationState(boolean registered) {
4159 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004160
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004163 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
Wink Saville36469e72014-06-11 15:17:00 -07004167 }
4168
4169 /**
Stuart Scott54788802015-03-30 13:18:01 -07004170 * Set the network selection mode to automatic.
4171 *
4172 */
4173 @Override
4174 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4176 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004177
Pengquan Meng466e2482018-09-21 15:54:48 -07004178 if (!isActiveSubscription(subId)) {
4179 return;
4180 }
4181
Malcolm Chend965c8b2018-02-28 15:00:40 -08004182 final long identity = Binder.clearCallingIdentity();
4183 try {
4184 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4185 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
Stuart Scott54788802015-03-30 13:18:01 -07004189 }
4190
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004191 /**
4192 * Ask the radio to connect to the input network and change selection mode to manual.
4193 *
4194 * @param subId the id of the subscription.
4195 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4196 * the operator to attach to.
4197 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4198 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4199 * normal network selection next time.
4200 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004201 */
4202 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004203 public boolean setNetworkSelectionModeManual(
4204 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4206 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004207
4208 if (!isActiveSubscription(subId)) {
4209 return false;
4210 }
4211
Malcolm Chend965c8b2018-02-28 15:00:40 -08004212 final long identity = Binder.clearCallingIdentity();
4213 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004214 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004215 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004216 if (DBG) {
4217 log("setNetworkSelectionModeManual: subId: " + subId
4218 + " operator: " + operatorInfo);
4219 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004220 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
4223 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004224 }
4225
4226 /**
4227 * Scans for available networks.
4228 */
4229 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004230 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4232 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004233 LocationAccessPolicy.LocationPermissionResult locationResult =
4234 LocationAccessPolicy.checkLocationPermission(mApp,
4235 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4236 .setCallingPackage(callingPackage)
4237 .setCallingPid(Binder.getCallingPid())
4238 .setCallingUid(Binder.getCallingUid())
4239 .setMethod("getCellNetworkScanResults")
4240 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4241 .build());
4242 switch (locationResult) {
4243 case DENIED_HARD:
4244 throw new SecurityException("Not allowed to access scan results -- location");
4245 case DENIED_SOFT:
4246 return null;
4247 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004248
Pengquan Meng0c05b502018-09-06 09:59:22 -07004249 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004250 try {
4251 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004252 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004253 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004254 } finally {
4255 Binder.restoreCallingIdentity(identity);
4256 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004257 }
4258
4259 /**
yinxub1bed742017-04-17 11:45:04 -07004260 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004261 *
yinxub1bed742017-04-17 11:45:04 -07004262 * @param subId id of the subscription
4263 * @param request contains the radio access networks with bands/channels to scan
4264 * @param messenger callback messenger for scan results or errors
4265 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004266 * @return the id of the requested scan which can be used to stop the scan.
4267 */
4268 @Override
4269 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004270 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4272 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004273
Hall Liuf19c44f2018-11-27 14:38:17 -08004274 LocationAccessPolicy.LocationPermissionResult locationResult =
4275 LocationAccessPolicy.checkLocationPermission(mApp,
4276 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4277 .setCallingPackage(callingPackage)
4278 .setCallingPid(Binder.getCallingPid())
4279 .setCallingUid(Binder.getCallingUid())
4280 .setMethod("requestNetworkScan")
4281 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4282 .build());
4283 switch (locationResult) {
4284 case DENIED_HARD:
4285 throw new SecurityException("Not allowed to request network scan -- location");
4286 case DENIED_SOFT:
4287 return -1;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004288 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004289
4290 return mNetworkScanRequestTracker.startNetworkScan(
4291 request, messenger, binder, getPhone(subId),
4292 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004293 }
4294
4295 /**
4296 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004297 *
4298 * @param subId id of the subscription
4299 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004300 */
4301 @Override
4302 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4304 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004305
4306 final long identity = Binder.clearCallingIdentity();
4307 try {
4308 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4309 } finally {
4310 Binder.restoreCallingIdentity(identity);
4311 }
yinxu504e1392017-04-12 16:03:22 -07004312 }
4313
4314 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004315 * Get the calculated preferred network type.
4316 * Used for debugging incorrect network type.
4317 *
4318 * @return the preferred network type, defined in RILConstants.java.
4319 */
4320 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004321 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004322 final Phone defaultPhone = getDefaultPhone();
4323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4324 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004325 return RILConstants.PREFERRED_NETWORK_MODE;
4326 }
4327
Malcolm Chend965c8b2018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004331 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004332 } finally {
4333 Binder.restoreCallingIdentity(identity);
4334 }
Junda Liu84d15a22014-07-02 11:21:04 -07004335 }
4336
4337 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004338 * Get the preferred network type.
4339 * Used for device configuration by some CDMA operators.
4340 *
4341 * @return the preferred network type, defined in RILConstants.java.
4342 */
4343 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004344 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004345 TelephonyPermissions
4346 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4347 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004348
4349 final long identity = Binder.clearCallingIdentity();
4350 try {
4351 if (DBG) log("getPreferredNetworkType");
4352 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4353 int networkType = (result != null ? result[0] : -1);
4354 if (DBG) log("getPreferredNetworkType: " + networkType);
4355 return networkType;
4356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004359 }
4360
4361 /**
4362 * Set the preferred network type.
4363 * Used for device configuration by some CDMA operators.
4364 *
4365 * @param networkType the preferred network type, defined in RILConstants.java.
4366 * @return true on success; false on any failure.
4367 */
4368 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004369 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4371 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004372
4373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4376 Boolean success = (Boolean) sendRequest(
4377 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4378 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4379 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004380 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004381 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4382 }
4383 return success;
4384 } finally {
4385 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004386 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004387 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004388
4389 /**
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004390 * Check whether DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004391 *
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004392 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004393 * @hide
4394 */
4395 @Override
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004396 public boolean getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004397 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004398 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004399 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004400 try {
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004401 return defaultPhone.hasMatchedTetherApnSetting();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004402 } finally {
4403 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004404 }
Junda Liu475951f2014-11-07 16:45:03 -08004405 }
4406
4407 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004408 * Set mobile data enabled
4409 * Used by the user through settings etc to turn on/off mobile data
4410 *
4411 * @param enable {@code true} turn turn data on, else {@code false}
4412 */
4413 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004414 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4416 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004417
4418 final long identity = Binder.clearCallingIdentity();
4419 try {
4420 int phoneId = mSubscriptionController.getPhoneId(subId);
4421 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4422 Phone phone = PhoneFactory.getPhone(phoneId);
4423 if (phone != null) {
4424 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004425 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004426 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004427 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004428 }
4429 } finally {
4430 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004431 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004432 }
4433
4434 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004435 * Get the user enabled state of Mobile Data.
4436 *
4437 * TODO: remove and use isUserDataEnabled.
4438 * This can't be removed now because some vendor codes
4439 * calls through ITelephony directly while they should
4440 * use TelephonyManager.
4441 *
4442 * @return true on enabled
4443 */
4444 @Override
4445 public boolean getDataEnabled(int subId) {
4446 return isUserDataEnabled(subId);
4447 }
4448
4449 /**
4450 * Get whether mobile data is enabled per user setting.
4451 *
4452 * There are other factors deciding whether mobile data is actually enabled, but they are
4453 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004454 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004455 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004456 *
4457 * @return {@code true} if data is enabled else {@code false}
4458 */
4459 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004460 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004461 try {
4462 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4463 null);
4464 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4466 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004467 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004468
4469 final long identity = Binder.clearCallingIdentity();
4470 try {
4471 int phoneId = mSubscriptionController.getPhoneId(subId);
4472 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4473 Phone phone = PhoneFactory.getPhone(phoneId);
4474 if (phone != null) {
4475 boolean retVal = phone.isUserDataEnabled();
4476 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4477 return retVal;
4478 } else {
4479 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4480 return false;
4481 }
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004484 }
4485 }
4486
4487 /**
4488 * Get whether mobile data is enabled.
4489 *
4490 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4491 * whether mobile data is actually enabled.
4492 *
4493 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4494 *
4495 * @return {@code true} if data is enabled else {@code false}
4496 */
4497 @Override
4498 public boolean isDataEnabled(int subId) {
4499 try {
4500 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4501 null);
4502 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4504 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004505 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004506
4507 final long identity = Binder.clearCallingIdentity();
4508 try {
4509 int phoneId = mSubscriptionController.getPhoneId(subId);
4510 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4511 Phone phone = PhoneFactory.getPhone(phoneId);
4512 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004513 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004514 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4515 return retVal;
4516 } else {
4517 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4518 return false;
4519 }
4520 } finally {
4521 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004522 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004523 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004524
4525 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004526 public int getCarrierPrivilegeStatus(int subId) {
4527 final Phone phone = getPhone(subId);
4528 if (phone == null) {
4529 loge("getCarrierPrivilegeStatus: Invalid subId");
4530 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4531 }
4532 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004533 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004534 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004535 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4536 }
4537 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004538 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004539 }
Junda Liu29340342014-07-10 15:23:27 -07004540
4541 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004542 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4543 final Phone phone = getPhone(subId);
4544 if (phone == null) {
4545 loge("getCarrierPrivilegeStatus: Invalid subId");
4546 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4547 }
4548 UiccProfile profile =
4549 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4550 if (profile == null) {
4551 loge("getCarrierPrivilegeStatus: No UICC");
4552 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4553 }
4554 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4555 }
4556
4557 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004558 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004559 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004560 if (TextUtils.isEmpty(pkgName))
4561 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004562 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004563 if (card == null) {
4564 loge("checkCarrierPrivilegesForPackage: No UICC");
4565 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4566 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004567 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4568 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004569 }
4570
4571 @Override
4572 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004573 if (TextUtils.isEmpty(pkgName))
4574 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004575 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4576 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4577 UiccCard card = UiccController.getInstance().getUiccCard(i);
4578 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004579 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004580 continue;
4581 }
4582
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004583 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004584 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4585 break;
4586 }
4587 }
4588
4589 return result;
Junda Liu29340342014-07-10 15:23:27 -07004590 }
Derek Tan89e89d42014-07-08 17:00:10 -07004591
4592 @Override
Junda Liue64de782015-04-16 17:19:16 -07004593 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4594 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4595 loge("phoneId " + phoneId + " is not valid.");
4596 return null;
4597 }
4598 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004599 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004600 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004601 return null ;
4602 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004603 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004604 }
4605
Amith Yamasani6e118872016-02-19 12:53:51 -08004606 @Override
4607 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004608 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004609 List<String> privilegedPackages = new ArrayList<>();
4610 List<PackageInfo> packages = null;
4611 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4612 UiccCard card = UiccController.getInstance().getUiccCard(i);
4613 if (card == null) {
4614 // No UICC in that slot.
4615 continue;
4616 }
4617 if (card.hasCarrierPrivilegeRules()) {
4618 if (packages == null) {
4619 // Only check packages in user 0 for now
4620 packages = pm.getInstalledPackagesAsUser(
4621 PackageManager.MATCH_DISABLED_COMPONENTS
4622 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4623 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4624 }
4625 for (int p = packages.size() - 1; p >= 0; p--) {
4626 PackageInfo pkgInfo = packages.get(p);
4627 if (pkgInfo != null && pkgInfo.packageName != null
4628 && card.getCarrierPrivilegeStatus(pkgInfo)
4629 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4630 privilegedPackages.add(pkgInfo.packageName);
4631 }
4632 }
4633 }
4634 }
4635 return privilegedPackages;
4636 }
4637
Wink Savilleb564aae2014-10-23 10:18:09 -07004638 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004639 final Phone phone = getPhone(subId);
4640 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004641 if (card == null) {
4642 loge("getIccId: No UICC");
4643 return null;
4644 }
4645 String iccId = card.getIccId();
4646 if (TextUtils.isEmpty(iccId)) {
4647 loge("getIccId: ICC ID is null or empty.");
4648 return null;
4649 }
4650 return iccId;
4651 }
4652
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004653 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004654 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4655 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004656 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4657 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004658
Malcolm Chend965c8b2018-02-28 15:00:40 -08004659 final long identity = Binder.clearCallingIdentity();
4660 try {
4661 final String iccId = getIccId(subId);
4662 final Phone phone = getPhone(subId);
4663 if (phone == null) {
4664 return false;
4665 }
4666 final String subscriberId = phone.getSubscriberId();
4667
4668 if (DBG_MERGE) {
4669 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4670 + subscriberId + " to " + number);
4671 }
4672
4673 if (TextUtils.isEmpty(iccId)) {
4674 return false;
4675 }
4676
4677 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4678
4679 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4680 if (alphaTag == null) {
4681 editor.remove(alphaTagPrefKey);
4682 } else {
4683 editor.putString(alphaTagPrefKey, alphaTag);
4684 }
4685
4686 // Record both the line number and IMSI for this ICCID, since we need to
4687 // track all merged IMSIs based on line number
4688 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4689 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4690 if (number == null) {
4691 editor.remove(numberPrefKey);
4692 editor.remove(subscriberPrefKey);
4693 } else {
4694 editor.putString(numberPrefKey, number);
4695 editor.putString(subscriberPrefKey, subscriberId);
4696 }
4697
4698 editor.commit();
4699 return true;
4700 } finally {
4701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004702 }
Derek Tan7226c842014-07-02 17:42:23 -07004703 }
4704
4705 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004706 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004707 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004709 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004710 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004711 return null;
4712 }
Derek Tan97ebb422014-09-05 16:55:38 -07004713
Malcolm Chend965c8b2018-02-28 15:00:40 -08004714 final long identity = Binder.clearCallingIdentity();
4715 try {
4716 String iccId = getIccId(subId);
4717 if (iccId != null) {
4718 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4719 if (DBG_MERGE) {
4720 log("getLine1NumberForDisplay returning "
4721 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4722 }
4723 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004724 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004725 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4726 return null;
4727 } finally {
4728 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004729 }
Derek Tan7226c842014-07-02 17:42:23 -07004730 }
4731
4732 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004733 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004735 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004736 return null;
4737 }
Derek Tan97ebb422014-09-05 16:55:38 -07004738
Malcolm Chend965c8b2018-02-28 15:00:40 -08004739 final long identity = Binder.clearCallingIdentity();
4740 try {
4741 String iccId = getIccId(subId);
4742 if (iccId != null) {
4743 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4744 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4745 }
4746 return null;
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004749 }
Derek Tan7226c842014-07-02 17:42:23 -07004750 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004751
4752 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004753 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004754 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4755 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004757 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4758 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004759 return null;
4760 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004761
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004762 final long identity = Binder.clearCallingIdentity();
4763 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004764 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004765 final TelephonyManager tele = TelephonyManager.from(context);
4766 final SubscriptionManager sub = SubscriptionManager.from(context);
4767
4768 // Figure out what subscribers are currently active
4769 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4770 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4771 // the process, where TelephonyManager was instantiated.
4772 // Otherwise AppOps check will fail.
4773
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004774 final int[] subIds = sub.getActiveSubscriptionIdList();
4775 for (int subId : subIds) {
4776 activeSubscriberIds.add(tele.getSubscriberId(subId));
4777 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004778
4779 // First pass, find a number override for an active subscriber
4780 String mergeNumber = null;
4781 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4782 for (String key : prefs.keySet()) {
4783 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4784 final String subscriberId = (String) prefs.get(key);
4785 if (activeSubscriberIds.contains(subscriberId)) {
4786 final String iccId = key.substring(
4787 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4788 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4789 mergeNumber = (String) prefs.get(numberKey);
4790 if (DBG_MERGE) {
4791 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4792 + " for active subscriber " + subscriberId);
4793 }
4794 if (!TextUtils.isEmpty(mergeNumber)) {
4795 break;
4796 }
4797 }
4798 }
4799 }
4800
4801 // Shortcut when no active merged subscribers
4802 if (TextUtils.isEmpty(mergeNumber)) {
4803 return null;
4804 }
4805
4806 // Second pass, find all subscribers under that line override
4807 final ArraySet<String> result = new ArraySet<>();
4808 for (String key : prefs.keySet()) {
4809 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4810 final String number = (String) prefs.get(key);
4811 if (mergeNumber.equals(number)) {
4812 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4813 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4814 final String subscriberId = (String) prefs.get(subscriberKey);
4815 if (!TextUtils.isEmpty(subscriberId)) {
4816 result.add(subscriberId);
4817 }
4818 }
4819 }
4820 }
4821
4822 final String[] resultArray = result.toArray(new String[result.size()]);
4823 Arrays.sort(resultArray);
4824 if (DBG_MERGE) {
4825 Slog.d(LOG_TAG,
4826 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4827 }
4828 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004829 } finally {
4830 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004831 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004832 }
4833
4834 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004835 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004836 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4837 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004838
4839 final long identity = Binder.clearCallingIdentity();
4840 try {
4841 final Phone phone = getPhone(subId);
4842 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4843 } finally {
4844 Binder.restoreCallingIdentity(identity);
4845 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004846 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004847
4848 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004849 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004850 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4851 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004852 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004853
4854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 final Phone phone = getPhone(subId);
4857 if (phone == null) {
4858 return false;
4859 }
4860 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4861 cdmaNonRoamingList);
4862 } finally {
4863 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004864 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004865 }
4866
4867 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004868 @Deprecated
4869 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4870 enforceModifyPermission();
4871
4872 int returnValue = 0;
4873 try {
vagdevie435a3e2018-08-15 16:01:53 -07004874 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004875 if(result.exception == null) {
4876 if (result.result != null) {
4877 byte[] responseData = (byte[])(result.result);
4878 if(responseData.length > oemResp.length) {
4879 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4880 responseData.length + "bytes. Buffer Size is " +
4881 oemResp.length + "bytes.");
4882 }
4883 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4884 returnValue = responseData.length;
4885 }
4886 } else {
4887 CommandException ex = (CommandException) result.exception;
4888 returnValue = ex.getCommandError().ordinal();
4889 if(returnValue > 0) returnValue *= -1;
4890 }
4891 } catch (RuntimeException e) {
4892 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4893 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4894 if(returnValue > 0) returnValue *= -1;
4895 }
4896
4897 return returnValue;
4898 }
4899
4900 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004901 public void setRadioCapability(RadioAccessFamily[] rafs) {
4902 try {
4903 ProxyController.getInstance().setRadioCapability(rafs);
4904 } catch (RuntimeException e) {
4905 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4906 }
4907 }
4908
4909 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004910 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004911 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004912 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004913 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004914 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004915 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004916 final long identity = Binder.clearCallingIdentity();
4917 try {
chen xufeeed752018-10-26 14:17:57 -07004918 TelephonyPermissions
4919 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4920 mApp, phone.getSubId(), "getRadioAccessFamily");
4921 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
chen xufeeed752018-10-26 14:17:57 -07004925 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004926 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004927
4928 @Override
4929 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004930 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004931 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004932
4933 final long identity = Binder.clearCallingIdentity();
4934 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004935 ImsManager.getInstance(defaultPhone.getContext(),
4936 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004940 }
4941
4942 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004943 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004944 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004946 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004947 return false;
4948 }
Svet Ganovb320e182015-04-16 12:30:10 -07004949
Malcolm Chend965c8b2018-02-28 15:00:40 -08004950 final long identity = Binder.clearCallingIdentity();
4951 try {
4952 // Check the user preference and the system-level IMS setting. Even if the user has
4953 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4954 // In the long run, we may instead need to check if there exists a connection service
4955 // which can support video calling.
4956 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004957 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004958 return imsManager.isVtEnabledByPlatform()
4959 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4960 && imsManager.isVtEnabledByUser();
4961 } finally {
4962 Binder.restoreCallingIdentity(identity);
4963 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004964 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004965
Andrew Leea1239f22015-03-02 17:44:07 -08004966 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004967 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4968 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4969 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4970 return false;
4971 }
4972
4973 final long identity = Binder.clearCallingIdentity();
4974 try {
4975 CarrierConfigManager configManager =
4976 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004977 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004978 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4979 } finally {
4980 Binder.restoreCallingIdentity(identity);
4981 }
Andrew Leea1239f22015-03-02 17:44:07 -08004982 }
4983
4984 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004985 public boolean isWorldPhone(int subId, String callingPackage) {
4986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4987 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4988 return false;
4989 }
4990
4991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 CarrierConfigManager configManager =
4994 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004995 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004996 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
Andrew Leea1239f22015-03-02 17:44:07 -08005000 }
5001
Andrew Lee9431b832015-03-09 18:46:45 -07005002 @Override
5003 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005004 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005005 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005006 }
5007
5008 @Override
5009 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005010 final long identity = Binder.clearCallingIdentity();
5011 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005012 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
Andrew Lee9431b832015-03-09 18:46:45 -07005016 }
5017
Hall Liuf6668912018-10-31 17:05:23 -07005018 /**
5019 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5020 * support for the feature and device firmware support.
5021 *
5022 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5023 */
5024 @Override
5025 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005026 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005027 final Phone phone = getPhone(subscriptionId);
5028 if (phone == null) {
5029 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5030 return false;
5031 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005032 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005033 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005034 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5035 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005036 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005037 return isCarrierSupported && isDeviceSupported;
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
5040 }
Hall Liu98187582018-01-22 19:15:32 -08005041 }
5042
Hall Liuf6668912018-10-31 17:05:23 -07005043 /**
5044 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5045 * both also support RTT.
5046 */
5047 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005048 final long identity = Binder.clearCallingIdentity();
5049 try {
Hall Liuf6668912018-10-31 17:05:23 -07005050 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005051 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005052 } finally {
5053 Binder.restoreCallingIdentity(identity);
5054 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005055 }
5056
Sanket Padawe7310cc72015-01-14 09:53:20 -08005057 /**
5058 * Returns the unique device ID of phone, for example, the IMEI for
5059 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5060 *
5061 * <p>Requires Permission:
5062 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5063 */
5064 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005065 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005066 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005067 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005068 return null;
5069 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005070 int subId = phone.getSubId();
5071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5072 mApp, subId, callingPackage, "getDeviceId")) {
5073 return null;
5074 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005075
5076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 return phone.getDeviceId();
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005082 }
5083
Ping Sunc67b7c22016-03-02 19:16:45 +08005084 /**
5085 * {@hide}
5086 * Returns the IMS Registration Status on a particular subid
5087 *
5088 * @param subId
5089 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005090 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005091 Phone phone = getPhone(subId);
5092 if (phone != null) {
5093 return phone.isImsRegistered();
5094 } else {
5095 return false;
5096 }
5097 }
5098
Santos Cordon7a1885b2015-02-03 11:15:19 -08005099 @Override
5100 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005101 final long identity = Binder.clearCallingIdentity();
5102 try {
5103 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005107 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005108
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005109 /**
5110 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005111 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005112 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 Phone phone = getPhone(subId);
5116 if (phone != null) {
5117 return phone.isWifiCallingEnabled();
5118 } else {
5119 return false;
5120 }
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005123 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005124 }
5125
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005126 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005127 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005128 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005129 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005130 final long identity = Binder.clearCallingIdentity();
5131 try {
5132 Phone phone = getPhone(subId);
5133 if (phone != null) {
5134 return phone.isVideoEnabled();
5135 } else {
5136 return false;
5137 }
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005140 }
5141 }
5142
5143 /**
5144 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5145 * defined in {@link ImsRegistrationImplBase}.
5146 */
5147 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005148 final long identity = Binder.clearCallingIdentity();
5149 try {
5150 Phone phone = getPhone(subId);
5151 if (phone != null) {
5152 return phone.getImsRegistrationTech();
5153 } else {
5154 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5155 }
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005158 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005159 }
5160
Stuart Scott8eef64f2015-04-08 15:13:54 -07005161 @Override
5162 public void factoryReset(int subId) {
5163 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005164 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5165 return;
5166 }
5167
Svet Ganovcc087f82015-05-12 20:35:54 -07005168 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005169
Svet Ganovcc087f82015-05-12 20:35:54 -07005170 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005171 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5172 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005173 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005174 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005175 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005176 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5177 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005178 }
5179 } finally {
5180 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005181 }
5182 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005183
5184 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005185 public String getSimLocaleForSubscriber(int subId) {
5186 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5187 final Phone phone = getPhone(subId);
5188 if (phone == null) {
5189 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005190 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005191 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005192 final long identity = Binder.clearCallingIdentity();
5193 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005194 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5195 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005196 // Try and fetch the locale from the carrier properties or from the SIM language
5197 // preferences (EF-PL and EF-LI)...
5198 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005199 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005200 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5201 if (localeFromDefaultSim != null) {
5202 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5203 if (DBG) log("Using locale from subId: " + subId + " locale: "
5204 + localeFromDefaultSim);
5205 return localeFromDefaultSim.toLanguageTag();
5206 } else {
5207 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005208 }
5209 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005210
Malcolm Chend965c8b2018-02-28 15:00:40 -08005211 // The SIM language preferences only store a language (e.g. fr = French), not an
5212 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5213 // the SIM and carrier preferences does not include a country we add the country
5214 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005215 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005216 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005217 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005218 return mccLocale.toLanguageTag();
5219 }
5220
5221 if (DBG) log("No locale found - returning null");
5222 return null;
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005226 }
5227
5228 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005229 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005230 }
5231
Malcolm Chend965c8b2018-02-28 15:00:40 -08005232 /**
5233 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5234 */
5235 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005236 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005237 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005238
Chenjie Yu1ba97252018-01-11 18:16:20 -08005239 private final ModemActivityInfo mLastModemActivityInfo =
5240 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5241
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005242 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005243 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5244 * representing the state of the modem.
5245 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005246 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5247 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005248 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005249 */
5250 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005251 public void requestModemActivityInfo(ResultReceiver result) {
5252 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005253 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005254
5255 final long identity = Binder.clearCallingIdentity();
5256 try {
5257 ModemActivityInfo ret = null;
5258 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005259 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5260 CMD_GET_MODEM_ACTIVITY_INFO,
5261 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005262 if (isModemActivityInfoValid(info)) {
5263 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5264 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5265 mergedTxTimeMs[i] =
5266 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5267 }
5268 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5269 mLastModemActivityInfo.setSleepTimeMillis(
5270 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5271 mLastModemActivityInfo.setIdleTimeMillis(
5272 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5273 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5274 mLastModemActivityInfo.setRxTimeMillis(
5275 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5276 mLastModemActivityInfo.setEnergyUsed(
5277 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005278 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005279 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5280 mLastModemActivityInfo.getSleepTimeMillis(),
5281 mLastModemActivityInfo.getIdleTimeMillis(),
5282 mLastModemActivityInfo.getTxTimeMillis(),
5283 mLastModemActivityInfo.getRxTimeMillis(),
5284 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005285 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005286 Bundle bundle = new Bundle();
5287 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5288 result.send(0, bundle);
5289 } finally {
5290 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005291 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005292 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005293
Siddharth Rayf5d29552018-06-17 15:02:38 -07005294 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5295 // less than total activity duration.
5296 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5297 if (info == null) {
5298 return false;
5299 }
5300 int activityDurationMs =
5301 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5302 int totalTxTimeMs = 0;
5303 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5304 totalTxTimeMs += info.getTxTimeMillis()[i];
5305 }
5306 return (info.isValid()
5307 && (info.getSleepTimeMillis() <= activityDurationMs)
5308 && (info.getIdleTimeMillis() <= activityDurationMs)
5309 && (info.getRxTimeMillis() <= activityDurationMs)
5310 && (totalTxTimeMs <= activityDurationMs));
5311 }
5312
Jack Yu85bd38a2015-11-09 11:34:32 -08005313 /**
5314 * {@hide}
5315 * Returns the service state information on specified subscription.
5316 */
5317 @Override
5318 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005320 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005321 return null;
5322 }
5323
Hall Liuf19c44f2018-11-27 14:38:17 -08005324 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5325 LocationAccessPolicy.checkLocationPermission(mApp,
5326 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5327 .setCallingPackage(callingPackage)
5328 .setCallingPid(Binder.getCallingPid())
5329 .setCallingUid(Binder.getCallingUid())
5330 .setMethod("getServiceStateForSubscriber")
5331 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5332 .build());
5333
5334 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5335 LocationAccessPolicy.checkLocationPermission(mApp,
5336 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5337 .setCallingPackage(callingPackage)
5338 .setCallingPid(Binder.getCallingPid())
5339 .setCallingUid(Binder.getCallingUid())
5340 .setMethod("getServiceStateForSubscriber")
5341 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5342 .build());
5343 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5344 boolean hasFinePermission =
5345 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5346 boolean hasCoarsePermission =
5347 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5348
Malcolm Chend965c8b2018-02-28 15:00:40 -08005349 final long identity = Binder.clearCallingIdentity();
5350 try {
5351 final Phone phone = getPhone(subId);
5352 if (phone == null) {
5353 return null;
5354 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005355
Hall Liuf19c44f2018-11-27 14:38:17 -08005356 ServiceState ss = phone.getServiceState();
5357
5358 // Scrub out the location info in ServiceState depending on what level of access
5359 // the caller has.
5360 if (hasFinePermission) return ss;
5361 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5362 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005363 } finally {
5364 Binder.restoreCallingIdentity(identity);
5365 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005366 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005367
5368 /**
5369 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5370 *
5371 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5372 * voicemail ringtone.
5373 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5374 * PhoneAccount.
5375 */
5376 @Override
5377 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005378 final long identity = Binder.clearCallingIdentity();
5379 try {
5380 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5381 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005382 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005383 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005384
Malcolm Chend965c8b2018-02-28 15:00:40 -08005385 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005389 }
5390
5391 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005392 * Sets the per-account voicemail ringtone.
5393 *
5394 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5395 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5396 *
5397 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5398 * voicemail ringtone.
5399 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5400 * PhoneAccount.
5401 */
5402 @Override
5403 public void setVoicemailRingtoneUri(String callingPackage,
5404 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005405 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005406 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5407 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005408 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5410 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5411 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005412 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005413
5414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5417 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005418 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005419 }
5420 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5421 } finally {
5422 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005423 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005424 }
5425
5426 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005427 * Returns whether vibration is set for voicemail notification in Phone settings.
5428 *
5429 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5430 * voicemail vibration setting.
5431 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5432 */
5433 @Override
5434 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005435 final long identity = Binder.clearCallingIdentity();
5436 try {
5437 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5438 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005439 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005440 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005441
Malcolm Chend965c8b2018-02-28 15:00:40 -08005442 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
5445 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005446 }
5447
Youhan Wange64578a2016-05-02 15:32:42 -07005448 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005449 * Sets the per-account voicemail vibration.
5450 *
5451 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5452 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5453 *
5454 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5455 * voicemail vibration setting.
5456 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5457 * specific PhoneAccount.
5458 */
5459 @Override
5460 public void setVoicemailVibrationEnabled(String callingPackage,
5461 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005462 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005463 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5464 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005465 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5467 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5468 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005469 }
5470
Malcolm Chend965c8b2018-02-28 15:00:40 -08005471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5474 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005475 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005476 }
5477 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5478 } finally {
5479 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005480 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005481 }
5482
5483 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005484 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5485 *
5486 * @throws SecurityException if the caller does not have the required permission
5487 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005488 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005489 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005490 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005491 }
5492
5493 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005494 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5495 * permission.
5496 *
5497 * @throws SecurityException if the caller does not have the required permission
5498 */
5499 private void enforceSendSmsPermission() {
5500 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5501 }
5502
5503 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005504 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005505 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005506 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005507 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005508 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005509 final long identity = Binder.clearCallingIdentity();
5510 try {
5511 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005512 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005513 if (componentName == null) {
5514 throw new SecurityException(
5515 "Caller not current active visual voicemail package[null]");
5516 }
5517 String vvmPackage = componentName.getPackageName();
5518 if (!callingPackage.equals(vvmPackage)) {
5519 throw new SecurityException("Caller not current active visual voicemail package["
5520 + vvmPackage + "]");
5521 }
5522 } finally {
5523 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005524 }
5525 }
5526
5527 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005528 * Return the application ID for the app type.
5529 *
5530 * @param subId the subscription ID that this request applies to.
5531 * @param appType the uicc app type.
5532 * @return Application ID for specificied app type, or null if no uicc.
5533 */
5534 @Override
5535 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005536 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005537 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005538
5539 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005540 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005541 if (phone == null) {
5542 return null;
5543 }
5544 String aid = null;
5545 try {
5546 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5547 .getApplicationByType(appType).getAid();
5548 } catch (Exception e) {
5549 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5550 }
5551 return aid;
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005554 }
Youhan Wange64578a2016-05-02 15:32:42 -07005555 }
5556
Youhan Wang4001d252016-05-11 10:29:41 -07005557 /**
5558 * Return the Electronic Serial Number.
5559 *
5560 * @param subId the subscription ID that this request applies to.
5561 * @return ESN or null if error.
5562 */
5563 @Override
5564 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005565 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005566 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005567
5568 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005569 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005570 if (phone == null) {
5571 return null;
5572 }
5573 String esn = null;
5574 try {
5575 esn = phone.getEsn();
5576 } catch (Exception e) {
5577 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5578 }
5579 return esn;
5580 } finally {
5581 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005582 }
Youhan Wang4001d252016-05-11 10:29:41 -07005583 }
5584
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005585 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005586 * Return the Preferred Roaming List Version.
5587 *
5588 * @param subId the subscription ID that this request applies to.
5589 * @return PRLVersion or null if error.
5590 */
5591 @Override
5592 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005593 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005594 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005595
5596 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005597 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005598 if (phone == null) {
5599 return null;
5600 }
5601 String cdmaPrlVersion = null;
5602 try {
5603 cdmaPrlVersion = phone.getCdmaPrlVersion();
5604 } catch (Exception e) {
5605 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5606 }
5607 return cdmaPrlVersion;
5608 } finally {
5609 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005610 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005611 }
5612
5613 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005614 * Get snapshot of Telephony histograms
5615 * @return List of Telephony histograms
5616 * @hide
5617 */
5618 @Override
5619 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5621 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005622
5623 final long identity = Binder.clearCallingIdentity();
5624 try {
5625 return RIL.getTelephonyRILTimingHistograms();
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005629 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005630
5631 /**
5632 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005633 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5634 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005635 * Require system privileges. In the future we may add this to carrier APIs.
5636 *
Michele Berionne0963c862018-11-27 18:57:59 -08005637 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005638 */
5639 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005640 @TelephonyManager.SetCarrierRestrictionResult
5641 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005642 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005643 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005644
Michele Berionne0963c862018-11-27 18:57:59 -08005645 if (carrierRestrictionRules == null) {
5646 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005647 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005648
Malcolm Chend965c8b2018-02-28 15:00:40 -08005649 final long identity = Binder.clearCallingIdentity();
5650 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005651 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005652 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005653 } finally {
5654 Binder.restoreCallingIdentity(identity);
5655 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005656 }
5657
5658 /**
5659 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005660 * Get the allowed carrier list and the excluded carrier list, including the priority between
5661 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005662 * Require system privileges. In the future we may add this to carrier APIs.
5663 *
Michele Berionne0963c862018-11-27 18:57:59 -08005664 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005665 */
5666 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005667 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005668 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005669 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005670
5671 final long identity = Binder.clearCallingIdentity();
5672 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005673 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5674 if (response instanceof CarrierRestrictionRules) {
5675 return (CarrierRestrictionRules) response;
5676 }
5677 // Response is an Exception of some kind,
5678 // which is signalled to the user as a NULL retval
5679 return null;
5680 } catch (Exception e) {
5681 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5682 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005686 }
5687
fionaxu59545b42016-05-25 15:53:37 -07005688 /**
5689 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5690 * @param subId the subscription ID that this action applies to.
5691 * @param enabled control enable or disable metered apns.
5692 * {@hide}
5693 */
5694 @Override
5695 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5696 enforceModifyPermission();
5697 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005698
5699 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005700 if (phone == null) {
5701 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5702 return;
5703 }
5704 try {
5705 phone.carrierActionSetMeteredApnsEnabled(enabled);
5706 } catch (Exception e) {
5707 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005708 } finally {
5709 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005710 }
5711 }
5712
5713 /**
5714 * Action set from carrier signalling broadcast receivers to enable/disable radio
5715 * @param subId the subscription ID that this action applies to.
5716 * @param enabled control enable or disable radio.
5717 * {@hide}
5718 */
5719 @Override
5720 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5721 enforceModifyPermission();
5722 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005723
5724 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005725 if (phone == null) {
5726 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5727 return;
5728 }
5729 try {
5730 phone.carrierActionSetRadioEnabled(enabled);
5731 } catch (Exception e) {
5732 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005733 } finally {
5734 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005735 }
5736 }
5737
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005738 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005739 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5740 * network status based on which carrier apps could apply actions accordingly,
5741 * enable/disable default url handler for example.
5742 *
5743 * @param subId the subscription ID that this action applies to.
5744 * @param report control start/stop reporting the default network status.
5745 * {@hide}
5746 */
5747 @Override
5748 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5749 enforceModifyPermission();
5750 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005751
5752 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005753 if (phone == null) {
5754 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5755 return;
5756 }
5757 try {
5758 phone.carrierActionReportDefaultNetworkStatus(report);
5759 } catch (Exception e) {
5760 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005761 } finally {
5762 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005763 }
5764 }
5765
5766 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005767 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5768 * bug report is being generated.
5769 */
5770 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005771 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005772 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5773 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005774 writer.println("Permission Denial: can't dump Phone from pid="
5775 + Binder.getCallingPid()
5776 + ", uid=" + Binder.getCallingUid()
5777 + "without permission "
5778 + android.Manifest.permission.DUMP);
5779 return;
5780 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005781 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005782 }
Jack Yueb89b242016-06-22 13:27:47 -07005783
Brad Ebingerdac2f002018-04-03 15:17:52 -07005784 @Override
5785 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5786 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5787 throws RemoteException {
5788 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5789 }
5790
Jack Yueb89b242016-06-22 13:27:47 -07005791 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005792 * Get aggregated video call data usage since boot.
5793 *
5794 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5795 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005796 * {@hide}
5797 */
5798 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005799 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005800 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5801 null);
5802
Malcolm Chend965c8b2018-02-28 15:00:40 -08005803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 // NetworkStatsService keeps tracking the active network interface and identity. It
5806 // records the delta with the corresponding network identity.
5807 // We just return the total video call data usage snapshot since boot.
5808 Phone phone = getPhone(subId);
5809 if (phone != null) {
5810 return phone.getVtDataUsage(perUidStats);
5811 }
5812 return null;
5813 } finally {
5814 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005815 }
Jack Yueb89b242016-06-22 13:27:47 -07005816 }
Jack Yu75ab2952016-07-08 14:29:33 -07005817
5818 /**
5819 * Policy control of data connection. Usually used when data limit is passed.
5820 * @param enabled True if enabling the data, otherwise disabling.
5821 * @param subId Subscription index
5822 * {@hide}
5823 */
5824 @Override
5825 public void setPolicyDataEnabled(boolean enabled, int subId) {
5826 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005827
5828 final long identity = Binder.clearCallingIdentity();
5829 try {
5830 Phone phone = getPhone(subId);
5831 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005832 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005833 }
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005836 }
5837 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005838
5839 /**
5840 * Get Client request stats
5841 * @return List of Client Request Stats
5842 * @hide
5843 */
5844 @Override
5845 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005846 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005847 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005848 return null;
5849 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005850 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005851
Malcolm Chend965c8b2018-02-28 15:00:40 -08005852 final long identity = Binder.clearCallingIdentity();
5853 try {
5854 if (phone != null) {
5855 return phone.getClientRequestStats();
5856 }
5857
5858 return null;
5859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005862 }
5863
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005864 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005865 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005866 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005867 }
Jack Yueb4124c2017-02-16 15:32:43 -08005868
5869 /**
Grace Chen70990072017-03-24 17:21:30 -07005870 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005871 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005872 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005873 * @param state State of SIM (power down, power up, pass through)
5874 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5875 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5876 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005877 *
5878 **/
5879 @Override
Grace Chen70990072017-03-24 17:21:30 -07005880 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005881 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005882 Phone phone = PhoneFactory.getPhone(slotIndex);
5883
vagdevie435a3e2018-08-15 16:01:53 -07005884 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5885
Malcolm Chend965c8b2018-02-28 15:00:40 -08005886 final long identity = Binder.clearCallingIdentity();
5887 try {
5888 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005889 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005890 }
5891 } finally {
5892 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005893 }
5894 }
Shuo Qiandd210312017-04-12 22:11:33 +00005895
Tyler Gunn65d45c22017-06-05 11:22:26 -07005896 private boolean isUssdApiAllowed(int subId) {
5897 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005898 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005899 if (configManager == null) {
5900 return false;
5901 }
5902 PersistableBundle pb = configManager.getConfigForSubId(subId);
5903 if (pb == null) {
5904 return false;
5905 }
5906 return pb.getBoolean(
5907 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5908 }
5909
Shuo Qiandd210312017-04-12 22:11:33 +00005910 /**
5911 * Check if phone is in emergency callback mode
5912 * @return true if phone is in emergency callback mode
5913 * @param subId sub id
5914 */
goneil9c5f4872017-12-05 14:07:56 -08005915 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005916 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005917 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005918 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005919
5920 final long identity = Binder.clearCallingIdentity();
5921 try {
5922 if (phone != null) {
5923 return phone.isInEcm();
5924 } else {
5925 return false;
5926 }
5927 } finally {
5928 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005929 }
5930 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005931
5932 /**
5933 * Get the current signal strength information for the given subscription.
5934 * Because this information is not updated when the device is in a low power state
5935 * it should not be relied-upon to be current.
5936 * @param subId Subscription index
5937 * @return the most recent cached signal strength info from the modem
5938 */
5939 @Override
5940 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005941 final long identity = Binder.clearCallingIdentity();
5942 try {
5943 Phone p = getPhone(subId);
5944 if (p == null) {
5945 return null;
5946 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005947
Malcolm Chend965c8b2018-02-28 15:00:40 -08005948 return p.getSignalStrength();
5949 } finally {
5950 Binder.restoreCallingIdentity(identity);
5951 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005952 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005953
Pengquan Meng9140aec2018-08-22 14:49:57 -07005954 /**
chen xu907e5a22018-10-11 13:21:04 -07005955 * Get the current modem radio state for the given slot.
5956 * @param slotIndex slot index.
5957 * @param callingPackage the name of the package making the call.
5958 * @return the current radio power state from the modem
5959 */
5960 @Override
5961 public int getRadioPowerState(int slotIndex, String callingPackage) {
5962 Phone phone = PhoneFactory.getPhone(slotIndex);
5963 if (phone != null) {
5964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5965 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5966 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5967 }
5968
5969 final long identity = Binder.clearCallingIdentity();
5970 try {
5971 return phone.getRadioPowerState();
5972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
5975 }
5976 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5977 }
5978
5979 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005980 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5981 *
5982 * <p>Requires one of the following permissions:
5983 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5984 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5985 * privileges.
5986 *
5987 * @param subId subscription id
5988 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5989 * {@code false}.
5990 */
5991 @Override
5992 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005993 boolean isEnabled = false;
5994 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005995 try {
5996 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005997 null /* message */);
5998 Phone phone = getPhone(subId);
5999 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006000 } catch (Exception e) {
6001 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6002 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006003 } finally {
6004 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006005 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006006 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006007 }
6008
6009
6010 /**
6011 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6012 *
6013 * <p> Requires permission:
6014 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6015 * privileges.
6016 *
6017 * @param subId subscription id
6018 * @param isEnabled {@code true} means enable, {@code false} means disable.
6019 */
6020 @Override
6021 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006022 final long identity = Binder.clearCallingIdentity();
6023 try {
6024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6025 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07006026
Pengquan Meng0c05b502018-09-06 09:59:22 -07006027 Phone phone = getPhone(subId);
6028 if (phone != null) {
6029 phone.setDataRoamingEnabled(isEnabled);
6030 }
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006033 }
6034 }
6035
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006036 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006037 public boolean isManualNetworkSelectionAllowed(int subId) {
6038 boolean isAllowed = true;
6039 final long identity = Binder.clearCallingIdentity();
6040 try {
6041 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6042 mApp, subId, "isManualNetworkSelectionAllowed");
6043 Phone phone = getPhone(subId);
6044 if (phone != null) {
6045 isAllowed = phone.isCspPlmnEnabled();
6046 }
6047 } finally {
6048 Binder.restoreCallingIdentity(identity);
6049 }
6050 return isAllowed;
6051 }
6052
6053 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006054 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006055 try {
6056 enforceReadPrivilegedPermission("getUiccCardsInfo");
6057 } catch (SecurityException e) {
6058 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6059 // has carrier privileges on an active UICC
6060 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6061 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6062 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6063 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006064 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006065
6066 final long identity = Binder.clearCallingIdentity();
6067 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006068 UiccController uiccController = UiccController.getInstance();
6069 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6070
6071 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6072 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6073 // Remove private info if the caller doesn't have access
6074 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6075 for (UiccCardInfo cardInfo : cardInfos) {
6076 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6077 UiccProfile profile = card.getUiccProfile();
6078 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6079 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6080 filteredInfos.add(cardInfo.getUnprivileged());
6081 } else {
6082 filteredInfos.add(cardInfo);
6083 }
6084 }
6085 return filteredInfos;
6086 }
6087 return cardInfos;
6088 } catch (PackageManager.NameNotFoundException e) {
6089 // This should not happen since we pass the package info in from TelephonyManager
6090 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
6094 }
6095
6096 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006097 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006098 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006099
Malcolm Chend965c8b2018-02-28 15:00:40 -08006100 final long identity = Binder.clearCallingIdentity();
6101 try {
6102 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6103 if (slots == null) {
6104 Rlog.i(LOG_TAG, "slots is null.");
6105 return null;
6106 }
6107
6108 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6109 for (int i = 0; i < slots.length; i++) {
6110 UiccSlot slot = slots[i];
6111 if (slot == null) {
6112 continue;
6113 }
6114
6115 String cardId;
6116 UiccCard card = slot.getUiccCard();
6117 if (card != null) {
6118 cardId = card.getCardId();
6119 } else {
6120 cardId = slot.getIccId();
6121 }
6122
6123 int cardState = 0;
6124 switch (slot.getCardState()) {
6125 case CARDSTATE_ABSENT:
6126 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6127 break;
6128 case CARDSTATE_PRESENT:
6129 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6130 break;
6131 case CARDSTATE_ERROR:
6132 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6133 break;
6134 case CARDSTATE_RESTRICTED:
6135 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6136 break;
6137 default:
6138 break;
6139
6140 }
6141
6142 infos[i] = new UiccSlotInfo(
6143 slot.isActive(),
6144 slot.isEuicc(),
6145 cardId,
6146 cardState,
6147 slot.getPhoneId(),
6148 slot.isExtendedApduSupported());
6149 }
6150 return infos;
6151 } finally {
6152 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006153 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006154 }
6155
6156 @Override
6157 public boolean switchSlots(int[] physicalSlots) {
6158 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006159
6160 final long identity = Binder.clearCallingIdentity();
6161 try {
6162 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006166 }
Jack Yu4c988042018-02-27 15:30:01 -08006167
6168 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006169 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006170 final long identity = Binder.clearCallingIdentity();
6171 try {
6172 return UiccController.getInstance().getCardIdForDefaultEuicc();
6173 } finally {
6174 Binder.restoreCallingIdentity(identity);
6175 }
6176 }
6177
6178 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006179 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6180 enforceModifyPermission();
6181 final Phone phone = getPhone(subId);
6182 if (phone == null) {
6183 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6184 return;
6185 }
6186
Malcolm Chend965c8b2018-02-28 15:00:40 -08006187 final long identity = Binder.clearCallingIdentity();
6188 try {
6189 phone.setRadioIndicationUpdateMode(filters, mode);
6190 } finally {
6191 Binder.restoreCallingIdentity(identity);
6192 }
Jack Yu4c988042018-02-27 15:30:01 -08006193 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006194
6195 /**
goneil47ffb6e2018-04-06 15:40:58 -07006196 * A test API to reload the UICC profile.
6197 *
6198 * <p>Requires that the calling app has permission
6199 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6200 * @hide
6201 */
6202 @Override
6203 public void refreshUiccProfile(int subId) {
6204 enforceModifyPermission();
6205
6206 final long identity = Binder.clearCallingIdentity();
6207 try {
6208 Phone phone = getPhone(subId);
6209 if (phone == null) {
6210 return;
6211 }
6212 UiccCard uiccCard = phone.getUiccCard();
6213 if (uiccCard == null) {
6214 return;
6215 }
6216 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6217 if (uiccProfile == null) {
6218 return;
6219 }
6220 uiccProfile.refresh();
6221 } finally {
6222 Binder.restoreCallingIdentity(identity);
6223 }
6224 }
6225
6226 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006227 * Returns false if the mobile data is disabled by default, otherwise return true.
6228 */
6229 private boolean getDefaultDataEnabled() {
6230 return "true".equalsIgnoreCase(
6231 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6232 }
6233
6234 /**
6235 * Returns true if the data roaming is enabled by default, i.e the system property
6236 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6237 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6238 */
6239 private boolean getDefaultDataRoamingEnabled(int subId) {
6240 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006241 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006242 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6243 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6244 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6245 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6246 return isDataRoamingEnabled;
6247 }
6248
6249 /**
6250 * Returns the default network type for the given {@code subId}, if the default network type is
6251 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6252 */
6253 private int getDefaultNetworkType(int subId) {
6254 return Integer.parseInt(
6255 TelephonyManager.getTelephonyProperty(
6256 mSubscriptionController.getPhoneId(subId),
6257 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6258 String.valueOf(Phone.PREFERRED_NT_MODE)));
6259 }
fionaxua13278b2018-03-21 00:08:13 -07006260
6261 @Override
6262 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6263 gid1, String gid2, String plmn, String spn) {
6264 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006265
6266 final long identity = Binder.clearCallingIdentity();
6267 try {
6268 final Phone phone = getPhone(subId);
6269 if (phone == null) {
6270 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6271 return;
6272 }
6273 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6274 } finally {
6275 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006276 }
fionaxua13278b2018-03-21 00:08:13 -07006277 }
6278
6279 @Override
6280 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006281 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006282
6283 final long identity = Binder.clearCallingIdentity();
6284 try {
6285 final Phone phone = getPhone(subId);
6286 if (phone == null) {
6287 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6288 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6289 }
6290 return phone.getCarrierIdListVersion();
6291 } finally {
6292 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006293 }
fionaxua13278b2018-03-21 00:08:13 -07006294 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006295
6296 @Override
6297 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6299 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6300 return -1;
6301 }
6302
6303 final long identity = Binder.clearCallingIdentity();
6304 try {
6305 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
6309 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006310
6311 @Override
6312 public int getCdmaRoamingMode(int subId) {
6313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6314 mApp, subId, "getCdmaRoamingMode");
6315
6316 final long identity = Binder.clearCallingIdentity();
6317 try {
6318 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321 }
6322 }
6323
6324 @Override
6325 public boolean setCdmaRoamingMode(int subId, int mode) {
6326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6327 mApp, subId, "setCdmaRoamingMode");
6328
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
6331 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
6335 }
6336
6337 @Override
6338 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6340 mApp, subId, "setCdmaSubscriptionMode");
6341
6342 final long identity = Binder.clearCallingIdentity();
6343 try {
6344 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
6348 }
chen xu7ee67862018-10-30 22:27:10 -07006349
sqian2fff4a32018-11-05 14:18:37 -08006350 private void ensureUserRunning(int userId) {
6351 if (!mUserManager.isUserRunning(userId)) {
6352 throw new IllegalStateException("User " + userId + " does not exist or not running");
6353 }
6354 }
6355
6356 /**
6357 * Returns a list of SMS apps on a given user.
6358 *
6359 * Only the shell user (UID 2000 or 0) can call it.
6360 * Target user must be running.
6361 */
6362 @Override
6363 public String[] getSmsApps(int userId) {
6364 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6365 ensureUserRunning(userId);
6366
6367 final Collection<SmsApplicationData> apps =
6368 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6369
6370 String[] ret = new String[apps.size()];
6371 int i = 0;
6372 for (SmsApplicationData app : apps) {
6373 ret[i++] = app.mPackageName;
6374 }
6375 return ret;
6376 }
6377
6378 /**
6379 * Returns the default SMS app package name on a given user.
6380 *
6381 * Only the shell user (UID 2000 or 0) can call it.
6382 * Target user must be running.
6383 */
6384 @Override
6385 public String getDefaultSmsApp(int userId) {
6386 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6387 ensureUserRunning(userId);
6388
6389 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6390 /* updateIfNeeded= */ true, userId);
6391 return cn == null ? null : cn.getPackageName();
6392 }
6393
6394 /**
6395 * Set a package as the default SMS app on a given user.
6396 *
6397 * Only the shell user (UID 2000 or 0) can call it.
6398 * Target user must be running.
6399 */
6400 @Override
6401 public void setDefaultSmsApp(int userId, String packageName) {
6402 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6403 ensureUserRunning(userId);
6404
6405 boolean found = false;
6406 for (String pkg : getSmsApps(userId)) {
6407 if (TextUtils.equals(packageName, pkg)) {
6408 found = true;
6409 break;
6410 }
6411 }
6412 if (!found) {
6413 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6414 }
6415
6416 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6417 }
6418
chen xu7ee67862018-10-30 22:27:10 -07006419 @Override
sqian04b86072018-11-07 14:02:21 -08006420 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6421 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006422 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6423 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6424 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6425 }
6426 final long identity = Binder.clearCallingIdentity();
6427 try {
sqian991b35e2018-12-12 16:48:18 -08006428 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6429 for (Phone phone: PhoneFactory.getPhones()) {
6430 if (phone.getEmergencyNumberTracker() != null
6431 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6432 emergencyNumberListInternal.put(
6433 phone.getSubId(),
6434 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6435 }
sqian03bca152018-12-05 18:48:28 -08006436 }
sqian991b35e2018-12-12 16:48:18 -08006437 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006438 } finally {
6439 Binder.restoreCallingIdentity(identity);
6440 }
sqian04b86072018-11-07 14:02:21 -08006441 }
6442
6443 @Override
sqian03bca152018-12-05 18:48:28 -08006444 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6445 final Phone defaultPhone = getDefaultPhone();
6446 if (!exactMatch) {
6447 TelephonyPermissions
6448 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6449 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6450 }
6451 final long identity = Binder.clearCallingIdentity();
6452 try {
sqian991b35e2018-12-12 16:48:18 -08006453 for (Phone phone: PhoneFactory.getPhones()) {
6454 if (phone.getEmergencyNumberTracker() != null
6455 && phone.getEmergencyNumberTracker() != null) {
6456 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6457 number, exactMatch)) {
6458 return true;
sqian03bca152018-12-05 18:48:28 -08006459 }
6460 }
sqian03bca152018-12-05 18:48:28 -08006461 }
6462 return false;
6463 } finally {
6464 Binder.restoreCallingIdentity(identity);
6465 }
6466 }
6467
sqian9d4df8b2019-01-15 18:32:07 -08006468 /**
6469 * Update emergency number list for test mode.
6470 */
6471 @Override
6472 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6473 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6474 "updateEmergencyNumberListTestMode");
6475
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
6478 for (Phone phone: PhoneFactory.getPhones()) {
6479 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6480 if (tracker != null) {
6481 tracker.executeEmergencyNumberTestModeCommand(action, num);
6482 }
6483 }
6484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
6487 }
6488
6489 /**
6490 * Get the full emergency number list for test mode.
6491 */
6492 @Override
6493 public List<String> getEmergencyNumberListTestMode() {
6494 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6495 "getEmergencyNumberListTestMode");
6496
6497 final long identity = Binder.clearCallingIdentity();
6498 try {
6499 Set<String> emergencyNumbers = new HashSet<>();
6500 for (Phone phone: PhoneFactory.getPhones()) {
6501 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6502 if (tracker != null) {
6503 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6504 emergencyNumbers.add(num.getNumber());
6505 }
6506 }
6507 }
6508 return new ArrayList<>(emergencyNumbers);
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
6512 }
6513
sqian04b86072018-11-07 14:02:21 -08006514 @Override
chen xu7ee67862018-10-30 22:27:10 -07006515 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6516 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6517 Phone phone = getPhone(subId);
6518 if (phone == null) {
6519 return null;
6520 }
6521 final long identity = Binder.clearCallingIdentity();
6522 try {
6523 UiccProfile profile = UiccController.getInstance()
6524 .getUiccProfileForPhone(phone.getPhoneId());
6525 if (profile != null) {
6526 return profile.getCertsFromCarrierPrivilegeAccessRules();
6527 }
6528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
6531 return null;
6532 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006533
6534 /**
6535 * Enable or disable a modem stack.
6536 */
6537 @Override
6538 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6539 enforceModifyPermission();
6540
6541 final long identity = Binder.clearCallingIdentity();
6542 try {
6543 Phone phone = PhoneFactory.getPhone(slotIndex);
6544 if (phone == null) {
6545 return false;
6546 } else {
6547 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6548 }
6549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
6552 }
Micheled3107c52018-12-21 15:00:11 -08006553
6554 @Override
6555 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6556 enforceModifyPermission();
6557
6558 final long identity = Binder.clearCallingIdentity();
6559 try {
6560 mTelephonySharedPreferences.edit()
6561 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6562 .commit();
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
6566 }
6567
6568 @Override
6569 public boolean isMultisimCarrierRestricted() {
6570 enforceReadPrivilegedPermission("isMultisimCarrierRestricted");
6571
6572 final long identity = Binder.clearCallingIdentity();
6573 try {
6574 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6575 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6576 if (numPhysicalSlots < 2) {
6577 loge("isMultisimCarrierRestricted: requires at least 2 cards");
6578 return true;
6579 }
6580
6581 // Default value is false. Multi SIM is allowed unless explicitly restricted.
6582 return mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false);
6583 } finally {
6584 Binder.restoreCallingIdentity(identity);
6585 }
6586 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006587
6588 /**
6589 * Switch configs to enable multi-sim or switch back to single-sim
6590 * @param numOfSims number of active sims we want to switch to
6591 */
6592 @Override
6593 public void switchMultiSimConfig(int numOfSims) {
6594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6595 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6596 final long identity = Binder.clearCallingIdentity();
6597 try {
6598 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6599 } finally {
6600 Binder.restoreCallingIdentity(identity);
6601 }
6602 }
6603
6604 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006605 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006606 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006607 */
6608 @Override
6609 public boolean isRebootRequiredForModemConfigChange() {
6610 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6611 final long identity = Binder.clearCallingIdentity();
6612 try {
6613 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
6617 }
6618
Pengquan Meng92d253b2019-02-06 11:12:53 -08006619 private void updateModemStateMetrics() {
6620 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6621 // TODO: check the state for each modem if the api is ready.
6622 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6623 }
6624
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006625 @Override
6626 public int[] getSlotsMapping() {
6627 enforceReadPrivilegedPermission("getSlotsMapping");
6628
6629 final long identity = Binder.clearCallingIdentity();
6630 try {
6631 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6632 // All logical slots should have a mapping to a physical slot.
6633 int[] logicalSlotsMapping = new int[phoneCount];
6634 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6635 for (int i = 0; i < slotInfos.length; i++) {
6636 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6637 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6638 }
6639 }
6640 return logicalSlotsMapping;
6641 } finally {
6642 Binder.restoreCallingIdentity(identity);
6643 }
6644 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006645
6646 /**
6647 * Get the IRadio HAL Version
6648 */
6649 @Override
6650 public int getRadioHalVersion() {
6651 Phone phone = getDefaultPhone();
6652 if (phone == null) return -1;
6653 HalVersion hv = phone.getHalVersion();
6654 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6655 return hv.major * 100 + hv.minor;
6656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006657}