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