blob: 8e9d8636008d4e6bcf597908c90dee12acda8ee4 [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;
Hall Liud892bec2018-11-30 14:51:45 -0800117import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800119import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700120import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100121import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700122import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700123import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700125import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800126import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700127import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700128import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700129import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700130import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700131import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700132import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800133import com.android.internal.telephony.SmsApplication;
134import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800135import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800136import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800137import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700138import com.android.internal.telephony.euicc.EuiccConnector;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800139import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.uicc.IccIoResult;
141import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800142import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700143import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800144import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800146import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000147import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700148import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800149import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700150import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800151import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700152import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700153import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800154
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700155import java.io.FileDescriptor;
156import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800157import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800159import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800160import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800161import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800162import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800163import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100164import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800165import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800166import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167
168/**
169 * Implementation of the ITelephony interface.
170 */
Santos Cordon117fee72014-05-16 17:56:12 -0700171public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172 private static final String LOG_TAG = "PhoneInterfaceManager";
173 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
174 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800175 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176
177 // Message codes used with mMainThreadHandler
178 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700179 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
180 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700181 private static final int CMD_OPEN_CHANNEL = 9;
182 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
183 private static final int CMD_CLOSE_CHANNEL = 11;
184 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800185 private static final int CMD_NV_READ_ITEM = 13;
186 private static final int EVENT_NV_READ_ITEM_DONE = 14;
187 private static final int CMD_NV_WRITE_ITEM = 15;
188 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
189 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
190 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700191 private static final int CMD_RESET_MODEM_CONFIG = 19;
192 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800193 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
194 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
195 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
196 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800197 private static final int CMD_SEND_ENVELOPE = 25;
198 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000199 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
200 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700201 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
202 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
203 private static final int CMD_EXCHANGE_SIM_IO = 31;
204 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800205 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
206 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700207 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
208 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700209 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
210 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700211 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
212 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
213 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
214 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700215 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
216 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
217 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
218 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700219 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800220 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
221 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000222 private static final int CMD_SWITCH_SLOTS = 50;
223 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700224 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
225 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
226 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
227 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
228 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
229 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
230 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
231 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700232 private static final int CMD_GET_ALL_CELL_INFO = 60;
233 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
234 private static final int CMD_GET_CELL_LOCATION = 62;
235 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700236 private static final int CMD_MODEM_REBOOT = 64;
237 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700238 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
239 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800240 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
241 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800243 // Parameters of select command.
244 private static final int SELECT_COMMAND = 0xA4;
245 private static final int SELECT_P1 = 0x04;
246 private static final int SELECT_P2 = 0;
247 private static final int SELECT_P3 = 0x10;
248
Pengquan Meng85728fb2018-03-12 16:31:21 -0700249 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
250 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
251 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
252
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 /** The singleton instance. */
254 private static PhoneInterfaceManager sInstance;
255
Wink Saville3ab207e2014-11-20 13:07:20 -0800256 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800257 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700258 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800259 private AppOpsManager mAppOps;
260 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800261 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800262 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700263 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700264
Derek Tan97ebb422014-09-05 16:55:38 -0700265 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
266 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800267 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800268 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700269
Micheled3107c52018-12-21 15:00:11 -0800270 // String to store multi SIM allowed
271 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
272
Derek Tan740e1672017-06-27 14:56:27 -0700273 // The AID of ISD-R.
274 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
275
yinxub1bed742017-04-17 11:45:04 -0700276 private NetworkScanRequestTracker mNetworkScanRequestTracker;
277
David Kelly5e06a7f2018-03-12 14:10:59 +0000278 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
279 private static final int MANUFACTURER_CODE_LENGTH = 8;
280
Derek Tan89e89d42014-07-08 17:00:10 -0700281 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700282 * A request object to use for transmitting data to an ICC.
283 */
284 private static final class IccAPDUArgument {
285 public int channel, cla, command, p1, p2, p3;
286 public String data;
287
288 public IccAPDUArgument(int channel, int cla, int command,
289 int p1, int p2, int p3, String data) {
290 this.channel = channel;
291 this.cla = cla;
292 this.command = command;
293 this.p1 = p1;
294 this.p2 = p2;
295 this.p3 = p3;
296 this.data = data;
297 }
298 }
299
300 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700301 * A request object to use for transmitting data to an ICC.
302 */
303 private static final class ManualNetworkSelectionArgument {
304 public OperatorInfo operatorInfo;
305 public boolean persistSelection;
306
307 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
308 this.operatorInfo = operatorInfo;
309 this.persistSelection = persistSelection;
310 }
311 }
312
313 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
315 * request after sending. The main thread will notify the request when it is complete.
316 */
317 private static final class MainThreadRequest {
318 /** The argument to use for the request */
319 public Object argument;
320 /** The result of the request that is run on the main thread */
321 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800322 // The subscriber id that this request applies to. Defaults to
323 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
324 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325
Nathan Harold92bed182018-10-12 18:16:49 -0700326 // In cases where subId is unavailable, the caller needs to specify the phone.
327 public Phone phone;
328
vagdevie435a3e2018-08-15 16:01:53 -0700329 public WorkSource workSource;
330
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 public MainThreadRequest(Object argument) {
332 this.argument = argument;
333 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800334
Nathan Harold92bed182018-10-12 18:16:49 -0700335 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
336 this.argument = argument;
337 if (phone != null) {
338 this.phone = phone;
339 }
340 this.workSource = workSource;
341 }
342
vagdevie435a3e2018-08-15 16:01:53 -0700343 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800344 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800345 if (subId != null) {
346 this.subId = subId;
347 }
vagdevie435a3e2018-08-15 16:01:53 -0700348 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 }
351
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800352 private static final class IncomingThirdPartyCallArgs {
353 public final ComponentName component;
354 public final String callId;
355 public final String callerDisplayName;
356
357 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
358 String callerDisplayName) {
359 this.component = component;
360 this.callId = callId;
361 this.callerDisplayName = callerDisplayName;
362 }
363 }
364
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 /**
366 * A handler that processes messages on the main thread in the phone process. Since many
367 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
368 * inbound binder threads to the main thread in the phone process. The Binder thread
369 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
370 * on, which will be notified when the operation completes and will contain the result of the
371 * request.
372 *
373 * <p>If a MainThreadRequest object is provided in the msg.obj field,
374 * note that request.result must be set to something non-null for the calling thread to
375 * unblock.
376 */
377 private final class MainThreadHandler extends Handler {
378 @Override
379 public void handleMessage(Message msg) {
380 MainThreadRequest request;
381 Message onCompleted;
382 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800383 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700384 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800385 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386
387 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700388 case CMD_HANDLE_USSD_REQUEST: {
389 request = (MainThreadRequest) msg.obj;
390 final Phone phone = getPhoneFromRequest(request);
391 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
392 String ussdRequest = ussdObject.first;
393 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700394
Pengquan Meng0c05b502018-09-06 09:59:22 -0700395 if (!isUssdApiAllowed(request.subId)) {
396 // Carrier does not support use of this API, return failure.
397 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
398 UssdResponse response = new UssdResponse(ussdRequest, null);
399 Bundle returnData = new Bundle();
400 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
401 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700402
Pengquan Meng0c05b502018-09-06 09:59:22 -0700403 request.result = true;
404 notifyRequester(request);
405 return;
406 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700407
Pengquan Meng0c05b502018-09-06 09:59:22 -0700408 try {
409 request.result = phone != null
410 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
411 } catch (CallStateException cse) {
412 request.result = false;
413 }
414 // Wake up the requesting thread
415 notifyRequester(request);
416 break;
pkanwar32d516d2016-10-14 19:37:38 -0700417 }
418
Yorke Lee716f67e2015-06-17 15:39:16 -0700419 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700421 final Phone phone = getPhoneFromRequest(request);
422 request.result = phone != null ?
423 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
424 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700426 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700430 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800433 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700434 if (uiccCard == null) {
435 loge("iccTransmitApduLogicalChannel: No UICC");
436 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700437 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700438 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700439 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
440 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700441 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 iccArgument.channel, iccArgument.cla, iccArgument.command,
443 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700445 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 break;
447
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 ar = (AsyncResult) msg.obj;
450 request = (MainThreadRequest) ar.userObj;
451 if (ar.exception == null && ar.result != null) {
452 request.result = ar.result;
453 } else {
454 request.result = new IccIoResult(0x6F, 0, (byte[])null);
455 if (ar.result == null) {
456 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800457 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800459 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 } else {
461 loge("iccTransmitApduLogicalChannel: Unknown exception");
462 }
463 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700464 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 break;
466
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
468 request = (MainThreadRequest) msg.obj;
469 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800470 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 if (uiccCard == null) {
472 loge("iccTransmitApduBasicChannel: No UICC");
473 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700474 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 } else {
476 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
477 request);
478 uiccCard.iccTransmitApduBasicChannel(
479 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
480 iccArgument.p3, iccArgument.data, onCompleted);
481 }
482 break;
483
484 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
485 ar = (AsyncResult) msg.obj;
486 request = (MainThreadRequest) ar.userObj;
487 if (ar.exception == null && ar.result != null) {
488 request.result = ar.result;
489 } else {
490 request.result = new IccIoResult(0x6F, 0, (byte[])null);
491 if (ar.result == null) {
492 loge("iccTransmitApduBasicChannel: Empty response");
493 } else if (ar.exception instanceof CommandException) {
494 loge("iccTransmitApduBasicChannel: CommandException: " +
495 ar.exception);
496 } else {
497 loge("iccTransmitApduBasicChannel: Unknown exception");
498 }
499 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700500 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 break;
502
503 case CMD_EXCHANGE_SIM_IO:
504 request = (MainThreadRequest) msg.obj;
505 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 if (uiccCard == null) {
508 loge("iccExchangeSimIO: No UICC");
509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700510 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700511 } else {
512 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
513 request);
514 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
515 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
516 iccArgument.data, onCompleted);
517 }
518 break;
519
520 case EVENT_EXCHANGE_SIM_IO_DONE:
521 ar = (AsyncResult) msg.obj;
522 request = (MainThreadRequest) ar.userObj;
523 if (ar.exception == null && ar.result != null) {
524 request.result = ar.result;
525 } else {
526 request.result = new IccIoResult(0x6f, 0, (byte[])null);
527 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 break;
530
Derek Tan4d5e5c12014-02-04 11:54:58 -0800531 case CMD_SEND_ENVELOPE:
532 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800533 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700534 if (uiccCard == null) {
535 loge("sendEnvelopeWithStatus: No UICC");
536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700537 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 } else {
539 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
540 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
541 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800542 break;
543
544 case EVENT_SEND_ENVELOPE_DONE:
545 ar = (AsyncResult) msg.obj;
546 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700547 if (ar.exception == null && ar.result != null) {
548 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700550 request.result = new IccIoResult(0x6F, 0, (byte[])null);
551 if (ar.result == null) {
552 loge("sendEnvelopeWithStatus: Empty response");
553 } else if (ar.exception instanceof CommandException) {
554 loge("sendEnvelopeWithStatus: CommandException: " +
555 ar.exception);
556 } else {
557 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
558 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700560 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 break;
562
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 case CMD_OPEN_CHANNEL:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800566 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 if (uiccCard == null) {
568 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800569 request.result = new IccOpenLogicalChannelResponse(-1,
570 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700571 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700572 } else {
573 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800574 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
575 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 break;
578
579 case EVENT_OPEN_CHANNEL_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 int[] result = (int[]) ar.result;
585 int channelId = result[0];
586 byte[] selectResponse = null;
587 if (result.length > 1) {
588 selectResponse = new byte[result.length - 1];
589 for (int i = 1; i < result.length; ++i) {
590 selectResponse[i - 1] = (byte) result[i];
591 }
592 }
593 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 if (ar.result == null) {
597 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 if (ar.exception != null) {
600 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
601 }
602
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700603 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700604 if (ar.exception instanceof CommandException) {
605 CommandException.Error error =
606 ((CommandException) (ar.exception)).getCommandError();
607 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700609 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 }
612 }
613 openChannelResp = new IccOpenLogicalChannelResponse(
614 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700616 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700617 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 break;
619
620 case CMD_CLOSE_CHANNEL:
621 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 if (uiccCard == null) {
624 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900625 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700626 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 } else {
628 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
629 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
630 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 break;
632
633 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800634 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
635 break;
636
637 case CMD_NV_READ_ITEM:
638 request = (MainThreadRequest) msg.obj;
639 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800640 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
641 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800642 break;
643
644 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 ar = (AsyncResult) msg.obj;
646 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800647 if (ar.exception == null && ar.result != null) {
648 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800650 request.result = "";
651 if (ar.result == null) {
652 loge("nvReadItem: Empty response");
653 } else if (ar.exception instanceof CommandException) {
654 loge("nvReadItem: CommandException: " +
655 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800657 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 }
659 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700660 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 break;
662
Jake Hambye994d462014-02-03 13:10:13 -0800663 case CMD_NV_WRITE_ITEM:
664 request = (MainThreadRequest) msg.obj;
665 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
666 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800667 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700668 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800669 break;
670
671 case EVENT_NV_WRITE_ITEM_DONE:
672 handleNullReturnEvent(msg, "nvWriteItem");
673 break;
674
675 case CMD_NV_WRITE_CDMA_PRL:
676 request = (MainThreadRequest) msg.obj;
677 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800678 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800679 break;
680
681 case EVENT_NV_WRITE_CDMA_PRL_DONE:
682 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
683 break;
684
chen xu1cc0abe2018-10-26 17:39:23 -0700685 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800686 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700687 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800688 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800689 break;
690
chen xu1cc0abe2018-10-26 17:39:23 -0700691 case EVENT_RESET_MODEM_CONFIG_DONE:
692 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800693 break;
694
Jake Hamby7c27be32014-03-03 13:25:59 -0800695 case CMD_GET_PREFERRED_NETWORK_TYPE:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700698 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800699 break;
700
701 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result; // Integer
706 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800707 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800708 if (ar.result == null) {
709 loge("getPreferredNetworkType: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("getPreferredNetworkType: CommandException: " +
712 ar.exception);
713 } else {
714 loge("getPreferredNetworkType: Unknown exception");
715 }
716 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700717 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 break;
719
720 case CMD_SET_PREFERRED_NETWORK_TYPE:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
723 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700724 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 break;
726
727 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
728 handleNullReturnEvent(msg, "setPreferredNetworkType");
729 break;
730
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000731 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
732 request = (MainThreadRequest)msg.obj;
733 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800734 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000735 break;
736
737 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
738 ar = (AsyncResult)msg.obj;
739 request = (MainThreadRequest)ar.userObj;
740 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700741 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000742 break;
743
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800744 case CMD_SET_VOICEMAIL_NUMBER:
745 request = (MainThreadRequest) msg.obj;
746 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
747 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800748 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
749 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800750 break;
751
752 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
753 handleNullReturnEvent(msg, "setVoicemailNumber");
754 break;
755
Stuart Scott54788802015-03-30 13:18:01 -0700756 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
759 request);
760 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
761 break;
762
763 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
764 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
765 break;
766
Shishir Agrawal302c8692015-06-19 13:49:39 -0700767 case CMD_PERFORM_NETWORK_SCAN:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
770 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
771 break;
772
773 case EVENT_PERFORM_NETWORK_SCAN_DONE:
774 ar = (AsyncResult) msg.obj;
775 request = (MainThreadRequest) ar.userObj;
776 CellNetworkScanResult cellScanResult;
777 if (ar.exception == null && ar.result != null) {
778 cellScanResult = new CellNetworkScanResult(
779 CellNetworkScanResult.STATUS_SUCCESS,
780 (List<OperatorInfo>) ar.result);
781 } else {
782 if (ar.result == null) {
783 loge("getCellNetworkScanResults: Empty response");
784 }
785 if (ar.exception != null) {
786 loge("getCellNetworkScanResults: Exception: " + ar.exception);
787 }
788 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
789 if (ar.exception instanceof CommandException) {
790 CommandException.Error error =
791 ((CommandException) (ar.exception)).getCommandError();
792 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
793 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
794 } else if (error == CommandException.Error.GENERIC_FAILURE) {
795 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
796 }
797 }
798 cellScanResult = new CellNetworkScanResult(errorCode, null);
799 }
800 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700801 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700802 break;
803
804 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
805 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700806 ManualNetworkSelectionArgument selArg =
807 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700808 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
809 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700810 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
811 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700812 break;
813
814 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700815 ar = (AsyncResult) msg.obj;
816 request = (MainThreadRequest) ar.userObj;
817 if (ar.exception == null) {
818 request.result = true;
819 } else {
820 request.result = false;
821 loge("setNetworkSelectionModeManual " + ar.exception);
822 }
823 notifyRequester(request);
824 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700825 break;
826
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700827 case CMD_GET_MODEM_ACTIVITY_INFO:
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800830 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700831 break;
832
833 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null && ar.result != null) {
837 request.result = ar.result;
838 } else {
839 if (ar.result == null) {
840 loge("queryModemActivityInfo: Empty response");
841 } else if (ar.exception instanceof CommandException) {
842 loge("queryModemActivityInfo: CommandException: " +
843 ar.exception);
844 } else {
845 loge("queryModemActivityInfo: Unknown exception");
846 }
847 }
Amit Mahajand4766222016-01-28 15:28:28 -0800848 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
849 if (request.result == null) {
850 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
851 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700852 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700853 break;
854
Meng Wang1a7c35a2016-05-05 20:56:15 -0700855 case CMD_SET_ALLOWED_CARRIERS:
856 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800857 CarrierRestrictionRules argument =
858 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700859 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800860 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700861 break;
862
863 case EVENT_SET_ALLOWED_CARRIERS_DONE:
864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result;
868 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800869 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
870 if (ar.exception instanceof CommandException) {
871 loge("setAllowedCarriers: CommandException: " + ar.exception);
872 CommandException.Error error =
873 ((CommandException) (ar.exception)).getCommandError();
874 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
875 request.result =
876 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
877 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 } else {
879 loge("setAllowedCarriers: Unknown exception");
880 }
881 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700882 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700883 break;
884
885 case CMD_GET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800888 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 break;
890
891 case EVENT_GET_ALLOWED_CARRIERS_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result;
896 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800897 request.result = new IllegalStateException(
898 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700899 if (ar.result == null) {
900 loge("getAllowedCarriers: Empty response");
901 } else if (ar.exception instanceof CommandException) {
902 loge("getAllowedCarriers: CommandException: " +
903 ar.exception);
904 } else {
905 loge("getAllowedCarriers: Unknown exception");
906 }
907 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700908 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 break;
910
Nathan Haroldb3014052017-01-25 15:57:32 -0800911 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
912 ar = (AsyncResult) msg.obj;
913 request = (MainThreadRequest) ar.userObj;
914 if (ar.exception == null && ar.result != null) {
915 request.result = ar.result;
916 } else {
917 request.result = new IllegalArgumentException(
918 "Failed to retrieve Forbidden Plmns");
919 if (ar.result == null) {
920 loge("getForbiddenPlmns: Empty response");
921 } else {
922 loge("getForbiddenPlmns: Unknown exception");
923 }
924 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700925 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800926 break;
927
928 case CMD_GET_FORBIDDEN_PLMNS:
929 request = (MainThreadRequest) msg.obj;
930 uiccCard = getUiccCardFromRequest(request);
931 if (uiccCard == null) {
932 loge("getForbiddenPlmns() UiccCard is null");
933 request.result = new IllegalArgumentException(
934 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700935 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800936 break;
937 }
938 Integer appType = (Integer) request.argument;
939 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
940 if (uiccApp == null) {
941 loge("getForbiddenPlmns() no app with specified type -- "
942 + appType);
943 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700944 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800945 break;
946 } else {
947 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
948 + " specified type -- " + appType);
949 }
950 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
951 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
952 onCompleted);
953 break;
954
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000955 case CMD_SWITCH_SLOTS:
956 request = (MainThreadRequest) msg.obj;
957 int[] physicalSlots = (int[]) request.argument;
958 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
959 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
960 break;
961
962 case EVENT_SWITCH_SLOTS_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700966 notifyRequester(request);
967 break;
968 case CMD_GET_NETWORK_SELECTION_MODE:
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
971 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
972 break;
973
974 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
975 ar = (AsyncResult) msg.obj;
976 request = (MainThreadRequest) ar.userObj;
977 if (ar.exception != null) {
978 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
979 } else {
980 int mode = ((int[]) ar.result)[0];
981 if (mode == 0) {
982 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
983 } else {
984 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
985 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000986 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700987 notifyRequester(request);
988 break;
989 case CMD_GET_CDMA_ROAMING_MODE:
990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
992 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
993 break;
994 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 if (ar.exception != null) {
998 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
999 } else {
1000 request.result = ((int[]) ar.result)[0];
1001 }
1002 notifyRequester(request);
1003 break;
1004 case CMD_SET_CDMA_ROAMING_MODE:
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1007 int mode = (int) request.argument;
1008 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1009 break;
1010 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 request.result = ar.exception == null;
1014 notifyRequester(request);
1015 break;
1016 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1017 request = (MainThreadRequest) msg.obj;
1018 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1019 int subscriptionMode = (int) request.argument;
1020 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1021 break;
1022 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1023 ar = (AsyncResult) msg.obj;
1024 request = (MainThreadRequest) ar.userObj;
1025 request.result = ar.exception == null;
1026 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001027 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001028 case CMD_GET_ALL_CELL_INFO:
1029 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001030 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001031 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001032 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001033 case EVENT_GET_ALL_CELL_INFO_DONE:
1034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001036 // If a timeout occurs, the response will be null
1037 request.result = (ar.exception == null && ar.result != null)
1038 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001039 synchronized (request) {
1040 request.notifyAll();
1041 }
1042 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001043 case CMD_REQUEST_CELL_INFO_UPDATE:
1044 request = (MainThreadRequest) msg.obj;
1045 request.phone.requestCellInfoUpdate(request.workSource,
1046 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1047 break;
1048 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1049 ar = (AsyncResult) msg.obj;
1050 request = (MainThreadRequest) ar.userObj;
1051 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1052 try {
1053 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001054 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001055 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1056 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001057 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001058 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001059 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 } else {
1061 // use the result as returned
1062 cb.onCellInfo((List<CellInfo>) ar.result);
1063 }
1064 } catch (RemoteException re) {
1065 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1066 }
1067 break;
1068 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 request = (MainThreadRequest) msg.obj;
1070 WorkSource ws = (WorkSource) request.argument;
1071 Phone phone = getPhoneFromRequest(request);
1072 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1073 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001075 ar = (AsyncResult) msg.obj;
1076 request = (MainThreadRequest) ar.userObj;
1077 if (ar.exception == null) {
1078 request.result = ar.result;
1079 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001081 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1082 ? new CdmaCellLocation() : new GsmCellLocation();
1083 }
1084
1085 synchronized (request) {
1086 request.notifyAll();
1087 }
1088 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001089 case CMD_MODEM_REBOOT:
1090 request = (MainThreadRequest) msg.obj;
1091 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001092 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001093 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001094 case EVENT_CMD_MODEM_REBOOT_DONE:
1095 handleNullReturnEvent(msg, "rebootModem");
1096 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001097 case CMD_REQUEST_ENABLE_MODEM:
1098 request = (MainThreadRequest) msg.obj;
1099 boolean enable = (boolean) request.argument;
1100 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1101 PhoneConfigurationManager.getInstance()
1102 .enablePhone(request.phone, enable, onCompleted);
1103 break;
1104 case EVENT_ENABLE_MODEM_DONE:
1105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
1107 request.result = (ar.exception == null);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001108 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001109 notifyRequester(request);
1110 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001111 default:
1112 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1113 break;
1114 }
1115 }
Jake Hambye994d462014-02-03 13:10:13 -08001116
Pengquan Meng0c05b502018-09-06 09:59:22 -07001117 private void notifyRequester(MainThreadRequest request) {
1118 synchronized (request) {
1119 request.notifyAll();
1120 }
1121 }
1122
Jake Hambye994d462014-02-03 13:10:13 -08001123 private void handleNullReturnEvent(Message msg, String command) {
1124 AsyncResult ar = (AsyncResult) msg.obj;
1125 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1126 if (ar.exception == null) {
1127 request.result = true;
1128 } else {
1129 request.result = false;
1130 if (ar.exception instanceof CommandException) {
1131 loge(command + ": CommandException: " + ar.exception);
1132 } else {
1133 loge(command + ": Unknown exception");
1134 }
1135 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001136 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 }
1139
1140 /**
1141 * Posts the specified command to be executed on the main thread,
1142 * waits for the request to complete, and returns the result.
1143 * @see #sendRequestAsync
1144 */
1145 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001146 return sendRequest(
1147 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001148 }
1149
1150 /**
1151 * Posts the specified command to be executed on the main thread,
1152 * waits for the request to complete, and returns the result.
1153 * @see #sendRequestAsync
1154 */
1155 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1156 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001157 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001158 }
1159
1160 /**
1161 * Posts the specified command to be executed on the main thread,
1162 * waits for the request to complete, and returns the result.
1163 * @see #sendRequestAsync
1164 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001165 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001166 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001167 }
1168
1169 /**
1170 * Posts the specified command to be executed on the main thread,
1171 * waits for the request to complete, and returns the result.
1172 * @see #sendRequestAsync
1173 */
Nathan Harold92bed182018-10-12 18:16:49 -07001174 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1175 return sendRequest(command, argument, subId, null, workSource);
1176 }
1177
1178 /**
1179 * Posts the specified command to be executed on the main thread,
1180 * waits for the request to complete, and returns the result.
1181 * @see #sendRequestAsync
1182 */
1183 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1184 return sendRequest(
1185 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1186 }
1187
1188 /**
1189 * Posts the specified command to be executed on the main thread,
1190 * waits for the request to complete, and returns the result.
1191 * @see #sendRequestAsync
1192 */
1193 private Object sendRequest(
1194 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1196 throw new RuntimeException("This method will deadlock if called from the main thread.");
1197 }
1198
Nathan Harold92bed182018-10-12 18:16:49 -07001199 MainThreadRequest request = null;
1200 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1201 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1202 } else if (phone != null) {
1203 request = new MainThreadRequest(argument, phone, workSource);
1204 } else {
1205 request = new MainThreadRequest(argument, subId, workSource);
1206 }
1207
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001208 Message msg = mMainThreadHandler.obtainMessage(command, request);
1209 msg.sendToTarget();
1210
1211 // Wait for the request to complete
1212 synchronized (request) {
1213 while (request.result == null) {
1214 try {
1215 request.wait();
1216 } catch (InterruptedException e) {
1217 // Do nothing, go back and wait until the request is complete
1218 }
1219 }
1220 }
1221 return request.result;
1222 }
1223
1224 /**
1225 * Asynchronous ("fire and forget") version of sendRequest():
1226 * Posts the specified command to be executed on the main thread, and
1227 * returns immediately.
1228 * @see #sendRequest
1229 */
1230 private void sendRequestAsync(int command) {
1231 mMainThreadHandler.sendEmptyMessage(command);
1232 }
1233
1234 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001235 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001236 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001237 */
1238 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001239 sendRequestAsync(command, argument, null, null);
1240 }
1241
1242 /**
1243 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1244 * @see {@link #sendRequest(int,Object)}
1245 */
1246 private void sendRequestAsync(
1247 int command, Object argument, Phone phone, WorkSource workSource) {
1248 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001249 Message msg = mMainThreadHandler.obtainMessage(command, request);
1250 msg.sendToTarget();
1251 }
1252
1253 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 * Initialize the singleton PhoneInterfaceManager instance.
1255 * This is only done once, at startup, from PhoneApp.onCreate().
1256 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001257 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 synchronized (PhoneInterfaceManager.class) {
1259 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001260 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 } else {
1262 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1263 }
1264 return sInstance;
1265 }
1266 }
1267
1268 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001269 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001272 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1274 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001275 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001276 mTelephonySharedPreferences =
1277 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001278 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001279 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 publish();
1282 }
1283
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001284 private Phone getDefaultPhone() {
1285 Phone thePhone = getPhone(getDefaultSubscription());
1286 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1287 }
1288
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001289 private void publish() {
1290 if (DBG) log("publish: " + this);
1291
1292 ServiceManager.addService("phone", this);
1293 }
1294
Stuart Scott584921c2015-01-15 17:10:34 -08001295 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001296 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001297 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001298 }
1299
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001300 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1301 Phone phone = getPhoneFromRequest(request);
1302 return phone == null ? null :
1303 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1304 }
1305
Wink Saville36469e72014-06-11 15:17:00 -07001306 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001307 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001308 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310
1311 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001312 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001313 }
1314
Wink Savilleb564aae2014-10-23 10:18:09 -07001315 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 if (DBG) log("dial: " + number);
1317 // No permission check needed here: This is just a wrapper around the
1318 // ACTION_DIAL intent, which is available to any app since it puts up
1319 // the UI before it does anything.
1320
Malcolm Chend965c8b2018-02-28 15:00:40 -08001321 final long identity = Binder.clearCallingIdentity();
1322 try {
1323 String url = createTelUrl(number);
1324 if (url == null) {
1325 return;
1326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327
Malcolm Chend965c8b2018-02-28 15:00:40 -08001328 // PENDING: should we just silently fail if phone is offhook or ringing?
1329 PhoneConstants.State state = mCM.getState(subId);
1330 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1331 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1332 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1333 mApp.startActivity(intent);
1334 }
1335 } finally {
1336 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337 }
1338 }
1339
1340 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001341 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001342 }
1343
Wink Savilleb564aae2014-10-23 10:18:09 -07001344 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001345 if (DBG) log("call: " + number);
1346
1347 // This is just a wrapper around the ACTION_CALL intent, but we still
1348 // need to do a permission check since we're calling startActivity()
1349 // from the context of the phone app.
1350 enforceCallPermission();
1351
1352 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1353 != AppOpsManager.MODE_ALLOWED) {
1354 return;
1355 }
1356
Malcolm Chend965c8b2018-02-28 15:00:40 -08001357 final long identity = Binder.clearCallingIdentity();
1358 try {
1359 String url = createTelUrl(number);
1360 if (url == null) {
1361 return;
1362 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363
Malcolm Chend965c8b2018-02-28 15:00:40 -08001364 boolean isValid = false;
1365 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1366 if (slist != null) {
1367 for (SubscriptionInfo subInfoRecord : slist) {
1368 if (subInfoRecord.getSubscriptionId() == subId) {
1369 isValid = true;
1370 break;
1371 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001372 }
Wink Saville08874612014-08-31 19:19:58 -07001373 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001374 if (!isValid) {
1375 return;
1376 }
Wink Saville08874612014-08-31 19:19:58 -07001377
Malcolm Chend965c8b2018-02-28 15:00:40 -08001378 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1379 intent.putExtra(SUBSCRIPTION_KEY, subId);
1380 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1381 mApp.startActivity(intent);
1382 } finally {
1383 Binder.restoreCallingIdentity(identity);
1384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 }
1386
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001388 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001389 }
1390
Wink Savilleb564aae2014-10-23 10:18:09 -07001391 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001392 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001393 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1394 }
1395
1396 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001397 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001398 }
1399
Wink Savilleb564aae2014-10-23 10:18:09 -07001400 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001401 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001402 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1403 }
1404
1405 /** {@hide} */
1406 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001407 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001408 }
1409
Wink Savilleb564aae2014-10-23 10:18:09 -07001410 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001412
1413 final long identity = Binder.clearCallingIdentity();
1414 try {
1415 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1416 checkSimPin.start();
1417 return checkSimPin.unlockSim(null, pin);
1418 } finally {
1419 Binder.restoreCallingIdentity(identity);
1420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421 }
1422
Wink Saville9de0f752013-10-22 19:04:03 -07001423 /** {@hide} */
1424 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001425 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001426 }
1427
Wink Savilleb564aae2014-10-23 10:18:09 -07001428 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001430
1431 final long identity = Binder.clearCallingIdentity();
1432 try {
1433 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1434 checkSimPuk.start();
1435 return checkSimPuk.unlockSim(puk, pin);
1436 } finally {
1437 Binder.restoreCallingIdentity(identity);
1438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439 }
1440
1441 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001442 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 * a synchronous one.
1444 */
1445 private static class UnlockSim extends Thread {
1446
1447 private final IccCard mSimCard;
1448
1449 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001450 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1451 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452
1453 // For replies from SimCard interface
1454 private Handler mHandler;
1455
1456 // For async handler to identify request type
1457 private static final int SUPPLY_PIN_COMPLETE = 100;
1458
1459 public UnlockSim(IccCard simCard) {
1460 mSimCard = simCard;
1461 }
1462
1463 @Override
1464 public void run() {
1465 Looper.prepare();
1466 synchronized (UnlockSim.this) {
1467 mHandler = new Handler() {
1468 @Override
1469 public void handleMessage(Message msg) {
1470 AsyncResult ar = (AsyncResult) msg.obj;
1471 switch (msg.what) {
1472 case SUPPLY_PIN_COMPLETE:
1473 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1474 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001475 mRetryCount = msg.arg1;
1476 if (ar.exception != null) {
1477 if (ar.exception instanceof CommandException &&
1478 ((CommandException)(ar.exception)).getCommandError()
1479 == CommandException.Error.PASSWORD_INCORRECT) {
1480 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1481 } else {
1482 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1483 }
1484 } else {
1485 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 mDone = true;
1488 UnlockSim.this.notifyAll();
1489 }
1490 break;
1491 }
1492 }
1493 };
1494 UnlockSim.this.notifyAll();
1495 }
1496 Looper.loop();
1497 }
1498
1499 /*
1500 * Use PIN or PUK to unlock SIM card
1501 *
1502 * If PUK is null, unlock SIM card with PIN
1503 *
1504 * If PUK is not null, unlock SIM card with PUK and set PIN code
1505 */
Wink Saville9de0f752013-10-22 19:04:03 -07001506 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507
1508 while (mHandler == null) {
1509 try {
1510 wait();
1511 } catch (InterruptedException e) {
1512 Thread.currentThread().interrupt();
1513 }
1514 }
1515 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1516
1517 if (puk == null) {
1518 mSimCard.supplyPin(pin, callback);
1519 } else {
1520 mSimCard.supplyPuk(puk, pin, callback);
1521 }
1522
1523 while (!mDone) {
1524 try {
1525 Log.d(LOG_TAG, "wait for done");
1526 wait();
1527 } catch (InterruptedException e) {
1528 // Restore the interrupted status
1529 Thread.currentThread().interrupt();
1530 }
1531 }
1532 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001533 int[] resultArray = new int[2];
1534 resultArray[0] = mResult;
1535 resultArray[1] = mRetryCount;
1536 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001537 }
1538 }
1539
1540 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001541 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001542
1543 }
1544
Wink Savilleb564aae2014-10-23 10:18:09 -07001545 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 // No permission check needed here: this call is harmless, and it's
1547 // needed for the ServiceState.requestStateUpdate() call (which is
1548 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001549 final long identity = Binder.clearCallingIdentity();
1550 try {
1551 final Phone phone = getPhone(subId);
1552 if (phone != null) {
1553 phone.updateServiceLocation();
1554 }
1555 } finally {
1556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 }
1559
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001560 @Override
1561 public boolean isRadioOn(String callingPackage) {
1562 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001563 }
1564
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001565 @Override
1566 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001568 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001569 return false;
1570 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001571
1572 final long identity = Binder.clearCallingIdentity();
1573 try {
1574 return isRadioOnForSubscriber(subId);
1575 } finally {
1576 Binder.restoreCallingIdentity(identity);
1577 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001578 }
1579
1580 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001581 final long identity = Binder.clearCallingIdentity();
1582 try {
1583 final Phone phone = getPhone(subId);
1584 if (phone != null) {
1585 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1586 } else {
1587 return false;
1588 }
1589 } finally {
1590 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 }
1593
1594 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001595 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 }
Wink Saville36469e72014-06-11 15:17:00 -07001597
Wink Savilleb564aae2014-10-23 10:18:09 -07001598 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001600
1601 final long identity = Binder.clearCallingIdentity();
1602 try {
1603 final Phone phone = getPhone(subId);
1604 if (phone != null) {
1605 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1606 }
1607 } finally {
1608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 }
Wink Saville36469e72014-06-11 15:17:00 -07001610 }
1611
1612 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001613 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001614 }
1615
Wink Savilleb564aae2014-10-23 10:18:09 -07001616 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001617 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001618
1619 final long identity = Binder.clearCallingIdentity();
1620 try {
1621 final Phone phone = getPhone(subId);
1622 if (phone == null) {
1623 return false;
1624 }
1625 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1626 toggleRadioOnOffForSubscriber(subId);
1627 }
1628 return true;
1629 } finally {
1630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 }
Wink Saville36469e72014-06-11 15:17:00 -07001633
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001634 public boolean needMobileRadioShutdown() {
1635 /*
1636 * If any of the Radios are available, it will need to be
1637 * shutdown. So return true if any Radio is available.
1638 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001639 final long identity = Binder.clearCallingIdentity();
1640 try {
1641 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1642 Phone phone = PhoneFactory.getPhone(i);
1643 if (phone != null && phone.isRadioAvailable()) return true;
1644 }
1645 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1646 return false;
1647 } finally {
1648 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001649 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001650 }
1651
Malcolm Chend965c8b2018-02-28 15:00:40 -08001652 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001653 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001654 enforceModifyPermission();
1655
1656 final long identity = Binder.clearCallingIdentity();
1657 try {
1658 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1659 logv("Shutting down Phone " + i);
1660 shutdownRadioUsingPhoneId(i);
1661 }
1662 } finally {
1663 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001664 }
1665 }
1666
1667 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001668 Phone phone = PhoneFactory.getPhone(phoneId);
1669 if (phone != null && phone.isRadioAvailable()) {
1670 phone.shutdownRadio();
1671 }
1672 }
1673
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001675 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001676
1677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1680 if (defaultPhone != null) {
1681 defaultPhone.setRadioPower(turnOn);
1682 return true;
1683 } else {
1684 loge("There's no default phone.");
1685 return false;
1686 }
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001689 }
Wink Saville36469e72014-06-11 15:17:00 -07001690 }
1691
Wink Savilleb564aae2014-10-23 10:18:09 -07001692 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001694
1695 final long identity = Binder.clearCallingIdentity();
1696 try {
1697 final Phone phone = getPhone(subId);
1698 if (phone != null) {
1699 phone.setRadioPower(turnOn);
1700 return true;
1701 } else {
1702 return false;
1703 }
1704 } finally {
1705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
1708
Wink Saville36469e72014-06-11 15:17:00 -07001709 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001710 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 public boolean enableDataConnectivity() {
1712 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 int subId = mSubscriptionController.getDefaultDataSubId();
1717 final Phone phone = getPhone(subId);
1718 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001719 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001720 return true;
1721 } else {
1722 return false;
1723 }
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 }
1728
Wink Saville36469e72014-06-11 15:17:00 -07001729 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001730 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 public boolean disableDataConnectivity() {
1732 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001733
1734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 int subId = mSubscriptionController.getDefaultDataSubId();
1737 final Phone phone = getPhone(subId);
1738 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001739 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001740 return true;
1741 } else {
1742 return false;
1743 }
1744 } finally {
1745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
1748
Sanket Padawe356d7632015-06-22 14:03:32 -07001749 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001750 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001751 final long identity = Binder.clearCallingIdentity();
1752 try {
1753 final Phone phone = getPhone(subId);
1754 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001755 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001756 } else {
1757 return false;
1758 }
1759 } finally {
1760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763
1764 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001765 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
pkanwarae03a6b2016-11-06 20:37:09 -08001768 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001769 enforceCallPermission();
1770
1771 final long identity = Binder.clearCallingIdentity();
1772 try {
1773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1774 return;
1775 }
1776 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1777 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1778 } finally {
1779 Binder.restoreCallingIdentity(identity);
1780 }
pkanwar32d516d2016-10-14 19:37:38 -07001781 };
1782
Wink Savilleb564aae2014-10-23 10:18:09 -07001783 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001785
1786 final long identity = Binder.clearCallingIdentity();
1787 try {
1788 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1789 return false;
1790 }
1791 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1792 } finally {
1793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 }
1796
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001798 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001799 }
1800
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001801 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001802 final long identity = Binder.clearCallingIdentity();
1803 try {
1804 Phone phone = PhoneFactory.getPhone(slotIndex);
1805 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1806 PhoneConstantConversions.convertCallState(phone.getState());
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
1809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 }
1811
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1817 if (phone != null) {
1818 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1819 } else {
1820 return PhoneConstantConversions.convertDataState(
1821 PhoneConstants.DataState.DISCONNECTED);
1822 }
1823 } finally {
1824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 }
1827
Sanket Padawe356d7632015-06-22 14:03:32 -07001828 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001830 final long identity = Binder.clearCallingIdentity();
1831 try {
1832 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1833 if (phone != null) {
1834 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1835 } else {
1836 return TelephonyManager.DATA_ACTIVITY_NONE;
1837 }
1838 } finally {
1839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 }
1842
1843 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001844 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001845 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001846 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001847
1848 LocationAccessPolicy.LocationPermissionResult locationResult =
1849 LocationAccessPolicy.checkLocationPermission(mApp,
1850 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1851 .setCallingPackage(callingPackage)
1852 .setCallingPid(Binder.getCallingPid())
1853 .setCallingUid(Binder.getCallingUid())
1854 .setMethod("getCellLocation")
1855 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1856 .build());
1857 switch (locationResult) {
1858 case DENIED_HARD:
1859 throw new SecurityException("Not allowed to access cell location");
1860 case DENIED_SOFT:
1861 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 }
1863
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001864 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001865 final long identity = Binder.clearCallingIdentity();
1866 try {
1867 if (DBG_LOC) log("getCellLocation: is active user");
1868 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001869 int subId = mSubscriptionController.getDefaultDataSubId();
1870 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1871 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001872 return data;
1873 } finally {
1874 Binder.restoreCallingIdentity(identity);
1875 }
Svetoslav64fad262015-04-14 14:35:21 -07001876 }
1877
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001879 public String getNetworkCountryIsoForPhone(int phoneId) {
1880 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1881 // registered cell info, so return a NULL country instead.
1882 final long identity = Binder.clearCallingIdentity();
1883 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001884 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1885 // Get default phone in this case.
1886 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1887 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001888 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001889 // Todo: fix this when we can get the actual cellular network info when the device
1890 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001891 if (TelephonyManager.NETWORK_TYPE_IWLAN
1892 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1893 return "";
1894 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001895 Phone phone = PhoneFactory.getPhone(phoneId);
1896 if (phone != null) {
1897 ServiceStateTracker sst = phone.getServiceStateTracker();
1898 if (sst != null) {
1899 LocaleTracker lt = sst.getLocaleTracker();
1900 if (lt != null) {
1901 return lt.getCurrentCountry();
1902 }
1903 }
1904 }
1905 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001906 } finally {
1907 Binder.restoreCallingIdentity(identity);
1908 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001909 }
1910
1911 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001913 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001914 }
1915
Sanket Padawe356d7632015-06-22 14:03:32 -07001916 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001917 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 mApp.enforceCallingOrSelfPermission(
1919 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001920
1921 final long identity = Binder.clearCallingIdentity();
1922 try {
1923 final Phone phone = getPhone(subId);
1924 if (phone != null) {
1925 phone.enableLocationUpdates();
1926 }
1927 } finally {
1928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 }
1931
1932 @Override
1933 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001934 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001935 }
1936
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001938 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 mApp.enforceCallingOrSelfPermission(
1940 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001941
1942 final long identity = Binder.clearCallingIdentity();
1943 try {
1944 final Phone phone = getPhone(subId);
1945 if (phone != null) {
1946 phone.disableLocationUpdates();
1947 }
1948 } finally {
1949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 }
1952
Nathan Harold31d7ff32018-10-15 20:20:30 -07001953 /**
1954 * Returns the target SDK version number for a given package name.
1955 *
1956 * @return target SDK if the package is found or INT_MAX.
1957 */
1958 private int getTargetSdk(String packageName) {
1959 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001960 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1961 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001962 if (ai != null) return ai.targetSdkVersion;
1963 } catch (PackageManager.NameNotFoundException unexpected) {
1964 }
1965 return Integer.MAX_VALUE;
1966 }
1967
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 @Override
1969 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001970 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1971 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001972 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1973 throw new SecurityException(
1974 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1975 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001976
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1978 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1979 return null;
1980 }
Svetoslav64fad262015-04-14 14:35:21 -07001981
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001982 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983
Nathan Haroldf180aac2018-06-01 18:43:55 -07001984 List<CellInfo> info = getAllCellInfo(callingPackage);
1985 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001986
Nathan Haroldf180aac2018-06-01 18:43:55 -07001987 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1988 for (CellInfo ci : info) {
1989 if (ci instanceof CellInfoGsm) {
1990 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1991 } else if (ci instanceof CellInfoWcdma) {
1992 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001995 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001998 private List<CellInfo> getCachedCellInfo() {
1999 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2000 for (Phone phone : PhoneFactory.getPhones()) {
2001 List<CellInfo> info = phone.getAllCellInfo();
2002 if (info != null) cellInfos.addAll(info);
2003 }
2004 return cellInfos;
2005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006
2007 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002008 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002009 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002010 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002011
2012 LocationAccessPolicy.LocationPermissionResult locationResult =
2013 LocationAccessPolicy.checkLocationPermission(mApp,
2014 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2015 .setCallingPackage(callingPackage)
2016 .setCallingPid(Binder.getCallingPid())
2017 .setCallingUid(Binder.getCallingUid())
2018 .setMethod("getAllCellInfo")
2019 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2020 .build());
2021 switch (locationResult) {
2022 case DENIED_HARD:
2023 throw new SecurityException("Not allowed to access cell info");
2024 case DENIED_SOFT:
2025 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 }
2027
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002028 final int targetSdk = getTargetSdk(callingPackage);
2029 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2030 return getCachedCellInfo();
2031 }
2032
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002033 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002034 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002035 final long identity = Binder.clearCallingIdentity();
2036 try {
2037 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2038 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002039 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002040 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002041 if (info != null) cellInfos.addAll(info);
2042 }
2043 return cellInfos;
2044 } finally {
2045 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 }
2047 }
2048
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002049 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002050 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2051 requestCellInfoUpdateInternal(
2052 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2053 }
2054
2055 @Override
2056 public void requestCellInfoUpdateWithWorkSource(
2057 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2058 enforceModifyPermission();
2059 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2060 }
2061
2062 private void requestCellInfoUpdateInternal(
2063 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002064 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002065 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002066
2067 LocationAccessPolicy.LocationPermissionResult locationResult =
2068 LocationAccessPolicy.checkLocationPermission(mApp,
2069 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2070 .setCallingPackage(callingPackage)
2071 .setCallingPid(Binder.getCallingPid())
2072 .setCallingUid(Binder.getCallingUid())
2073 .setMethod("requestCellInfoUpdate")
2074 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2075 .build());
2076 switch (locationResult) {
2077 case DENIED_HARD:
2078 throw new SecurityException("Not allowed to access cell info");
2079 case DENIED_SOFT:
2080 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002081 }
2082
2083 final Phone phone = getPhone(subId);
2084 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2085
2086 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2087 }
2088
2089 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002091 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002092 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002093
2094 final long identity = Binder.clearCallingIdentity();
2095 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002096 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002097 } finally {
2098 Binder.restoreCallingIdentity(identity);
2099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 }
2101
Shishir Agrawala9f32182016-04-12 12:00:16 -07002102 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002103 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002104 Phone phone = PhoneFactory.getPhone(slotIndex);
2105 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002106 return null;
2107 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002108 int subId = phone.getSubId();
2109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2110 mApp, subId, callingPackage, "getImeiForSlot")) {
2111 return null;
2112 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 return phone.getImei();
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002120 }
2121
2122 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002123 public String getTypeAllocationCodeForSlot(int slotIndex) {
2124 Phone phone = PhoneFactory.getPhone(slotIndex);
2125 String tac = null;
2126 if (phone != null) {
2127 String imei = phone.getImei();
2128 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2129 }
2130 return tac;
2131 }
2132
2133 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002134 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002135 Phone phone = PhoneFactory.getPhone(slotIndex);
2136 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002137 return null;
2138 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002139
Jeff Davidson913390f2018-02-23 17:11:49 -08002140 int subId = phone.getSubId();
2141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2142 mApp, subId, callingPackage, "getMeidForSlot")) {
2143 return null;
2144 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002145
2146 final long identity = Binder.clearCallingIdentity();
2147 try {
2148 return phone.getMeid();
2149 } finally {
2150 Binder.restoreCallingIdentity(identity);
2151 }
Jack Yu2af8d712017-03-15 17:14:14 -07002152 }
2153
2154 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002155 public String getManufacturerCodeForSlot(int slotIndex) {
2156 Phone phone = PhoneFactory.getPhone(slotIndex);
2157 String manufacturerCode = null;
2158 if (phone != null) {
2159 String meid = phone.getMeid();
2160 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2161 }
2162 return manufacturerCode;
2163 }
2164
2165 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002166 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002167 Phone phone = PhoneFactory.getPhone(slotIndex);
2168 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002169 return null;
2170 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002171 int subId = phone.getSubId();
2172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2173 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2174 return null;
2175 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002176
2177 final long identity = Binder.clearCallingIdentity();
2178 try {
2179 return phone.getDeviceSvn();
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
2182 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002183 }
2184
fionaxu43304da2017-11-27 22:51:16 -08002185 @Override
2186 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002187 final long identity = Binder.clearCallingIdentity();
2188 try {
2189 final Phone phone = getPhone(subId);
2190 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2191 } finally {
2192 Binder.restoreCallingIdentity(identity);
2193 }
fionaxu43304da2017-11-27 22:51:16 -08002194 }
2195
2196 @Override
2197 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002198 final long identity = Binder.clearCallingIdentity();
2199 try {
2200 final Phone phone = getPhone(subId);
2201 return phone == null ? null : phone.getCarrierName();
2202 } finally {
2203 Binder.restoreCallingIdentity(identity);
2204 }
fionaxu43304da2017-11-27 22:51:16 -08002205 }
2206
calvinpaneed9ae82018-11-01 19:43:06 +08002207 @Override
chen xuc93cc282018-11-04 17:17:00 -08002208 public int getSubscriptionPreciseCarrierId(int subId) {
2209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 final Phone phone = getPhone(subId);
2212 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2213 : phone.getPreciseCarrierId();
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
2216 }
2217 }
2218
2219 @Override
2220 public String getSubscriptionPreciseCarrierName(int subId) {
2221 final long identity = Binder.clearCallingIdentity();
2222 try {
2223 final Phone phone = getPhone(subId);
2224 return phone == null ? null : phone.getPreciseCarrierName();
2225 } finally {
2226 Binder.restoreCallingIdentity(identity);
2227 }
2228 }
2229
chen xu02581692018-11-11 19:03:44 -08002230 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002231 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2232 if (!isSubscriptionMccMnc) {
2233 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2234 }
chen xu02581692018-11-11 19:03:44 -08002235 final Phone phone = PhoneFactory.getPhone(slotIndex);
2236 if (phone == null) {
2237 return TelephonyManager.UNKNOWN_CARRIER_ID;
2238 }
2239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2242 } finally {
2243 Binder.restoreCallingIdentity(identity);
2244 }
2245 }
2246
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 //
2248 // Internal helper methods.
2249 //
2250
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002251 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2253 *
2254 * @throws SecurityException if the caller does not have the required permission
2255 */
2256 private void enforceModifyPermission() {
2257 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2258 }
2259
2260 /**
2261 * Make sure the caller has the CALL_PHONE permission.
2262 *
2263 * @throws SecurityException if the caller does not have the required permission
2264 */
2265 private void enforceCallPermission() {
2266 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2267 }
2268
Stuart Scott8eef64f2015-04-08 15:13:54 -07002269 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002270 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002271 "ConnectivityService");
2272 }
2273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 private String createTelUrl(String number) {
2275 if (TextUtils.isEmpty(number)) {
2276 return null;
2277 }
2278
Jake Hambye994d462014-02-03 13:10:13 -08002279 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281
Ihab Awadf9e92732013-12-05 18:02:52 -08002282 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2284 }
2285
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002286 private static void logv(String msg) {
2287 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2288 }
2289
Ihab Awadf9e92732013-12-05 18:02:52 -08002290 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2292 }
2293
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002294 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002296 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002297 }
2298
Sanket Padawe356d7632015-06-22 14:03:32 -07002299 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002300 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 final Phone phone = PhoneFactory.getPhone(slotIndex);
2304 if (phone == null) {
2305 return PhoneConstants.PHONE_TYPE_NONE;
2306 } else {
2307 return phone.getPhoneType();
2308 }
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
2314 /**
2315 * Returns the CDMA ERI icon index to display
2316 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002317 @Override
2318 public int getCdmaEriIconIndex(String callingPackage) {
2319 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002320 }
2321
Sanket Padawe356d7632015-06-22 14:03:32 -07002322 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002323 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002325 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002326 return -1;
2327 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002328
2329 final long identity = Binder.clearCallingIdentity();
2330 try {
2331 final Phone phone = getPhone(subId);
2332 if (phone != null) {
2333 return phone.getCdmaEriIconIndex();
2334 } else {
2335 return -1;
2336 }
2337 } finally {
2338 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
2341
2342 /**
2343 * Returns the CDMA ERI icon mode,
2344 * 0 - ON
2345 * 1 - FLASHING
2346 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002347 @Override
2348 public int getCdmaEriIconMode(String callingPackage) {
2349 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002350 }
2351
Sanket Padawe356d7632015-06-22 14:03:32 -07002352 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002353 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002354 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002355 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002356 return -1;
2357 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002358
2359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 final Phone phone = getPhone(subId);
2362 if (phone != null) {
2363 return phone.getCdmaEriIconMode();
2364 } else {
2365 return -1;
2366 }
2367 } finally {
2368 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 }
2371
2372 /**
2373 * Returns the CDMA ERI text,
2374 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002375 @Override
2376 public String getCdmaEriText(String callingPackage) {
2377 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002378 }
2379
Sanket Padawe356d7632015-06-22 14:03:32 -07002380 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002381 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002383 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002384 return null;
2385 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002386
2387 final long identity = Binder.clearCallingIdentity();
2388 try {
2389 final Phone phone = getPhone(subId);
2390 if (phone != null) {
2391 return phone.getCdmaEriText();
2392 } else {
2393 return null;
2394 }
2395 } finally {
2396 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398 }
2399
2400 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002401 * Returns the CDMA MDN.
2402 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002403 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002404 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2406 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002407
2408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002411 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002412 return phone.getLine1Number();
2413 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002414 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002415 return null;
2416 }
2417 } finally {
2418 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002419 }
2420 }
2421
2422 /**
2423 * Returns the CDMA MIN.
2424 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002425 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002426 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2428 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002429
2430 final long identity = Binder.clearCallingIdentity();
2431 try {
2432 final Phone phone = getPhone(subId);
2433 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2434 return phone.getCdmaMin();
2435 } else {
2436 return null;
2437 }
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002440 }
2441 }
2442
Hall Liud892bec2018-11-30 14:51:45 -08002443 @Override
2444 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2445 INumberVerificationCallback callback, String callingPackage) {
2446 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2447 != PERMISSION_GRANTED) {
2448 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2449 }
2450 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2451
2452 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2453 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2454 throw new SecurityException("Calling package must be configured in the device config");
2455 }
2456
2457 if (range == null) {
2458 throw new NullPointerException("Range must be non-null");
2459 }
2460
2461 timeoutMillis = Math.min(timeoutMillis,
2462 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2463
2464 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2465 }
2466
Junda Liuca05d5d2014-08-14 22:36:34 -07002467 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 * Returns true if CDMA provisioning needs to run.
2469 */
2470 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002471 final long identity = Binder.clearCallingIdentity();
2472 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002473 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002474 } finally {
2475 Binder.restoreCallingIdentity(identity);
2476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
2479 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002480 * Sets the voice mail number of a given subId.
2481 */
2482 @Override
2483 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002484 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002485
2486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2489 new Pair<String, String>(alphaTag, number), new Integer(subId));
2490 return success;
2491 } finally {
2492 Binder.restoreCallingIdentity(identity);
2493 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002494 }
2495
Ta-wei Yen87c49842016-05-13 21:19:52 -07002496 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002497 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2498 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002499 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002500 if (!TextUtils.equals(callingPackage, systemDialer)) {
2501 throw new SecurityException("caller must be system dialer");
2502 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2507 if (phoneAccountHandle == null) {
2508 return null;
2509 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002510 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002511 } finally {
2512 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002513 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002514 }
2515
2516 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002517 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002519 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002520 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002521 return null;
2522 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002523
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002524 final long identity = Binder.clearCallingIdentity();
2525 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002526 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002527 } finally {
2528 Binder.restoreCallingIdentity(identity);
2529 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002530 }
2531
2532 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002533 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2534 VisualVoicemailSmsFilterSettings settings) {
2535 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002536
2537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002540 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002541 } finally {
2542 Binder.restoreCallingIdentity(identity);
2543 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002544 }
2545
2546 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002547 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2548 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002549
2550 final long identity = Binder.clearCallingIdentity();
2551 try {
2552 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002553 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002554 } finally {
2555 Binder.restoreCallingIdentity(identity);
2556 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002557 }
2558
2559 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002560 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2561 String callingPackage, int subId) {
2562 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002563
2564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002567 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002568 } finally {
2569 Binder.restoreCallingIdentity(identity);
2570 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002571 }
2572
2573 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002574 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002575 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002580 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002581 } finally {
2582 Binder.restoreCallingIdentity(identity);
2583 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002584 }
2585
2586 @Override
2587 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2588 String number, int port, String text, PendingIntent sentIntent) {
2589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002590 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002591 enforceSendSmsPermission();
2592 // Make the calls as the phone process.
2593 final long identity = Binder.clearCallingIdentity();
2594 try {
2595 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2596 if (port == 0) {
2597 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2598 sentIntent, null, false);
2599 } else {
2600 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2601 smsManager.sendDataMessageWithSelfPermissions(number, null,
2602 (short) port, data, sentIntent, null);
2603 }
2604 } finally {
2605 Binder.restoreCallingIdentity(identity);
2606 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002607 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002608 /**
fionaxu0152e512016-11-14 13:36:14 -08002609 * Sets the voice activation state of a given subId.
2610 */
2611 @Override
2612 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2614 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002615
2616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 final Phone phone = getPhone(subId);
2619 if (phone != null) {
2620 phone.setVoiceActivationState(activationState);
2621 } else {
2622 loge("setVoiceActivationState fails with invalid subId: " + subId);
2623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002626 }
2627 }
2628
2629 /**
2630 * Sets the data activation state of a given subId.
2631 */
2632 @Override
2633 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2635 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 if (phone != null) {
2641 phone.setDataActivationState(activationState);
2642 } else {
2643 loge("setVoiceActivationState fails with invalid subId: " + subId);
2644 }
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002647 }
2648 }
2649
2650 /**
2651 * Returns the voice activation state of a given subId.
2652 */
2653 @Override
2654 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002655 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002656
fionaxu0152e512016-11-14 13:36:14 -08002657 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 if (phone != null) {
2661 return phone.getVoiceActivationState();
2662 } else {
2663 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2664 }
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002667 }
2668 }
2669
2670 /**
2671 * Returns the data activation state of a given subId.
2672 */
2673 @Override
2674 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002675 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002676
fionaxu0152e512016-11-14 13:36:14 -08002677 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 if (phone != null) {
2681 return phone.getDataActivationState();
2682 } else {
2683 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2684 }
2685 } finally {
2686 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002687 }
2688 }
2689
2690 /**
Wink Saville36469e72014-06-11 15:17:00 -07002691 * Returns the unread count of voicemails for a subId
2692 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002694 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2696 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2697 return 0;
2698 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 final Phone phone = getPhone(subId);
2702 if (phone != null) {
2703 return phone.getVoiceMessageCount();
2704 } else {
2705 return 0;
2706 }
2707 } finally {
2708 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 }
2711
2712 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002713 * returns true, if the device is in a state where both voice and data
2714 * are supported simultaneously. This can change based on location or network condition.
2715 */
2716 @Override
2717 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 final Phone phone = getPhone(subId);
2721 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
2724 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002725 }
2726
2727 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002728 * Send the dialer code if called from the current default dialer or the caller has
2729 * carrier privilege.
2730 * @param inputCode The dialer code to send
2731 */
2732 @Override
2733 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002734 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002736 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2737 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002738 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002739 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2740 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002741 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002742
2743 final long identity = Binder.clearCallingIdentity();
2744 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002745 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002746 } finally {
2747 Binder.restoreCallingIdentity(identity);
2748 }
fionaxu235cc5e2017-03-06 22:25:57 -08002749 }
2750
2751 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002752 * Returns the data network type.
2753 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 *
2755 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2756 */
2757 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002758 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 final Phone phone = getPhone(getDefaultSubscription());
2762 if (phone != null) {
2763 return phone.getServiceState().getDataNetworkType();
2764 } else {
2765 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2766 }
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002769 }
Wink Saville36469e72014-06-11 15:17:00 -07002770 }
2771
Pengquan Meng0c05b502018-09-06 09:59:22 -07002772 @Override
2773 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002774 if (!isActiveSubscription(subId)) {
2775 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2776 }
2777
Pengquan Meng0c05b502018-09-06 09:59:22 -07002778 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2779 }
2780
Brad Ebinger4c460712018-10-01 10:40:55 -07002781 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002782 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2783 throws RemoteException {
2784 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002785 final long token = Binder.clearCallingIdentity();
2786 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002787 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002788 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002789 .addRegistrationCallbackForSubscription(c, subId);
2790 } finally {
2791 Binder.restoreCallingIdentity(token);
2792 }
2793 }
2794
2795 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002796 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2797 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002798 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2799 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2800 }
2801 Binder.withCleanCallingIdentity(() -> {
2802 try {
2803 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002804 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002805 .removeRegistrationCallbackForSubscription(c, subId);
2806 } catch (IllegalArgumentException e) {
2807 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2808 + "is inactive, ignoring unregister.");
2809 // If the subscription is no longer active, just return, since the callback
2810 // will already have been removed internally.
2811 }
2812 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002813 }
2814
2815 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002816 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2817 throws RemoteException {
2818 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002819 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2820 final long token = Binder.clearCallingIdentity();
2821 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002822 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002823 .addCapabilitiesCallbackForSubscription(c, subId);
2824 } finally {
2825 Binder.restoreCallingIdentity(token);
2826 }
2827 }
2828
2829 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002830 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2831 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002832
2833 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2834 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2835 }
2836 Binder.withCleanCallingIdentity(() -> {
2837 try {
2838 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002839 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002840 .removeCapabilitiesCallbackForSubscription(c, subId);
2841 } catch (IllegalArgumentException e) {
2842 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2843 + "is inactive, ignoring unregister.");
2844 // If the subscription is no longer active, just return, since the callback
2845 // will already have been removed internally.
2846 }
2847 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002848 }
2849
2850 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002851 public boolean isCapable(int subId, int capability, int regTech) {
2852 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2854 final long token = Binder.clearCallingIdentity();
2855 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002856 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002857 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2858 } catch (ImsException e) {
2859 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2860 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002861 } catch (IllegalArgumentException e) {
2862 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2863 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002864 } finally {
2865 Binder.restoreCallingIdentity(token);
2866 }
2867 }
2868
2869 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002870 public boolean isAvailable(int subId, int capability, int regTech) {
2871 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002872 final long token = Binder.clearCallingIdentity();
2873 try {
2874 Phone phone = getPhone(subId);
2875 if (phone == null) return false;
2876 return phone.isImsCapabilityAvailable(capability, regTech);
2877 } finally {
2878 Binder.restoreCallingIdentity(token);
2879 }
2880 }
2881
2882 @Override
2883 public boolean isAdvancedCallingSettingEnabled(int subId) {
2884 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2886 final long token = Binder.clearCallingIdentity();
2887 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002888 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002889 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2890 } finally {
2891 Binder.restoreCallingIdentity(token);
2892 }
2893 }
2894
2895 @Override
2896 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2898 "setAdvancedCallingSetting");
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002902 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002903 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
2907 }
2908
2909 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002910 public boolean isVtSettingEnabled(int subId) {
2911 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002912 final long identity = Binder.clearCallingIdentity();
2913 try {
2914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002915 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002916 getSlotIndexOrException(subId)).isVtEnabledByUser();
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
2920 }
2921
2922 @Override
2923 public void setVtSetting(int subId, boolean isEnabled) {
2924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2925 "setVtSetting");
2926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002929 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
2933 }
2934
2935 @Override
2936 public boolean isVoWiFiSettingEnabled(int subId) {
2937 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002941 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002942 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
2946 }
2947
2948 @Override
2949 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2951 "setVoWiFiSetting");
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002955 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
2959 }
2960
2961 @Override
2962 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2963 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002967 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002968 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
2972 }
2973
2974 @Override
2975 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2977 "setVoWiFiRoamingSetting");
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002981 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002982 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
2986 }
2987
2988 @Override
2989 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2991 "setVoWiFiNonPersistent");
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002995 boolean isRoaming = TelephonyManager.from(
2996 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002997 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08002998 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07002999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
3002 }
3003
3004 @Override
3005 public int getVoWiFiModeSetting(int subId) {
3006 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3007 final long identity = Binder.clearCallingIdentity();
3008 try {
3009 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003010 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003011 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
3014 }
3015 }
3016
3017 @Override
3018 public void setVoWiFiModeSetting(int subId, int mode) {
3019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3020 "setVoWiFiModeSetting");
3021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003024 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003025 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3026 } finally {
3027 Binder.restoreCallingIdentity(identity);
3028 }
3029 }
3030
3031 @Override
3032 public int getVoWiFiRoamingModeSetting(int subId) {
3033 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003037 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003038 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
3042 }
3043
3044 @Override
3045 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3047 "setVoWiFiRoamingModeSetting");
3048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003051 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003052 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
3056 }
3057
3058 @Override
3059 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3061 "setRttCapabilityEnabled");
3062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003065 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003066 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
3070 }
3071
3072 @Override
3073 public boolean isTtyOverVolteEnabled(int subId) {
3074 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003078 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003079 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
3083 }
3084
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003085 @Override
3086 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3087 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3088 final long identity = Binder.clearCallingIdentity();
3089 try {
3090 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003091 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003092 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
3096 }
3097
3098 @Override
3099 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3100 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3101 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003102 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3103 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3104 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003105 try {
3106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003107 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003108 .removeProvisioningCallbackForSubscription(callback, subId);
3109 } catch (IllegalArgumentException e) {
3110 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3111 + "is inactive, ignoring unregister.");
3112 // If the subscription is no longer active, just return, since the callback will already
3113 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
3117 }
3118
3119 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003120 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3121 boolean isProvisioned) {
3122 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3123 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3124 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3125 }
3126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3127 "setProvisioningStatusForCapability");
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3131 Phone phone = getPhone(subId);
3132 if (phone == null) {
3133 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3134 + subId);
3135 return;
3136 }
3137 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3138 return;
3139 }
3140
3141 // this capability requires provisioning, route to the correct API.
3142 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3143 switch (capability) {
3144 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3145 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3146 ims.setVolteProvisioned(isProvisioned);
3147 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3148 ims.setWfcProvisioned(isProvisioned);
3149 }
3150 break;
3151 }
3152 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3153 // There is currently no difference in VT provisioning type.
3154 ims.setVtProvisioned(isProvisioned);
3155 break;
3156 }
3157 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3158 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3159 // change the capability of the feature instead if needed.
3160 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3161 == isProvisioned) {
3162 // No change in provisioning.
3163 return;
3164 }
3165 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3166 try {
3167 ims.changeMmTelCapability(capability, tech, isProvisioned);
3168 } catch (ImsException e) {
3169 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3170 + ", Exception" + e.getMessage());
3171 }
3172 break;
3173 }
3174 default: {
3175 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3176 + capability + "', which does not require provisioning.");
3177 }
3178 }
3179
3180 } finally {
3181 Binder.restoreCallingIdentity(identity);
3182 }
3183 }
3184
3185 @Override
3186 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3187 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3188 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3189 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3190 }
3191 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3195 Phone phone = getPhone(subId);
3196 if (phone == null) {
3197 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3198 + subId);
3199 // We will fail with "true" as the provisioning status because this is the default
3200 // if we do not require provisioning.
3201 return true;
3202 }
3203
3204 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3205 return true;
3206 }
3207
3208 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3209 switch (capability) {
3210 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3211 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3212 return ims.isVolteProvisionedOnDevice();
3213 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3214 return ims.isWfcProvisionedOnDevice();
3215 }
3216 // This should never happen, since we are checking tech above to make sure it
3217 // is either LTE or IWLAN.
3218 throw new IllegalArgumentException("Invalid radio technology for voice "
3219 + "capability.");
3220 }
3221 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3222 // There is currently no difference in VT provisioning type.
3223 return ims.isVtProvisionedOnDevice();
3224 }
3225 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3226 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3227 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3228 }
3229 default: {
3230 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3231 + capability + "', which does not require provisioning.");
3232 }
3233 }
3234
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
3238 }
3239
3240 @Override
3241 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3242 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3243 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3244 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3245 }
3246 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3247 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3248 return (provisionedBits & capability) > 0;
3249 }
3250
3251 @Override
3252 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3253 boolean isProvisioned) {
3254 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3255 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3256 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3257 }
3258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3259 "setProvisioningStatusForCapability");
3260 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3261 // If the current provisioning status for capability already matches isProvisioned,
3262 // do nothing.
3263 if (((provisionedBits & capability) > 0) == isProvisioned) {
3264 return;
3265 }
3266 if (isProvisioned) {
3267 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3268 } else {
3269 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3270 }
3271 }
3272
3273 /**
3274 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3275 * technology. The bitfield should mirror the bitfield defined by
3276 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3277 */
3278 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3279 String key = getMmTelProvisioningKey(subId, tech);
3280 // Default is no capabilities are provisioned.
3281 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3282 }
3283
3284 /**
3285 * Sets the MmTel capability provisioning bitfield (defined by
3286 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3287 * technology specified.
3288 *
3289 * Note: This is a synchronous command and should not be called on UI thread.
3290 */
3291 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3292 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3293 String key = getMmTelProvisioningKey(subId, tech);
3294 editor.putInt(key, newField);
3295 editor.commit();
3296 }
3297
3298 private static String getMmTelProvisioningKey(int subId, int tech) {
3299 // resulting key is provision_ims_mmtel_{subId}_{tech}
3300 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3301 }
3302
3303 /**
3304 * Query CarrierConfig to see if the specified capability requires provisioning for the
3305 * carrier associated with the subscription id.
3306 */
3307 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3308 int capability) {
3309 CarrierConfigManager configManager = new CarrierConfigManager(context);
3310 PersistableBundle c = configManager.getConfigForSubId(subId);
3311 boolean requireUtProvisioning = c.getBoolean(
3312 // By default, this config is true (even if there is no SIM). We also check to make
3313 // sure the subscription needs provisioning here, so we do not need to check for
3314 // the no-SIM case, where we would normally shortcut this to false.
3315 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3316 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3317 false);
3318 boolean requireVoiceVtProvisioning = c.getBoolean(
3319 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3320
3321 // First check to make sure that the capability requires provisioning.
3322 switch (capability) {
3323 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3324 // intentional fallthrough
3325 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3326 if (requireVoiceVtProvisioning) {
3327 // Voice and Video requires provisioning
3328 return true;
3329 }
3330 break;
3331 }
3332 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3333 if (requireUtProvisioning) {
3334 // UT requires provisioning
3335 return true;
3336 }
3337 break;
3338 }
3339 }
3340 return false;
3341 }
3342
3343 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003344 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003345 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3346 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3347 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003348 enforceReadPrivilegedPermission("getImsProvisioningInt");
3349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003352 int slotId = getSlotIndex(subId);
3353 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3354 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3355 + subId + "' for key:" + key);
3356 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3357 }
3358 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003359 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003360 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3361 + subId + "' for key:" + key);
3362 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003363 } finally {
3364 Binder.restoreCallingIdentity(identity);
3365 }
3366 }
3367
3368 @Override
3369 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003370 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3371 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3372 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003373 enforceReadPrivilegedPermission("getImsProvisioningString");
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003377 int slotId = getSlotIndex(subId);
3378 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3379 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3380 + subId + "' for key:" + key);
3381 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3382 }
3383 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003384 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003385 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3386 + subId + "' for key:" + key);
3387 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003388 } finally {
3389 Binder.restoreCallingIdentity(identity);
3390 }
3391 }
3392
3393 @Override
3394 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003395 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3396 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3397 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3399 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003403 int slotId = getSlotIndex(subId);
3404 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3405 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3406 + subId + "' for key:" + key);
3407 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3408 }
3409 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003410 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003411 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3412 + "' for key:" + key);
3413 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003414 } finally {
3415 Binder.restoreCallingIdentity(identity);
3416 }
3417 }
3418
3419 @Override
3420 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3422 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3423 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3425 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003429 int slotId = getSlotIndex(subId);
3430 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3431 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3432 + subId + "' for key:" + key);
3433 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3434 }
3435 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003436 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003437 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3438 + "' for key:" + key);
3439 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
3443 }
3444
Brad Ebinger4c460712018-10-01 10:40:55 -07003445 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3446 int slotId = SubscriptionManager.getSlotIndex(subId);
3447 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003448 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003449 }
3450 return slotId;
3451 }
3452
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003453 private int getSlotIndex(int subId) {
3454 int slotId = SubscriptionManager.getSlotIndex(subId);
3455 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3456 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3457 }
3458 return slotId;
3459 }
3460
Wink Saville36469e72014-06-11 15:17:00 -07003461 /**
3462 * Returns the network type for a subId
3463 */
3464 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003465 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003467 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003468 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3469 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003470
Malcolm Chend965c8b2018-02-28 15:00:40 -08003471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 final Phone phone = getPhone(subId);
3474 if (phone != null) {
3475 return phone.getServiceState().getDataNetworkType();
3476 } else {
3477 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3478 }
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003482 }
3483
3484 /**
3485 * Returns the data network type
3486 */
3487 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003488 public int getDataNetworkType(String callingPackage) {
3489 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003490 }
3491
3492 /**
3493 * Returns the data network type for a subId
3494 */
3495 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003496 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003498 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003499 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3500 }
3501
Malcolm Chend965c8b2018-02-28 15:00:40 -08003502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 final Phone phone = getPhone(subId);
3505 if (phone != null) {
3506 return phone.getServiceState().getDataNetworkType();
3507 } else {
3508 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3509 }
3510 } finally {
3511 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003513 }
3514
3515 /**
Wink Saville36469e72014-06-11 15:17:00 -07003516 * Returns the Voice network type for a subId
3517 */
3518 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003519 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003521 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003522 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3523 }
3524
Malcolm Chend965c8b2018-02-28 15:00:40 -08003525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 final Phone phone = getPhone(subId);
3528 if (phone != null) {
3529 return phone.getServiceState().getVoiceNetworkType();
3530 } else {
3531 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3532 }
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 }
3537
3538 /**
3539 * @return true if a ICC card is present
3540 */
3541 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003542 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003543 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3544 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003545 }
3546
3547 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003548 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003549 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003550 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003551 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 final Phone phone = PhoneFactory.getPhone(slotIndex);
3555 if (phone != null) {
3556 return phone.getIccCard().hasIccCard();
3557 } else {
3558 return false;
3559 }
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003563 }
3564
3565 /**
3566 * Return if the current radio is LTE on CDMA. This
3567 * is a tri-state return value as for a period of time
3568 * the mode may be unknown.
3569 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003570 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003571 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003572 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003573 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003574 @Override
3575 public int getLteOnCdmaMode(String callingPackage) {
3576 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003577 }
3578
Sanket Padawe356d7632015-06-22 14:03:32 -07003579 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003580 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003582 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003583 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3584 }
3585
Malcolm Chend965c8b2018-02-28 15:00:40 -08003586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 final Phone phone = getPhone(subId);
3589 if (phone == null) {
3590 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3591 } else {
3592 return phone.getLteOnCdmaMode();
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003596 }
Wink Saville36469e72014-06-11 15:17:00 -07003597 }
3598
Wink Saville36469e72014-06-11 15:17:00 -07003599 /**
3600 * {@hide}
3601 * Returns Default subId, 0 in the case of single standby.
3602 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003603 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003604 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003605 }
3606
Shishir Agrawala9f32182016-04-12 12:00:16 -07003607 private int getSlotForDefaultSubscription() {
3608 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3609 }
3610
Wink Savilleb564aae2014-10-23 10:18:09 -07003611 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003612 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003613 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003614
Pengquan Meng466e2482018-09-21 15:54:48 -07003615 private boolean isActiveSubscription(int subId) {
3616 return mSubscriptionController.isActiveSubId(subId);
3617 }
3618
Ihab Awadf2177b72013-11-25 13:33:23 -08003619 /**
3620 * @see android.telephony.TelephonyManager.WifiCallingChoices
3621 */
3622 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003623 final long identity = Binder.clearCallingIdentity();
3624 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003625 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003626 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3627 getWhenToMakeWifiCallsDefaultPreference());
3628 } finally {
3629 Binder.restoreCallingIdentity(identity);
3630 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003631 }
3632
3633 /**
3634 * @see android.telephony.TelephonyManager.WifiCallingChoices
3635 */
3636 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003640 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003641 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003645 }
3646
Sailesh Nepald1e68152013-12-12 19:08:02 -08003647 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003648 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003649 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003650 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003651
Shishir Agrawal566b7612013-10-28 14:41:00 -07003652 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003653 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3654 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3656 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003657 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003658
Malcolm Chend965c8b2018-02-28 15:00:40 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 if (TextUtils.equals(ISDR_AID, aid)) {
3662 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003663 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3664 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003665 if (bestComponent == null
3666 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3667 loge("The calling package is not allowed to access ISD-R.");
3668 throw new SecurityException(
3669 "The calling package is not allowed to access ISD-R.");
3670 }
Derek Tan740e1672017-06-27 14:56:27 -07003671 }
Derek Tan740e1672017-06-27 14:56:27 -07003672
Malcolm Chend965c8b2018-02-28 15:00:40 -08003673 if (DBG) {
3674 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3675 }
3676 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3677 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3678 if (DBG) log("iccOpenLogicalChannel: " + response);
3679 return response;
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003683 }
3684
3685 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003686 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3688 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003689
Malcolm Chend965c8b2018-02-28 15:00:40 -08003690 final long identity = Binder.clearCallingIdentity();
3691 try {
3692 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3693 if (channel < 0) {
3694 return false;
3695 }
3696 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3697 if (DBG) log("iccCloseLogicalChannel: " + success);
3698 return success;
3699 } finally {
3700 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003701 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003702 }
3703
3704 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003705 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003706 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3708 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003709
Malcolm Chend965c8b2018-02-28 15:00:40 -08003710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 if (DBG) {
3713 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3714 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3715 + p3 + " data=" + data);
3716 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003717
Malcolm Chend965c8b2018-02-28 15:00:40 -08003718 if (channel < 0) {
3719 return "";
3720 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003721
Malcolm Chend965c8b2018-02-28 15:00:40 -08003722 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3723 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3724 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003725
Malcolm Chend965c8b2018-02-28 15:00:40 -08003726 // Append the returned status code to the end of the response payload.
3727 String s = Integer.toHexString(
3728 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3729 if (response.payload != null) {
3730 s = IccUtils.bytesToHexString(response.payload) + s;
3731 }
3732 return s;
3733 } finally {
3734 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003735 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003736 }
Jake Hambye994d462014-02-03 13:10:13 -08003737
Evan Charltonc66da362014-05-16 14:06:40 -07003738 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003739 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3740 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3742 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003743 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003744
Malcolm Chend965c8b2018-02-28 15:00:40 -08003745 final long identity = Binder.clearCallingIdentity();
3746 try {
3747 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3748 && TextUtils.equals(ISDR_AID, data)) {
3749 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003750 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3751 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003752 if (bestComponent == null
3753 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3754 loge("The calling package is not allowed to select ISD-R.");
3755 throw new SecurityException(
3756 "The calling package is not allowed to select ISD-R.");
3757 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003758 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003759
Malcolm Chend965c8b2018-02-28 15:00:40 -08003760 if (DBG) {
3761 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3762 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3763 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003764
Malcolm Chend965c8b2018-02-28 15:00:40 -08003765 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3766 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3767 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003768
Malcolm Chend965c8b2018-02-28 15:00:40 -08003769 // Append the returned status code to the end of the response payload.
3770 String s = Integer.toHexString(
3771 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3772 if (response.payload != null) {
3773 s = IccUtils.bytesToHexString(response.payload) + s;
3774 }
3775 return s;
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003778 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003779 }
3780
3781 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003782 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003783 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3785 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003786
Malcolm Chend965c8b2018-02-28 15:00:40 -08003787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 if (DBG) {
3790 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3791 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3792 }
3793
3794 IccIoResult response =
3795 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3796 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3797 subId);
3798
3799 if (DBG) {
3800 log("Exchange SIM_IO [R]" + response);
3801 }
3802
3803 byte[] result = null;
3804 int length = 2;
3805 if (response.payload != null) {
3806 length = 2 + response.payload.length;
3807 result = new byte[length];
3808 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3809 } else {
3810 result = new byte[length];
3811 }
3812
3813 result[length - 1] = (byte) response.sw2;
3814 result[length - 2] = (byte) response.sw1;
3815 return result;
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003818 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003819 }
3820
Nathan Haroldb3014052017-01-25 15:57:32 -08003821 /**
3822 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3823 * on a particular subscription
3824 */
sqianb6e41952018-03-12 14:54:01 -07003825 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3827 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3828 return null;
3829 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003830
3831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 if (appType != TelephonyManager.APPTYPE_USIM
3834 && appType != TelephonyManager.APPTYPE_SIM) {
3835 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3836 return null;
3837 }
3838 Object response = sendRequest(
3839 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3840 if (response instanceof String[]) {
3841 return (String[]) response;
3842 }
3843 // Response is an Exception of some kind,
3844 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003845 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003846 } finally {
3847 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003848 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003849 }
3850
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003851 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003852 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3854 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003855
Malcolm Chend965c8b2018-02-28 15:00:40 -08003856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3859 if (response.payload == null) {
3860 return "";
3861 }
Evan Charltonc66da362014-05-16 14:06:40 -07003862
Malcolm Chend965c8b2018-02-28 15:00:40 -08003863 // Append the returned status code to the end of the response payload.
3864 String s = Integer.toHexString(
3865 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3866 s = IccUtils.bytesToHexString(response.payload) + s;
3867 return s;
3868 } finally {
3869 Binder.restoreCallingIdentity(identity);
3870 }
Evan Charltonc66da362014-05-16 14:06:40 -07003871 }
3872
Jake Hambye994d462014-02-03 13:10:13 -08003873 /**
3874 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3875 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3876 *
3877 * @param itemID the ID of the item to read
3878 * @return the NV item as a String, or null on error.
3879 */
3880 @Override
3881 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003882 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3884 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003885
3886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003889 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003890 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3891 return value;
3892 } finally {
3893 Binder.restoreCallingIdentity(identity);
3894 }
Jake Hambye994d462014-02-03 13:10:13 -08003895 }
3896
3897 /**
3898 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3899 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3900 *
3901 * @param itemID the ID of the item to read
3902 * @param itemValue the value to write, as a String
3903 * @return true on success; false on any failure
3904 */
3905 @Override
3906 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003907 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3909 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003910
3911 final long identity = Binder.clearCallingIdentity();
3912 try {
3913 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3914 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003915 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003916 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3917 return success;
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
Jake Hambye994d462014-02-03 13:10:13 -08003921 }
3922
3923 /**
3924 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3925 * Used for device configuration by some CDMA operators.
3926 *
3927 * @param preferredRoamingList byte array containing the new PRL
3928 * @return true on success; false on any failure
3929 */
3930 @Override
3931 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3933 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003934
3935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3938 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3939 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3940 return success;
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
3943 }
Jake Hambye994d462014-02-03 13:10:13 -08003944 }
3945
3946 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003947 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003948 * Used for device configuration by some CDMA operators.
3949 *
chen xu1cc0abe2018-10-26 17:39:23 -07003950 * @param slotIndex - device slot.
3951 *
Jake Hambye994d462014-02-03 13:10:13 -08003952 * @return true on success; false on any failure
3953 */
3954 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003955 public boolean resetModemConfig(int slotIndex) {
3956 Phone phone = PhoneFactory.getPhone(slotIndex);
3957 if (phone != null) {
3958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3959 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003960
chen xu1cc0abe2018-10-26 17:39:23 -07003961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3964 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3965 return success;
3966 } finally {
3967 Binder.restoreCallingIdentity(identity);
3968 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003969 }
chen xu1cc0abe2018-10-26 17:39:23 -07003970 return false;
3971 }
3972
3973 /**
3974 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3975 *
3976 * @param slotIndex - device slot.
3977 *
3978 * @return true on success; false on any failure
3979 */
3980 @Override
3981 public boolean rebootModem(int slotIndex) {
3982 Phone phone = PhoneFactory.getPhone(slotIndex);
3983 if (phone != null) {
3984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3985 mApp, phone.getSubId(), "rebootModem");
3986
3987 final long identity = Binder.clearCallingIdentity();
3988 try {
3989 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3990 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3991 return success;
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
3995 }
3996 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003997 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003998
Svet Ganovb320e182015-04-16 12:30:10 -07003999 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004000 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004002 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004003 return new String[0];
4004 }
4005
Malcolm Chend965c8b2018-02-28 15:00:40 -08004006 final long identity = Binder.clearCallingIdentity();
4007 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004008 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
Wink Saville36469e72014-06-11 15:17:00 -07004012 }
4013
Brad Ebinger51f743a2017-01-23 13:50:20 -08004014 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004015 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4016 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004017 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004018 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004019 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004020
4021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 PhoneFactory.getImsResolver().enableIms(slotId);
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
4026 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004027 }
4028
4029 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004030 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4031 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004032 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004033 public void disableIms(int slotId) {
4034 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004035
4036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 PhoneFactory.getImsResolver().disableIms(slotId);
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
4041 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004042 }
4043
4044 /**
4045 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4046 * feature or {@link null} if the service is not available. If the feature is available, the
4047 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4048 */
4049 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004050 IImsServiceFeatureCallback callback) {
4051 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004052
4053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004059 }
4060
4061 /**
4062 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4063 * feature during emergency calling or {@link null} if the service is not available. If the
4064 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4065 * listener for feature updates.
4066 */
4067 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4068 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004069
4070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4073 } finally {
4074 Binder.restoreCallingIdentity(identity);
4075 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004076 }
4077
Brad Ebinger5f64b052017-12-14 14:26:15 -08004078 /**
4079 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4080 * specified.
4081 */
4082 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4083 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004084
4085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004091 }
4092
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004093 /**
4094 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4095 * specified.
4096 */
4097 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4098 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004099
4100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004106 }
4107
Brad Ebinger884c07b2018-02-15 16:17:40 -08004108 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004109 * Sets the ImsService Package Name that Telephony will bind to.
4110 *
4111 * @param slotId the slot ID that the ImsService should bind for.
4112 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4113 * ImsService is the device default ImsService.
4114 * @param packageName The package name of the application that contains the ImsService to bind
4115 * to.
4116 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4117 * @hide
4118 */
4119 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004120 int[] subIds = SubscriptionManager.getSubId(slotId);
4121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4122 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4123 "setImsService");
4124
Malcolm Chend965c8b2018-02-28 15:00:40 -08004125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4128 isCarrierImsService, packageName);
4129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004132 }
4133
4134 /**
4135 * Return the ImsService configuration.
4136 *
4137 * @param slotId The slot that the ImsService is associated with.
4138 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4139 * the device default.
4140 * @return the package name of the ImsService configuration.
4141 */
4142 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004143 int[] subIds = SubscriptionManager.getSubId(slotId);
4144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4145 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4146 "getImsService");
4147
Malcolm Chend965c8b2018-02-28 15:00:40 -08004148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4151 isCarrierImsService);
4152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004155 }
4156
Wink Saville36469e72014-06-11 15:17:00 -07004157 public void setImsRegistrationState(boolean registered) {
4158 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004159
4160 final long identity = Binder.clearCallingIdentity();
4161 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004162 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
Wink Saville36469e72014-06-11 15:17:00 -07004166 }
4167
4168 /**
Stuart Scott54788802015-03-30 13:18:01 -07004169 * Set the network selection mode to automatic.
4170 *
4171 */
4172 @Override
4173 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4175 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004176
Pengquan Meng466e2482018-09-21 15:54:48 -07004177 if (!isActiveSubscription(subId)) {
4178 return;
4179 }
4180
Malcolm Chend965c8b2018-02-28 15:00:40 -08004181 final long identity = Binder.clearCallingIdentity();
4182 try {
4183 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4184 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
Stuart Scott54788802015-03-30 13:18:01 -07004188 }
4189
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004190 /**
4191 * Ask the radio to connect to the input network and change selection mode to manual.
4192 *
4193 * @param subId the id of the subscription.
4194 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4195 * the operator to attach to.
4196 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4197 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4198 * normal network selection next time.
4199 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004200 */
4201 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004202 public boolean setNetworkSelectionModeManual(
4203 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4205 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004206
4207 if (!isActiveSubscription(subId)) {
4208 return false;
4209 }
4210
Malcolm Chend965c8b2018-02-28 15:00:40 -08004211 final long identity = Binder.clearCallingIdentity();
4212 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004213 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004214 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004215 if (DBG) {
4216 log("setNetworkSelectionModeManual: subId: " + subId
4217 + " operator: " + operatorInfo);
4218 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004219 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4220 } finally {
4221 Binder.restoreCallingIdentity(identity);
4222 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004223 }
4224
4225 /**
4226 * Scans for available networks.
4227 */
4228 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004229 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4231 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004232 LocationAccessPolicy.LocationPermissionResult locationResult =
4233 LocationAccessPolicy.checkLocationPermission(mApp,
4234 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4235 .setCallingPackage(callingPackage)
4236 .setCallingPid(Binder.getCallingPid())
4237 .setCallingUid(Binder.getCallingUid())
4238 .setMethod("getCellNetworkScanResults")
4239 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4240 .build());
4241 switch (locationResult) {
4242 case DENIED_HARD:
4243 throw new SecurityException("Not allowed to access scan results -- location");
4244 case DENIED_SOFT:
4245 return null;
4246 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004247
Pengquan Meng0c05b502018-09-06 09:59:22 -07004248 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004249 try {
4250 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004251 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004252 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004256 }
4257
4258 /**
yinxub1bed742017-04-17 11:45:04 -07004259 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004260 *
yinxub1bed742017-04-17 11:45:04 -07004261 * @param subId id of the subscription
4262 * @param request contains the radio access networks with bands/channels to scan
4263 * @param messenger callback messenger for scan results or errors
4264 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004265 * @return the id of the requested scan which can be used to stop the scan.
4266 */
4267 @Override
4268 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004269 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4271 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004272
Hall Liuf19c44f2018-11-27 14:38:17 -08004273 LocationAccessPolicy.LocationPermissionResult locationResult =
4274 LocationAccessPolicy.checkLocationPermission(mApp,
4275 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4276 .setCallingPackage(callingPackage)
4277 .setCallingPid(Binder.getCallingPid())
4278 .setCallingUid(Binder.getCallingUid())
4279 .setMethod("requestNetworkScan")
4280 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4281 .build());
4282 switch (locationResult) {
4283 case DENIED_HARD:
4284 throw new SecurityException("Not allowed to request network scan -- location");
4285 case DENIED_SOFT:
4286 return -1;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004287 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004288
4289 return mNetworkScanRequestTracker.startNetworkScan(
4290 request, messenger, binder, getPhone(subId),
4291 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004292 }
4293
4294 /**
4295 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004296 *
4297 * @param subId id of the subscription
4298 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004299 */
4300 @Override
4301 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4303 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004304
4305 final long identity = Binder.clearCallingIdentity();
4306 try {
4307 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
yinxu504e1392017-04-12 16:03:22 -07004311 }
4312
4313 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004314 * Get the calculated preferred network type.
4315 * Used for debugging incorrect network type.
4316 *
4317 * @return the preferred network type, defined in RILConstants.java.
4318 */
4319 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004320 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004321 final Phone defaultPhone = getDefaultPhone();
4322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4323 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004324 return RILConstants.PREFERRED_NETWORK_MODE;
4325 }
4326
Malcolm Chend965c8b2018-02-28 15:00:40 -08004327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004330 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004331 } finally {
4332 Binder.restoreCallingIdentity(identity);
4333 }
Junda Liu84d15a22014-07-02 11:21:04 -07004334 }
4335
4336 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004337 * Get the preferred network type.
4338 * Used for device configuration by some CDMA operators.
4339 *
4340 * @return the preferred network type, defined in RILConstants.java.
4341 */
4342 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004343 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004344 TelephonyPermissions
4345 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4346 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004347
4348 final long identity = Binder.clearCallingIdentity();
4349 try {
4350 if (DBG) log("getPreferredNetworkType");
4351 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4352 int networkType = (result != null ? result[0] : -1);
4353 if (DBG) log("getPreferredNetworkType: " + networkType);
4354 return networkType;
4355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004358 }
4359
4360 /**
4361 * Set the preferred network type.
4362 * Used for device configuration by some CDMA operators.
4363 *
4364 * @param networkType the preferred network type, defined in RILConstants.java.
4365 * @return true on success; false on any failure.
4366 */
4367 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004368 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4370 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004371
4372 final long identity = Binder.clearCallingIdentity();
4373 try {
4374 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4375 Boolean success = (Boolean) sendRequest(
4376 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4377 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4378 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004379 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004380 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4381 }
4382 return success;
4383 } finally {
4384 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004385 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004386 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004387
4388 /**
Junda Liu475951f2014-11-07 16:45:03 -08004389 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004390 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004391 * tethering.
4392 *
4393 * @return 0: Not required. 1: required. 2: Not set.
4394 * @hide
4395 */
4396 @Override
4397 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004398 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004399
4400 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004401 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004402 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004403 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004404 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004405 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004406 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004407 dunRequired = 1;
4408 }
4409 return dunRequired;
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004412 }
Junda Liu475951f2014-11-07 16:45:03 -08004413 }
4414
4415 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004416 * Set mobile data enabled
4417 * Used by the user through settings etc to turn on/off mobile data
4418 *
4419 * @param enable {@code true} turn turn data on, else {@code false}
4420 */
4421 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004422 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4424 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004425
4426 final long identity = Binder.clearCallingIdentity();
4427 try {
4428 int phoneId = mSubscriptionController.getPhoneId(subId);
4429 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4430 Phone phone = PhoneFactory.getPhone(phoneId);
4431 if (phone != null) {
4432 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004433 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004434 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004435 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004436 }
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004439 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004440 }
4441
4442 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004443 * Get the user enabled state of Mobile Data.
4444 *
4445 * TODO: remove and use isUserDataEnabled.
4446 * This can't be removed now because some vendor codes
4447 * calls through ITelephony directly while they should
4448 * use TelephonyManager.
4449 *
4450 * @return true on enabled
4451 */
4452 @Override
4453 public boolean getDataEnabled(int subId) {
4454 return isUserDataEnabled(subId);
4455 }
4456
4457 /**
4458 * Get whether mobile data is enabled per user setting.
4459 *
4460 * There are other factors deciding whether mobile data is actually enabled, but they are
4461 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004462 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004463 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004464 *
4465 * @return {@code true} if data is enabled else {@code false}
4466 */
4467 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004468 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004469 try {
4470 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4471 null);
4472 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4474 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004475 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004476
4477 final long identity = Binder.clearCallingIdentity();
4478 try {
4479 int phoneId = mSubscriptionController.getPhoneId(subId);
4480 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4481 Phone phone = PhoneFactory.getPhone(phoneId);
4482 if (phone != null) {
4483 boolean retVal = phone.isUserDataEnabled();
4484 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4485 return retVal;
4486 } else {
4487 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4488 return false;
4489 }
4490 } finally {
4491 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004492 }
4493 }
4494
4495 /**
4496 * Get whether mobile data is enabled.
4497 *
4498 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4499 * whether mobile data is actually enabled.
4500 *
4501 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4502 *
4503 * @return {@code true} if data is enabled else {@code false}
4504 */
4505 @Override
4506 public boolean isDataEnabled(int subId) {
4507 try {
4508 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4509 null);
4510 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4512 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004513 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004514
4515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 int phoneId = mSubscriptionController.getPhoneId(subId);
4518 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4519 Phone phone = PhoneFactory.getPhone(phoneId);
4520 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004521 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004522 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4523 return retVal;
4524 } else {
4525 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4526 return false;
4527 }
4528 } finally {
4529 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004530 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004531 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004532
4533 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004534 public int getCarrierPrivilegeStatus(int subId) {
4535 final Phone phone = getPhone(subId);
4536 if (phone == null) {
4537 loge("getCarrierPrivilegeStatus: Invalid subId");
4538 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4539 }
4540 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004541 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004542 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004543 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4544 }
4545 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004546 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004547 }
Junda Liu29340342014-07-10 15:23:27 -07004548
4549 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004550 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4551 final Phone phone = getPhone(subId);
4552 if (phone == null) {
4553 loge("getCarrierPrivilegeStatus: Invalid subId");
4554 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4555 }
4556 UiccProfile profile =
4557 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4558 if (profile == null) {
4559 loge("getCarrierPrivilegeStatus: No UICC");
4560 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4561 }
4562 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4563 }
4564
4565 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004566 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004567 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004568 if (TextUtils.isEmpty(pkgName))
4569 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004570 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004571 if (card == null) {
4572 loge("checkCarrierPrivilegesForPackage: No UICC");
4573 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4574 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004575 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4576 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004577 }
4578
4579 @Override
4580 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004581 if (TextUtils.isEmpty(pkgName))
4582 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004583 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4584 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4585 UiccCard card = UiccController.getInstance().getUiccCard(i);
4586 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004587 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004588 continue;
4589 }
4590
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004591 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004592 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4593 break;
4594 }
4595 }
4596
4597 return result;
Junda Liu29340342014-07-10 15:23:27 -07004598 }
Derek Tan89e89d42014-07-08 17:00:10 -07004599
4600 @Override
Junda Liue64de782015-04-16 17:19:16 -07004601 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4602 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4603 loge("phoneId " + phoneId + " is not valid.");
4604 return null;
4605 }
4606 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004607 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004608 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004609 return null ;
4610 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004611 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004612 }
4613
Amith Yamasani6e118872016-02-19 12:53:51 -08004614 @Override
4615 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004616 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004617 List<String> privilegedPackages = new ArrayList<>();
4618 List<PackageInfo> packages = null;
4619 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4620 UiccCard card = UiccController.getInstance().getUiccCard(i);
4621 if (card == null) {
4622 // No UICC in that slot.
4623 continue;
4624 }
4625 if (card.hasCarrierPrivilegeRules()) {
4626 if (packages == null) {
4627 // Only check packages in user 0 for now
4628 packages = pm.getInstalledPackagesAsUser(
4629 PackageManager.MATCH_DISABLED_COMPONENTS
4630 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4631 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4632 }
4633 for (int p = packages.size() - 1; p >= 0; p--) {
4634 PackageInfo pkgInfo = packages.get(p);
4635 if (pkgInfo != null && pkgInfo.packageName != null
4636 && card.getCarrierPrivilegeStatus(pkgInfo)
4637 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4638 privilegedPackages.add(pkgInfo.packageName);
4639 }
4640 }
4641 }
4642 }
4643 return privilegedPackages;
4644 }
4645
Wink Savilleb564aae2014-10-23 10:18:09 -07004646 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004647 final Phone phone = getPhone(subId);
4648 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004649 if (card == null) {
4650 loge("getIccId: No UICC");
4651 return null;
4652 }
4653 String iccId = card.getIccId();
4654 if (TextUtils.isEmpty(iccId)) {
4655 loge("getIccId: ICC ID is null or empty.");
4656 return null;
4657 }
4658 return iccId;
4659 }
4660
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004661 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004662 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4663 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004664 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4665 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004666
Malcolm Chend965c8b2018-02-28 15:00:40 -08004667 final long identity = Binder.clearCallingIdentity();
4668 try {
4669 final String iccId = getIccId(subId);
4670 final Phone phone = getPhone(subId);
4671 if (phone == null) {
4672 return false;
4673 }
4674 final String subscriberId = phone.getSubscriberId();
4675
4676 if (DBG_MERGE) {
4677 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4678 + subscriberId + " to " + number);
4679 }
4680
4681 if (TextUtils.isEmpty(iccId)) {
4682 return false;
4683 }
4684
4685 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4686
4687 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4688 if (alphaTag == null) {
4689 editor.remove(alphaTagPrefKey);
4690 } else {
4691 editor.putString(alphaTagPrefKey, alphaTag);
4692 }
4693
4694 // Record both the line number and IMSI for this ICCID, since we need to
4695 // track all merged IMSIs based on line number
4696 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4697 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4698 if (number == null) {
4699 editor.remove(numberPrefKey);
4700 editor.remove(subscriberPrefKey);
4701 } else {
4702 editor.putString(numberPrefKey, number);
4703 editor.putString(subscriberPrefKey, subscriberId);
4704 }
4705
4706 editor.commit();
4707 return true;
4708 } finally {
4709 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004710 }
Derek Tan7226c842014-07-02 17:42:23 -07004711 }
4712
4713 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004714 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004715 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004717 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004718 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004719 return null;
4720 }
Derek Tan97ebb422014-09-05 16:55:38 -07004721
Malcolm Chend965c8b2018-02-28 15:00:40 -08004722 final long identity = Binder.clearCallingIdentity();
4723 try {
4724 String iccId = getIccId(subId);
4725 if (iccId != null) {
4726 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4727 if (DBG_MERGE) {
4728 log("getLine1NumberForDisplay returning "
4729 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4730 }
4731 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004732 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004733 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4734 return null;
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004737 }
Derek Tan7226c842014-07-02 17:42:23 -07004738 }
4739
4740 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004741 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004742 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004743 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004744 return null;
4745 }
Derek Tan97ebb422014-09-05 16:55:38 -07004746
Malcolm Chend965c8b2018-02-28 15:00:40 -08004747 final long identity = Binder.clearCallingIdentity();
4748 try {
4749 String iccId = getIccId(subId);
4750 if (iccId != null) {
4751 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4752 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4753 }
4754 return null;
4755 } finally {
4756 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004757 }
Derek Tan7226c842014-07-02 17:42:23 -07004758 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004759
4760 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004761 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004762 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4763 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004765 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4766 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004767 return null;
4768 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004769
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004770 final long identity = Binder.clearCallingIdentity();
4771 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004772 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004773 final TelephonyManager tele = TelephonyManager.from(context);
4774 final SubscriptionManager sub = SubscriptionManager.from(context);
4775
4776 // Figure out what subscribers are currently active
4777 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4778 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4779 // the process, where TelephonyManager was instantiated.
4780 // Otherwise AppOps check will fail.
4781
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004782 final int[] subIds = sub.getActiveSubscriptionIdList();
4783 for (int subId : subIds) {
4784 activeSubscriberIds.add(tele.getSubscriberId(subId));
4785 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004786
4787 // First pass, find a number override for an active subscriber
4788 String mergeNumber = null;
4789 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4790 for (String key : prefs.keySet()) {
4791 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4792 final String subscriberId = (String) prefs.get(key);
4793 if (activeSubscriberIds.contains(subscriberId)) {
4794 final String iccId = key.substring(
4795 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4796 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4797 mergeNumber = (String) prefs.get(numberKey);
4798 if (DBG_MERGE) {
4799 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4800 + " for active subscriber " + subscriberId);
4801 }
4802 if (!TextUtils.isEmpty(mergeNumber)) {
4803 break;
4804 }
4805 }
4806 }
4807 }
4808
4809 // Shortcut when no active merged subscribers
4810 if (TextUtils.isEmpty(mergeNumber)) {
4811 return null;
4812 }
4813
4814 // Second pass, find all subscribers under that line override
4815 final ArraySet<String> result = new ArraySet<>();
4816 for (String key : prefs.keySet()) {
4817 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4818 final String number = (String) prefs.get(key);
4819 if (mergeNumber.equals(number)) {
4820 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4821 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4822 final String subscriberId = (String) prefs.get(subscriberKey);
4823 if (!TextUtils.isEmpty(subscriberId)) {
4824 result.add(subscriberId);
4825 }
4826 }
4827 }
4828 }
4829
4830 final String[] resultArray = result.toArray(new String[result.size()]);
4831 Arrays.sort(resultArray);
4832 if (DBG_MERGE) {
4833 Slog.d(LOG_TAG,
4834 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4835 }
4836 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004837 } finally {
4838 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004839 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004840 }
4841
4842 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004843 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004844 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4845 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004846
4847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 final Phone phone = getPhone(subId);
4850 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4851 } finally {
4852 Binder.restoreCallingIdentity(identity);
4853 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004854 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004855
4856 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004857 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004858 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4859 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004860 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004861
4862 final long identity = Binder.clearCallingIdentity();
4863 try {
4864 final Phone phone = getPhone(subId);
4865 if (phone == null) {
4866 return false;
4867 }
4868 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4869 cdmaNonRoamingList);
4870 } finally {
4871 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004872 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004873 }
4874
4875 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004876 @Deprecated
4877 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4878 enforceModifyPermission();
4879
4880 int returnValue = 0;
4881 try {
vagdevie435a3e2018-08-15 16:01:53 -07004882 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004883 if(result.exception == null) {
4884 if (result.result != null) {
4885 byte[] responseData = (byte[])(result.result);
4886 if(responseData.length > oemResp.length) {
4887 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4888 responseData.length + "bytes. Buffer Size is " +
4889 oemResp.length + "bytes.");
4890 }
4891 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4892 returnValue = responseData.length;
4893 }
4894 } else {
4895 CommandException ex = (CommandException) result.exception;
4896 returnValue = ex.getCommandError().ordinal();
4897 if(returnValue > 0) returnValue *= -1;
4898 }
4899 } catch (RuntimeException e) {
4900 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4901 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4902 if(returnValue > 0) returnValue *= -1;
4903 }
4904
4905 return returnValue;
4906 }
4907
4908 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004909 public void setRadioCapability(RadioAccessFamily[] rafs) {
4910 try {
4911 ProxyController.getInstance().setRadioCapability(rafs);
4912 } catch (RuntimeException e) {
4913 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4914 }
4915 }
4916
4917 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004918 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004919 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004920 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004921 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004922 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004923 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004924 final long identity = Binder.clearCallingIdentity();
4925 try {
chen xufeeed752018-10-26 14:17:57 -07004926 TelephonyPermissions
4927 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4928 mApp, phone.getSubId(), "getRadioAccessFamily");
4929 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
chen xufeeed752018-10-26 14:17:57 -07004933 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004934 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004935
4936 @Override
4937 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004938 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004939 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004940
4941 final long identity = Binder.clearCallingIdentity();
4942 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004943 ImsManager.getInstance(defaultPhone.getContext(),
4944 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004948 }
4949
4950 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004951 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004952 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004953 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004954 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004955 return false;
4956 }
Svet Ganovb320e182015-04-16 12:30:10 -07004957
Malcolm Chend965c8b2018-02-28 15:00:40 -08004958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 // Check the user preference and the system-level IMS setting. Even if the user has
4961 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4962 // In the long run, we may instead need to check if there exists a connection service
4963 // which can support video calling.
4964 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004965 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004966 return imsManager.isVtEnabledByPlatform()
4967 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4968 && imsManager.isVtEnabledByUser();
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004972 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004973
Andrew Leea1239f22015-03-02 17:44:07 -08004974 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004975 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4977 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4978 return false;
4979 }
4980
4981 final long identity = Binder.clearCallingIdentity();
4982 try {
4983 CarrierConfigManager configManager =
4984 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004985 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004986 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4987 } finally {
4988 Binder.restoreCallingIdentity(identity);
4989 }
Andrew Leea1239f22015-03-02 17:44:07 -08004990 }
4991
4992 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004993 public boolean isWorldPhone(int subId, String callingPackage) {
4994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4995 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4996 return false;
4997 }
4998
4999 final long identity = Binder.clearCallingIdentity();
5000 try {
5001 CarrierConfigManager configManager =
5002 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005003 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005004 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5005 } finally {
5006 Binder.restoreCallingIdentity(identity);
5007 }
Andrew Leea1239f22015-03-02 17:44:07 -08005008 }
5009
Andrew Lee9431b832015-03-09 18:46:45 -07005010 @Override
5011 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005012 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005013 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005014 }
5015
5016 @Override
5017 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005018 final long identity = Binder.clearCallingIdentity();
5019 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005020 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
Andrew Lee9431b832015-03-09 18:46:45 -07005024 }
5025
Hall Liuf6668912018-10-31 17:05:23 -07005026 /**
5027 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5028 * support for the feature and device firmware support.
5029 *
5030 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5031 */
5032 @Override
5033 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005034 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005035 final Phone phone = getPhone(subscriptionId);
5036 if (phone == null) {
5037 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5038 return false;
5039 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005040 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005041 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005042 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5043 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005044 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005045 return isCarrierSupported && isDeviceSupported;
5046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
Hall Liu98187582018-01-22 19:15:32 -08005049 }
5050
Hall Liuf6668912018-10-31 17:05:23 -07005051 /**
5052 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5053 * both also support RTT.
5054 */
5055 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
Hall Liuf6668912018-10-31 17:05:23 -07005058 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005059 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005060 } finally {
5061 Binder.restoreCallingIdentity(identity);
5062 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005063 }
5064
Sanket Padawe7310cc72015-01-14 09:53:20 -08005065 /**
5066 * Returns the unique device ID of phone, for example, the IMEI for
5067 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5068 *
5069 * <p>Requires Permission:
5070 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5071 */
5072 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005073 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005074 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005075 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005076 return null;
5077 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005078 int subId = phone.getSubId();
5079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5080 mApp, subId, callingPackage, "getDeviceId")) {
5081 return null;
5082 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005083
5084 final long identity = Binder.clearCallingIdentity();
5085 try {
5086 return phone.getDeviceId();
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
5089 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005090 }
5091
Ping Sunc67b7c22016-03-02 19:16:45 +08005092 /**
5093 * {@hide}
5094 * Returns the IMS Registration Status on a particular subid
5095 *
5096 * @param subId
5097 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005098 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005099 Phone phone = getPhone(subId);
5100 if (phone != null) {
5101 return phone.isImsRegistered();
5102 } else {
5103 return false;
5104 }
5105 }
5106
Santos Cordon7a1885b2015-02-03 11:15:19 -08005107 @Override
5108 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005109 final long identity = Binder.clearCallingIdentity();
5110 try {
5111 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005115 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005116
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005117 /**
5118 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005119 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005120 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 Phone phone = getPhone(subId);
5124 if (phone != null) {
5125 return phone.isWifiCallingEnabled();
5126 } else {
5127 return false;
5128 }
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005131 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005132 }
5133
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005134 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005135 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005136 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005137 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005138 final long identity = Binder.clearCallingIdentity();
5139 try {
5140 Phone phone = getPhone(subId);
5141 if (phone != null) {
5142 return phone.isVideoEnabled();
5143 } else {
5144 return false;
5145 }
5146 } finally {
5147 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005148 }
5149 }
5150
5151 /**
5152 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5153 * defined in {@link ImsRegistrationImplBase}.
5154 */
5155 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005156 final long identity = Binder.clearCallingIdentity();
5157 try {
5158 Phone phone = getPhone(subId);
5159 if (phone != null) {
5160 return phone.getImsRegistrationTech();
5161 } else {
5162 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5163 }
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005166 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005167 }
5168
Stuart Scott8eef64f2015-04-08 15:13:54 -07005169 @Override
5170 public void factoryReset(int subId) {
5171 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005172 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5173 return;
5174 }
5175
Svet Ganovcc087f82015-05-12 20:35:54 -07005176 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005177
Svet Ganovcc087f82015-05-12 20:35:54 -07005178 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005179 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5180 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005181 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005182 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005183 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005184 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5185 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005186 }
5187 } finally {
5188 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005189 }
5190 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005191
5192 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005193 public String getSimLocaleForSubscriber(int subId) {
5194 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5195 final Phone phone = getPhone(subId);
5196 if (phone == null) {
5197 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005198 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005199 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005200 final long identity = Binder.clearCallingIdentity();
5201 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005202 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5203 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005204 // Try and fetch the locale from the carrier properties or from the SIM language
5205 // preferences (EF-PL and EF-LI)...
5206 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005207 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005208 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5209 if (localeFromDefaultSim != null) {
5210 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5211 if (DBG) log("Using locale from subId: " + subId + " locale: "
5212 + localeFromDefaultSim);
5213 return localeFromDefaultSim.toLanguageTag();
5214 } else {
5215 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005216 }
5217 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005218
Malcolm Chend965c8b2018-02-28 15:00:40 -08005219 // The SIM language preferences only store a language (e.g. fr = French), not an
5220 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5221 // the SIM and carrier preferences does not include a country we add the country
5222 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005223 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005224 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005225 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005226 return mccLocale.toLanguageTag();
5227 }
5228
5229 if (DBG) log("No locale found - returning null");
5230 return null;
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005234 }
5235
5236 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005237 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005238 }
5239
Malcolm Chend965c8b2018-02-28 15:00:40 -08005240 /**
5241 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5242 */
5243 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005244 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005245 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005246
Chenjie Yu1ba97252018-01-11 18:16:20 -08005247 private final ModemActivityInfo mLastModemActivityInfo =
5248 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5249
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005250 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005251 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5252 * representing the state of the modem.
5253 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005254 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5255 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005256 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005257 */
5258 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005259 public void requestModemActivityInfo(ResultReceiver result) {
5260 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005261 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005262
5263 final long identity = Binder.clearCallingIdentity();
5264 try {
5265 ModemActivityInfo ret = null;
5266 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005267 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5268 CMD_GET_MODEM_ACTIVITY_INFO,
5269 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005270 if (isModemActivityInfoValid(info)) {
5271 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5272 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5273 mergedTxTimeMs[i] =
5274 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5275 }
5276 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5277 mLastModemActivityInfo.setSleepTimeMillis(
5278 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5279 mLastModemActivityInfo.setIdleTimeMillis(
5280 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5281 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5282 mLastModemActivityInfo.setRxTimeMillis(
5283 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5284 mLastModemActivityInfo.setEnergyUsed(
5285 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005286 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005287 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5288 mLastModemActivityInfo.getSleepTimeMillis(),
5289 mLastModemActivityInfo.getIdleTimeMillis(),
5290 mLastModemActivityInfo.getTxTimeMillis(),
5291 mLastModemActivityInfo.getRxTimeMillis(),
5292 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005293 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005294 Bundle bundle = new Bundle();
5295 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5296 result.send(0, bundle);
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005299 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005300 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005301
Siddharth Rayf5d29552018-06-17 15:02:38 -07005302 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5303 // less than total activity duration.
5304 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5305 if (info == null) {
5306 return false;
5307 }
5308 int activityDurationMs =
5309 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5310 int totalTxTimeMs = 0;
5311 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5312 totalTxTimeMs += info.getTxTimeMillis()[i];
5313 }
5314 return (info.isValid()
5315 && (info.getSleepTimeMillis() <= activityDurationMs)
5316 && (info.getIdleTimeMillis() <= activityDurationMs)
5317 && (info.getRxTimeMillis() <= activityDurationMs)
5318 && (totalTxTimeMs <= activityDurationMs));
5319 }
5320
Jack Yu85bd38a2015-11-09 11:34:32 -08005321 /**
5322 * {@hide}
5323 * Returns the service state information on specified subscription.
5324 */
5325 @Override
5326 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005328 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005329 return null;
5330 }
5331
Hall Liuf19c44f2018-11-27 14:38:17 -08005332 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5333 LocationAccessPolicy.checkLocationPermission(mApp,
5334 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5335 .setCallingPackage(callingPackage)
5336 .setCallingPid(Binder.getCallingPid())
5337 .setCallingUid(Binder.getCallingUid())
5338 .setMethod("getServiceStateForSubscriber")
5339 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5340 .build());
5341
5342 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5343 LocationAccessPolicy.checkLocationPermission(mApp,
5344 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5345 .setCallingPackage(callingPackage)
5346 .setCallingPid(Binder.getCallingPid())
5347 .setCallingUid(Binder.getCallingUid())
5348 .setMethod("getServiceStateForSubscriber")
5349 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5350 .build());
5351 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5352 boolean hasFinePermission =
5353 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5354 boolean hasCoarsePermission =
5355 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5356
Malcolm Chend965c8b2018-02-28 15:00:40 -08005357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 final Phone phone = getPhone(subId);
5360 if (phone == null) {
5361 return null;
5362 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005363
Hall Liuf19c44f2018-11-27 14:38:17 -08005364 ServiceState ss = phone.getServiceState();
5365
5366 // Scrub out the location info in ServiceState depending on what level of access
5367 // the caller has.
5368 if (hasFinePermission) return ss;
5369 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5370 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005374 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005375
5376 /**
5377 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5378 *
5379 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5380 * voicemail ringtone.
5381 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5382 * PhoneAccount.
5383 */
5384 @Override
5385 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
5388 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5389 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005390 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005391 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005392
Malcolm Chend965c8b2018-02-28 15:00:40 -08005393 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5394 } finally {
5395 Binder.restoreCallingIdentity(identity);
5396 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005397 }
5398
5399 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005400 * Sets the per-account voicemail ringtone.
5401 *
5402 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5403 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5404 *
5405 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5406 * voicemail ringtone.
5407 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5408 * PhoneAccount.
5409 */
5410 @Override
5411 public void setVoicemailRingtoneUri(String callingPackage,
5412 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005413 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005414 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5415 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005416 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5418 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5419 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005420 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005421
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5425 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005426 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005427 }
5428 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5429 } finally {
5430 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005431 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005432 }
5433
5434 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005435 * Returns whether vibration is set for voicemail notification in Phone settings.
5436 *
5437 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5438 * voicemail vibration setting.
5439 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5440 */
5441 @Override
5442 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005443 final long identity = Binder.clearCallingIdentity();
5444 try {
5445 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5446 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005447 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005448 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005449
Malcolm Chend965c8b2018-02-28 15:00:40 -08005450 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
5453 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005454 }
5455
Youhan Wange64578a2016-05-02 15:32:42 -07005456 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005457 * Sets the per-account voicemail vibration.
5458 *
5459 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5460 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5461 *
5462 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5463 * voicemail vibration setting.
5464 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5465 * specific PhoneAccount.
5466 */
5467 @Override
5468 public void setVoicemailVibrationEnabled(String callingPackage,
5469 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005470 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5472 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005473 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5475 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5476 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005477 }
5478
Malcolm Chend965c8b2018-02-28 15:00:40 -08005479 final long identity = Binder.clearCallingIdentity();
5480 try {
5481 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5482 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005483 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005484 }
5485 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5486 } finally {
5487 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005488 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005489 }
5490
5491 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005492 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5493 *
5494 * @throws SecurityException if the caller does not have the required permission
5495 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005496 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005497 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005498 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005499 }
5500
5501 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005502 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5503 * permission.
5504 *
5505 * @throws SecurityException if the caller does not have the required permission
5506 */
5507 private void enforceSendSmsPermission() {
5508 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5509 }
5510
5511 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005512 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005513 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005514 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005515 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005516 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005520 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005521 if (componentName == null) {
5522 throw new SecurityException(
5523 "Caller not current active visual voicemail package[null]");
5524 }
5525 String vvmPackage = componentName.getPackageName();
5526 if (!callingPackage.equals(vvmPackage)) {
5527 throw new SecurityException("Caller not current active visual voicemail package["
5528 + vvmPackage + "]");
5529 }
5530 } finally {
5531 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005532 }
5533 }
5534
5535 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005536 * Return the application ID for the app type.
5537 *
5538 * @param subId the subscription ID that this request applies to.
5539 * @param appType the uicc app type.
5540 * @return Application ID for specificied app type, or null if no uicc.
5541 */
5542 @Override
5543 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005544 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005545 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005546
5547 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005548 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005549 if (phone == null) {
5550 return null;
5551 }
5552 String aid = null;
5553 try {
5554 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5555 .getApplicationByType(appType).getAid();
5556 } catch (Exception e) {
5557 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5558 }
5559 return aid;
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005562 }
Youhan Wange64578a2016-05-02 15:32:42 -07005563 }
5564
Youhan Wang4001d252016-05-11 10:29:41 -07005565 /**
5566 * Return the Electronic Serial Number.
5567 *
5568 * @param subId the subscription ID that this request applies to.
5569 * @return ESN or null if error.
5570 */
5571 @Override
5572 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005573 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005574 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005575
5576 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005577 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005578 if (phone == null) {
5579 return null;
5580 }
5581 String esn = null;
5582 try {
5583 esn = phone.getEsn();
5584 } catch (Exception e) {
5585 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5586 }
5587 return esn;
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005590 }
Youhan Wang4001d252016-05-11 10:29:41 -07005591 }
5592
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005593 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005594 * Return the Preferred Roaming List Version.
5595 *
5596 * @param subId the subscription ID that this request applies to.
5597 * @return PRLVersion or null if error.
5598 */
5599 @Override
5600 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005601 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005602 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005603
5604 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005605 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005606 if (phone == null) {
5607 return null;
5608 }
5609 String cdmaPrlVersion = null;
5610 try {
5611 cdmaPrlVersion = phone.getCdmaPrlVersion();
5612 } catch (Exception e) {
5613 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5614 }
5615 return cdmaPrlVersion;
5616 } finally {
5617 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005618 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005619 }
5620
5621 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005622 * Get snapshot of Telephony histograms
5623 * @return List of Telephony histograms
5624 * @hide
5625 */
5626 @Override
5627 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5629 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005630
5631 final long identity = Binder.clearCallingIdentity();
5632 try {
5633 return RIL.getTelephonyRILTimingHistograms();
5634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005637 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005638
5639 /**
5640 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005641 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5642 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005643 * Require system privileges. In the future we may add this to carrier APIs.
5644 *
Michele Berionne0963c862018-11-27 18:57:59 -08005645 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005646 */
5647 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005648 @TelephonyManager.SetCarrierRestrictionResult
5649 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005650 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005651 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005652
Michele Berionne0963c862018-11-27 18:57:59 -08005653 if (carrierRestrictionRules == null) {
5654 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005655 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005656
Malcolm Chend965c8b2018-02-28 15:00:40 -08005657 final long identity = Binder.clearCallingIdentity();
5658 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005659 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005660 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005661 } finally {
5662 Binder.restoreCallingIdentity(identity);
5663 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005664 }
5665
5666 /**
5667 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005668 * Get the allowed carrier list and the excluded carrier list, including the priority between
5669 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005670 * Require system privileges. In the future we may add this to carrier APIs.
5671 *
Michele Berionne0963c862018-11-27 18:57:59 -08005672 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005673 */
5674 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005675 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005676 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005677 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005678
5679 final long identity = Binder.clearCallingIdentity();
5680 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005681 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5682 if (response instanceof CarrierRestrictionRules) {
5683 return (CarrierRestrictionRules) response;
5684 }
5685 // Response is an Exception of some kind,
5686 // which is signalled to the user as a NULL retval
5687 return null;
5688 } catch (Exception e) {
5689 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5690 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005694 }
5695
fionaxu59545b42016-05-25 15:53:37 -07005696 /**
5697 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5698 * @param subId the subscription ID that this action applies to.
5699 * @param enabled control enable or disable metered apns.
5700 * {@hide}
5701 */
5702 @Override
5703 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5704 enforceModifyPermission();
5705 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005706
5707 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005708 if (phone == null) {
5709 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5710 return;
5711 }
5712 try {
5713 phone.carrierActionSetMeteredApnsEnabled(enabled);
5714 } catch (Exception e) {
5715 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005716 } finally {
5717 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005718 }
5719 }
5720
5721 /**
5722 * Action set from carrier signalling broadcast receivers to enable/disable radio
5723 * @param subId the subscription ID that this action applies to.
5724 * @param enabled control enable or disable radio.
5725 * {@hide}
5726 */
5727 @Override
5728 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5729 enforceModifyPermission();
5730 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005731
5732 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005733 if (phone == null) {
5734 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5735 return;
5736 }
5737 try {
5738 phone.carrierActionSetRadioEnabled(enabled);
5739 } catch (Exception e) {
5740 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005741 } finally {
5742 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005743 }
5744 }
5745
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005746 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005747 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5748 * network status based on which carrier apps could apply actions accordingly,
5749 * enable/disable default url handler for example.
5750 *
5751 * @param subId the subscription ID that this action applies to.
5752 * @param report control start/stop reporting the default network status.
5753 * {@hide}
5754 */
5755 @Override
5756 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5757 enforceModifyPermission();
5758 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005759
5760 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005761 if (phone == null) {
5762 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5763 return;
5764 }
5765 try {
5766 phone.carrierActionReportDefaultNetworkStatus(report);
5767 } catch (Exception e) {
5768 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005769 } finally {
5770 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005771 }
5772 }
5773
5774 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005775 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5776 * bug report is being generated.
5777 */
5778 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005779 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005780 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5781 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005782 writer.println("Permission Denial: can't dump Phone from pid="
5783 + Binder.getCallingPid()
5784 + ", uid=" + Binder.getCallingUid()
5785 + "without permission "
5786 + android.Manifest.permission.DUMP);
5787 return;
5788 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005789 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005790 }
Jack Yueb89b242016-06-22 13:27:47 -07005791
Brad Ebingerdac2f002018-04-03 15:17:52 -07005792 @Override
5793 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5794 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5795 throws RemoteException {
5796 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5797 }
5798
Jack Yueb89b242016-06-22 13:27:47 -07005799 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005800 * Get aggregated video call data usage since boot.
5801 *
5802 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5803 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005804 * {@hide}
5805 */
5806 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005807 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005808 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5809 null);
5810
Malcolm Chend965c8b2018-02-28 15:00:40 -08005811 final long identity = Binder.clearCallingIdentity();
5812 try {
5813 // NetworkStatsService keeps tracking the active network interface and identity. It
5814 // records the delta with the corresponding network identity.
5815 // We just return the total video call data usage snapshot since boot.
5816 Phone phone = getPhone(subId);
5817 if (phone != null) {
5818 return phone.getVtDataUsage(perUidStats);
5819 }
5820 return null;
5821 } finally {
5822 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005823 }
Jack Yueb89b242016-06-22 13:27:47 -07005824 }
Jack Yu75ab2952016-07-08 14:29:33 -07005825
5826 /**
5827 * Policy control of data connection. Usually used when data limit is passed.
5828 * @param enabled True if enabling the data, otherwise disabling.
5829 * @param subId Subscription index
5830 * {@hide}
5831 */
5832 @Override
5833 public void setPolicyDataEnabled(boolean enabled, int subId) {
5834 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005835
5836 final long identity = Binder.clearCallingIdentity();
5837 try {
5838 Phone phone = getPhone(subId);
5839 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005840 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005841 }
5842 } finally {
5843 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005844 }
5845 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005846
5847 /**
5848 * Get Client request stats
5849 * @return List of Client Request Stats
5850 * @hide
5851 */
5852 @Override
5853 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005854 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005855 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005856 return null;
5857 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005858 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005859
Malcolm Chend965c8b2018-02-28 15:00:40 -08005860 final long identity = Binder.clearCallingIdentity();
5861 try {
5862 if (phone != null) {
5863 return phone.getClientRequestStats();
5864 }
5865
5866 return null;
5867 } finally {
5868 Binder.restoreCallingIdentity(identity);
5869 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005870 }
5871
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005872 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005873 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005874 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005875 }
Jack Yueb4124c2017-02-16 15:32:43 -08005876
5877 /**
Grace Chen70990072017-03-24 17:21:30 -07005878 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005879 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005880 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005881 * @param state State of SIM (power down, power up, pass through)
5882 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5883 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5884 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005885 *
5886 **/
5887 @Override
Grace Chen70990072017-03-24 17:21:30 -07005888 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005889 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005890 Phone phone = PhoneFactory.getPhone(slotIndex);
5891
vagdevie435a3e2018-08-15 16:01:53 -07005892 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5893
Malcolm Chend965c8b2018-02-28 15:00:40 -08005894 final long identity = Binder.clearCallingIdentity();
5895 try {
5896 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005897 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005898 }
5899 } finally {
5900 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005901 }
5902 }
Shuo Qiandd210312017-04-12 22:11:33 +00005903
Tyler Gunn65d45c22017-06-05 11:22:26 -07005904 private boolean isUssdApiAllowed(int subId) {
5905 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005906 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005907 if (configManager == null) {
5908 return false;
5909 }
5910 PersistableBundle pb = configManager.getConfigForSubId(subId);
5911 if (pb == null) {
5912 return false;
5913 }
5914 return pb.getBoolean(
5915 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5916 }
5917
Shuo Qiandd210312017-04-12 22:11:33 +00005918 /**
5919 * Check if phone is in emergency callback mode
5920 * @return true if phone is in emergency callback mode
5921 * @param subId sub id
5922 */
goneil9c5f4872017-12-05 14:07:56 -08005923 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005924 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005925 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005926 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005927
5928 final long identity = Binder.clearCallingIdentity();
5929 try {
5930 if (phone != null) {
5931 return phone.isInEcm();
5932 } else {
5933 return false;
5934 }
5935 } finally {
5936 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005937 }
5938 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005939
5940 /**
5941 * Get the current signal strength information for the given subscription.
5942 * Because this information is not updated when the device is in a low power state
5943 * it should not be relied-upon to be current.
5944 * @param subId Subscription index
5945 * @return the most recent cached signal strength info from the modem
5946 */
5947 @Override
5948 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005949 final long identity = Binder.clearCallingIdentity();
5950 try {
5951 Phone p = getPhone(subId);
5952 if (p == null) {
5953 return null;
5954 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005955
Malcolm Chend965c8b2018-02-28 15:00:40 -08005956 return p.getSignalStrength();
5957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005960 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005961
Pengquan Meng9140aec2018-08-22 14:49:57 -07005962 /**
chen xu907e5a22018-10-11 13:21:04 -07005963 * Get the current modem radio state for the given slot.
5964 * @param slotIndex slot index.
5965 * @param callingPackage the name of the package making the call.
5966 * @return the current radio power state from the modem
5967 */
5968 @Override
5969 public int getRadioPowerState(int slotIndex, String callingPackage) {
5970 Phone phone = PhoneFactory.getPhone(slotIndex);
5971 if (phone != null) {
5972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5973 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5974 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5975 }
5976
5977 final long identity = Binder.clearCallingIdentity();
5978 try {
5979 return phone.getRadioPowerState();
5980 } finally {
5981 Binder.restoreCallingIdentity(identity);
5982 }
5983 }
5984 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5985 }
5986
5987 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005988 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5989 *
5990 * <p>Requires one of the following permissions:
5991 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5992 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5993 * privileges.
5994 *
5995 * @param subId subscription id
5996 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5997 * {@code false}.
5998 */
5999 @Override
6000 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006001 boolean isEnabled = false;
6002 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006003 try {
6004 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07006005 null /* message */);
6006 Phone phone = getPhone(subId);
6007 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006008 } catch (Exception e) {
6009 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6010 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006011 } finally {
6012 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006013 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006014 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006015 }
6016
6017
6018 /**
6019 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6020 *
6021 * <p> Requires permission:
6022 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6023 * privileges.
6024 *
6025 * @param subId subscription id
6026 * @param isEnabled {@code true} means enable, {@code false} means disable.
6027 */
6028 @Override
6029 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006030 final long identity = Binder.clearCallingIdentity();
6031 try {
6032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6033 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07006034
Pengquan Meng0c05b502018-09-06 09:59:22 -07006035 Phone phone = getPhone(subId);
6036 if (phone != null) {
6037 phone.setDataRoamingEnabled(isEnabled);
6038 }
6039 } finally {
6040 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006041 }
6042 }
6043
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006044 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006045 public boolean isManualNetworkSelectionAllowed(int subId) {
6046 boolean isAllowed = true;
6047 final long identity = Binder.clearCallingIdentity();
6048 try {
6049 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6050 mApp, subId, "isManualNetworkSelectionAllowed");
6051 Phone phone = getPhone(subId);
6052 if (phone != null) {
6053 isAllowed = phone.isCspPlmnEnabled();
6054 }
6055 } finally {
6056 Binder.restoreCallingIdentity(identity);
6057 }
6058 return isAllowed;
6059 }
6060
6061 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006062 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006063 try {
6064 enforceReadPrivilegedPermission("getUiccCardsInfo");
6065 } catch (SecurityException e) {
6066 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6067 // has carrier privileges on an active UICC
6068 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6069 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6070 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6071 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006072 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006073
6074 final long identity = Binder.clearCallingIdentity();
6075 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006076 UiccController uiccController = UiccController.getInstance();
6077 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6078
6079 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6080 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6081 // Remove private info if the caller doesn't have access
6082 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6083 for (UiccCardInfo cardInfo : cardInfos) {
6084 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6085 UiccProfile profile = card.getUiccProfile();
6086 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6087 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6088 filteredInfos.add(cardInfo.getUnprivileged());
6089 } else {
6090 filteredInfos.add(cardInfo);
6091 }
6092 }
6093 return filteredInfos;
6094 }
6095 return cardInfos;
6096 } catch (PackageManager.NameNotFoundException e) {
6097 // This should not happen since we pass the package info in from TelephonyManager
6098 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
6102 }
6103
6104 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006105 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006106 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006107
Malcolm Chend965c8b2018-02-28 15:00:40 -08006108 final long identity = Binder.clearCallingIdentity();
6109 try {
6110 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6111 if (slots == null) {
6112 Rlog.i(LOG_TAG, "slots is null.");
6113 return null;
6114 }
6115
6116 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6117 for (int i = 0; i < slots.length; i++) {
6118 UiccSlot slot = slots[i];
6119 if (slot == null) {
6120 continue;
6121 }
6122
6123 String cardId;
6124 UiccCard card = slot.getUiccCard();
6125 if (card != null) {
6126 cardId = card.getCardId();
6127 } else {
6128 cardId = slot.getIccId();
6129 }
6130
6131 int cardState = 0;
6132 switch (slot.getCardState()) {
6133 case CARDSTATE_ABSENT:
6134 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6135 break;
6136 case CARDSTATE_PRESENT:
6137 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6138 break;
6139 case CARDSTATE_ERROR:
6140 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6141 break;
6142 case CARDSTATE_RESTRICTED:
6143 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6144 break;
6145 default:
6146 break;
6147
6148 }
6149
6150 infos[i] = new UiccSlotInfo(
6151 slot.isActive(),
6152 slot.isEuicc(),
6153 cardId,
6154 cardState,
6155 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006156 slot.isExtendedApduSupported(),
6157 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006158 }
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 /**
6614 * Get how many sims have been activated on the phone
6615 */
6616 @Override
6617 public int getNumOfActiveSims() {
6618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 return mPhoneConfigurationManager.getNumOfActiveSims();
6621 } finally {
6622 Binder.restoreCallingIdentity(identity);
6623 }
6624 }
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006625
6626 /**
6627 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006628 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006629 */
6630 @Override
6631 public boolean isRebootRequiredForModemConfigChange() {
6632 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
6638 }
6639 }
6640
Pengquan Meng92d253b2019-02-06 11:12:53 -08006641 private void updateModemStateMetrics() {
6642 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6643 // TODO: check the state for each modem if the api is ready.
6644 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6645 }
6646
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006647 @Override
6648 public int[] getSlotsMapping() {
6649 enforceReadPrivilegedPermission("getSlotsMapping");
6650
6651 final long identity = Binder.clearCallingIdentity();
6652 try {
6653 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6654 // All logical slots should have a mapping to a physical slot.
6655 int[] logicalSlotsMapping = new int[phoneCount];
6656 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6657 for (int i = 0; i < slotInfos.length; i++) {
6658 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6659 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6660 }
6661 }
6662 return logicalSlotsMapping;
6663 } finally {
6664 Binder.restoreCallingIdentity(identity);
6665 }
6666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006667}