blob: e9031b9276e6e9d4f7100a8428db204e71ff215f [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")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002020 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002021 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2022 .build());
2023 switch (locationResult) {
2024 case DENIED_HARD:
2025 throw new SecurityException("Not allowed to access cell info");
2026 case DENIED_SOFT:
2027 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 }
2029
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002030 final int targetSdk = getTargetSdk(callingPackage);
2031 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2032 return getCachedCellInfo();
2033 }
2034
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002035 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002036 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2040 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002041 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002042 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002043 if (info != null) cellInfos.addAll(info);
2044 }
2045 return cellInfos;
2046 } finally {
2047 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 }
2049 }
2050
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002051 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002052 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2053 requestCellInfoUpdateInternal(
2054 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2055 }
2056
2057 @Override
2058 public void requestCellInfoUpdateWithWorkSource(
2059 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2060 enforceModifyPermission();
2061 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2062 }
2063
2064 private void requestCellInfoUpdateInternal(
2065 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002066 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002067 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002068
2069 LocationAccessPolicy.LocationPermissionResult locationResult =
2070 LocationAccessPolicy.checkLocationPermission(mApp,
2071 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2072 .setCallingPackage(callingPackage)
2073 .setCallingPid(Binder.getCallingPid())
2074 .setCallingUid(Binder.getCallingUid())
2075 .setMethod("requestCellInfoUpdate")
2076 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2077 .build());
2078 switch (locationResult) {
2079 case DENIED_HARD:
2080 throw new SecurityException("Not allowed to access cell info");
2081 case DENIED_SOFT:
2082 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002083 }
2084
2085 final Phone phone = getPhone(subId);
2086 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2087
2088 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2089 }
2090
2091 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002093 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002094 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002095
2096 final long identity = Binder.clearCallingIdentity();
2097 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002098 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002099 } finally {
2100 Binder.restoreCallingIdentity(identity);
2101 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 }
2103
Shishir Agrawala9f32182016-04-12 12:00:16 -07002104 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002105 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002106 Phone phone = PhoneFactory.getPhone(slotIndex);
2107 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002108 return null;
2109 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002110 int subId = phone.getSubId();
2111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2112 mApp, subId, callingPackage, "getImeiForSlot")) {
2113 return null;
2114 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002115
2116 final long identity = Binder.clearCallingIdentity();
2117 try {
2118 return phone.getImei();
2119 } finally {
2120 Binder.restoreCallingIdentity(identity);
2121 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002122 }
2123
2124 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002125 public String getTypeAllocationCodeForSlot(int slotIndex) {
2126 Phone phone = PhoneFactory.getPhone(slotIndex);
2127 String tac = null;
2128 if (phone != null) {
2129 String imei = phone.getImei();
2130 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2131 }
2132 return tac;
2133 }
2134
2135 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002136 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002137 Phone phone = PhoneFactory.getPhone(slotIndex);
2138 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002139 return null;
2140 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002141
Jeff Davidson913390f2018-02-23 17:11:49 -08002142 int subId = phone.getSubId();
2143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2144 mApp, subId, callingPackage, "getMeidForSlot")) {
2145 return null;
2146 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002147
2148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 return phone.getMeid();
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
2153 }
Jack Yu2af8d712017-03-15 17:14:14 -07002154 }
2155
2156 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002157 public String getManufacturerCodeForSlot(int slotIndex) {
2158 Phone phone = PhoneFactory.getPhone(slotIndex);
2159 String manufacturerCode = null;
2160 if (phone != null) {
2161 String meid = phone.getMeid();
2162 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2163 }
2164 return manufacturerCode;
2165 }
2166
2167 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002168 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002169 Phone phone = PhoneFactory.getPhone(slotIndex);
2170 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002171 return null;
2172 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002173 int subId = phone.getSubId();
2174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2175 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2176 return null;
2177 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002178
2179 final long identity = Binder.clearCallingIdentity();
2180 try {
2181 return phone.getDeviceSvn();
2182 } finally {
2183 Binder.restoreCallingIdentity(identity);
2184 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002185 }
2186
fionaxu43304da2017-11-27 22:51:16 -08002187 @Override
2188 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002189 final long identity = Binder.clearCallingIdentity();
2190 try {
2191 final Phone phone = getPhone(subId);
2192 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2193 } finally {
2194 Binder.restoreCallingIdentity(identity);
2195 }
fionaxu43304da2017-11-27 22:51:16 -08002196 }
2197
2198 @Override
2199 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 final Phone phone = getPhone(subId);
2203 return phone == null ? null : phone.getCarrierName();
2204 } finally {
2205 Binder.restoreCallingIdentity(identity);
2206 }
fionaxu43304da2017-11-27 22:51:16 -08002207 }
2208
calvinpaneed9ae82018-11-01 19:43:06 +08002209 @Override
chen xuc93cc282018-11-04 17:17:00 -08002210 public int getSubscriptionPreciseCarrierId(int subId) {
2211 final long identity = Binder.clearCallingIdentity();
2212 try {
2213 final Phone phone = getPhone(subId);
2214 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2215 : phone.getPreciseCarrierId();
2216 } finally {
2217 Binder.restoreCallingIdentity(identity);
2218 }
2219 }
2220
2221 @Override
2222 public String getSubscriptionPreciseCarrierName(int subId) {
2223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 final Phone phone = getPhone(subId);
2226 return phone == null ? null : phone.getPreciseCarrierName();
2227 } finally {
2228 Binder.restoreCallingIdentity(identity);
2229 }
2230 }
2231
chen xu02581692018-11-11 19:03:44 -08002232 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002233 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2234 if (!isSubscriptionMccMnc) {
2235 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2236 }
chen xu02581692018-11-11 19:03:44 -08002237 final Phone phone = PhoneFactory.getPhone(slotIndex);
2238 if (phone == null) {
2239 return TelephonyManager.UNKNOWN_CARRIER_ID;
2240 }
2241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2244 } finally {
2245 Binder.restoreCallingIdentity(identity);
2246 }
2247 }
2248
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 //
2250 // Internal helper methods.
2251 //
2252
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002253 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2255 *
2256 * @throws SecurityException if the caller does not have the required permission
2257 */
2258 private void enforceModifyPermission() {
2259 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2260 }
2261
2262 /**
2263 * Make sure the caller has the CALL_PHONE permission.
2264 *
2265 * @throws SecurityException if the caller does not have the required permission
2266 */
2267 private void enforceCallPermission() {
2268 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2269 }
2270
Stuart Scott8eef64f2015-04-08 15:13:54 -07002271 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002272 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002273 "ConnectivityService");
2274 }
2275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 private String createTelUrl(String number) {
2277 if (TextUtils.isEmpty(number)) {
2278 return null;
2279 }
2280
Jake Hambye994d462014-02-03 13:10:13 -08002281 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
Ihab Awadf9e92732013-12-05 18:02:52 -08002284 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2286 }
2287
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002288 private static void logv(String msg) {
2289 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2290 }
2291
Ihab Awadf9e92732013-12-05 18:02:52 -08002292 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2294 }
2295
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002296 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002298 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002299 }
2300
Sanket Padawe356d7632015-06-22 14:03:32 -07002301 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002302 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002303 final long identity = Binder.clearCallingIdentity();
2304 try {
2305 final Phone phone = PhoneFactory.getPhone(slotIndex);
2306 if (phone == null) {
2307 return PhoneConstants.PHONE_TYPE_NONE;
2308 } else {
2309 return phone.getPhoneType();
2310 }
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 }
2315
2316 /**
2317 * Returns the CDMA ERI icon index to display
2318 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002319 @Override
2320 public int getCdmaEriIconIndex(String callingPackage) {
2321 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002322 }
2323
Sanket Padawe356d7632015-06-22 14:03:32 -07002324 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002325 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002327 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002328 return -1;
2329 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002330
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
2333 final Phone phone = getPhone(subId);
2334 if (phone != null) {
2335 return phone.getCdmaEriIconIndex();
2336 } else {
2337 return -1;
2338 }
2339 } finally {
2340 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
2343
2344 /**
2345 * Returns the CDMA ERI icon mode,
2346 * 0 - ON
2347 * 1 - FLASHING
2348 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002349 @Override
2350 public int getCdmaEriIconMode(String callingPackage) {
2351 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002352 }
2353
Sanket Padawe356d7632015-06-22 14:03:32 -07002354 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002355 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002357 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002358 return -1;
2359 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002360
2361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 final Phone phone = getPhone(subId);
2364 if (phone != null) {
2365 return phone.getCdmaEriIconMode();
2366 } else {
2367 return -1;
2368 }
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
2374 /**
2375 * Returns the CDMA ERI text,
2376 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002377 @Override
2378 public String getCdmaEriText(String callingPackage) {
2379 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002380 }
2381
Sanket Padawe356d7632015-06-22 14:03:32 -07002382 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002383 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002385 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002386 return null;
2387 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002388
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 final Phone phone = getPhone(subId);
2392 if (phone != null) {
2393 return phone.getCdmaEriText();
2394 } else {
2395 return null;
2396 }
2397 } finally {
2398 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 }
2401
2402 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002403 * Returns the CDMA MDN.
2404 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002405 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002406 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2408 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002409
2410 final long identity = Binder.clearCallingIdentity();
2411 try {
2412 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002413 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002414 return phone.getLine1Number();
2415 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002416 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002417 return null;
2418 }
2419 } finally {
2420 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002421 }
2422 }
2423
2424 /**
2425 * Returns the CDMA MIN.
2426 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002427 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002428 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2430 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002431
2432 final long identity = Binder.clearCallingIdentity();
2433 try {
2434 final Phone phone = getPhone(subId);
2435 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2436 return phone.getCdmaMin();
2437 } else {
2438 return null;
2439 }
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002442 }
2443 }
2444
Hall Liud892bec2018-11-30 14:51:45 -08002445 @Override
2446 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2447 INumberVerificationCallback callback, String callingPackage) {
2448 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2449 != PERMISSION_GRANTED) {
2450 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2451 }
2452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2453
2454 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2455 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2456 throw new SecurityException("Calling package must be configured in the device config");
2457 }
2458
2459 if (range == null) {
2460 throw new NullPointerException("Range must be non-null");
2461 }
2462
2463 timeoutMillis = Math.min(timeoutMillis,
2464 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2465
2466 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2467 }
2468
Junda Liuca05d5d2014-08-14 22:36:34 -07002469 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 * Returns true if CDMA provisioning needs to run.
2471 */
2472 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002473 final long identity = Binder.clearCallingIdentity();
2474 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002475 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002476 } finally {
2477 Binder.restoreCallingIdentity(identity);
2478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 }
2480
2481 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002482 * Sets the voice mail number of a given subId.
2483 */
2484 @Override
2485 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002486 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2491 new Pair<String, String>(alphaTag, number), new Integer(subId));
2492 return success;
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
2495 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002496 }
2497
Ta-wei Yen87c49842016-05-13 21:19:52 -07002498 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002499 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002501 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002502 if (!TextUtils.equals(callingPackage, systemDialer)) {
2503 throw new SecurityException("caller must be system dialer");
2504 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2509 if (phoneAccountHandle == null) {
2510 return null;
2511 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002512 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002513 } finally {
2514 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002515 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002516 }
2517
2518 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002519 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002520 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002522 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002523 return null;
2524 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002525
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002526 final long identity = Binder.clearCallingIdentity();
2527 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002528 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002529 } finally {
2530 Binder.restoreCallingIdentity(identity);
2531 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002532 }
2533
2534 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002535 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2536 VisualVoicemailSmsFilterSettings settings) {
2537 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002538
2539 final long identity = Binder.clearCallingIdentity();
2540 try {
2541 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002542 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002546 }
2547
2548 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002549 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002551
2552 final long identity = Binder.clearCallingIdentity();
2553 try {
2554 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002555 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002556 } finally {
2557 Binder.restoreCallingIdentity(identity);
2558 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002559 }
2560
2561 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002562 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2563 String callingPackage, int subId) {
2564 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002569 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002570 } finally {
2571 Binder.restoreCallingIdentity(identity);
2572 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002573 }
2574
2575 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002576 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002577 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002582 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002583 } finally {
2584 Binder.restoreCallingIdentity(identity);
2585 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002586 }
2587
2588 @Override
2589 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2590 String number, int port, String text, PendingIntent sentIntent) {
2591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002592 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002593 enforceSendSmsPermission();
2594 // Make the calls as the phone process.
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2598 if (port == 0) {
2599 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2600 sentIntent, null, false);
2601 } else {
2602 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2603 smsManager.sendDataMessageWithSelfPermissions(number, null,
2604 (short) port, data, sentIntent, null);
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
2608 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002609 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002610 /**
fionaxu0152e512016-11-14 13:36:14 -08002611 * Sets the voice activation state of a given subId.
2612 */
2613 @Override
2614 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2616 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002617
2618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 final Phone phone = getPhone(subId);
2621 if (phone != null) {
2622 phone.setVoiceActivationState(activationState);
2623 } else {
2624 loge("setVoiceActivationState fails with invalid subId: " + subId);
2625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002628 }
2629 }
2630
2631 /**
2632 * Sets the data activation state of a given subId.
2633 */
2634 @Override
2635 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2637 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 final Phone phone = getPhone(subId);
2642 if (phone != null) {
2643 phone.setDataActivationState(activationState);
2644 } else {
2645 loge("setVoiceActivationState fails with invalid subId: " + subId);
2646 }
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002649 }
2650 }
2651
2652 /**
2653 * Returns the voice activation state of a given subId.
2654 */
2655 @Override
2656 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002657 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002658
fionaxu0152e512016-11-14 13:36:14 -08002659 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 if (phone != null) {
2663 return phone.getVoiceActivationState();
2664 } else {
2665 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2666 }
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002669 }
2670 }
2671
2672 /**
2673 * Returns the data activation state of a given subId.
2674 */
2675 @Override
2676 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002677 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002678
fionaxu0152e512016-11-14 13:36:14 -08002679 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002680 final long identity = Binder.clearCallingIdentity();
2681 try {
2682 if (phone != null) {
2683 return phone.getDataActivationState();
2684 } else {
2685 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2686 }
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002689 }
2690 }
2691
2692 /**
Wink Saville36469e72014-06-11 15:17:00 -07002693 * Returns the unread count of voicemails for a subId
2694 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002695 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002696 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2697 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2698 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2699 return 0;
2700 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 final Phone phone = getPhone(subId);
2704 if (phone != null) {
2705 return phone.getVoiceMessageCount();
2706 } else {
2707 return 0;
2708 }
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 }
2713
2714 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002715 * returns true, if the device is in a state where both voice and data
2716 * are supported simultaneously. This can change based on location or network condition.
2717 */
2718 @Override
2719 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 final Phone phone = getPhone(subId);
2723 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
2726 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002727 }
2728
2729 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002730 * Send the dialer code if called from the current default dialer or the caller has
2731 * carrier privilege.
2732 * @param inputCode The dialer code to send
2733 */
2734 @Override
2735 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002736 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002738 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2739 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002740 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002741 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2742 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002743 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002744
2745 final long identity = Binder.clearCallingIdentity();
2746 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002747 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002748 } finally {
2749 Binder.restoreCallingIdentity(identity);
2750 }
fionaxu235cc5e2017-03-06 22:25:57 -08002751 }
2752
2753 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002754 * Returns the data network type.
2755 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 *
2757 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2758 */
2759 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002760 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 final Phone phone = getPhone(getDefaultSubscription());
2764 if (phone != null) {
2765 return phone.getServiceState().getDataNetworkType();
2766 } else {
2767 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2768 }
2769 } finally {
2770 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002771 }
Wink Saville36469e72014-06-11 15:17:00 -07002772 }
2773
Pengquan Meng0c05b502018-09-06 09:59:22 -07002774 @Override
2775 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002776 if (!isActiveSubscription(subId)) {
2777 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2778 }
2779
Pengquan Meng0c05b502018-09-06 09:59:22 -07002780 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2781 }
2782
Brad Ebinger4c460712018-10-01 10:40:55 -07002783 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002784 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2785 throws RemoteException {
2786 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002787 final long token = Binder.clearCallingIdentity();
2788 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002789 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002790 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002791 .addRegistrationCallbackForSubscription(c, subId);
2792 } finally {
2793 Binder.restoreCallingIdentity(token);
2794 }
2795 }
2796
2797 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002798 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2799 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002800 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2801 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2802 }
2803 Binder.withCleanCallingIdentity(() -> {
2804 try {
2805 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002806 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002807 .removeRegistrationCallbackForSubscription(c, subId);
2808 } catch (IllegalArgumentException e) {
2809 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2810 + "is inactive, ignoring unregister.");
2811 // If the subscription is no longer active, just return, since the callback
2812 // will already have been removed internally.
2813 }
2814 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002815 }
2816
2817 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002818 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2819 throws RemoteException {
2820 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2822 final long token = Binder.clearCallingIdentity();
2823 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002824 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002825 .addCapabilitiesCallbackForSubscription(c, subId);
2826 } finally {
2827 Binder.restoreCallingIdentity(token);
2828 }
2829 }
2830
2831 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002832 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2833 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002834
2835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2836 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2837 }
2838 Binder.withCleanCallingIdentity(() -> {
2839 try {
2840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002841 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002842 .removeCapabilitiesCallbackForSubscription(c, subId);
2843 } catch (IllegalArgumentException e) {
2844 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2845 + "is inactive, ignoring unregister.");
2846 // If the subscription is no longer active, just return, since the callback
2847 // will already have been removed internally.
2848 }
2849 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002850 }
2851
2852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002853 public boolean isCapable(int subId, int capability, int regTech) {
2854 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2856 final long token = Binder.clearCallingIdentity();
2857 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002858 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002859 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2860 } catch (ImsException e) {
2861 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2862 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002863 } catch (IllegalArgumentException e) {
2864 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2865 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002866 } finally {
2867 Binder.restoreCallingIdentity(token);
2868 }
2869 }
2870
2871 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002872 public boolean isAvailable(int subId, int capability, int regTech) {
2873 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002874 final long token = Binder.clearCallingIdentity();
2875 try {
2876 Phone phone = getPhone(subId);
2877 if (phone == null) return false;
2878 return phone.isImsCapabilityAvailable(capability, regTech);
2879 } finally {
2880 Binder.restoreCallingIdentity(token);
2881 }
2882 }
2883
2884 @Override
2885 public boolean isAdvancedCallingSettingEnabled(int subId) {
2886 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2888 final long token = Binder.clearCallingIdentity();
2889 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002890 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002891 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2892 } finally {
2893 Binder.restoreCallingIdentity(token);
2894 }
2895 }
2896
2897 @Override
2898 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2900 "setAdvancedCallingSetting");
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002904 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002905 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
2909 }
2910
2911 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002912 public boolean isVtSettingEnabled(int subId) {
2913 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002914 final long identity = Binder.clearCallingIdentity();
2915 try {
2916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002917 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002918 getSlotIndexOrException(subId)).isVtEnabledByUser();
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
2921 }
2922 }
2923
2924 @Override
2925 public void setVtSetting(int subId, boolean isEnabled) {
2926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2927 "setVtSetting");
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002931 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002932 } finally {
2933 Binder.restoreCallingIdentity(identity);
2934 }
2935 }
2936
2937 @Override
2938 public boolean isVoWiFiSettingEnabled(int subId) {
2939 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002943 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002944 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
2947 }
2948 }
2949
2950 @Override
2951 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2953 "setVoWiFiSetting");
2954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002957 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002958 } finally {
2959 Binder.restoreCallingIdentity(identity);
2960 }
2961 }
2962
2963 @Override
2964 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2965 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2966 final long identity = Binder.clearCallingIdentity();
2967 try {
2968 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002969 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002970 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2971 } finally {
2972 Binder.restoreCallingIdentity(identity);
2973 }
2974 }
2975
2976 @Override
2977 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2979 "setVoWiFiRoamingSetting");
2980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002983 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002984 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
2988 }
2989
2990 @Override
2991 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2993 "setVoWiFiNonPersistent");
2994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002997 boolean isRoaming = TelephonyManager.from(
2998 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002999 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003000 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
3004 }
3005
3006 @Override
3007 public int getVoWiFiModeSetting(int subId) {
3008 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003012 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003013 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
3016 }
3017 }
3018
3019 @Override
3020 public void setVoWiFiModeSetting(int subId, int mode) {
3021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3022 "setVoWiFiModeSetting");
3023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003026 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003027 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
3031 }
3032
3033 @Override
3034 public int getVoWiFiRoamingModeSetting(int subId) {
3035 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003039 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003040 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
3046 @Override
3047 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3049 "setVoWiFiRoamingModeSetting");
3050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003053 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003054 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3055 } finally {
3056 Binder.restoreCallingIdentity(identity);
3057 }
3058 }
3059
3060 @Override
3061 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3062 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3063 "setRttCapabilityEnabled");
3064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003067 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003068 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
3072 }
3073
3074 @Override
3075 public boolean isTtyOverVolteEnabled(int subId) {
3076 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3077 final long identity = Binder.clearCallingIdentity();
3078 try {
3079 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003080 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003081 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
3084 }
3085 }
3086
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003087 @Override
3088 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3089 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003093 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003094 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003095 } finally {
3096 Binder.restoreCallingIdentity(identity);
3097 }
3098 }
3099
3100 @Override
3101 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3102 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3103 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003104 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3105 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3106 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003107 try {
3108 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003109 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003110 .removeProvisioningCallbackForSubscription(callback, subId);
3111 } catch (IllegalArgumentException e) {
3112 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3113 + "is inactive, ignoring unregister.");
3114 // If the subscription is no longer active, just return, since the callback will already
3115 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
3119 }
3120
3121 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003122 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3123 boolean isProvisioned) {
3124 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3125 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3126 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3127 }
3128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3129 "setProvisioningStatusForCapability");
3130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3133 Phone phone = getPhone(subId);
3134 if (phone == null) {
3135 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3136 + subId);
3137 return;
3138 }
3139 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3140 return;
3141 }
3142
3143 // this capability requires provisioning, route to the correct API.
3144 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3145 switch (capability) {
3146 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3147 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3148 ims.setVolteProvisioned(isProvisioned);
3149 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3150 ims.setWfcProvisioned(isProvisioned);
3151 }
3152 break;
3153 }
3154 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3155 // There is currently no difference in VT provisioning type.
3156 ims.setVtProvisioned(isProvisioned);
3157 break;
3158 }
3159 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3160 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3161 // change the capability of the feature instead if needed.
3162 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3163 == isProvisioned) {
3164 // No change in provisioning.
3165 return;
3166 }
3167 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3168 try {
3169 ims.changeMmTelCapability(capability, tech, isProvisioned);
3170 } catch (ImsException e) {
3171 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3172 + ", Exception" + e.getMessage());
3173 }
3174 break;
3175 }
3176 default: {
3177 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3178 + capability + "', which does not require provisioning.");
3179 }
3180 }
3181
3182 } finally {
3183 Binder.restoreCallingIdentity(identity);
3184 }
3185 }
3186
3187 @Override
3188 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3189 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3190 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3191 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3192 }
3193 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3197 Phone phone = getPhone(subId);
3198 if (phone == null) {
3199 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3200 + subId);
3201 // We will fail with "true" as the provisioning status because this is the default
3202 // if we do not require provisioning.
3203 return true;
3204 }
3205
3206 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3207 return true;
3208 }
3209
3210 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3211 switch (capability) {
3212 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3213 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3214 return ims.isVolteProvisionedOnDevice();
3215 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3216 return ims.isWfcProvisionedOnDevice();
3217 }
3218 // This should never happen, since we are checking tech above to make sure it
3219 // is either LTE or IWLAN.
3220 throw new IllegalArgumentException("Invalid radio technology for voice "
3221 + "capability.");
3222 }
3223 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3224 // There is currently no difference in VT provisioning type.
3225 return ims.isVtProvisionedOnDevice();
3226 }
3227 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3228 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3229 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3230 }
3231 default: {
3232 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3233 + capability + "', which does not require provisioning.");
3234 }
3235 }
3236
3237 } finally {
3238 Binder.restoreCallingIdentity(identity);
3239 }
3240 }
3241
3242 @Override
3243 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3244 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3245 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3246 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3247 }
3248 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3249 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3250 return (provisionedBits & capability) > 0;
3251 }
3252
3253 @Override
3254 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3255 boolean isProvisioned) {
3256 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3257 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3258 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3259 }
3260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3261 "setProvisioningStatusForCapability");
3262 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3263 // If the current provisioning status for capability already matches isProvisioned,
3264 // do nothing.
3265 if (((provisionedBits & capability) > 0) == isProvisioned) {
3266 return;
3267 }
3268 if (isProvisioned) {
3269 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3270 } else {
3271 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3272 }
3273 }
3274
3275 /**
3276 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3277 * technology. The bitfield should mirror the bitfield defined by
3278 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3279 */
3280 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3281 String key = getMmTelProvisioningKey(subId, tech);
3282 // Default is no capabilities are provisioned.
3283 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3284 }
3285
3286 /**
3287 * Sets the MmTel capability provisioning bitfield (defined by
3288 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3289 * technology specified.
3290 *
3291 * Note: This is a synchronous command and should not be called on UI thread.
3292 */
3293 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3294 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3295 String key = getMmTelProvisioningKey(subId, tech);
3296 editor.putInt(key, newField);
3297 editor.commit();
3298 }
3299
3300 private static String getMmTelProvisioningKey(int subId, int tech) {
3301 // resulting key is provision_ims_mmtel_{subId}_{tech}
3302 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3303 }
3304
3305 /**
3306 * Query CarrierConfig to see if the specified capability requires provisioning for the
3307 * carrier associated with the subscription id.
3308 */
3309 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3310 int capability) {
3311 CarrierConfigManager configManager = new CarrierConfigManager(context);
3312 PersistableBundle c = configManager.getConfigForSubId(subId);
3313 boolean requireUtProvisioning = c.getBoolean(
3314 // By default, this config is true (even if there is no SIM). We also check to make
3315 // sure the subscription needs provisioning here, so we do not need to check for
3316 // the no-SIM case, where we would normally shortcut this to false.
3317 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3318 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3319 false);
3320 boolean requireVoiceVtProvisioning = c.getBoolean(
3321 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3322
3323 // First check to make sure that the capability requires provisioning.
3324 switch (capability) {
3325 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3326 // intentional fallthrough
3327 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3328 if (requireVoiceVtProvisioning) {
3329 // Voice and Video requires provisioning
3330 return true;
3331 }
3332 break;
3333 }
3334 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3335 if (requireUtProvisioning) {
3336 // UT requires provisioning
3337 return true;
3338 }
3339 break;
3340 }
3341 }
3342 return false;
3343 }
3344
3345 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003346 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003347 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3348 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3349 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003350 enforceReadPrivilegedPermission("getImsProvisioningInt");
3351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003354 int slotId = getSlotIndex(subId);
3355 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3356 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3357 + subId + "' for key:" + key);
3358 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3359 }
3360 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003361 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003362 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3363 + subId + "' for key:" + key);
3364 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
3368 }
3369
3370 @Override
3371 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003372 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3373 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3374 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003375 enforceReadPrivilegedPermission("getImsProvisioningString");
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003379 int slotId = getSlotIndex(subId);
3380 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3381 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3382 + subId + "' for key:" + key);
3383 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3384 }
3385 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003386 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003387 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3388 + subId + "' for key:" + key);
3389 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003390 } finally {
3391 Binder.restoreCallingIdentity(identity);
3392 }
3393 }
3394
3395 @Override
3396 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003397 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3398 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3399 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3401 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003405 int slotId = getSlotIndex(subId);
3406 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3407 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3408 + subId + "' for key:" + key);
3409 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3410 }
3411 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003412 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003413 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3414 + "' for key:" + key);
3415 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
3419 }
3420
3421 @Override
3422 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003423 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3424 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3425 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3427 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003428 final long identity = Binder.clearCallingIdentity();
3429 try {
3430 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003431 int slotId = getSlotIndex(subId);
3432 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3433 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3434 + subId + "' for key:" + key);
3435 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3436 }
3437 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003438 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003439 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3440 + "' for key:" + key);
3441 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
3445 }
3446
Brad Ebinger4c460712018-10-01 10:40:55 -07003447 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3448 int slotId = SubscriptionManager.getSlotIndex(subId);
3449 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003450 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003451 }
3452 return slotId;
3453 }
3454
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003455 private int getSlotIndex(int subId) {
3456 int slotId = SubscriptionManager.getSlotIndex(subId);
3457 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3458 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3459 }
3460 return slotId;
3461 }
3462
Wink Saville36469e72014-06-11 15:17:00 -07003463 /**
3464 * Returns the network type for a subId
3465 */
3466 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003467 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003469 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003470 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3471 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003472
Malcolm Chend965c8b2018-02-28 15:00:40 -08003473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 final Phone phone = getPhone(subId);
3476 if (phone != null) {
3477 return phone.getServiceState().getDataNetworkType();
3478 } else {
3479 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3480 }
3481 } finally {
3482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003484 }
3485
3486 /**
3487 * Returns the data network type
3488 */
3489 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003490 public int getDataNetworkType(String callingPackage) {
3491 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003492 }
3493
3494 /**
3495 * Returns the data network type for a subId
3496 */
3497 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003498 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003500 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003501 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3502 }
3503
Malcolm Chend965c8b2018-02-28 15:00:40 -08003504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 final Phone phone = getPhone(subId);
3507 if (phone != null) {
3508 return phone.getServiceState().getDataNetworkType();
3509 } else {
3510 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3511 }
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515 }
3516
3517 /**
Wink Saville36469e72014-06-11 15:17:00 -07003518 * Returns the Voice network type for a subId
3519 */
3520 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003521 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003523 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003524 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3525 }
3526
Malcolm Chend965c8b2018-02-28 15:00:40 -08003527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 final Phone phone = getPhone(subId);
3530 if (phone != null) {
3531 return phone.getServiceState().getVoiceNetworkType();
3532 } else {
3533 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3534 }
3535 } finally {
3536 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003538 }
3539
3540 /**
3541 * @return true if a ICC card is present
3542 */
3543 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003544 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003545 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3546 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003547 }
3548
3549 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003550 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003551 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003552 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003553 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003554 final long identity = Binder.clearCallingIdentity();
3555 try {
3556 final Phone phone = PhoneFactory.getPhone(slotIndex);
3557 if (phone != null) {
3558 return phone.getIccCard().hasIccCard();
3559 } else {
3560 return false;
3561 }
3562 } finally {
3563 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003565 }
3566
3567 /**
3568 * Return if the current radio is LTE on CDMA. This
3569 * is a tri-state return value as for a period of time
3570 * the mode may be unknown.
3571 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003572 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003573 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003574 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003575 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003576 @Override
3577 public int getLteOnCdmaMode(String callingPackage) {
3578 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003579 }
3580
Sanket Padawe356d7632015-06-22 14:03:32 -07003581 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003582 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003584 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003585 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3586 }
3587
Malcolm Chend965c8b2018-02-28 15:00:40 -08003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 final Phone phone = getPhone(subId);
3591 if (phone == null) {
3592 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3593 } else {
3594 return phone.getLteOnCdmaMode();
3595 }
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003598 }
Wink Saville36469e72014-06-11 15:17:00 -07003599 }
3600
Wink Saville36469e72014-06-11 15:17:00 -07003601 /**
3602 * {@hide}
3603 * Returns Default subId, 0 in the case of single standby.
3604 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003605 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003606 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003607 }
3608
Shishir Agrawala9f32182016-04-12 12:00:16 -07003609 private int getSlotForDefaultSubscription() {
3610 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3611 }
3612
Wink Savilleb564aae2014-10-23 10:18:09 -07003613 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003614 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003615 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003616
Pengquan Meng466e2482018-09-21 15:54:48 -07003617 private boolean isActiveSubscription(int subId) {
3618 return mSubscriptionController.isActiveSubId(subId);
3619 }
3620
Ihab Awadf2177b72013-11-25 13:33:23 -08003621 /**
3622 * @see android.telephony.TelephonyManager.WifiCallingChoices
3623 */
3624 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003625 final long identity = Binder.clearCallingIdentity();
3626 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003627 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003628 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3629 getWhenToMakeWifiCallsDefaultPreference());
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003633 }
3634
3635 /**
3636 * @see android.telephony.TelephonyManager.WifiCallingChoices
3637 */
3638 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003642 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003643 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003647 }
3648
Sailesh Nepald1e68152013-12-12 19:08:02 -08003649 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003650 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003651 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003652 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003653
Shishir Agrawal566b7612013-10-28 14:41:00 -07003654 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003655 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3656 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3658 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003660
Malcolm Chend965c8b2018-02-28 15:00:40 -08003661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 if (TextUtils.equals(ISDR_AID, aid)) {
3664 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003665 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3666 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003667 if (bestComponent == null
3668 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3669 loge("The calling package is not allowed to access ISD-R.");
3670 throw new SecurityException(
3671 "The calling package is not allowed to access ISD-R.");
3672 }
Derek Tan740e1672017-06-27 14:56:27 -07003673 }
Derek Tan740e1672017-06-27 14:56:27 -07003674
Malcolm Chend965c8b2018-02-28 15:00:40 -08003675 if (DBG) {
3676 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3677 }
3678 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3679 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3680 if (DBG) log("iccOpenLogicalChannel: " + response);
3681 return response;
3682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003685 }
3686
3687 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003688 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3690 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003691
Malcolm Chend965c8b2018-02-28 15:00:40 -08003692 final long identity = Binder.clearCallingIdentity();
3693 try {
3694 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3695 if (channel < 0) {
3696 return false;
3697 }
3698 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3699 if (DBG) log("iccCloseLogicalChannel: " + success);
3700 return success;
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003703 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003704 }
3705
3706 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003707 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003708 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3710 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003711
Malcolm Chend965c8b2018-02-28 15:00:40 -08003712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 if (DBG) {
3715 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3716 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3717 + p3 + " data=" + data);
3718 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003719
Malcolm Chend965c8b2018-02-28 15:00:40 -08003720 if (channel < 0) {
3721 return "";
3722 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003723
Malcolm Chend965c8b2018-02-28 15:00:40 -08003724 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3725 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3726 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003727
Malcolm Chend965c8b2018-02-28 15:00:40 -08003728 // Append the returned status code to the end of the response payload.
3729 String s = Integer.toHexString(
3730 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3731 if (response.payload != null) {
3732 s = IccUtils.bytesToHexString(response.payload) + s;
3733 }
3734 return s;
3735 } finally {
3736 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003737 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003738 }
Jake Hambye994d462014-02-03 13:10:13 -08003739
Evan Charltonc66da362014-05-16 14:06:40 -07003740 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003741 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3742 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3744 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003745 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003746
Malcolm Chend965c8b2018-02-28 15:00:40 -08003747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3750 && TextUtils.equals(ISDR_AID, data)) {
3751 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003752 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3753 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003754 if (bestComponent == null
3755 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3756 loge("The calling package is not allowed to select ISD-R.");
3757 throw new SecurityException(
3758 "The calling package is not allowed to select ISD-R.");
3759 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003760 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003761
Malcolm Chend965c8b2018-02-28 15:00:40 -08003762 if (DBG) {
3763 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3764 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3765 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003766
Malcolm Chend965c8b2018-02-28 15:00:40 -08003767 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3768 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3769 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003770
Malcolm Chend965c8b2018-02-28 15:00:40 -08003771 // Append the returned status code to the end of the response payload.
3772 String s = Integer.toHexString(
3773 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3774 if (response.payload != null) {
3775 s = IccUtils.bytesToHexString(response.payload) + s;
3776 }
3777 return s;
3778 } finally {
3779 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003780 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003781 }
3782
3783 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003784 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003785 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3787 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003788
Malcolm Chend965c8b2018-02-28 15:00:40 -08003789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 if (DBG) {
3792 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3793 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3794 }
3795
3796 IccIoResult response =
3797 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3798 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3799 subId);
3800
3801 if (DBG) {
3802 log("Exchange SIM_IO [R]" + response);
3803 }
3804
3805 byte[] result = null;
3806 int length = 2;
3807 if (response.payload != null) {
3808 length = 2 + response.payload.length;
3809 result = new byte[length];
3810 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3811 } else {
3812 result = new byte[length];
3813 }
3814
3815 result[length - 1] = (byte) response.sw2;
3816 result[length - 2] = (byte) response.sw1;
3817 return result;
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003820 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003821 }
3822
Nathan Haroldb3014052017-01-25 15:57:32 -08003823 /**
3824 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3825 * on a particular subscription
3826 */
sqianb6e41952018-03-12 14:54:01 -07003827 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3828 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3829 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3830 return null;
3831 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003832
3833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 if (appType != TelephonyManager.APPTYPE_USIM
3836 && appType != TelephonyManager.APPTYPE_SIM) {
3837 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3838 return null;
3839 }
3840 Object response = sendRequest(
3841 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3842 if (response instanceof String[]) {
3843 return (String[]) response;
3844 }
3845 // Response is an Exception of some kind,
3846 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003847 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003848 } finally {
3849 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003850 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003851 }
3852
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003853 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003854 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3856 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003857
Malcolm Chend965c8b2018-02-28 15:00:40 -08003858 final long identity = Binder.clearCallingIdentity();
3859 try {
3860 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3861 if (response.payload == null) {
3862 return "";
3863 }
Evan Charltonc66da362014-05-16 14:06:40 -07003864
Malcolm Chend965c8b2018-02-28 15:00:40 -08003865 // Append the returned status code to the end of the response payload.
3866 String s = Integer.toHexString(
3867 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3868 s = IccUtils.bytesToHexString(response.payload) + s;
3869 return s;
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
3872 }
Evan Charltonc66da362014-05-16 14:06:40 -07003873 }
3874
Jake Hambye994d462014-02-03 13:10:13 -08003875 /**
3876 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3877 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3878 *
3879 * @param itemID the ID of the item to read
3880 * @return the NV item as a String, or null on error.
3881 */
3882 @Override
3883 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003884 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3886 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003887
3888 final long identity = Binder.clearCallingIdentity();
3889 try {
3890 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003891 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003892 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3893 return value;
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
3896 }
Jake Hambye994d462014-02-03 13:10:13 -08003897 }
3898
3899 /**
3900 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3901 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3902 *
3903 * @param itemID the ID of the item to read
3904 * @param itemValue the value to write, as a String
3905 * @return true on success; false on any failure
3906 */
3907 @Override
3908 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003909 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3911 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003912
3913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3916 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003917 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003918 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3919 return success;
3920 } finally {
3921 Binder.restoreCallingIdentity(identity);
3922 }
Jake Hambye994d462014-02-03 13:10:13 -08003923 }
3924
3925 /**
3926 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3927 * Used for device configuration by some CDMA operators.
3928 *
3929 * @param preferredRoamingList byte array containing the new PRL
3930 * @return true on success; false on any failure
3931 */
3932 @Override
3933 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3935 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003936
3937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3940 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3941 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3942 return success;
3943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
Jake Hambye994d462014-02-03 13:10:13 -08003946 }
3947
3948 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003949 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003950 * Used for device configuration by some CDMA operators.
3951 *
chen xu1cc0abe2018-10-26 17:39:23 -07003952 * @param slotIndex - device slot.
3953 *
Jake Hambye994d462014-02-03 13:10:13 -08003954 * @return true on success; false on any failure
3955 */
3956 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003957 public boolean resetModemConfig(int slotIndex) {
3958 Phone phone = PhoneFactory.getPhone(slotIndex);
3959 if (phone != null) {
3960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3961 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003962
chen xu1cc0abe2018-10-26 17:39:23 -07003963 final long identity = Binder.clearCallingIdentity();
3964 try {
3965 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3966 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3967 return success;
3968 } finally {
3969 Binder.restoreCallingIdentity(identity);
3970 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003971 }
chen xu1cc0abe2018-10-26 17:39:23 -07003972 return false;
3973 }
3974
3975 /**
3976 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3977 *
3978 * @param slotIndex - device slot.
3979 *
3980 * @return true on success; false on any failure
3981 */
3982 @Override
3983 public boolean rebootModem(int slotIndex) {
3984 Phone phone = PhoneFactory.getPhone(slotIndex);
3985 if (phone != null) {
3986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3987 mApp, phone.getSubId(), "rebootModem");
3988
3989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3992 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3993 return success;
3994 } finally {
3995 Binder.restoreCallingIdentity(identity);
3996 }
3997 }
3998 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003999 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004000
Svet Ganovb320e182015-04-16 12:30:10 -07004001 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004002 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004004 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004005 return new String[0];
4006 }
4007
Malcolm Chend965c8b2018-02-28 15:00:40 -08004008 final long identity = Binder.clearCallingIdentity();
4009 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004010 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
Wink Saville36469e72014-06-11 15:17:00 -07004014 }
4015
Brad Ebinger51f743a2017-01-23 13:50:20 -08004016 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004017 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4018 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004019 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004020 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004021 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004022
4023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 PhoneFactory.getImsResolver().enableIms(slotId);
4026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004029 }
4030
4031 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004032 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4033 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004034 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004035 public void disableIms(int slotId) {
4036 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004037
4038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 PhoneFactory.getImsResolver().disableIms(slotId);
4041 } finally {
4042 Binder.restoreCallingIdentity(identity);
4043 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004044 }
4045
4046 /**
4047 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4048 * feature or {@link null} if the service is not available. If the feature is available, the
4049 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4050 */
4051 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004052 IImsServiceFeatureCallback callback) {
4053 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004054
4055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004061 }
4062
4063 /**
4064 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4065 * feature during emergency calling or {@link null} if the service is not available. If the
4066 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4067 * listener for feature updates.
4068 */
4069 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4070 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004071
4072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004078 }
4079
Brad Ebinger5f64b052017-12-14 14:26:15 -08004080 /**
4081 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4082 * specified.
4083 */
4084 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4085 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004086
4087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4090 } finally {
4091 Binder.restoreCallingIdentity(identity);
4092 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004093 }
4094
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004095 /**
4096 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4097 * specified.
4098 */
4099 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4100 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004101
4102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4105 } finally {
4106 Binder.restoreCallingIdentity(identity);
4107 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004108 }
4109
Brad Ebinger884c07b2018-02-15 16:17:40 -08004110 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004111 * Sets the ImsService Package Name that Telephony will bind to.
4112 *
4113 * @param slotId the slot ID that the ImsService should bind for.
4114 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4115 * ImsService is the device default ImsService.
4116 * @param packageName The package name of the application that contains the ImsService to bind
4117 * to.
4118 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4119 * @hide
4120 */
4121 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004122 int[] subIds = SubscriptionManager.getSubId(slotId);
4123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4124 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4125 "setImsService");
4126
Malcolm Chend965c8b2018-02-28 15:00:40 -08004127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4130 isCarrierImsService, packageName);
4131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004134 }
4135
4136 /**
4137 * Return the ImsService configuration.
4138 *
4139 * @param slotId The slot that the ImsService is associated with.
4140 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4141 * the device default.
4142 * @return the package name of the ImsService configuration.
4143 */
4144 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004145 int[] subIds = SubscriptionManager.getSubId(slotId);
4146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4147 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4148 "getImsService");
4149
Malcolm Chend965c8b2018-02-28 15:00:40 -08004150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4153 isCarrierImsService);
4154 } finally {
4155 Binder.restoreCallingIdentity(identity);
4156 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004157 }
4158
Wink Saville36469e72014-06-11 15:17:00 -07004159 public void setImsRegistrationState(boolean registered) {
4160 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004161
4162 final long identity = Binder.clearCallingIdentity();
4163 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004164 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
Wink Saville36469e72014-06-11 15:17:00 -07004168 }
4169
4170 /**
Stuart Scott54788802015-03-30 13:18:01 -07004171 * Set the network selection mode to automatic.
4172 *
4173 */
4174 @Override
4175 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4177 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004178
Pengquan Meng466e2482018-09-21 15:54:48 -07004179 if (!isActiveSubscription(subId)) {
4180 return;
4181 }
4182
Malcolm Chend965c8b2018-02-28 15:00:40 -08004183 final long identity = Binder.clearCallingIdentity();
4184 try {
4185 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4186 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4187 } finally {
4188 Binder.restoreCallingIdentity(identity);
4189 }
Stuart Scott54788802015-03-30 13:18:01 -07004190 }
4191
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004192 /**
4193 * Ask the radio to connect to the input network and change selection mode to manual.
4194 *
4195 * @param subId the id of the subscription.
4196 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4197 * the operator to attach to.
4198 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4199 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4200 * normal network selection next time.
4201 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004202 */
4203 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004204 public boolean setNetworkSelectionModeManual(
4205 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4207 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004208
4209 if (!isActiveSubscription(subId)) {
4210 return false;
4211 }
4212
Malcolm Chend965c8b2018-02-28 15:00:40 -08004213 final long identity = Binder.clearCallingIdentity();
4214 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004215 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004216 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004217 if (DBG) {
4218 log("setNetworkSelectionModeManual: subId: " + subId
4219 + " operator: " + operatorInfo);
4220 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004221 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4222 } finally {
4223 Binder.restoreCallingIdentity(identity);
4224 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004225 }
4226
4227 /**
4228 * Scans for available networks.
4229 */
4230 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004231 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4233 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004234 LocationAccessPolicy.LocationPermissionResult locationResult =
4235 LocationAccessPolicy.checkLocationPermission(mApp,
4236 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4237 .setCallingPackage(callingPackage)
4238 .setCallingPid(Binder.getCallingPid())
4239 .setCallingUid(Binder.getCallingUid())
4240 .setMethod("getCellNetworkScanResults")
4241 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4242 .build());
4243 switch (locationResult) {
4244 case DENIED_HARD:
4245 throw new SecurityException("Not allowed to access scan results -- location");
4246 case DENIED_SOFT:
4247 return null;
4248 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004249
Pengquan Meng0c05b502018-09-06 09:59:22 -07004250 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004251 try {
4252 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004253 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004254 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004258 }
4259
4260 /**
yinxub1bed742017-04-17 11:45:04 -07004261 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004262 *
yinxub1bed742017-04-17 11:45:04 -07004263 * @param subId id of the subscription
4264 * @param request contains the radio access networks with bands/channels to scan
4265 * @param messenger callback messenger for scan results or errors
4266 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004267 * @return the id of the requested scan which can be used to stop the scan.
4268 */
4269 @Override
4270 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004271 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4273 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004274
Hall Liuf19c44f2018-11-27 14:38:17 -08004275 LocationAccessPolicy.LocationPermissionResult locationResult =
4276 LocationAccessPolicy.checkLocationPermission(mApp,
4277 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4278 .setCallingPackage(callingPackage)
4279 .setCallingPid(Binder.getCallingPid())
4280 .setCallingUid(Binder.getCallingUid())
4281 .setMethod("requestNetworkScan")
4282 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4283 .build());
4284 switch (locationResult) {
4285 case DENIED_HARD:
4286 throw new SecurityException("Not allowed to request network scan -- location");
4287 case DENIED_SOFT:
4288 return -1;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004289 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004290
4291 return mNetworkScanRequestTracker.startNetworkScan(
4292 request, messenger, binder, getPhone(subId),
4293 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004294 }
4295
4296 /**
4297 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004298 *
4299 * @param subId id of the subscription
4300 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004301 */
4302 @Override
4303 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4305 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004306
4307 final long identity = Binder.clearCallingIdentity();
4308 try {
4309 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4310 } finally {
4311 Binder.restoreCallingIdentity(identity);
4312 }
yinxu504e1392017-04-12 16:03:22 -07004313 }
4314
4315 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004316 * Get the calculated preferred network type.
4317 * Used for debugging incorrect network type.
4318 *
4319 * @return the preferred network type, defined in RILConstants.java.
4320 */
4321 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004322 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004323 final Phone defaultPhone = getDefaultPhone();
4324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4325 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004326 return RILConstants.PREFERRED_NETWORK_MODE;
4327 }
4328
Malcolm Chend965c8b2018-02-28 15:00:40 -08004329 final long identity = Binder.clearCallingIdentity();
4330 try {
4331 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004332 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
Junda Liu84d15a22014-07-02 11:21:04 -07004336 }
4337
4338 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004339 * Get the preferred network type.
4340 * Used for device configuration by some CDMA operators.
4341 *
4342 * @return the preferred network type, defined in RILConstants.java.
4343 */
4344 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004345 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004346 TelephonyPermissions
4347 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4348 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004349
4350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 if (DBG) log("getPreferredNetworkType");
4353 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4354 int networkType = (result != null ? result[0] : -1);
4355 if (DBG) log("getPreferredNetworkType: " + networkType);
4356 return networkType;
4357 } finally {
4358 Binder.restoreCallingIdentity(identity);
4359 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004360 }
4361
4362 /**
4363 * Set the preferred network type.
4364 * Used for device configuration by some CDMA operators.
4365 *
4366 * @param networkType the preferred network type, defined in RILConstants.java.
4367 * @return true on success; false on any failure.
4368 */
4369 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004370 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4372 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004373
4374 final long identity = Binder.clearCallingIdentity();
4375 try {
4376 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4377 Boolean success = (Boolean) sendRequest(
4378 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4379 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4380 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004381 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004382 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4383 }
4384 return success;
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004387 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004388 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004389
4390 /**
Junda Liu475951f2014-11-07 16:45:03 -08004391 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004392 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004393 * tethering.
4394 *
4395 * @return 0: Not required. 1: required. 2: Not set.
4396 * @hide
4397 */
4398 @Override
4399 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004400 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004401
4402 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004403 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004404 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004405 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004406 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004407 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004408 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004409 dunRequired = 1;
4410 }
4411 return dunRequired;
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004414 }
Junda Liu475951f2014-11-07 16:45:03 -08004415 }
4416
4417 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004418 * Set mobile data enabled
4419 * Used by the user through settings etc to turn on/off mobile data
4420 *
4421 * @param enable {@code true} turn turn data on, else {@code false}
4422 */
4423 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004424 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4426 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004427
4428 final long identity = Binder.clearCallingIdentity();
4429 try {
4430 int phoneId = mSubscriptionController.getPhoneId(subId);
4431 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4432 Phone phone = PhoneFactory.getPhone(phoneId);
4433 if (phone != null) {
4434 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004435 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004436 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004437 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004438 }
4439 } finally {
4440 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004441 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004442 }
4443
4444 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004445 * Get the user enabled state of Mobile Data.
4446 *
4447 * TODO: remove and use isUserDataEnabled.
4448 * This can't be removed now because some vendor codes
4449 * calls through ITelephony directly while they should
4450 * use TelephonyManager.
4451 *
4452 * @return true on enabled
4453 */
4454 @Override
4455 public boolean getDataEnabled(int subId) {
4456 return isUserDataEnabled(subId);
4457 }
4458
4459 /**
4460 * Get whether mobile data is enabled per user setting.
4461 *
4462 * There are other factors deciding whether mobile data is actually enabled, but they are
4463 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004464 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004465 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004466 *
4467 * @return {@code true} if data is enabled else {@code false}
4468 */
4469 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004470 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004471 try {
4472 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4473 null);
4474 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4476 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004477 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004478
4479 final long identity = Binder.clearCallingIdentity();
4480 try {
4481 int phoneId = mSubscriptionController.getPhoneId(subId);
4482 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4483 Phone phone = PhoneFactory.getPhone(phoneId);
4484 if (phone != null) {
4485 boolean retVal = phone.isUserDataEnabled();
4486 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4487 return retVal;
4488 } else {
4489 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4490 return false;
4491 }
4492 } finally {
4493 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004494 }
4495 }
4496
4497 /**
4498 * Get whether mobile data is enabled.
4499 *
4500 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4501 * whether mobile data is actually enabled.
4502 *
4503 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4504 *
4505 * @return {@code true} if data is enabled else {@code false}
4506 */
4507 @Override
4508 public boolean isDataEnabled(int subId) {
4509 try {
4510 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4511 null);
4512 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4514 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004515 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004516
4517 final long identity = Binder.clearCallingIdentity();
4518 try {
4519 int phoneId = mSubscriptionController.getPhoneId(subId);
4520 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4521 Phone phone = PhoneFactory.getPhone(phoneId);
4522 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004523 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004524 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4525 return retVal;
4526 } else {
4527 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4528 return false;
4529 }
4530 } finally {
4531 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004532 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004533 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004534
4535 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004536 public int getCarrierPrivilegeStatus(int subId) {
4537 final Phone phone = getPhone(subId);
4538 if (phone == null) {
4539 loge("getCarrierPrivilegeStatus: Invalid subId");
4540 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4541 }
4542 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004543 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004544 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004545 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4546 }
4547 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004548 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004549 }
Junda Liu29340342014-07-10 15:23:27 -07004550
4551 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004552 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4553 final Phone phone = getPhone(subId);
4554 if (phone == null) {
4555 loge("getCarrierPrivilegeStatus: Invalid subId");
4556 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4557 }
4558 UiccProfile profile =
4559 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4560 if (profile == null) {
4561 loge("getCarrierPrivilegeStatus: No UICC");
4562 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4563 }
4564 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4565 }
4566
4567 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004568 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004569 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004570 if (TextUtils.isEmpty(pkgName))
4571 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004572 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004573 if (card == null) {
4574 loge("checkCarrierPrivilegesForPackage: No UICC");
4575 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4576 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004577 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4578 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004579 }
4580
4581 @Override
4582 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004583 if (TextUtils.isEmpty(pkgName))
4584 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004585 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4586 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4587 UiccCard card = UiccController.getInstance().getUiccCard(i);
4588 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004589 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004590 continue;
4591 }
4592
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004593 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004594 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4595 break;
4596 }
4597 }
4598
4599 return result;
Junda Liu29340342014-07-10 15:23:27 -07004600 }
Derek Tan89e89d42014-07-08 17:00:10 -07004601
4602 @Override
Junda Liue64de782015-04-16 17:19:16 -07004603 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4604 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4605 loge("phoneId " + phoneId + " is not valid.");
4606 return null;
4607 }
4608 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004609 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004610 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004611 return null ;
4612 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004613 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004614 }
4615
Amith Yamasani6e118872016-02-19 12:53:51 -08004616 @Override
4617 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004618 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004619 List<String> privilegedPackages = new ArrayList<>();
4620 List<PackageInfo> packages = null;
4621 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4622 UiccCard card = UiccController.getInstance().getUiccCard(i);
4623 if (card == null) {
4624 // No UICC in that slot.
4625 continue;
4626 }
4627 if (card.hasCarrierPrivilegeRules()) {
4628 if (packages == null) {
4629 // Only check packages in user 0 for now
4630 packages = pm.getInstalledPackagesAsUser(
4631 PackageManager.MATCH_DISABLED_COMPONENTS
4632 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4633 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4634 }
4635 for (int p = packages.size() - 1; p >= 0; p--) {
4636 PackageInfo pkgInfo = packages.get(p);
4637 if (pkgInfo != null && pkgInfo.packageName != null
4638 && card.getCarrierPrivilegeStatus(pkgInfo)
4639 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4640 privilegedPackages.add(pkgInfo.packageName);
4641 }
4642 }
4643 }
4644 }
4645 return privilegedPackages;
4646 }
4647
Wink Savilleb564aae2014-10-23 10:18:09 -07004648 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004649 final Phone phone = getPhone(subId);
4650 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004651 if (card == null) {
4652 loge("getIccId: No UICC");
4653 return null;
4654 }
4655 String iccId = card.getIccId();
4656 if (TextUtils.isEmpty(iccId)) {
4657 loge("getIccId: ICC ID is null or empty.");
4658 return null;
4659 }
4660 return iccId;
4661 }
4662
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004663 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004664 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4665 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004666 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4667 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004668
Malcolm Chend965c8b2018-02-28 15:00:40 -08004669 final long identity = Binder.clearCallingIdentity();
4670 try {
4671 final String iccId = getIccId(subId);
4672 final Phone phone = getPhone(subId);
4673 if (phone == null) {
4674 return false;
4675 }
4676 final String subscriberId = phone.getSubscriberId();
4677
4678 if (DBG_MERGE) {
4679 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4680 + subscriberId + " to " + number);
4681 }
4682
4683 if (TextUtils.isEmpty(iccId)) {
4684 return false;
4685 }
4686
4687 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4688
4689 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4690 if (alphaTag == null) {
4691 editor.remove(alphaTagPrefKey);
4692 } else {
4693 editor.putString(alphaTagPrefKey, alphaTag);
4694 }
4695
4696 // Record both the line number and IMSI for this ICCID, since we need to
4697 // track all merged IMSIs based on line number
4698 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4699 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4700 if (number == null) {
4701 editor.remove(numberPrefKey);
4702 editor.remove(subscriberPrefKey);
4703 } else {
4704 editor.putString(numberPrefKey, number);
4705 editor.putString(subscriberPrefKey, subscriberId);
4706 }
4707
4708 editor.commit();
4709 return true;
4710 } finally {
4711 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004712 }
Derek Tan7226c842014-07-02 17:42:23 -07004713 }
4714
4715 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004716 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004717 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004719 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004720 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004721 return null;
4722 }
Derek Tan97ebb422014-09-05 16:55:38 -07004723
Malcolm Chend965c8b2018-02-28 15:00:40 -08004724 final long identity = Binder.clearCallingIdentity();
4725 try {
4726 String iccId = getIccId(subId);
4727 if (iccId != null) {
4728 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4729 if (DBG_MERGE) {
4730 log("getLine1NumberForDisplay returning "
4731 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4732 }
4733 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004734 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004735 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4736 return null;
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004739 }
Derek Tan7226c842014-07-02 17:42:23 -07004740 }
4741
4742 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004743 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004745 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004746 return null;
4747 }
Derek Tan97ebb422014-09-05 16:55:38 -07004748
Malcolm Chend965c8b2018-02-28 15:00:40 -08004749 final long identity = Binder.clearCallingIdentity();
4750 try {
4751 String iccId = getIccId(subId);
4752 if (iccId != null) {
4753 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4754 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4755 }
4756 return null;
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004759 }
Derek Tan7226c842014-07-02 17:42:23 -07004760 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004761
4762 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004763 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004764 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4765 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004766 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004767 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4768 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004769 return null;
4770 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004771
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004772 final long identity = Binder.clearCallingIdentity();
4773 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004774 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004775 final TelephonyManager tele = TelephonyManager.from(context);
4776 final SubscriptionManager sub = SubscriptionManager.from(context);
4777
4778 // Figure out what subscribers are currently active
4779 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4780 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4781 // the process, where TelephonyManager was instantiated.
4782 // Otherwise AppOps check will fail.
4783
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004784 final int[] subIds = sub.getActiveSubscriptionIdList();
4785 for (int subId : subIds) {
4786 activeSubscriberIds.add(tele.getSubscriberId(subId));
4787 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004788
4789 // First pass, find a number override for an active subscriber
4790 String mergeNumber = null;
4791 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4792 for (String key : prefs.keySet()) {
4793 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4794 final String subscriberId = (String) prefs.get(key);
4795 if (activeSubscriberIds.contains(subscriberId)) {
4796 final String iccId = key.substring(
4797 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4798 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4799 mergeNumber = (String) prefs.get(numberKey);
4800 if (DBG_MERGE) {
4801 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4802 + " for active subscriber " + subscriberId);
4803 }
4804 if (!TextUtils.isEmpty(mergeNumber)) {
4805 break;
4806 }
4807 }
4808 }
4809 }
4810
4811 // Shortcut when no active merged subscribers
4812 if (TextUtils.isEmpty(mergeNumber)) {
4813 return null;
4814 }
4815
4816 // Second pass, find all subscribers under that line override
4817 final ArraySet<String> result = new ArraySet<>();
4818 for (String key : prefs.keySet()) {
4819 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4820 final String number = (String) prefs.get(key);
4821 if (mergeNumber.equals(number)) {
4822 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4823 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4824 final String subscriberId = (String) prefs.get(subscriberKey);
4825 if (!TextUtils.isEmpty(subscriberId)) {
4826 result.add(subscriberId);
4827 }
4828 }
4829 }
4830 }
4831
4832 final String[] resultArray = result.toArray(new String[result.size()]);
4833 Arrays.sort(resultArray);
4834 if (DBG_MERGE) {
4835 Slog.d(LOG_TAG,
4836 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4837 }
4838 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004839 } finally {
4840 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004841 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004842 }
4843
4844 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004845 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004846 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4847 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004848
4849 final long identity = Binder.clearCallingIdentity();
4850 try {
4851 final Phone phone = getPhone(subId);
4852 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004856 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004857
4858 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004859 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004860 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4861 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004862 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004863
4864 final long identity = Binder.clearCallingIdentity();
4865 try {
4866 final Phone phone = getPhone(subId);
4867 if (phone == null) {
4868 return false;
4869 }
4870 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4871 cdmaNonRoamingList);
4872 } finally {
4873 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004874 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004875 }
4876
4877 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004878 @Deprecated
4879 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4880 enforceModifyPermission();
4881
4882 int returnValue = 0;
4883 try {
vagdevie435a3e2018-08-15 16:01:53 -07004884 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004885 if(result.exception == null) {
4886 if (result.result != null) {
4887 byte[] responseData = (byte[])(result.result);
4888 if(responseData.length > oemResp.length) {
4889 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4890 responseData.length + "bytes. Buffer Size is " +
4891 oemResp.length + "bytes.");
4892 }
4893 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4894 returnValue = responseData.length;
4895 }
4896 } else {
4897 CommandException ex = (CommandException) result.exception;
4898 returnValue = ex.getCommandError().ordinal();
4899 if(returnValue > 0) returnValue *= -1;
4900 }
4901 } catch (RuntimeException e) {
4902 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4903 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4904 if(returnValue > 0) returnValue *= -1;
4905 }
4906
4907 return returnValue;
4908 }
4909
4910 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004911 public void setRadioCapability(RadioAccessFamily[] rafs) {
4912 try {
4913 ProxyController.getInstance().setRadioCapability(rafs);
4914 } catch (RuntimeException e) {
4915 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4916 }
4917 }
4918
4919 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004920 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004921 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004922 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004923 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004924 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004925 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004926 final long identity = Binder.clearCallingIdentity();
4927 try {
chen xufeeed752018-10-26 14:17:57 -07004928 TelephonyPermissions
4929 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4930 mApp, phone.getSubId(), "getRadioAccessFamily");
4931 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
chen xufeeed752018-10-26 14:17:57 -07004935 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004936 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004937
4938 @Override
4939 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004940 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004941 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004942
4943 final long identity = Binder.clearCallingIdentity();
4944 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004945 ImsManager.getInstance(defaultPhone.getContext(),
4946 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004947 } finally {
4948 Binder.restoreCallingIdentity(identity);
4949 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004950 }
4951
4952 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004953 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004954 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004956 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004957 return false;
4958 }
Svet Ganovb320e182015-04-16 12:30:10 -07004959
Malcolm Chend965c8b2018-02-28 15:00:40 -08004960 final long identity = Binder.clearCallingIdentity();
4961 try {
4962 // Check the user preference and the system-level IMS setting. Even if the user has
4963 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4964 // In the long run, we may instead need to check if there exists a connection service
4965 // which can support video calling.
4966 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004967 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004968 return imsManager.isVtEnabledByPlatform()
4969 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4970 && imsManager.isVtEnabledByUser();
4971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004974 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004975
Andrew Leea1239f22015-03-02 17:44:07 -08004976 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004977 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4979 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4980 return false;
4981 }
4982
4983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 CarrierConfigManager configManager =
4986 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004987 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004988 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
Andrew Leea1239f22015-03-02 17:44:07 -08004992 }
4993
4994 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004995 public boolean isWorldPhone(int subId, String callingPackage) {
4996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4997 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4998 return false;
4999 }
5000
5001 final long identity = Binder.clearCallingIdentity();
5002 try {
5003 CarrierConfigManager configManager =
5004 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005005 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005006 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5007 } finally {
5008 Binder.restoreCallingIdentity(identity);
5009 }
Andrew Leea1239f22015-03-02 17:44:07 -08005010 }
5011
Andrew Lee9431b832015-03-09 18:46:45 -07005012 @Override
5013 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005014 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005015 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005016 }
5017
5018 @Override
5019 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005020 final long identity = Binder.clearCallingIdentity();
5021 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005022 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005023 } finally {
5024 Binder.restoreCallingIdentity(identity);
5025 }
Andrew Lee9431b832015-03-09 18:46:45 -07005026 }
5027
Hall Liuf6668912018-10-31 17:05:23 -07005028 /**
5029 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5030 * support for the feature and device firmware support.
5031 *
5032 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5033 */
5034 @Override
5035 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005036 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005037 final Phone phone = getPhone(subscriptionId);
5038 if (phone == null) {
5039 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5040 return false;
5041 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005042 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005043 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005044 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5045 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005046 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005047 return isCarrierSupported && isDeviceSupported;
5048 } finally {
5049 Binder.restoreCallingIdentity(identity);
5050 }
Hall Liu98187582018-01-22 19:15:32 -08005051 }
5052
Hall Liuf6668912018-10-31 17:05:23 -07005053 /**
5054 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5055 * both also support RTT.
5056 */
5057 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005058 final long identity = Binder.clearCallingIdentity();
5059 try {
Hall Liuf6668912018-10-31 17:05:23 -07005060 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005061 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005062 } finally {
5063 Binder.restoreCallingIdentity(identity);
5064 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005065 }
5066
Sanket Padawe7310cc72015-01-14 09:53:20 -08005067 /**
5068 * Returns the unique device ID of phone, for example, the IMEI for
5069 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5070 *
5071 * <p>Requires Permission:
5072 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5073 */
5074 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005075 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005076 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005077 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005078 return null;
5079 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005080 int subId = phone.getSubId();
5081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5082 mApp, subId, callingPackage, "getDeviceId")) {
5083 return null;
5084 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005085
5086 final long identity = Binder.clearCallingIdentity();
5087 try {
5088 return phone.getDeviceId();
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005092 }
5093
Ping Sunc67b7c22016-03-02 19:16:45 +08005094 /**
5095 * {@hide}
5096 * Returns the IMS Registration Status on a particular subid
5097 *
5098 * @param subId
5099 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005100 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005101 Phone phone = getPhone(subId);
5102 if (phone != null) {
5103 return phone.isImsRegistered();
5104 } else {
5105 return false;
5106 }
5107 }
5108
Santos Cordon7a1885b2015-02-03 11:15:19 -08005109 @Override
5110 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005111 final long identity = Binder.clearCallingIdentity();
5112 try {
5113 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005117 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005118
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005119 /**
5120 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005121 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005122 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005123 final long identity = Binder.clearCallingIdentity();
5124 try {
5125 Phone phone = getPhone(subId);
5126 if (phone != null) {
5127 return phone.isWifiCallingEnabled();
5128 } else {
5129 return false;
5130 }
5131 } finally {
5132 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005133 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005134 }
5135
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005136 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005137 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005138 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005139 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005140 final long identity = Binder.clearCallingIdentity();
5141 try {
5142 Phone phone = getPhone(subId);
5143 if (phone != null) {
5144 return phone.isVideoEnabled();
5145 } else {
5146 return false;
5147 }
5148 } finally {
5149 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005150 }
5151 }
5152
5153 /**
5154 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5155 * defined in {@link ImsRegistrationImplBase}.
5156 */
5157 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005158 final long identity = Binder.clearCallingIdentity();
5159 try {
5160 Phone phone = getPhone(subId);
5161 if (phone != null) {
5162 return phone.getImsRegistrationTech();
5163 } else {
5164 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5165 }
5166 } finally {
5167 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005168 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005169 }
5170
Stuart Scott8eef64f2015-04-08 15:13:54 -07005171 @Override
5172 public void factoryReset(int subId) {
5173 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005174 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5175 return;
5176 }
5177
Svet Ganovcc087f82015-05-12 20:35:54 -07005178 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005179
Svet Ganovcc087f82015-05-12 20:35:54 -07005180 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005181 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5182 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005183 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005184 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005185 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005186 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5187 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005188 }
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005191 }
5192 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005193
5194 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005195 public String getSimLocaleForSubscriber(int subId) {
5196 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5197 final Phone phone = getPhone(subId);
5198 if (phone == null) {
5199 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005200 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005201 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005202 final long identity = Binder.clearCallingIdentity();
5203 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005204 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5205 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005206 // Try and fetch the locale from the carrier properties or from the SIM language
5207 // preferences (EF-PL and EF-LI)...
5208 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005209 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005210 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5211 if (localeFromDefaultSim != null) {
5212 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5213 if (DBG) log("Using locale from subId: " + subId + " locale: "
5214 + localeFromDefaultSim);
5215 return localeFromDefaultSim.toLanguageTag();
5216 } else {
5217 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005218 }
5219 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005220
Malcolm Chend965c8b2018-02-28 15:00:40 -08005221 // The SIM language preferences only store a language (e.g. fr = French), not an
5222 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5223 // the SIM and carrier preferences does not include a country we add the country
5224 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005225 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005226 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005227 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005228 return mccLocale.toLanguageTag();
5229 }
5230
5231 if (DBG) log("No locale found - returning null");
5232 return null;
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005236 }
5237
5238 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005239 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005240 }
5241
Malcolm Chend965c8b2018-02-28 15:00:40 -08005242 /**
5243 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5244 */
5245 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005246 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005247 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005248
Chenjie Yu1ba97252018-01-11 18:16:20 -08005249 private final ModemActivityInfo mLastModemActivityInfo =
5250 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5251
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005252 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005253 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5254 * representing the state of the modem.
5255 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005256 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5257 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005258 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005259 */
5260 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005261 public void requestModemActivityInfo(ResultReceiver result) {
5262 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005264
5265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 ModemActivityInfo ret = null;
5268 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005269 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5270 CMD_GET_MODEM_ACTIVITY_INFO,
5271 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005272 if (isModemActivityInfoValid(info)) {
5273 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5274 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5275 mergedTxTimeMs[i] =
5276 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5277 }
5278 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5279 mLastModemActivityInfo.setSleepTimeMillis(
5280 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5281 mLastModemActivityInfo.setIdleTimeMillis(
5282 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5283 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5284 mLastModemActivityInfo.setRxTimeMillis(
5285 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5286 mLastModemActivityInfo.setEnergyUsed(
5287 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005288 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005289 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5290 mLastModemActivityInfo.getSleepTimeMillis(),
5291 mLastModemActivityInfo.getIdleTimeMillis(),
5292 mLastModemActivityInfo.getTxTimeMillis(),
5293 mLastModemActivityInfo.getRxTimeMillis(),
5294 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005295 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005296 Bundle bundle = new Bundle();
5297 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5298 result.send(0, bundle);
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005301 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005302 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005303
Siddharth Rayf5d29552018-06-17 15:02:38 -07005304 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5305 // less than total activity duration.
5306 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5307 if (info == null) {
5308 return false;
5309 }
5310 int activityDurationMs =
5311 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5312 int totalTxTimeMs = 0;
5313 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5314 totalTxTimeMs += info.getTxTimeMillis()[i];
5315 }
5316 return (info.isValid()
5317 && (info.getSleepTimeMillis() <= activityDurationMs)
5318 && (info.getIdleTimeMillis() <= activityDurationMs)
5319 && (info.getRxTimeMillis() <= activityDurationMs)
5320 && (totalTxTimeMs <= activityDurationMs));
5321 }
5322
Jack Yu85bd38a2015-11-09 11:34:32 -08005323 /**
5324 * {@hide}
5325 * Returns the service state information on specified subscription.
5326 */
5327 @Override
5328 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005330 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005331 return null;
5332 }
5333
Hall Liuf19c44f2018-11-27 14:38:17 -08005334 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5335 LocationAccessPolicy.checkLocationPermission(mApp,
5336 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5337 .setCallingPackage(callingPackage)
5338 .setCallingPid(Binder.getCallingPid())
5339 .setCallingUid(Binder.getCallingUid())
5340 .setMethod("getServiceStateForSubscriber")
5341 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5342 .build());
5343
5344 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5345 LocationAccessPolicy.checkLocationPermission(mApp,
5346 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5347 .setCallingPackage(callingPackage)
5348 .setCallingPid(Binder.getCallingPid())
5349 .setCallingUid(Binder.getCallingUid())
5350 .setMethod("getServiceStateForSubscriber")
5351 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5352 .build());
5353 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5354 boolean hasFinePermission =
5355 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5356 boolean hasCoarsePermission =
5357 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5358
Malcolm Chend965c8b2018-02-28 15:00:40 -08005359 final long identity = Binder.clearCallingIdentity();
5360 try {
5361 final Phone phone = getPhone(subId);
5362 if (phone == null) {
5363 return null;
5364 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005365
Hall Liuf19c44f2018-11-27 14:38:17 -08005366 ServiceState ss = phone.getServiceState();
5367
5368 // Scrub out the location info in ServiceState depending on what level of access
5369 // the caller has.
5370 if (hasFinePermission) return ss;
5371 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5372 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005376 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005377
5378 /**
5379 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5380 *
5381 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5382 * voicemail ringtone.
5383 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5384 * PhoneAccount.
5385 */
5386 @Override
5387 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5391 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005392 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005393 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005394
Malcolm Chend965c8b2018-02-28 15:00:40 -08005395 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005399 }
5400
5401 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005402 * Sets the per-account voicemail ringtone.
5403 *
5404 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5405 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5406 *
5407 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5408 * voicemail ringtone.
5409 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5410 * PhoneAccount.
5411 */
5412 @Override
5413 public void setVoicemailRingtoneUri(String callingPackage,
5414 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005415 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005416 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5417 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005418 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5420 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5421 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005422 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005423
5424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5427 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005428 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005429 }
5430 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5431 } finally {
5432 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005433 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005434 }
5435
5436 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005437 * Returns whether vibration is set for voicemail notification in Phone settings.
5438 *
5439 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5440 * voicemail vibration setting.
5441 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5442 */
5443 @Override
5444 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005445 final long identity = Binder.clearCallingIdentity();
5446 try {
5447 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5448 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005449 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005450 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005451
Malcolm Chend965c8b2018-02-28 15:00:40 -08005452 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
5455 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005456 }
5457
Youhan Wange64578a2016-05-02 15:32:42 -07005458 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005459 * Sets the per-account voicemail vibration.
5460 *
5461 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5462 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5463 *
5464 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5465 * voicemail vibration setting.
5466 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5467 * specific PhoneAccount.
5468 */
5469 @Override
5470 public void setVoicemailVibrationEnabled(String callingPackage,
5471 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005472 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5474 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005475 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5477 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5478 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005479 }
5480
Malcolm Chend965c8b2018-02-28 15:00:40 -08005481 final long identity = Binder.clearCallingIdentity();
5482 try {
5483 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5484 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005485 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005486 }
5487 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005490 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005491 }
5492
5493 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005494 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5495 *
5496 * @throws SecurityException if the caller does not have the required permission
5497 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005498 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005499 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005500 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005501 }
5502
5503 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005504 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5505 * permission.
5506 *
5507 * @throws SecurityException if the caller does not have the required permission
5508 */
5509 private void enforceSendSmsPermission() {
5510 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5511 }
5512
5513 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005514 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005515 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005516 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005517 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005518 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005519 final long identity = Binder.clearCallingIdentity();
5520 try {
5521 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005522 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005523 if (componentName == null) {
5524 throw new SecurityException(
5525 "Caller not current active visual voicemail package[null]");
5526 }
5527 String vvmPackage = componentName.getPackageName();
5528 if (!callingPackage.equals(vvmPackage)) {
5529 throw new SecurityException("Caller not current active visual voicemail package["
5530 + vvmPackage + "]");
5531 }
5532 } finally {
5533 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005534 }
5535 }
5536
5537 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005538 * Return the application ID for the app type.
5539 *
5540 * @param subId the subscription ID that this request applies to.
5541 * @param appType the uicc app type.
5542 * @return Application ID for specificied app type, or null if no uicc.
5543 */
5544 @Override
5545 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005546 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005547 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005548
5549 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005550 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005551 if (phone == null) {
5552 return null;
5553 }
5554 String aid = null;
5555 try {
5556 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5557 .getApplicationByType(appType).getAid();
5558 } catch (Exception e) {
5559 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5560 }
5561 return aid;
5562 } finally {
5563 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005564 }
Youhan Wange64578a2016-05-02 15:32:42 -07005565 }
5566
Youhan Wang4001d252016-05-11 10:29:41 -07005567 /**
5568 * Return the Electronic Serial Number.
5569 *
5570 * @param subId the subscription ID that this request applies to.
5571 * @return ESN or null if error.
5572 */
5573 @Override
5574 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005575 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005576 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005577
5578 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005579 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005580 if (phone == null) {
5581 return null;
5582 }
5583 String esn = null;
5584 try {
5585 esn = phone.getEsn();
5586 } catch (Exception e) {
5587 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5588 }
5589 return esn;
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005592 }
Youhan Wang4001d252016-05-11 10:29:41 -07005593 }
5594
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005595 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005596 * Return the Preferred Roaming List Version.
5597 *
5598 * @param subId the subscription ID that this request applies to.
5599 * @return PRLVersion or null if error.
5600 */
5601 @Override
5602 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005603 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005604 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005605
5606 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005607 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005608 if (phone == null) {
5609 return null;
5610 }
5611 String cdmaPrlVersion = null;
5612 try {
5613 cdmaPrlVersion = phone.getCdmaPrlVersion();
5614 } catch (Exception e) {
5615 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5616 }
5617 return cdmaPrlVersion;
5618 } finally {
5619 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005620 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005621 }
5622
5623 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005624 * Get snapshot of Telephony histograms
5625 * @return List of Telephony histograms
5626 * @hide
5627 */
5628 @Override
5629 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5631 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005632
5633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 return RIL.getTelephonyRILTimingHistograms();
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
5638 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005639 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005640
5641 /**
5642 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005643 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5644 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005645 * Require system privileges. In the future we may add this to carrier APIs.
5646 *
Michele Berionne0963c862018-11-27 18:57:59 -08005647 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005648 */
5649 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005650 @TelephonyManager.SetCarrierRestrictionResult
5651 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005652 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005653 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005654
Michele Berionne0963c862018-11-27 18:57:59 -08005655 if (carrierRestrictionRules == null) {
5656 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005657 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005658
Malcolm Chend965c8b2018-02-28 15:00:40 -08005659 final long identity = Binder.clearCallingIdentity();
5660 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005661 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005662 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005666 }
5667
5668 /**
5669 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005670 * Get the allowed carrier list and the excluded carrier list, including the priority between
5671 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005672 * Require system privileges. In the future we may add this to carrier APIs.
5673 *
Michele Berionne0963c862018-11-27 18:57:59 -08005674 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005675 */
5676 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005677 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005678 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005679 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005680
5681 final long identity = Binder.clearCallingIdentity();
5682 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005683 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5684 if (response instanceof CarrierRestrictionRules) {
5685 return (CarrierRestrictionRules) response;
5686 }
5687 // Response is an Exception of some kind,
5688 // which is signalled to the user as a NULL retval
5689 return null;
5690 } catch (Exception e) {
5691 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5692 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005696 }
5697
fionaxu59545b42016-05-25 15:53:37 -07005698 /**
5699 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5700 * @param subId the subscription ID that this action applies to.
5701 * @param enabled control enable or disable metered apns.
5702 * {@hide}
5703 */
5704 @Override
5705 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5706 enforceModifyPermission();
5707 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005708
5709 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005710 if (phone == null) {
5711 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5712 return;
5713 }
5714 try {
5715 phone.carrierActionSetMeteredApnsEnabled(enabled);
5716 } catch (Exception e) {
5717 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005718 } finally {
5719 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005720 }
5721 }
5722
5723 /**
5724 * Action set from carrier signalling broadcast receivers to enable/disable radio
5725 * @param subId the subscription ID that this action applies to.
5726 * @param enabled control enable or disable radio.
5727 * {@hide}
5728 */
5729 @Override
5730 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5731 enforceModifyPermission();
5732 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005733
5734 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005735 if (phone == null) {
5736 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5737 return;
5738 }
5739 try {
5740 phone.carrierActionSetRadioEnabled(enabled);
5741 } catch (Exception e) {
5742 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005745 }
5746 }
5747
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005748 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005749 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5750 * network status based on which carrier apps could apply actions accordingly,
5751 * enable/disable default url handler for example.
5752 *
5753 * @param subId the subscription ID that this action applies to.
5754 * @param report control start/stop reporting the default network status.
5755 * {@hide}
5756 */
5757 @Override
5758 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5759 enforceModifyPermission();
5760 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005761
5762 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005763 if (phone == null) {
5764 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5765 return;
5766 }
5767 try {
5768 phone.carrierActionReportDefaultNetworkStatus(report);
5769 } catch (Exception e) {
5770 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005773 }
5774 }
5775
5776 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005777 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5778 * bug report is being generated.
5779 */
5780 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005781 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005782 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5783 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005784 writer.println("Permission Denial: can't dump Phone from pid="
5785 + Binder.getCallingPid()
5786 + ", uid=" + Binder.getCallingUid()
5787 + "without permission "
5788 + android.Manifest.permission.DUMP);
5789 return;
5790 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005791 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005792 }
Jack Yueb89b242016-06-22 13:27:47 -07005793
Brad Ebingerdac2f002018-04-03 15:17:52 -07005794 @Override
5795 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5796 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5797 throws RemoteException {
5798 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5799 }
5800
Jack Yueb89b242016-06-22 13:27:47 -07005801 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005802 * Get aggregated video call data usage since boot.
5803 *
5804 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5805 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005806 * {@hide}
5807 */
5808 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005809 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005810 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5811 null);
5812
Malcolm Chend965c8b2018-02-28 15:00:40 -08005813 final long identity = Binder.clearCallingIdentity();
5814 try {
5815 // NetworkStatsService keeps tracking the active network interface and identity. It
5816 // records the delta with the corresponding network identity.
5817 // We just return the total video call data usage snapshot since boot.
5818 Phone phone = getPhone(subId);
5819 if (phone != null) {
5820 return phone.getVtDataUsage(perUidStats);
5821 }
5822 return null;
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005825 }
Jack Yueb89b242016-06-22 13:27:47 -07005826 }
Jack Yu75ab2952016-07-08 14:29:33 -07005827
5828 /**
5829 * Policy control of data connection. Usually used when data limit is passed.
5830 * @param enabled True if enabling the data, otherwise disabling.
5831 * @param subId Subscription index
5832 * {@hide}
5833 */
5834 @Override
5835 public void setPolicyDataEnabled(boolean enabled, int subId) {
5836 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005837
5838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 Phone phone = getPhone(subId);
5841 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005842 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005843 }
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005846 }
5847 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005848
5849 /**
5850 * Get Client request stats
5851 * @return List of Client Request Stats
5852 * @hide
5853 */
5854 @Override
5855 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005857 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005858 return null;
5859 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005860 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005861
Malcolm Chend965c8b2018-02-28 15:00:40 -08005862 final long identity = Binder.clearCallingIdentity();
5863 try {
5864 if (phone != null) {
5865 return phone.getClientRequestStats();
5866 }
5867
5868 return null;
5869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005872 }
5873
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005874 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005875 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005876 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005877 }
Jack Yueb4124c2017-02-16 15:32:43 -08005878
5879 /**
Grace Chen70990072017-03-24 17:21:30 -07005880 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005881 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005882 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005883 * @param state State of SIM (power down, power up, pass through)
5884 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5885 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5886 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005887 *
5888 **/
5889 @Override
Grace Chen70990072017-03-24 17:21:30 -07005890 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005891 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005892 Phone phone = PhoneFactory.getPhone(slotIndex);
5893
vagdevie435a3e2018-08-15 16:01:53 -07005894 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5895
Malcolm Chend965c8b2018-02-28 15:00:40 -08005896 final long identity = Binder.clearCallingIdentity();
5897 try {
5898 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005899 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005900 }
5901 } finally {
5902 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005903 }
5904 }
Shuo Qiandd210312017-04-12 22:11:33 +00005905
Tyler Gunn65d45c22017-06-05 11:22:26 -07005906 private boolean isUssdApiAllowed(int subId) {
5907 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005908 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005909 if (configManager == null) {
5910 return false;
5911 }
5912 PersistableBundle pb = configManager.getConfigForSubId(subId);
5913 if (pb == null) {
5914 return false;
5915 }
5916 return pb.getBoolean(
5917 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5918 }
5919
Shuo Qiandd210312017-04-12 22:11:33 +00005920 /**
5921 * Check if phone is in emergency callback mode
5922 * @return true if phone is in emergency callback mode
5923 * @param subId sub id
5924 */
goneil9c5f4872017-12-05 14:07:56 -08005925 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005926 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005927 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005928 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005929
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
5932 if (phone != null) {
5933 return phone.isInEcm();
5934 } else {
5935 return false;
5936 }
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005939 }
5940 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005941
5942 /**
5943 * Get the current signal strength information for the given subscription.
5944 * Because this information is not updated when the device is in a low power state
5945 * it should not be relied-upon to be current.
5946 * @param subId Subscription index
5947 * @return the most recent cached signal strength info from the modem
5948 */
5949 @Override
5950 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005951 final long identity = Binder.clearCallingIdentity();
5952 try {
5953 Phone p = getPhone(subId);
5954 if (p == null) {
5955 return null;
5956 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005957
Malcolm Chend965c8b2018-02-28 15:00:40 -08005958 return p.getSignalStrength();
5959 } finally {
5960 Binder.restoreCallingIdentity(identity);
5961 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005962 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005963
Pengquan Meng9140aec2018-08-22 14:49:57 -07005964 /**
chen xu907e5a22018-10-11 13:21:04 -07005965 * Get the current modem radio state for the given slot.
5966 * @param slotIndex slot index.
5967 * @param callingPackage the name of the package making the call.
5968 * @return the current radio power state from the modem
5969 */
5970 @Override
5971 public int getRadioPowerState(int slotIndex, String callingPackage) {
5972 Phone phone = PhoneFactory.getPhone(slotIndex);
5973 if (phone != null) {
5974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5975 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5976 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5977 }
5978
5979 final long identity = Binder.clearCallingIdentity();
5980 try {
5981 return phone.getRadioPowerState();
5982 } finally {
5983 Binder.restoreCallingIdentity(identity);
5984 }
5985 }
5986 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5987 }
5988
5989 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005990 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5991 *
5992 * <p>Requires one of the following permissions:
5993 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5994 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5995 * privileges.
5996 *
5997 * @param subId subscription id
5998 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5999 * {@code false}.
6000 */
6001 @Override
6002 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006003 boolean isEnabled = false;
6004 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006005 try {
6006 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07006007 null /* message */);
6008 Phone phone = getPhone(subId);
6009 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006010 } catch (Exception e) {
6011 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6012 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006013 } finally {
6014 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006015 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006016 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006017 }
6018
6019
6020 /**
6021 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6022 *
6023 * <p> Requires permission:
6024 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6025 * privileges.
6026 *
6027 * @param subId subscription id
6028 * @param isEnabled {@code true} means enable, {@code false} means disable.
6029 */
6030 @Override
6031 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006032 final long identity = Binder.clearCallingIdentity();
6033 try {
6034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6035 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07006036
Pengquan Meng0c05b502018-09-06 09:59:22 -07006037 Phone phone = getPhone(subId);
6038 if (phone != null) {
6039 phone.setDataRoamingEnabled(isEnabled);
6040 }
6041 } finally {
6042 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006043 }
6044 }
6045
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006046 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006047 public boolean isManualNetworkSelectionAllowed(int subId) {
6048 boolean isAllowed = true;
6049 final long identity = Binder.clearCallingIdentity();
6050 try {
6051 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6052 mApp, subId, "isManualNetworkSelectionAllowed");
6053 Phone phone = getPhone(subId);
6054 if (phone != null) {
6055 isAllowed = phone.isCspPlmnEnabled();
6056 }
6057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
6060 return isAllowed;
6061 }
6062
6063 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006064 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006065 try {
6066 enforceReadPrivilegedPermission("getUiccCardsInfo");
6067 } catch (SecurityException e) {
6068 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6069 // has carrier privileges on an active UICC
6070 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6071 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6072 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6073 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006074 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006075
6076 final long identity = Binder.clearCallingIdentity();
6077 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006078 UiccController uiccController = UiccController.getInstance();
6079 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6080
6081 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6082 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6083 // Remove private info if the caller doesn't have access
6084 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6085 for (UiccCardInfo cardInfo : cardInfos) {
6086 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6087 UiccProfile profile = card.getUiccProfile();
6088 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6089 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6090 filteredInfos.add(cardInfo.getUnprivileged());
6091 } else {
6092 filteredInfos.add(cardInfo);
6093 }
6094 }
6095 return filteredInfos;
6096 }
6097 return cardInfos;
6098 } catch (PackageManager.NameNotFoundException e) {
6099 // This should not happen since we pass the package info in from TelephonyManager
6100 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
6105
6106 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006107 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006108 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006109
Malcolm Chend965c8b2018-02-28 15:00:40 -08006110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6113 if (slots == null) {
6114 Rlog.i(LOG_TAG, "slots is null.");
6115 return null;
6116 }
6117
6118 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6119 for (int i = 0; i < slots.length; i++) {
6120 UiccSlot slot = slots[i];
6121 if (slot == null) {
6122 continue;
6123 }
6124
6125 String cardId;
6126 UiccCard card = slot.getUiccCard();
6127 if (card != null) {
6128 cardId = card.getCardId();
6129 } else {
6130 cardId = slot.getIccId();
6131 }
6132
6133 int cardState = 0;
6134 switch (slot.getCardState()) {
6135 case CARDSTATE_ABSENT:
6136 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6137 break;
6138 case CARDSTATE_PRESENT:
6139 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6140 break;
6141 case CARDSTATE_ERROR:
6142 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6143 break;
6144 case CARDSTATE_RESTRICTED:
6145 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6146 break;
6147 default:
6148 break;
6149
6150 }
6151
6152 infos[i] = new UiccSlotInfo(
6153 slot.isActive(),
6154 slot.isEuicc(),
6155 cardId,
6156 cardState,
6157 slot.getPhoneId(),
6158 slot.isExtendedApduSupported());
6159 }
6160 return infos;
6161 } finally {
6162 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006163 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006164 }
6165
6166 @Override
6167 public boolean switchSlots(int[] physicalSlots) {
6168 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006169
6170 final long identity = Binder.clearCallingIdentity();
6171 try {
6172 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6173 } finally {
6174 Binder.restoreCallingIdentity(identity);
6175 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006176 }
Jack Yu4c988042018-02-27 15:30:01 -08006177
6178 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006179 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006180 final long identity = Binder.clearCallingIdentity();
6181 try {
6182 return UiccController.getInstance().getCardIdForDefaultEuicc();
6183 } finally {
6184 Binder.restoreCallingIdentity(identity);
6185 }
6186 }
6187
6188 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006189 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6190 enforceModifyPermission();
6191 final Phone phone = getPhone(subId);
6192 if (phone == null) {
6193 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6194 return;
6195 }
6196
Malcolm Chend965c8b2018-02-28 15:00:40 -08006197 final long identity = Binder.clearCallingIdentity();
6198 try {
6199 phone.setRadioIndicationUpdateMode(filters, mode);
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
Jack Yu4c988042018-02-27 15:30:01 -08006203 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006204
6205 /**
goneil47ffb6e2018-04-06 15:40:58 -07006206 * A test API to reload the UICC profile.
6207 *
6208 * <p>Requires that the calling app has permission
6209 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6210 * @hide
6211 */
6212 @Override
6213 public void refreshUiccProfile(int subId) {
6214 enforceModifyPermission();
6215
6216 final long identity = Binder.clearCallingIdentity();
6217 try {
6218 Phone phone = getPhone(subId);
6219 if (phone == null) {
6220 return;
6221 }
6222 UiccCard uiccCard = phone.getUiccCard();
6223 if (uiccCard == null) {
6224 return;
6225 }
6226 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6227 if (uiccProfile == null) {
6228 return;
6229 }
6230 uiccProfile.refresh();
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
6234 }
6235
6236 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006237 * Returns false if the mobile data is disabled by default, otherwise return true.
6238 */
6239 private boolean getDefaultDataEnabled() {
6240 return "true".equalsIgnoreCase(
6241 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6242 }
6243
6244 /**
6245 * Returns true if the data roaming is enabled by default, i.e the system property
6246 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6247 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6248 */
6249 private boolean getDefaultDataRoamingEnabled(int subId) {
6250 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006251 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006252 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6253 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6254 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6255 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6256 return isDataRoamingEnabled;
6257 }
6258
6259 /**
6260 * Returns the default network type for the given {@code subId}, if the default network type is
6261 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6262 */
6263 private int getDefaultNetworkType(int subId) {
6264 return Integer.parseInt(
6265 TelephonyManager.getTelephonyProperty(
6266 mSubscriptionController.getPhoneId(subId),
6267 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6268 String.valueOf(Phone.PREFERRED_NT_MODE)));
6269 }
fionaxua13278b2018-03-21 00:08:13 -07006270
6271 @Override
6272 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6273 gid1, String gid2, String plmn, String spn) {
6274 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006275
6276 final long identity = Binder.clearCallingIdentity();
6277 try {
6278 final Phone phone = getPhone(subId);
6279 if (phone == null) {
6280 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6281 return;
6282 }
6283 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6284 } finally {
6285 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006286 }
fionaxua13278b2018-03-21 00:08:13 -07006287 }
6288
6289 @Override
6290 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006291 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006292
6293 final long identity = Binder.clearCallingIdentity();
6294 try {
6295 final Phone phone = getPhone(subId);
6296 if (phone == null) {
6297 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6298 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6299 }
6300 return phone.getCarrierIdListVersion();
6301 } finally {
6302 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006303 }
fionaxua13278b2018-03-21 00:08:13 -07006304 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006305
6306 @Override
6307 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6309 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6310 return -1;
6311 }
6312
6313 final long identity = Binder.clearCallingIdentity();
6314 try {
6315 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6316 } finally {
6317 Binder.restoreCallingIdentity(identity);
6318 }
6319 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006320
6321 @Override
6322 public int getCdmaRoamingMode(int subId) {
6323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6324 mApp, subId, "getCdmaRoamingMode");
6325
6326 final long identity = Binder.clearCallingIdentity();
6327 try {
6328 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
6332 }
6333
6334 @Override
6335 public boolean setCdmaRoamingMode(int subId, int mode) {
6336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6337 mApp, subId, "setCdmaRoamingMode");
6338
6339 final long identity = Binder.clearCallingIdentity();
6340 try {
6341 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6342 } finally {
6343 Binder.restoreCallingIdentity(identity);
6344 }
6345 }
6346
6347 @Override
6348 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6350 mApp, subId, "setCdmaSubscriptionMode");
6351
6352 final long identity = Binder.clearCallingIdentity();
6353 try {
6354 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6355 } finally {
6356 Binder.restoreCallingIdentity(identity);
6357 }
6358 }
chen xu7ee67862018-10-30 22:27:10 -07006359
sqian2fff4a32018-11-05 14:18:37 -08006360 private void ensureUserRunning(int userId) {
6361 if (!mUserManager.isUserRunning(userId)) {
6362 throw new IllegalStateException("User " + userId + " does not exist or not running");
6363 }
6364 }
6365
6366 /**
6367 * Returns a list of SMS apps on a given user.
6368 *
6369 * Only the shell user (UID 2000 or 0) can call it.
6370 * Target user must be running.
6371 */
6372 @Override
6373 public String[] getSmsApps(int userId) {
6374 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6375 ensureUserRunning(userId);
6376
6377 final Collection<SmsApplicationData> apps =
6378 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6379
6380 String[] ret = new String[apps.size()];
6381 int i = 0;
6382 for (SmsApplicationData app : apps) {
6383 ret[i++] = app.mPackageName;
6384 }
6385 return ret;
6386 }
6387
6388 /**
6389 * Returns the default SMS app package name on a given user.
6390 *
6391 * Only the shell user (UID 2000 or 0) can call it.
6392 * Target user must be running.
6393 */
6394 @Override
6395 public String getDefaultSmsApp(int userId) {
6396 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6397 ensureUserRunning(userId);
6398
6399 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6400 /* updateIfNeeded= */ true, userId);
6401 return cn == null ? null : cn.getPackageName();
6402 }
6403
6404 /**
6405 * Set a package as the default SMS app on a given user.
6406 *
6407 * Only the shell user (UID 2000 or 0) can call it.
6408 * Target user must be running.
6409 */
6410 @Override
6411 public void setDefaultSmsApp(int userId, String packageName) {
6412 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6413 ensureUserRunning(userId);
6414
6415 boolean found = false;
6416 for (String pkg : getSmsApps(userId)) {
6417 if (TextUtils.equals(packageName, pkg)) {
6418 found = true;
6419 break;
6420 }
6421 }
6422 if (!found) {
6423 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6424 }
6425
6426 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6427 }
6428
chen xu7ee67862018-10-30 22:27:10 -07006429 @Override
sqian04b86072018-11-07 14:02:21 -08006430 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6431 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6433 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6434 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6435 }
6436 final long identity = Binder.clearCallingIdentity();
6437 try {
sqian991b35e2018-12-12 16:48:18 -08006438 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6439 for (Phone phone: PhoneFactory.getPhones()) {
6440 if (phone.getEmergencyNumberTracker() != null
6441 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6442 emergencyNumberListInternal.put(
6443 phone.getSubId(),
6444 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6445 }
sqian03bca152018-12-05 18:48:28 -08006446 }
sqian991b35e2018-12-12 16:48:18 -08006447 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
sqian04b86072018-11-07 14:02:21 -08006451 }
6452
6453 @Override
sqian03bca152018-12-05 18:48:28 -08006454 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6455 final Phone defaultPhone = getDefaultPhone();
6456 if (!exactMatch) {
6457 TelephonyPermissions
6458 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6459 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6460 }
6461 final long identity = Binder.clearCallingIdentity();
6462 try {
sqian991b35e2018-12-12 16:48:18 -08006463 for (Phone phone: PhoneFactory.getPhones()) {
6464 if (phone.getEmergencyNumberTracker() != null
6465 && phone.getEmergencyNumberTracker() != null) {
6466 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6467 number, exactMatch)) {
6468 return true;
sqian03bca152018-12-05 18:48:28 -08006469 }
6470 }
sqian03bca152018-12-05 18:48:28 -08006471 }
6472 return false;
6473 } finally {
6474 Binder.restoreCallingIdentity(identity);
6475 }
6476 }
6477
sqian9d4df8b2019-01-15 18:32:07 -08006478 /**
6479 * Update emergency number list for test mode.
6480 */
6481 @Override
6482 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6483 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6484 "updateEmergencyNumberListTestMode");
6485
6486 final long identity = Binder.clearCallingIdentity();
6487 try {
6488 for (Phone phone: PhoneFactory.getPhones()) {
6489 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6490 if (tracker != null) {
6491 tracker.executeEmergencyNumberTestModeCommand(action, num);
6492 }
6493 }
6494 } finally {
6495 Binder.restoreCallingIdentity(identity);
6496 }
6497 }
6498
6499 /**
6500 * Get the full emergency number list for test mode.
6501 */
6502 @Override
6503 public List<String> getEmergencyNumberListTestMode() {
6504 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6505 "getEmergencyNumberListTestMode");
6506
6507 final long identity = Binder.clearCallingIdentity();
6508 try {
6509 Set<String> emergencyNumbers = new HashSet<>();
6510 for (Phone phone: PhoneFactory.getPhones()) {
6511 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6512 if (tracker != null) {
6513 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6514 emergencyNumbers.add(num.getNumber());
6515 }
6516 }
6517 }
6518 return new ArrayList<>(emergencyNumbers);
6519 } finally {
6520 Binder.restoreCallingIdentity(identity);
6521 }
6522 }
6523
sqian04b86072018-11-07 14:02:21 -08006524 @Override
chen xu7ee67862018-10-30 22:27:10 -07006525 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6526 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6527 Phone phone = getPhone(subId);
6528 if (phone == null) {
6529 return null;
6530 }
6531 final long identity = Binder.clearCallingIdentity();
6532 try {
6533 UiccProfile profile = UiccController.getInstance()
6534 .getUiccProfileForPhone(phone.getPhoneId());
6535 if (profile != null) {
6536 return profile.getCertsFromCarrierPrivilegeAccessRules();
6537 }
6538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
6541 return null;
6542 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006543
6544 /**
6545 * Enable or disable a modem stack.
6546 */
6547 @Override
6548 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6549 enforceModifyPermission();
6550
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
6553 Phone phone = PhoneFactory.getPhone(slotIndex);
6554 if (phone == null) {
6555 return false;
6556 } else {
6557 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6558 }
6559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
6562 }
Micheled3107c52018-12-21 15:00:11 -08006563
6564 @Override
6565 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6566 enforceModifyPermission();
6567
6568 final long identity = Binder.clearCallingIdentity();
6569 try {
6570 mTelephonySharedPreferences.edit()
6571 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6572 .commit();
6573 } finally {
6574 Binder.restoreCallingIdentity(identity);
6575 }
6576 }
6577
6578 @Override
6579 public boolean isMultisimCarrierRestricted() {
6580 enforceReadPrivilegedPermission("isMultisimCarrierRestricted");
6581
6582 final long identity = Binder.clearCallingIdentity();
6583 try {
6584 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6585 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6586 if (numPhysicalSlots < 2) {
6587 loge("isMultisimCarrierRestricted: requires at least 2 cards");
6588 return true;
6589 }
6590
6591 // Default value is false. Multi SIM is allowed unless explicitly restricted.
6592 return mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false);
6593 } finally {
6594 Binder.restoreCallingIdentity(identity);
6595 }
6596 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006597
6598 /**
6599 * Switch configs to enable multi-sim or switch back to single-sim
6600 * @param numOfSims number of active sims we want to switch to
6601 */
6602 @Override
6603 public void switchMultiSimConfig(int numOfSims) {
6604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6605 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6606 final long identity = Binder.clearCallingIdentity();
6607 try {
6608 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6609 } finally {
6610 Binder.restoreCallingIdentity(identity);
6611 }
6612 }
6613
6614 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006615 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006616 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006617 */
6618 @Override
6619 public boolean isRebootRequiredForModemConfigChange() {
6620 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6621 final long identity = Binder.clearCallingIdentity();
6622 try {
6623 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6624 } finally {
6625 Binder.restoreCallingIdentity(identity);
6626 }
6627 }
6628
Pengquan Meng92d253b2019-02-06 11:12:53 -08006629 private void updateModemStateMetrics() {
6630 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6631 // TODO: check the state for each modem if the api is ready.
6632 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6633 }
6634
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006635 @Override
6636 public int[] getSlotsMapping() {
6637 enforceReadPrivilegedPermission("getSlotsMapping");
6638
6639 final long identity = Binder.clearCallingIdentity();
6640 try {
6641 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6642 // All logical slots should have a mapping to a physical slot.
6643 int[] logicalSlotsMapping = new int[phoneCount];
6644 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6645 for (int i = 0; i < slotInfos.length; i++) {
6646 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6647 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6648 }
6649 }
6650 return logicalSlotsMapping;
6651 } finally {
6652 Binder.restoreCallingIdentity(identity);
6653 }
6654 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006655
6656 /**
6657 * Get the IRadio HAL Version
6658 */
6659 @Override
6660 public int getRadioHalVersion() {
6661 Phone phone = getDefaultPhone();
6662 if (phone == null) return -1;
6663 HalVersion hv = phone.getHalVersion();
6664 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6665 return hv.major * 100 + hv.minor;
6666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006667}