blob: b16a75bbe405d2d7b09e11179e94109e55dcdb2a [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;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070055import android.service.carrier.CarrierIdentifier;
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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
87import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070089import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080090import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070091import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080092import android.telephony.ims.aidl.IImsMmTelFeature;
93import android.telephony.ims.aidl.IImsRcsFeature;
94import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070095import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080096import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800100import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800102
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700104import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800105import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700107import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700108import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800109import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800113import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800115import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700116import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100117import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700118import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700121import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800122import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700123import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700124import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700125import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700126import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700127import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700129import com.android.internal.telephony.SmsApplication;
130import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800131import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800132import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700133import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700134import com.android.internal.telephony.uicc.IccIoResult;
135import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800136import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700137import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800138import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800140import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000141import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700142import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800143import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700144import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800145import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700146import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700147import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800148
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700149import java.io.FileDescriptor;
150import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800151import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800153import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700154import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800155import java.util.HashMap;
Jake Hambye994d462014-02-03 13:10:13 -0800156import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100157import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159
160/**
161 * Implementation of the ITelephony interface.
162 */
Santos Cordon117fee72014-05-16 17:56:12 -0700163public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 private static final String LOG_TAG = "PhoneInterfaceManager";
165 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
166 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168
169 // Message codes used with mMainThreadHandler
170 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700171 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
172 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173 private static final int CMD_OPEN_CHANNEL = 9;
174 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
175 private static final int CMD_CLOSE_CHANNEL = 11;
176 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800177 private static final int CMD_NV_READ_ITEM = 13;
178 private static final int EVENT_NV_READ_ITEM_DONE = 14;
179 private static final int CMD_NV_WRITE_ITEM = 15;
180 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
181 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
182 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700183 private static final int CMD_RESET_MODEM_CONFIG = 19;
184 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800185 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
186 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
187 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
188 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800189 private static final int CMD_SEND_ENVELOPE = 25;
190 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000191 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
192 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700193 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
194 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
195 private static final int CMD_EXCHANGE_SIM_IO = 31;
196 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800197 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
198 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700199 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
200 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700201 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
202 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700203 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
204 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
205 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
206 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700207 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
208 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
209 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
210 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700211 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800212 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
213 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000214 private static final int CMD_SWITCH_SLOTS = 50;
215 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700216 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
217 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
218 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
219 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
220 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
221 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
222 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
223 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700224 private static final int CMD_GET_ALL_CELL_INFO = 60;
225 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
226 private static final int CMD_GET_CELL_LOCATION = 62;
227 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700228 private static final int CMD_MODEM_REBOOT = 64;
229 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700230 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
231 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800233 // Parameters of select command.
234 private static final int SELECT_COMMAND = 0xA4;
235 private static final int SELECT_P1 = 0x04;
236 private static final int SELECT_P2 = 0;
237 private static final int SELECT_P3 = 0x10;
238
Pengquan Meng85728fb2018-03-12 16:31:21 -0700239 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
240 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
241 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
242
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 /** The singleton instance. */
244 private static PhoneInterfaceManager sInstance;
245
Wink Saville3ab207e2014-11-20 13:07:20 -0800246 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800247 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700248 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800249 private AppOpsManager mAppOps;
250 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800251 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800252 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700253 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
Derek Tan97ebb422014-09-05 16:55:38 -0700255 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
256 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700258
Derek Tan740e1672017-06-27 14:56:27 -0700259 // The AID of ISD-R.
260 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
261
yinxub1bed742017-04-17 11:45:04 -0700262 private NetworkScanRequestTracker mNetworkScanRequestTracker;
263
David Kelly5e06a7f2018-03-12 14:10:59 +0000264 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
265 private static final int MANUFACTURER_CODE_LENGTH = 8;
266
Derek Tan89e89d42014-07-08 17:00:10 -0700267 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700268 * A request object to use for transmitting data to an ICC.
269 */
270 private static final class IccAPDUArgument {
271 public int channel, cla, command, p1, p2, p3;
272 public String data;
273
274 public IccAPDUArgument(int channel, int cla, int command,
275 int p1, int p2, int p3, String data) {
276 this.channel = channel;
277 this.cla = cla;
278 this.command = command;
279 this.p1 = p1;
280 this.p2 = p2;
281 this.p3 = p3;
282 this.data = data;
283 }
284 }
285
286 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700287 * A request object to use for transmitting data to an ICC.
288 */
289 private static final class ManualNetworkSelectionArgument {
290 public OperatorInfo operatorInfo;
291 public boolean persistSelection;
292
293 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
294 this.operatorInfo = operatorInfo;
295 this.persistSelection = persistSelection;
296 }
297 }
298
299 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
301 * request after sending. The main thread will notify the request when it is complete.
302 */
303 private static final class MainThreadRequest {
304 /** The argument to use for the request */
305 public Object argument;
306 /** The result of the request that is run on the main thread */
307 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800308 // The subscriber id that this request applies to. Defaults to
309 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
310 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Nathan Harold92bed182018-10-12 18:16:49 -0700312 // In cases where subId is unavailable, the caller needs to specify the phone.
313 public Phone phone;
314
vagdeviaf9a5b92018-08-15 16:01:53 -0700315 public WorkSource workSource;
316
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317 public MainThreadRequest(Object argument) {
318 this.argument = argument;
319 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800320
Nathan Harold92bed182018-10-12 18:16:49 -0700321 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
322 this.argument = argument;
323 if (phone != null) {
324 this.phone = phone;
325 }
326 this.workSource = workSource;
327 }
328
vagdeviaf9a5b92018-08-15 16:01:53 -0700329 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800330 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800331 if (subId != null) {
332 this.subId = subId;
333 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700334 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 }
337
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800338 private static final class IncomingThirdPartyCallArgs {
339 public final ComponentName component;
340 public final String callId;
341 public final String callerDisplayName;
342
343 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
344 String callerDisplayName) {
345 this.component = component;
346 this.callId = callId;
347 this.callerDisplayName = callerDisplayName;
348 }
349 }
350
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 /**
352 * A handler that processes messages on the main thread in the phone process. Since many
353 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
354 * inbound binder threads to the main thread in the phone process. The Binder thread
355 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
356 * on, which will be notified when the operation completes and will contain the result of the
357 * request.
358 *
359 * <p>If a MainThreadRequest object is provided in the msg.obj field,
360 * note that request.result must be set to something non-null for the calling thread to
361 * unblock.
362 */
363 private final class MainThreadHandler extends Handler {
364 @Override
365 public void handleMessage(Message msg) {
366 MainThreadRequest request;
367 Message onCompleted;
368 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800369 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700370 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800371 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
373 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700374 case CMD_HANDLE_USSD_REQUEST: {
375 request = (MainThreadRequest) msg.obj;
376 final Phone phone = getPhoneFromRequest(request);
377 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
378 String ussdRequest = ussdObject.first;
379 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700380
Pengquan Menga1bb6272018-09-06 09:59:22 -0700381 if (!isUssdApiAllowed(request.subId)) {
382 // Carrier does not support use of this API, return failure.
383 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
384 UssdResponse response = new UssdResponse(ussdRequest, null);
385 Bundle returnData = new Bundle();
386 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
387 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700388
Pengquan Menga1bb6272018-09-06 09:59:22 -0700389 request.result = true;
390 notifyRequester(request);
391 return;
392 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700393
Pengquan Menga1bb6272018-09-06 09:59:22 -0700394 try {
395 request.result = phone != null
396 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
397 } catch (CallStateException cse) {
398 request.result = false;
399 }
400 // Wake up the requesting thread
401 notifyRequester(request);
402 break;
pkanwar32d516d2016-10-14 19:37:38 -0700403 }
404
Yorke Lee716f67e2015-06-17 15:39:16 -0700405 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700407 final Phone phone = getPhoneFromRequest(request);
408 request.result = phone != null ?
409 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
410 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700412 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800419 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700420 if (uiccCard == null) {
421 loge("iccTransmitApduLogicalChannel: No UICC");
422 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700424 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
426 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 iccArgument.channel, iccArgument.cla, iccArgument.command,
429 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 break;
433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 ar = (AsyncResult) msg.obj;
436 request = (MainThreadRequest) ar.userObj;
437 if (ar.exception == null && ar.result != null) {
438 request.result = ar.result;
439 } else {
440 request.result = new IccIoResult(0x6F, 0, (byte[])null);
441 if (ar.result == null) {
442 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800443 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800445 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 } else {
447 loge("iccTransmitApduLogicalChannel: Unknown exception");
448 }
449 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700450 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 break;
452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
454 request = (MainThreadRequest) msg.obj;
455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduBasicChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 } else {
462 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
463 request);
464 uiccCard.iccTransmitApduBasicChannel(
465 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
466 iccArgument.p3, iccArgument.data, onCompleted);
467 }
468 break;
469
470 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
471 ar = (AsyncResult) msg.obj;
472 request = (MainThreadRequest) ar.userObj;
473 if (ar.exception == null && ar.result != null) {
474 request.result = ar.result;
475 } else {
476 request.result = new IccIoResult(0x6F, 0, (byte[])null);
477 if (ar.result == null) {
478 loge("iccTransmitApduBasicChannel: Empty response");
479 } else if (ar.exception instanceof CommandException) {
480 loge("iccTransmitApduBasicChannel: CommandException: " +
481 ar.exception);
482 } else {
483 loge("iccTransmitApduBasicChannel: Unknown exception");
484 }
485 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 break;
488
489 case CMD_EXCHANGE_SIM_IO:
490 request = (MainThreadRequest) msg.obj;
491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 if (uiccCard == null) {
494 loge("iccExchangeSimIO: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 } else {
498 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
499 request);
500 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
501 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
502 iccArgument.data, onCompleted);
503 }
504 break;
505
506 case EVENT_EXCHANGE_SIM_IO_DONE:
507 ar = (AsyncResult) msg.obj;
508 request = (MainThreadRequest) ar.userObj;
509 if (ar.exception == null && ar.result != null) {
510 request.result = ar.result;
511 } else {
512 request.result = new IccIoResult(0x6f, 0, (byte[])null);
513 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 break;
516
Derek Tan4d5e5c12014-02-04 11:54:58 -0800517 case CMD_SEND_ENVELOPE:
518 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800519 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700520 if (uiccCard == null) {
521 loge("sendEnvelopeWithStatus: No UICC");
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700524 } else {
525 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
526 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
527 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800528 break;
529
530 case EVENT_SEND_ENVELOPE_DONE:
531 ar = (AsyncResult) msg.obj;
532 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700533 if (ar.exception == null && ar.result != null) {
534 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
537 if (ar.result == null) {
538 loge("sendEnvelopeWithStatus: Empty response");
539 } else if (ar.exception instanceof CommandException) {
540 loge("sendEnvelopeWithStatus: CommandException: " +
541 ar.exception);
542 } else {
543 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
544 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 break;
548
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 case CMD_OPEN_CHANNEL:
550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800552 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800555 request.result = new IccOpenLogicalChannelResponse(-1,
556 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 } else {
559 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800560 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
561 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 break;
564
565 case EVENT_OPEN_CHANNEL_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 int[] result = (int[]) ar.result;
571 int channelId = result[0];
572 byte[] selectResponse = null;
573 if (result.length > 1) {
574 selectResponse = new byte[result.length - 1];
575 for (int i = 1; i < result.length; ++i) {
576 selectResponse[i - 1] = (byte) result[i];
577 }
578 }
579 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700580 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 if (ar.result == null) {
583 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 if (ar.exception != null) {
586 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
587 }
588
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700589 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700590 if (ar.exception instanceof CommandException) {
591 CommandException.Error error =
592 ((CommandException) (ar.exception)).getCommandError();
593 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700595 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 }
598 }
599 openChannelResp = new IccOpenLogicalChannelResponse(
600 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700602 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 break;
605
606 case CMD_CLOSE_CHANNEL:
607 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800608 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700609 if (uiccCard == null) {
610 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900611 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700613 } else {
614 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
615 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
616 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 break;
618
619 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800620 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
621 break;
622
623 case CMD_NV_READ_ITEM:
624 request = (MainThreadRequest) msg.obj;
625 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800626 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
627 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800628 break;
629
630 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800636 request.result = "";
637 if (ar.result == null) {
638 loge("nvReadItem: Empty response");
639 } else if (ar.exception instanceof CommandException) {
640 loge("nvReadItem: CommandException: " +
641 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800643 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
Jake Hambye994d462014-02-03 13:10:13 -0800649 case CMD_NV_WRITE_ITEM:
650 request = (MainThreadRequest) msg.obj;
651 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
652 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800653 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700654 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800655 break;
656
657 case EVENT_NV_WRITE_ITEM_DONE:
658 handleNullReturnEvent(msg, "nvWriteItem");
659 break;
660
661 case CMD_NV_WRITE_CDMA_PRL:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800664 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800665 break;
666
667 case EVENT_NV_WRITE_CDMA_PRL_DONE:
668 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
669 break;
670
chen xu6dac5ab2018-10-26 17:39:23 -0700671 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800672 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700673 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800674 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800675 break;
676
chen xu6dac5ab2018-10-26 17:39:23 -0700677 case EVENT_RESET_MODEM_CONFIG_DONE:
678 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800679 break;
680
Jake Hamby7c27be32014-03-03 13:25:59 -0800681 case CMD_GET_PREFERRED_NETWORK_TYPE:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700684 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800685 break;
686
687 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
688 ar = (AsyncResult) msg.obj;
689 request = (MainThreadRequest) ar.userObj;
690 if (ar.exception == null && ar.result != null) {
691 request.result = ar.result; // Integer
692 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800693 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800694 if (ar.result == null) {
695 loge("getPreferredNetworkType: Empty response");
696 } else if (ar.exception instanceof CommandException) {
697 loge("getPreferredNetworkType: CommandException: " +
698 ar.exception);
699 } else {
700 loge("getPreferredNetworkType: Unknown exception");
701 }
702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case CMD_SET_PREFERRED_NETWORK_TYPE:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
709 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700710 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 break;
712
713 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
714 handleNullReturnEvent(msg, "setPreferredNetworkType");
715 break;
716
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000717 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
718 request = (MainThreadRequest)msg.obj;
719 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800720 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000721 break;
722
723 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
724 ar = (AsyncResult)msg.obj;
725 request = (MainThreadRequest)ar.userObj;
726 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000728 break;
729
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800730 case CMD_SET_VOICEMAIL_NUMBER:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
733 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800734 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
735 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800736 break;
737
738 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
739 handleNullReturnEvent(msg, "setVoicemailNumber");
740 break;
741
Stuart Scott54788802015-03-30 13:18:01 -0700742 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
745 request);
746 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
747 break;
748
749 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
750 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
751 break;
752
Shishir Agrawal302c8692015-06-19 13:49:39 -0700753 case CMD_PERFORM_NETWORK_SCAN:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
756 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
757 break;
758
759 case EVENT_PERFORM_NETWORK_SCAN_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
762 CellNetworkScanResult cellScanResult;
763 if (ar.exception == null && ar.result != null) {
764 cellScanResult = new CellNetworkScanResult(
765 CellNetworkScanResult.STATUS_SUCCESS,
766 (List<OperatorInfo>) ar.result);
767 } else {
768 if (ar.result == null) {
769 loge("getCellNetworkScanResults: Empty response");
770 }
771 if (ar.exception != null) {
772 loge("getCellNetworkScanResults: Exception: " + ar.exception);
773 }
774 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
775 if (ar.exception instanceof CommandException) {
776 CommandException.Error error =
777 ((CommandException) (ar.exception)).getCommandError();
778 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
779 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
780 } else if (error == CommandException.Error.GENERIC_FAILURE) {
781 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
782 }
783 }
784 cellScanResult = new CellNetworkScanResult(errorCode, null);
785 }
786 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700787 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700788 break;
789
790 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
791 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700792 ManualNetworkSelectionArgument selArg =
793 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
795 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700796 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
797 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 break;
799
800 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700801 ar = (AsyncResult) msg.obj;
802 request = (MainThreadRequest) ar.userObj;
803 if (ar.exception == null) {
804 request.result = true;
805 } else {
806 request.result = false;
807 loge("setNetworkSelectionModeManual " + ar.exception);
808 }
809 notifyRequester(request);
810 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700811 break;
812
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700813 case CMD_GET_MODEM_ACTIVITY_INFO:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800816 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700817 break;
818
819 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null && ar.result != null) {
823 request.result = ar.result;
824 } else {
825 if (ar.result == null) {
826 loge("queryModemActivityInfo: Empty response");
827 } else if (ar.exception instanceof CommandException) {
828 loge("queryModemActivityInfo: CommandException: " +
829 ar.exception);
830 } else {
831 loge("queryModemActivityInfo: Unknown exception");
832 }
833 }
Amit Mahajand4766222016-01-28 15:28:28 -0800834 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
835 if (request.result == null) {
836 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
837 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700838 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 break;
840
Meng Wang1a7c35a2016-05-05 20:56:15 -0700841 case CMD_SET_ALLOWED_CARRIERS:
842 request = (MainThreadRequest) msg.obj;
843 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800844 defaultPhone.setAllowedCarriers(
Meng Wang1a7c35a2016-05-05 20:56:15 -0700845 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700846 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 break;
848
849 case EVENT_SET_ALLOWED_CARRIERS_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result;
854 } else {
855 if (ar.result == null) {
856 loge("setAllowedCarriers: Empty response");
857 } else if (ar.exception instanceof CommandException) {
858 loge("setAllowedCarriers: CommandException: " +
859 ar.exception);
860 } else {
861 loge("setAllowedCarriers: Unknown exception");
862 }
863 }
864 // Result cannot be null. Return -1 on error.
865 if (request.result == null) {
866 request.result = new int[]{-1};
867 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700868 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 break;
870
871 case CMD_GET_ALLOWED_CARRIERS:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800874 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 break;
876
877 case EVENT_GET_ALLOWED_CARRIERS_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result;
882 } else {
883 if (ar.result == null) {
884 loge("getAllowedCarriers: Empty response");
885 } else if (ar.exception instanceof CommandException) {
886 loge("getAllowedCarriers: CommandException: " +
887 ar.exception);
888 } else {
889 loge("getAllowedCarriers: Unknown exception");
890 }
891 }
892 // Result cannot be null. Return empty list of CarrierIdentifier.
893 if (request.result == null) {
894 request.result = new ArrayList<CarrierIdentifier>(0);
895 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700896 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 break;
898
Nathan Haroldb3014052017-01-25 15:57:32 -0800899 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
900 ar = (AsyncResult) msg.obj;
901 request = (MainThreadRequest) ar.userObj;
902 if (ar.exception == null && ar.result != null) {
903 request.result = ar.result;
904 } else {
905 request.result = new IllegalArgumentException(
906 "Failed to retrieve Forbidden Plmns");
907 if (ar.result == null) {
908 loge("getForbiddenPlmns: Empty response");
909 } else {
910 loge("getForbiddenPlmns: Unknown exception");
911 }
912 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700913 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800914 break;
915
916 case CMD_GET_FORBIDDEN_PLMNS:
917 request = (MainThreadRequest) msg.obj;
918 uiccCard = getUiccCardFromRequest(request);
919 if (uiccCard == null) {
920 loge("getForbiddenPlmns() UiccCard is null");
921 request.result = new IllegalArgumentException(
922 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700923 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800924 break;
925 }
926 Integer appType = (Integer) request.argument;
927 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
928 if (uiccApp == null) {
929 loge("getForbiddenPlmns() no app with specified type -- "
930 + appType);
931 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700932 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800933 break;
934 } else {
935 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
936 + " specified type -- " + appType);
937 }
938 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
939 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
940 onCompleted);
941 break;
942
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000943 case CMD_SWITCH_SLOTS:
944 request = (MainThreadRequest) msg.obj;
945 int[] physicalSlots = (int[]) request.argument;
946 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
947 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
948 break;
949
950 case EVENT_SWITCH_SLOTS_DONE:
951 ar = (AsyncResult) msg.obj;
952 request = (MainThreadRequest) ar.userObj;
953 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700954 notifyRequester(request);
955 break;
956 case CMD_GET_NETWORK_SELECTION_MODE:
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
959 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
960 break;
961
962 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception != null) {
966 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
967 } else {
968 int mode = ((int[]) ar.result)[0];
969 if (mode == 0) {
970 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
971 } else {
972 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
973 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000974 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700975 notifyRequester(request);
976 break;
977 case CMD_GET_CDMA_ROAMING_MODE:
978 request = (MainThreadRequest) msg.obj;
979 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
980 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
981 break;
982 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 if (ar.exception != null) {
986 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
987 } else {
988 request.result = ((int[]) ar.result)[0];
989 }
990 notifyRequester(request);
991 break;
992 case CMD_SET_CDMA_ROAMING_MODE:
993 request = (MainThreadRequest) msg.obj;
994 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
995 int mode = (int) request.argument;
996 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
997 break;
998 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 request.result = ar.exception == null;
1002 notifyRequester(request);
1003 break;
1004 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1007 int subscriptionMode = (int) request.argument;
1008 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1009 break;
1010 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 request.result = ar.exception == null;
1014 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001015 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001016 case CMD_GET_ALL_CELL_INFO:
1017 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001019 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001020 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001021 case EVENT_GET_ALL_CELL_INFO_DONE:
1022 ar = (AsyncResult) msg.obj;
1023 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001024 // If a timeout occurs, the response will be null
1025 request.result = (ar.exception == null && ar.result != null)
1026 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001027 synchronized (request) {
1028 request.notifyAll();
1029 }
1030 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001031 case CMD_REQUEST_CELL_INFO_UPDATE:
1032 request = (MainThreadRequest) msg.obj;
1033 request.phone.requestCellInfoUpdate(request.workSource,
1034 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1035 break;
1036 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1040 try {
1041 if (ar.exception != null) {
1042 // something went wrong... the response is null
1043 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1044 cb.onCellInfo(null);
1045 } else if (ar.result == null) {
1046 // timeout occurred, so force the result to non-null "empty"
1047 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1048 cb.onCellInfo(new ArrayList<CellInfo>());
1049 } else {
1050 // use the result as returned
1051 cb.onCellInfo((List<CellInfo>) ar.result);
1052 }
1053 } catch (RemoteException re) {
1054 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1055 }
1056 break;
1057 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 request = (MainThreadRequest) msg.obj;
1059 WorkSource ws = (WorkSource) request.argument;
1060 Phone phone = getPhoneFromRequest(request);
1061 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1062 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001063 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
1066 if (ar.exception == null) {
1067 request.result = ar.result;
1068 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001069 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001070 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1071 ? new CdmaCellLocation() : new GsmCellLocation();
1072 }
1073
1074 synchronized (request) {
1075 request.notifyAll();
1076 }
1077 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001078 case CMD_MODEM_REBOOT:
1079 request = (MainThreadRequest) msg.obj;
1080 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001081 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001082 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001083 case EVENT_CMD_MODEM_REBOOT_DONE:
1084 handleNullReturnEvent(msg, "rebootModem");
1085 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001086 default:
1087 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1088 break;
1089 }
1090 }
Jake Hambye994d462014-02-03 13:10:13 -08001091
Pengquan Menga1bb6272018-09-06 09:59:22 -07001092 private void notifyRequester(MainThreadRequest request) {
1093 synchronized (request) {
1094 request.notifyAll();
1095 }
1096 }
1097
Jake Hambye994d462014-02-03 13:10:13 -08001098 private void handleNullReturnEvent(Message msg, String command) {
1099 AsyncResult ar = (AsyncResult) msg.obj;
1100 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1101 if (ar.exception == null) {
1102 request.result = true;
1103 } else {
1104 request.result = false;
1105 if (ar.exception instanceof CommandException) {
1106 loge(command + ": CommandException: " + ar.exception);
1107 } else {
1108 loge(command + ": Unknown exception");
1109 }
1110 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001111 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001113 }
1114
1115 /**
1116 * Posts the specified command to be executed on the main thread,
1117 * waits for the request to complete, and returns the result.
1118 * @see #sendRequestAsync
1119 */
1120 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001121 return sendRequest(
1122 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001123 }
1124
1125 /**
1126 * Posts the specified command to be executed on the main thread,
1127 * waits for the request to complete, and returns the result.
1128 * @see #sendRequestAsync
1129 */
1130 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1131 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001132 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001133 }
1134
1135 /**
1136 * Posts the specified command to be executed on the main thread,
1137 * waits for the request to complete, and returns the result.
1138 * @see #sendRequestAsync
1139 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001140 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001141 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001142 }
1143
1144 /**
1145 * Posts the specified command to be executed on the main thread,
1146 * waits for the request to complete, and returns the result.
1147 * @see #sendRequestAsync
1148 */
Nathan Harold92bed182018-10-12 18:16:49 -07001149 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1150 return sendRequest(command, argument, subId, null, workSource);
1151 }
1152
1153 /**
1154 * Posts the specified command to be executed on the main thread,
1155 * waits for the request to complete, and returns the result.
1156 * @see #sendRequestAsync
1157 */
1158 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1159 return sendRequest(
1160 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1161 }
1162
1163 /**
1164 * Posts the specified command to be executed on the main thread,
1165 * waits for the request to complete, and returns the result.
1166 * @see #sendRequestAsync
1167 */
1168 private Object sendRequest(
1169 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001170 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1171 throw new RuntimeException("This method will deadlock if called from the main thread.");
1172 }
1173
Nathan Harold92bed182018-10-12 18:16:49 -07001174 MainThreadRequest request = null;
1175 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1176 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1177 } else if (phone != null) {
1178 request = new MainThreadRequest(argument, phone, workSource);
1179 } else {
1180 request = new MainThreadRequest(argument, subId, workSource);
1181 }
1182
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001183 Message msg = mMainThreadHandler.obtainMessage(command, request);
1184 msg.sendToTarget();
1185
1186 // Wait for the request to complete
1187 synchronized (request) {
1188 while (request.result == null) {
1189 try {
1190 request.wait();
1191 } catch (InterruptedException e) {
1192 // Do nothing, go back and wait until the request is complete
1193 }
1194 }
1195 }
1196 return request.result;
1197 }
1198
1199 /**
1200 * Asynchronous ("fire and forget") version of sendRequest():
1201 * Posts the specified command to be executed on the main thread, and
1202 * returns immediately.
1203 * @see #sendRequest
1204 */
1205 private void sendRequestAsync(int command) {
1206 mMainThreadHandler.sendEmptyMessage(command);
1207 }
1208
1209 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001210 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001211 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001212 */
1213 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001214 sendRequestAsync(command, argument, null, null);
1215 }
1216
1217 /**
1218 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1219 * @see {@link #sendRequest(int,Object)}
1220 */
1221 private void sendRequestAsync(
1222 int command, Object argument, Phone phone, WorkSource workSource) {
1223 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001224 Message msg = mMainThreadHandler.obtainMessage(command, request);
1225 msg.sendToTarget();
1226 }
1227
1228 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 * Initialize the singleton PhoneInterfaceManager instance.
1230 * This is only done once, at startup, from PhoneApp.onCreate().
1231 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001232 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 synchronized (PhoneInterfaceManager.class) {
1234 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001235 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 } else {
1237 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1238 }
1239 return sInstance;
1240 }
1241 }
1242
1243 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001244 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001247 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1249 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001250 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001251 mTelephonySharedPreferences =
1252 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001253 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001254 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001255
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001256 publish();
1257 }
1258
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001259 private Phone getDefaultPhone() {
1260 Phone thePhone = getPhone(getDefaultSubscription());
1261 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1262 }
1263
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 private void publish() {
1265 if (DBG) log("publish: " + this);
1266
1267 ServiceManager.addService("phone", this);
1268 }
1269
Stuart Scott584921c2015-01-15 17:10:34 -08001270 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001271 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001272 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001273 }
1274
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001275 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1276 Phone phone = getPhoneFromRequest(request);
1277 return phone == null ? null :
1278 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1279 }
1280
Wink Saville36469e72014-06-11 15:17:00 -07001281 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001282 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001283 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285
1286 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001287 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001288 }
1289
Wink Savilleb564aae2014-10-23 10:18:09 -07001290 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001291 if (DBG) log("dial: " + number);
1292 // No permission check needed here: This is just a wrapper around the
1293 // ACTION_DIAL intent, which is available to any app since it puts up
1294 // the UI before it does anything.
1295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001296 final long identity = Binder.clearCallingIdentity();
1297 try {
1298 String url = createTelUrl(number);
1299 if (url == null) {
1300 return;
1301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001303 // PENDING: should we just silently fail if phone is offhook or ringing?
1304 PhoneConstants.State state = mCM.getState(subId);
1305 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1306 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1307 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1308 mApp.startActivity(intent);
1309 }
1310 } finally {
1311 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 }
1313 }
1314
1315 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001316 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001317 }
1318
Wink Savilleb564aae2014-10-23 10:18:09 -07001319 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 if (DBG) log("call: " + number);
1321
1322 // This is just a wrapper around the ACTION_CALL intent, but we still
1323 // need to do a permission check since we're calling startActivity()
1324 // from the context of the phone app.
1325 enforceCallPermission();
1326
1327 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1328 != AppOpsManager.MODE_ALLOWED) {
1329 return;
1330 }
1331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001332 final long identity = Binder.clearCallingIdentity();
1333 try {
1334 String url = createTelUrl(number);
1335 if (url == null) {
1336 return;
1337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001339 boolean isValid = false;
1340 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1341 if (slist != null) {
1342 for (SubscriptionInfo subInfoRecord : slist) {
1343 if (subInfoRecord.getSubscriptionId() == subId) {
1344 isValid = true;
1345 break;
1346 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001347 }
Wink Saville08874612014-08-31 19:19:58 -07001348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001349 if (!isValid) {
1350 return;
1351 }
Wink Saville08874612014-08-31 19:19:58 -07001352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001353 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1354 intent.putExtra(SUBSCRIPTION_KEY, subId);
1355 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1356 mApp.startActivity(intent);
1357 } finally {
1358 Binder.restoreCallingIdentity(identity);
1359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 }
1361
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001363 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001364 }
1365
Wink Savilleb564aae2014-10-23 10:18:09 -07001366 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001367 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001368 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1369 }
1370
1371 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001372 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001373 }
1374
Wink Savilleb564aae2014-10-23 10:18:09 -07001375 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001376 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001377 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1378 }
1379
1380 /** {@hide} */
1381 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001382 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001383 }
1384
Wink Savilleb564aae2014-10-23 10:18:09 -07001385 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001387
1388 final long identity = Binder.clearCallingIdentity();
1389 try {
1390 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1391 checkSimPin.start();
1392 return checkSimPin.unlockSim(null, pin);
1393 } finally {
1394 Binder.restoreCallingIdentity(identity);
1395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 }
1397
Wink Saville9de0f752013-10-22 19:04:03 -07001398 /** {@hide} */
1399 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001400 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001401 }
1402
Wink Savilleb564aae2014-10-23 10:18:09 -07001403 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001405
1406 final long identity = Binder.clearCallingIdentity();
1407 try {
1408 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1409 checkSimPuk.start();
1410 return checkSimPuk.unlockSim(puk, pin);
1411 } finally {
1412 Binder.restoreCallingIdentity(identity);
1413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414 }
1415
1416 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001417 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 * a synchronous one.
1419 */
1420 private static class UnlockSim extends Thread {
1421
1422 private final IccCard mSimCard;
1423
1424 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001425 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1426 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427
1428 // For replies from SimCard interface
1429 private Handler mHandler;
1430
1431 // For async handler to identify request type
1432 private static final int SUPPLY_PIN_COMPLETE = 100;
1433
1434 public UnlockSim(IccCard simCard) {
1435 mSimCard = simCard;
1436 }
1437
1438 @Override
1439 public void run() {
1440 Looper.prepare();
1441 synchronized (UnlockSim.this) {
1442 mHandler = new Handler() {
1443 @Override
1444 public void handleMessage(Message msg) {
1445 AsyncResult ar = (AsyncResult) msg.obj;
1446 switch (msg.what) {
1447 case SUPPLY_PIN_COMPLETE:
1448 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1449 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001450 mRetryCount = msg.arg1;
1451 if (ar.exception != null) {
1452 if (ar.exception instanceof CommandException &&
1453 ((CommandException)(ar.exception)).getCommandError()
1454 == CommandException.Error.PASSWORD_INCORRECT) {
1455 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1456 } else {
1457 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1458 }
1459 } else {
1460 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 mDone = true;
1463 UnlockSim.this.notifyAll();
1464 }
1465 break;
1466 }
1467 }
1468 };
1469 UnlockSim.this.notifyAll();
1470 }
1471 Looper.loop();
1472 }
1473
1474 /*
1475 * Use PIN or PUK to unlock SIM card
1476 *
1477 * If PUK is null, unlock SIM card with PIN
1478 *
1479 * If PUK is not null, unlock SIM card with PUK and set PIN code
1480 */
Wink Saville9de0f752013-10-22 19:04:03 -07001481 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482
1483 while (mHandler == null) {
1484 try {
1485 wait();
1486 } catch (InterruptedException e) {
1487 Thread.currentThread().interrupt();
1488 }
1489 }
1490 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1491
1492 if (puk == null) {
1493 mSimCard.supplyPin(pin, callback);
1494 } else {
1495 mSimCard.supplyPuk(puk, pin, callback);
1496 }
1497
1498 while (!mDone) {
1499 try {
1500 Log.d(LOG_TAG, "wait for done");
1501 wait();
1502 } catch (InterruptedException e) {
1503 // Restore the interrupted status
1504 Thread.currentThread().interrupt();
1505 }
1506 }
1507 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001508 int[] resultArray = new int[2];
1509 resultArray[0] = mResult;
1510 resultArray[1] = mRetryCount;
1511 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 }
1513 }
1514
1515 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001516 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001517
1518 }
1519
Wink Savilleb564aae2014-10-23 10:18:09 -07001520 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001521 // No permission check needed here: this call is harmless, and it's
1522 // needed for the ServiceState.requestStateUpdate() call (which is
1523 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001524 final long identity = Binder.clearCallingIdentity();
1525 try {
1526 final Phone phone = getPhone(subId);
1527 if (phone != null) {
1528 phone.updateServiceLocation();
1529 }
1530 } finally {
1531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 }
1534
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001535 @Override
1536 public boolean isRadioOn(String callingPackage) {
1537 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001538 }
1539
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001540 @Override
1541 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001543 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001544 return false;
1545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001546
1547 final long identity = Binder.clearCallingIdentity();
1548 try {
1549 return isRadioOnForSubscriber(subId);
1550 } finally {
1551 Binder.restoreCallingIdentity(identity);
1552 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001553 }
1554
1555 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001556 final long identity = Binder.clearCallingIdentity();
1557 try {
1558 final Phone phone = getPhone(subId);
1559 if (phone != null) {
1560 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1561 } else {
1562 return false;
1563 }
1564 } finally {
1565 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
1568
1569 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001570 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 }
Wink Saville36469e72014-06-11 15:17:00 -07001572
Wink Savilleb564aae2014-10-23 10:18:09 -07001573 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001575
1576 final long identity = Binder.clearCallingIdentity();
1577 try {
1578 final Phone phone = getPhone(subId);
1579 if (phone != null) {
1580 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1581 }
1582 } finally {
1583 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001584 }
Wink Saville36469e72014-06-11 15:17:00 -07001585 }
1586
1587 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001588 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001589 }
1590
Wink Savilleb564aae2014-10-23 10:18:09 -07001591 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001592 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001593
1594 final long identity = Binder.clearCallingIdentity();
1595 try {
1596 final Phone phone = getPhone(subId);
1597 if (phone == null) {
1598 return false;
1599 }
1600 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1601 toggleRadioOnOffForSubscriber(subId);
1602 }
1603 return true;
1604 } finally {
1605 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 }
Wink Saville36469e72014-06-11 15:17:00 -07001608
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001609 public boolean needMobileRadioShutdown() {
1610 /*
1611 * If any of the Radios are available, it will need to be
1612 * shutdown. So return true if any Radio is available.
1613 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001614 final long identity = Binder.clearCallingIdentity();
1615 try {
1616 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1617 Phone phone = PhoneFactory.getPhone(i);
1618 if (phone != null && phone.isRadioAvailable()) return true;
1619 }
1620 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1621 return false;
1622 } finally {
1623 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001624 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001625 }
1626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001627 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001628 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001629 enforceModifyPermission();
1630
1631 final long identity = Binder.clearCallingIdentity();
1632 try {
1633 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1634 logv("Shutting down Phone " + i);
1635 shutdownRadioUsingPhoneId(i);
1636 }
1637 } finally {
1638 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001639 }
1640 }
1641
1642 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001643 Phone phone = PhoneFactory.getPhone(phoneId);
1644 if (phone != null && phone.isRadioAvailable()) {
1645 phone.shutdownRadio();
1646 }
1647 }
1648
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001650 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001651
1652 final long identity = Binder.clearCallingIdentity();
1653 try {
1654 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1655 if (defaultPhone != null) {
1656 defaultPhone.setRadioPower(turnOn);
1657 return true;
1658 } else {
1659 loge("There's no default phone.");
1660 return false;
1661 }
1662 } finally {
1663 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001664 }
Wink Saville36469e72014-06-11 15:17:00 -07001665 }
1666
Wink Savilleb564aae2014-10-23 10:18:09 -07001667 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001669
1670 final long identity = Binder.clearCallingIdentity();
1671 try {
1672 final Phone phone = getPhone(subId);
1673 if (phone != null) {
1674 phone.setRadioPower(turnOn);
1675 return true;
1676 } else {
1677 return false;
1678 }
1679 } finally {
1680 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001681 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 }
1683
Wink Saville36469e72014-06-11 15:17:00 -07001684 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 public boolean enableDataConnectivity() {
1687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001688
1689 final long identity = Binder.clearCallingIdentity();
1690 try {
1691 int subId = mSubscriptionController.getDefaultDataSubId();
1692 final Phone phone = getPhone(subId);
1693 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001694 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001695 return true;
1696 } else {
1697 return false;
1698 }
1699 } finally {
1700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 }
1703
Wink Saville36469e72014-06-11 15:17:00 -07001704 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001705 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 public boolean disableDataConnectivity() {
1707 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001708
1709 final long identity = Binder.clearCallingIdentity();
1710 try {
1711 int subId = mSubscriptionController.getDefaultDataSubId();
1712 final Phone phone = getPhone(subId);
1713 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001714 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715 return true;
1716 } else {
1717 return false;
1718 }
1719 } finally {
1720 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001722 }
1723
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001725 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001726 final long identity = Binder.clearCallingIdentity();
1727 try {
1728 final Phone phone = getPhone(subId);
1729 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001730 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001731 } else {
1732 return false;
1733 }
1734 } finally {
1735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 }
1738
1739 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001740 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001741 }
1742
pkanwarae03a6b2016-11-06 20:37:09 -08001743 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001744 enforceCallPermission();
1745
1746 final long identity = Binder.clearCallingIdentity();
1747 try {
1748 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1749 return;
1750 }
1751 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1752 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1753 } finally {
1754 Binder.restoreCallingIdentity(identity);
1755 }
pkanwar32d516d2016-10-14 19:37:38 -07001756 };
1757
Wink Savilleb564aae2014-10-23 10:18:09 -07001758 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1764 return false;
1765 }
1766 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1767 } finally {
1768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001773 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001774 }
1775
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001776 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 Phone phone = PhoneFactory.getPhone(slotIndex);
1780 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1781 PhoneConstantConversions.convertCallState(phone.getState());
1782 } finally {
1783 Binder.restoreCallingIdentity(identity);
1784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Sanket Padawe356d7632015-06-22 14:03:32 -07001787 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001789 final long identity = Binder.clearCallingIdentity();
1790 try {
1791 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1792 if (phone != null) {
1793 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1794 } else {
1795 return PhoneConstantConversions.convertDataState(
1796 PhoneConstants.DataState.DISCONNECTED);
1797 }
1798 } finally {
1799 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001800 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 }
1802
Sanket Padawe356d7632015-06-22 14:03:32 -07001803 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805 final long identity = Binder.clearCallingIdentity();
1806 try {
1807 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1808 if (phone != null) {
1809 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1810 } else {
1811 return TelephonyManager.DATA_ACTIVITY_NONE;
1812 }
1813 } finally {
1814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 }
1817
1818 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001819 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001820 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001821 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001822 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1823 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001824 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 }
1826
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001827 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001828 final long identity = Binder.clearCallingIdentity();
1829 try {
1830 if (DBG_LOC) log("getCellLocation: is active user");
1831 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001832 int subId = mSubscriptionController.getDefaultDataSubId();
1833 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1834 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835 return data;
1836 } finally {
1837 Binder.restoreCallingIdentity(identity);
1838 }
Svetoslav64fad262015-04-14 14:35:21 -07001839 }
1840
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001842 public String getNetworkCountryIsoForPhone(int phoneId) {
1843 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1844 // registered cell info, so return a NULL country instead.
1845 final long identity = Binder.clearCallingIdentity();
1846 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001847 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1848 // Get default phone in this case.
1849 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1850 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001851 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001852 // Todo: fix this when we can get the actual cellular network info when the device
1853 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001854 if (TelephonyManager.NETWORK_TYPE_IWLAN
1855 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1856 return "";
1857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001858 Phone phone = PhoneFactory.getPhone(phoneId);
1859 if (phone != null) {
1860 ServiceStateTracker sst = phone.getServiceStateTracker();
1861 if (sst != null) {
1862 LocaleTracker lt = sst.getLocaleTracker();
1863 if (lt != null) {
1864 return lt.getCurrentCountry();
1865 }
1866 }
1867 }
1868 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001869 } finally {
1870 Binder.restoreCallingIdentity(identity);
1871 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001872 }
1873
1874 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001876 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001877 }
1878
Sanket Padawe356d7632015-06-22 14:03:32 -07001879 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001880 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 mApp.enforceCallingOrSelfPermission(
1882 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001883
1884 final long identity = Binder.clearCallingIdentity();
1885 try {
1886 final Phone phone = getPhone(subId);
1887 if (phone != null) {
1888 phone.enableLocationUpdates();
1889 }
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 }
1894
1895 @Override
1896 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001897 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001898 }
1899
Sanket Padawe356d7632015-06-22 14:03:32 -07001900 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001901 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 mApp.enforceCallingOrSelfPermission(
1903 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001904
1905 final long identity = Binder.clearCallingIdentity();
1906 try {
1907 final Phone phone = getPhone(subId);
1908 if (phone != null) {
1909 phone.disableLocationUpdates();
1910 }
1911 } finally {
1912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 }
1915
Nathan Harold31d7ff32018-10-15 20:20:30 -07001916 /**
1917 * Returns the target SDK version number for a given package name.
1918 *
1919 * @return target SDK if the package is found or INT_MAX.
1920 */
1921 private int getTargetSdk(String packageName) {
1922 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001923 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1924 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001925 if (ai != null) return ai.targetSdkVersion;
1926 } catch (PackageManager.NameNotFoundException unexpected) {
1927 }
1928 return Integer.MAX_VALUE;
1929 }
1930
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 @Override
1932 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001933 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1934 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001935 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1936 throw new SecurityException(
1937 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1938 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001939
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1941 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1942 return null;
1943 }
Svetoslav64fad262015-04-14 14:35:21 -07001944
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001945 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946
Nathan Haroldf180aac2018-06-01 18:43:55 -07001947 List<CellInfo> info = getAllCellInfo(callingPackage);
1948 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949
Nathan Haroldf180aac2018-06-01 18:43:55 -07001950 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1951 for (CellInfo ci : info) {
1952 if (ci instanceof CellInfoGsm) {
1953 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1954 } else if (ci instanceof CellInfoWcdma) {
1955 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001958 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 }
1960
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001961 private List<CellInfo> getCachedCellInfo() {
1962 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1963 for (Phone phone : PhoneFactory.getPhones()) {
1964 List<CellInfo> info = phone.getAllCellInfo();
1965 if (info != null) cellInfos.addAll(info);
1966 }
1967 return cellInfos;
1968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969
1970 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001971 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001972 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001973 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001974 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001975 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001976 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001979 final int targetSdk = getTargetSdk(callingPackage);
1980 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1981 return getCachedCellInfo();
1982 }
1983
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001984 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001985 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1989 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001990 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001991 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001992 if (info != null) cellInfos.addAll(info);
1993 }
1994 return cellInfos;
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 }
1998 }
1999
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002000 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002001 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2002 requestCellInfoUpdateInternal(
2003 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2004 }
2005
2006 @Override
2007 public void requestCellInfoUpdateWithWorkSource(
2008 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2009 enforceModifyPermission();
2010 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2011 }
2012
2013 private void requestCellInfoUpdateInternal(
2014 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002015 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002016 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002017 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2018 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002019 return;
2020 }
2021
2022 final Phone phone = getPhone(subId);
2023 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2024
2025 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2026 }
2027
2028 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002030 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002031 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002032
2033 final long identity = Binder.clearCallingIdentity();
2034 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002035 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036 } finally {
2037 Binder.restoreCallingIdentity(identity);
2038 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 }
2040
Shishir Agrawala9f32182016-04-12 12:00:16 -07002041 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002042 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002043 Phone phone = PhoneFactory.getPhone(slotIndex);
2044 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002045 return null;
2046 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002047 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002048 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2049 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002050 return null;
2051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002052
2053 final long identity = Binder.clearCallingIdentity();
2054 try {
2055 return phone.getImei();
2056 } finally {
2057 Binder.restoreCallingIdentity(identity);
2058 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002059 }
2060
2061 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002062 public String getTypeAllocationCodeForSlot(int slotIndex) {
2063 Phone phone = PhoneFactory.getPhone(slotIndex);
2064 String tac = null;
2065 if (phone != null) {
2066 String imei = phone.getImei();
2067 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2068 }
2069 return tac;
2070 }
2071
2072 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002073 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002074 Phone phone = PhoneFactory.getPhone(slotIndex);
2075 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002076 return null;
2077 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002078
Jeff Davidson913390f2018-02-23 17:11:49 -08002079 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002080 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2081 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002082 return null;
2083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002084
2085 final long identity = Binder.clearCallingIdentity();
2086 try {
2087 return phone.getMeid();
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
2090 }
Jack Yu2af8d712017-03-15 17:14:14 -07002091 }
2092
2093 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002094 public String getManufacturerCodeForSlot(int slotIndex) {
2095 Phone phone = PhoneFactory.getPhone(slotIndex);
2096 String manufacturerCode = null;
2097 if (phone != null) {
2098 String meid = phone.getMeid();
2099 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2100 }
2101 return manufacturerCode;
2102 }
2103
2104 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002105 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002106 Phone phone = PhoneFactory.getPhone(slotIndex);
2107 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002108 return null;
2109 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002110 int subId = phone.getSubId();
2111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2112 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2113 return null;
2114 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002115
2116 final long identity = Binder.clearCallingIdentity();
2117 try {
2118 return phone.getDeviceSvn();
2119 } finally {
2120 Binder.restoreCallingIdentity(identity);
2121 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002122 }
2123
fionaxu43304da2017-11-27 22:51:16 -08002124 @Override
2125 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002126 final long identity = Binder.clearCallingIdentity();
2127 try {
2128 final Phone phone = getPhone(subId);
2129 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
2132 }
fionaxu43304da2017-11-27 22:51:16 -08002133 }
2134
2135 @Override
2136 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002137 final long identity = Binder.clearCallingIdentity();
2138 try {
2139 final Phone phone = getPhone(subId);
2140 return phone == null ? null : phone.getCarrierName();
2141 } finally {
2142 Binder.restoreCallingIdentity(identity);
2143 }
fionaxu43304da2017-11-27 22:51:16 -08002144 }
2145
calvinpanffe225e2018-11-01 19:43:06 +08002146 @Override
chen xu25637222018-11-04 17:17:00 -08002147 public int getSubscriptionPreciseCarrierId(int subId) {
2148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 final Phone phone = getPhone(subId);
2151 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2152 : phone.getPreciseCarrierId();
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
2155 }
2156 }
2157
2158 @Override
2159 public String getSubscriptionPreciseCarrierName(int subId) {
2160 final long identity = Binder.clearCallingIdentity();
2161 try {
2162 final Phone phone = getPhone(subId);
2163 return phone == null ? null : phone.getPreciseCarrierName();
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
2166 }
2167 }
2168
chen xu651eec72018-11-11 19:03:44 -08002169 @Override
chen xu864e11c2018-12-06 22:10:03 -08002170 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2171 if (!isSubscriptionMccMnc) {
2172 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2173 }
chen xu651eec72018-11-11 19:03:44 -08002174 final Phone phone = PhoneFactory.getPhone(slotIndex);
2175 if (phone == null) {
2176 return TelephonyManager.UNKNOWN_CARRIER_ID;
2177 }
2178 final long identity = Binder.clearCallingIdentity();
2179 try {
2180 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2181 } finally {
2182 Binder.restoreCallingIdentity(identity);
2183 }
2184 }
2185
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 //
2187 // Internal helper methods.
2188 //
2189
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002190 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2192 *
2193 * @throws SecurityException if the caller does not have the required permission
2194 */
2195 private void enforceModifyPermission() {
2196 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2197 }
2198
2199 /**
2200 * Make sure the caller has the CALL_PHONE permission.
2201 *
2202 * @throws SecurityException if the caller does not have the required permission
2203 */
2204 private void enforceCallPermission() {
2205 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2206 }
2207
Stuart Scott8eef64f2015-04-08 15:13:54 -07002208 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002209 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002210 "ConnectivityService");
2211 }
2212
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 private String createTelUrl(String number) {
2214 if (TextUtils.isEmpty(number)) {
2215 return null;
2216 }
2217
Jake Hambye994d462014-02-03 13:10:13 -08002218 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220
Ihab Awadf9e92732013-12-05 18:02:52 -08002221 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2223 }
2224
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002225 private static void logv(String msg) {
2226 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2227 }
2228
Ihab Awadf9e92732013-12-05 18:02:52 -08002229 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2231 }
2232
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002235 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002236 }
2237
Sanket Padawe356d7632015-06-22 14:03:32 -07002238 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002239 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240 final long identity = Binder.clearCallingIdentity();
2241 try {
2242 final Phone phone = PhoneFactory.getPhone(slotIndex);
2243 if (phone == null) {
2244 return PhoneConstants.PHONE_TYPE_NONE;
2245 } else {
2246 return phone.getPhoneType();
2247 }
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
2253 /**
2254 * Returns the CDMA ERI icon index to display
2255 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002256 @Override
2257 public int getCdmaEriIconIndex(String callingPackage) {
2258 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002259 }
2260
Sanket Padawe356d7632015-06-22 14:03:32 -07002261 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002264 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002265 return -1;
2266 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002267
2268 final long identity = Binder.clearCallingIdentity();
2269 try {
2270 final Phone phone = getPhone(subId);
2271 if (phone != null) {
2272 return phone.getCdmaEriIconIndex();
2273 } else {
2274 return -1;
2275 }
2276 } finally {
2277 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280
2281 /**
2282 * Returns the CDMA ERI icon mode,
2283 * 0 - ON
2284 * 1 - FLASHING
2285 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002286 @Override
2287 public int getCdmaEriIconMode(String callingPackage) {
2288 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002289 }
2290
Sanket Padawe356d7632015-06-22 14:03:32 -07002291 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002292 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002294 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002295 return -1;
2296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297
2298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 final Phone phone = getPhone(subId);
2301 if (phone != null) {
2302 return phone.getCdmaEriIconMode();
2303 } else {
2304 return -1;
2305 }
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
2310
2311 /**
2312 * Returns the CDMA ERI text,
2313 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 @Override
2315 public String getCdmaEriText(String callingPackage) {
2316 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002317 }
2318
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002320 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002322 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002323 return null;
2324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325
2326 final long identity = Binder.clearCallingIdentity();
2327 try {
2328 final Phone phone = getPhone(subId);
2329 if (phone != null) {
2330 return phone.getCdmaEriText();
2331 } else {
2332 return null;
2333 }
2334 } finally {
2335 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 }
2338
2339 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002340 * Returns the CDMA MDN.
2341 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002342 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002343 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2345 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346
2347 final long identity = Binder.clearCallingIdentity();
2348 try {
2349 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002350 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351 return phone.getLine1Number();
2352 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002353 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002354 return null;
2355 }
2356 } finally {
2357 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002358 }
2359 }
2360
2361 /**
2362 * Returns the CDMA MIN.
2363 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002365 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2367 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002368
2369 final long identity = Binder.clearCallingIdentity();
2370 try {
2371 final Phone phone = getPhone(subId);
2372 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2373 return phone.getCdmaMin();
2374 } else {
2375 return null;
2376 }
2377 } finally {
2378 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002379 }
2380 }
2381
Hall Liud892bec2018-11-30 14:51:45 -08002382 @Override
2383 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2384 INumberVerificationCallback callback, String callingPackage) {
2385 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2386 != PERMISSION_GRANTED) {
2387 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2388 }
2389 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2390
2391 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2392 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2393 throw new SecurityException("Calling package must be configured in the device config");
2394 }
2395
2396 if (range == null) {
2397 throw new NullPointerException("Range must be non-null");
2398 }
2399
2400 timeoutMillis = Math.min(timeoutMillis,
2401 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2402
2403 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2404 }
2405
Junda Liuca05d5d2014-08-14 22:36:34 -07002406 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 * Returns true if CDMA provisioning needs to run.
2408 */
2409 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002412 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417
2418 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002419 * Sets the voice mail number of a given subId.
2420 */
2421 @Override
2422 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002423 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424
2425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2428 new Pair<String, String>(alphaTag, number), new Integer(subId));
2429 return success;
2430 } finally {
2431 Binder.restoreCallingIdentity(identity);
2432 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002433 }
2434
Ta-wei Yen87c49842016-05-13 21:19:52 -07002435 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002436 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2437 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002438 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002439 if (!TextUtils.equals(callingPackage, systemDialer)) {
2440 throw new SecurityException("caller must be system dialer");
2441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442
2443 final long identity = Binder.clearCallingIdentity();
2444 try {
2445 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2446 if (phoneAccountHandle == null) {
2447 return null;
2448 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002449 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450 } finally {
2451 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002452 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002453 }
2454
2455 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002456 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002459 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002460 return null;
2461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002463 final long identity = Binder.clearCallingIdentity();
2464 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002465 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002466 } finally {
2467 Binder.restoreCallingIdentity(identity);
2468 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002469 }
2470
2471 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002472 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2473 VisualVoicemailSmsFilterSettings settings) {
2474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475
2476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002479 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 } finally {
2481 Binder.restoreCallingIdentity(identity);
2482 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002483 }
2484
2485 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002486 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002492 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493 } finally {
2494 Binder.restoreCallingIdentity(identity);
2495 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002496 }
2497
2498 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002499 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2500 String callingPackage, int subId) {
2501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002502
2503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002506 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 } finally {
2508 Binder.restoreCallingIdentity(identity);
2509 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002510 }
2511
2512 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002513 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002514 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002515
2516 final long identity = Binder.clearCallingIdentity();
2517 try {
2518 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002519 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002520 } finally {
2521 Binder.restoreCallingIdentity(identity);
2522 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002523 }
2524
2525 @Override
2526 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2527 String number, int port, String text, PendingIntent sentIntent) {
2528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002529 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002530 enforceSendSmsPermission();
2531 // Make the calls as the phone process.
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2535 if (port == 0) {
2536 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2537 sentIntent, null, false);
2538 } else {
2539 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2540 smsManager.sendDataMessageWithSelfPermissions(number, null,
2541 (short) port, data, sentIntent, null);
2542 }
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002546 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002547 /**
fionaxu0152e512016-11-14 13:36:14 -08002548 * Sets the voice activation state of a given subId.
2549 */
2550 @Override
2551 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2553 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 final Phone phone = getPhone(subId);
2558 if (phone != null) {
2559 phone.setVoiceActivationState(activationState);
2560 } else {
2561 loge("setVoiceActivationState fails with invalid subId: " + subId);
2562 }
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002565 }
2566 }
2567
2568 /**
2569 * Sets the data activation state of a given subId.
2570 */
2571 @Override
2572 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2574 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575
2576 final long identity = Binder.clearCallingIdentity();
2577 try {
2578 final Phone phone = getPhone(subId);
2579 if (phone != null) {
2580 phone.setDataActivationState(activationState);
2581 } else {
2582 loge("setVoiceActivationState fails with invalid subId: " + subId);
2583 }
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002586 }
2587 }
2588
2589 /**
2590 * Returns the voice activation state of a given subId.
2591 */
2592 @Override
2593 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002594 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595
fionaxu0152e512016-11-14 13:36:14 -08002596 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 if (phone != null) {
2600 return phone.getVoiceActivationState();
2601 } else {
2602 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2603 }
2604 } finally {
2605 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002606 }
2607 }
2608
2609 /**
2610 * Returns the data activation state of a given subId.
2611 */
2612 @Override
2613 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002614 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615
fionaxu0152e512016-11-14 13:36:14 -08002616 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 if (phone != null) {
2620 return phone.getDataActivationState();
2621 } else {
2622 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002626 }
2627 }
2628
2629 /**
Wink Saville36469e72014-06-11 15:17:00 -07002630 * Returns the unread count of voicemails for a subId
2631 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002632 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002633 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2635 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2636 return 0;
2637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 final Phone phone = getPhone(subId);
2641 if (phone != null) {
2642 return phone.getVoiceMessageCount();
2643 } else {
2644 return 0;
2645 }
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 }
2650
2651 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002652 * returns true, if the device is in a state where both voice and data
2653 * are supported simultaneously. This can change based on location or network condition.
2654 */
2655 @Override
2656 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002664 }
2665
2666 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002667 * Send the dialer code if called from the current default dialer or the caller has
2668 * carrier privilege.
2669 * @param inputCode The dialer code to send
2670 */
2671 @Override
2672 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002673 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002674 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002675 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2676 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002677 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002678 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2679 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002684 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685 } finally {
2686 Binder.restoreCallingIdentity(identity);
2687 }
fionaxu235cc5e2017-03-06 22:25:57 -08002688 }
2689
2690 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002691 * Returns the data network type.
2692 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 *
2694 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2695 */
2696 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002697 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 final Phone phone = getPhone(getDefaultSubscription());
2701 if (phone != null) {
2702 return phone.getServiceState().getDataNetworkType();
2703 } else {
2704 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2705 }
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002708 }
Wink Saville36469e72014-06-11 15:17:00 -07002709 }
2710
Pengquan Menga1bb6272018-09-06 09:59:22 -07002711 @Override
2712 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002713 if (!isActiveSubscription(subId)) {
2714 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2715 }
2716
Pengquan Menga1bb6272018-09-06 09:59:22 -07002717 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2718 }
2719
Brad Ebinger35c841c2018-10-01 10:40:55 -07002720 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002721 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2722 throws RemoteException {
2723 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002724 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2725 final long token = Binder.clearCallingIdentity();
2726 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002727 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002728 .addRegistrationCallbackForSubscription(c, subId);
2729 } finally {
2730 Binder.restoreCallingIdentity(token);
2731 }
2732 }
2733
2734 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002735 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2736 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2738 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002739 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002740 .removeRegistrationCallbackForSubscription(c, subId));
2741 }
2742
2743 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002744 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2745 throws RemoteException {
2746 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002747 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2748 final long token = Binder.clearCallingIdentity();
2749 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002750 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002751 .addCapabilitiesCallbackForSubscription(c, subId);
2752 } finally {
2753 Binder.restoreCallingIdentity(token);
2754 }
2755 }
2756
2757 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002758 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2759 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002760 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2761 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002762 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002763 .removeCapabilitiesCallbackForSubscription(c, subId));
2764 }
2765
2766 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002767 public boolean isCapable(int subId, int capability, int regTech) {
2768 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002769 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2770 final long token = Binder.clearCallingIdentity();
2771 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002772 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002773 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2774 } catch (ImsException e) {
2775 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2776 return false;
2777 } finally {
2778 Binder.restoreCallingIdentity(token);
2779 }
2780 }
2781
2782 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002783 public boolean isAvailable(int subId, int capability, int regTech) {
2784 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002785 final long token = Binder.clearCallingIdentity();
2786 try {
2787 Phone phone = getPhone(subId);
2788 if (phone == null) return false;
2789 return phone.isImsCapabilityAvailable(capability, regTech);
2790 } finally {
2791 Binder.restoreCallingIdentity(token);
2792 }
2793 }
2794
2795 @Override
2796 public boolean isAdvancedCallingSettingEnabled(int subId) {
2797 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2798 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2799 final long token = Binder.clearCallingIdentity();
2800 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002801 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002802 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2803 } finally {
2804 Binder.restoreCallingIdentity(token);
2805 }
2806 }
2807
2808 @Override
2809 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2811 "setAdvancedCallingSetting");
2812 final long identity = Binder.clearCallingIdentity();
2813 try {
2814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002815 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002816 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2817 } finally {
2818 Binder.restoreCallingIdentity(identity);
2819 }
2820 }
2821
2822 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002823 public boolean isVtSettingEnabled(int subId) {
2824 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002828 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002829 getSlotIndexOrException(subId)).isVtEnabledByUser();
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
2832 }
2833 }
2834
2835 @Override
2836 public void setVtSetting(int subId, boolean isEnabled) {
2837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2838 "setVtSetting");
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002842 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002843 } finally {
2844 Binder.restoreCallingIdentity(identity);
2845 }
2846 }
2847
2848 @Override
2849 public boolean isVoWiFiSettingEnabled(int subId) {
2850 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002854 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002855 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
2859 }
2860
2861 @Override
2862 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2864 "setVoWiFiSetting");
2865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002868 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002869 } finally {
2870 Binder.restoreCallingIdentity(identity);
2871 }
2872 }
2873
2874 @Override
2875 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2876 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
2879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002880 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002881 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
2885 }
2886
2887 @Override
2888 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2890 "setVoWiFiRoamingSetting");
2891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002894 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002895 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
2898 }
2899 }
2900
2901 @Override
2902 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2904 "setVoWiFiNonPersistent");
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002908 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002909 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
2912 }
2913 }
2914
2915 @Override
2916 public int getVoWiFiModeSetting(int subId) {
2917 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002921 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002922 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2923 } finally {
2924 Binder.restoreCallingIdentity(identity);
2925 }
2926 }
2927
2928 @Override
2929 public void setVoWiFiModeSetting(int subId, int mode) {
2930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2931 "setVoWiFiModeSetting");
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002935 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002936 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
2940 }
2941
2942 @Override
2943 public int getVoWiFiRoamingModeSetting(int subId) {
2944 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2945 final long identity = Binder.clearCallingIdentity();
2946 try {
2947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002948 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002949 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
2952 }
2953 }
2954
2955 @Override
2956 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2958 "setVoWiFiRoamingModeSetting");
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002962 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002963 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
2967 }
2968
2969 @Override
2970 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2972 "setRttCapabilityEnabled");
2973 final long identity = Binder.clearCallingIdentity();
2974 try {
2975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002976 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002977 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
2983 @Override
2984 public boolean isTtyOverVolteEnabled(int subId) {
2985 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002989 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
2994 }
2995
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002996 @Override
2997 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2998 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003002 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003003 .getConfigInterface().addConfigCallback(callback);
3004 } catch (ImsException e) {
3005 throw new IllegalArgumentException(e.getMessage());
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
3011 @Override
3012 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3013 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003017 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003018 .getConfigInterface().removeConfigCallback(callback);
3019 } catch (ImsException e) {
3020 throw new IllegalArgumentException(e.getMessage());
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
3024 }
3025
3026 @Override
3027 public int getImsProvisioningInt(int subId, int key) {
3028 enforceReadPrivilegedPermission("getImsProvisioningInt");
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003032 return ImsManager.getInstance(mApp,
3033 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003034 } catch (ImsException e) {
3035 throw new IllegalArgumentException(e.getMessage());
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
3039 }
3040
3041 @Override
3042 public String getImsProvisioningString(int subId, int key) {
3043 enforceReadPrivilegedPermission("getImsProvisioningString");
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003047 return ImsManager.getInstance(mApp,
3048 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003049 } catch (ImsException e) {
3050 throw new IllegalArgumentException(e.getMessage());
3051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
3054 }
3055
3056 @Override
3057 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3059 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003063 return ImsManager.getInstance(mApp,
3064 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003065 } catch (ImsException e) {
3066 throw new IllegalArgumentException(e.getMessage());
3067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
3070 }
3071
3072 @Override
3073 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3075 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003079 return ImsManager.getInstance(mApp,
3080 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003081 } catch (ImsException e) {
3082 throw new IllegalArgumentException(e.getMessage());
3083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
3086 }
3087
Brad Ebinger35c841c2018-10-01 10:40:55 -07003088 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3089 int slotId = SubscriptionManager.getSlotIndex(subId);
3090 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3091 throw new IllegalArgumentException("Invalid Subscription Id.");
3092 }
3093 return slotId;
3094 }
3095
Wink Saville36469e72014-06-11 15:17:00 -07003096 /**
3097 * Returns the network type for a subId
3098 */
3099 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003100 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003102 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003103 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3104 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 final Phone phone = getPhone(subId);
3109 if (phone != null) {
3110 return phone.getServiceState().getDataNetworkType();
3111 } else {
3112 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3113 }
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 }
3118
3119 /**
3120 * Returns the data network type
3121 */
3122 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003123 public int getDataNetworkType(String callingPackage) {
3124 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003125 }
3126
3127 /**
3128 * Returns the data network type for a subId
3129 */
3130 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003131 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003133 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003134 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3135 }
3136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 final Phone phone = getPhone(subId);
3140 if (phone != null) {
3141 return phone.getServiceState().getDataNetworkType();
3142 } else {
3143 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3144 }
3145 } finally {
3146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 }
3149
3150 /**
Wink Saville36469e72014-06-11 15:17:00 -07003151 * Returns the Voice network type for a subId
3152 */
3153 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003154 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003155 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003156 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003157 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3158 }
3159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003160 final long identity = Binder.clearCallingIdentity();
3161 try {
3162 final Phone phone = getPhone(subId);
3163 if (phone != null) {
3164 return phone.getServiceState().getVoiceNetworkType();
3165 } else {
3166 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3167 }
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 }
3172
3173 /**
3174 * @return true if a ICC card is present
3175 */
3176 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003177 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003178 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3179 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003180 }
3181
3182 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003183 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003184 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003186 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 final Phone phone = PhoneFactory.getPhone(slotIndex);
3190 if (phone != null) {
3191 return phone.getIccCard().hasIccCard();
3192 } else {
3193 return false;
3194 }
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 }
3199
3200 /**
3201 * Return if the current radio is LTE on CDMA. This
3202 * is a tri-state return value as for a period of time
3203 * the mode may be unknown.
3204 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003205 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003207 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003209 @Override
3210 public int getLteOnCdmaMode(String callingPackage) {
3211 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003212 }
3213
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003215 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003217 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003218 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3219 }
3220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 final Phone phone = getPhone(subId);
3224 if (phone == null) {
3225 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3226 } else {
3227 return phone.getLteOnCdmaMode();
3228 }
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 }
Wink Saville36469e72014-06-11 15:17:00 -07003232 }
3233
Wink Saville36469e72014-06-11 15:17:00 -07003234 /**
3235 * {@hide}
3236 * Returns Default subId, 0 in the case of single standby.
3237 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003238 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003239 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003240 }
3241
Shishir Agrawala9f32182016-04-12 12:00:16 -07003242 private int getSlotForDefaultSubscription() {
3243 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3244 }
3245
Wink Savilleb564aae2014-10-23 10:18:09 -07003246 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003247 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003249
Pengquan Menge92a50d2018-09-21 15:54:48 -07003250 private boolean isActiveSubscription(int subId) {
3251 return mSubscriptionController.isActiveSubId(subId);
3252 }
3253
Ihab Awadf2177b72013-11-25 13:33:23 -08003254 /**
3255 * @see android.telephony.TelephonyManager.WifiCallingChoices
3256 */
3257 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258 final long identity = Binder.clearCallingIdentity();
3259 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003260 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3262 getWhenToMakeWifiCallsDefaultPreference());
3263 } finally {
3264 Binder.restoreCallingIdentity(identity);
3265 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003266 }
3267
3268 /**
3269 * @see android.telephony.TelephonyManager.WifiCallingChoices
3270 */
3271 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272 final long identity = Binder.clearCallingIdentity();
3273 try {
3274 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003275 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003280 }
3281
Sailesh Nepald1e68152013-12-12 19:08:02 -08003282 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003283 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003284 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003285 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003286
Shishir Agrawal566b7612013-10-28 14:41:00 -07003287 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003288 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3289 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 if (TextUtils.equals(ISDR_AID, aid)) {
3297 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003298 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3299 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003300 if (bestComponent == null
3301 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3302 loge("The calling package is not allowed to access ISD-R.");
3303 throw new SecurityException(
3304 "The calling package is not allowed to access ISD-R.");
3305 }
Derek Tan740e1672017-06-27 14:56:27 -07003306 }
Derek Tan740e1672017-06-27 14:56:27 -07003307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308 if (DBG) {
3309 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3310 }
3311 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3312 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3313 if (DBG) log("iccOpenLogicalChannel: " + response);
3314 return response;
3315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003318 }
3319
3320 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003321 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3323 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3328 if (channel < 0) {
3329 return false;
3330 }
3331 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3332 if (DBG) log("iccCloseLogicalChannel: " + success);
3333 return success;
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003337 }
3338
3339 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003340 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003341 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3343 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 if (DBG) {
3348 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3349 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3350 + p3 + " data=" + data);
3351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 if (channel < 0) {
3354 return "";
3355 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3358 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3359 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361 // Append the returned status code to the end of the response payload.
3362 String s = Integer.toHexString(
3363 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3364 if (response.payload != null) {
3365 s = IccUtils.bytesToHexString(response.payload) + s;
3366 }
3367 return s;
3368 } finally {
3369 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003370 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003371 }
Jake Hambye994d462014-02-03 13:10:13 -08003372
Evan Charltonc66da362014-05-16 14:06:40 -07003373 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003374 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3375 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3377 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3383 && TextUtils.equals(ISDR_AID, data)) {
3384 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003385 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3386 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387 if (bestComponent == null
3388 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3389 loge("The calling package is not allowed to select ISD-R.");
3390 throw new SecurityException(
3391 "The calling package is not allowed to select ISD-R.");
3392 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003393 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395 if (DBG) {
3396 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3397 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3398 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3401 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3402 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 // Append the returned status code to the end of the response payload.
3405 String s = Integer.toHexString(
3406 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3407 if (response.payload != null) {
3408 s = IccUtils.bytesToHexString(response.payload) + s;
3409 }
3410 return s;
3411 } finally {
3412 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003413 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003414 }
3415
3416 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003417 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003418 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3420 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 if (DBG) {
3425 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3426 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3427 }
3428
3429 IccIoResult response =
3430 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3431 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3432 subId);
3433
3434 if (DBG) {
3435 log("Exchange SIM_IO [R]" + response);
3436 }
3437
3438 byte[] result = null;
3439 int length = 2;
3440 if (response.payload != null) {
3441 length = 2 + response.payload.length;
3442 result = new byte[length];
3443 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3444 } else {
3445 result = new byte[length];
3446 }
3447
3448 result[length - 1] = (byte) response.sw2;
3449 result[length - 2] = (byte) response.sw1;
3450 return result;
3451 } finally {
3452 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003453 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003454 }
3455
Nathan Haroldb3014052017-01-25 15:57:32 -08003456 /**
3457 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3458 * on a particular subscription
3459 */
sqianb6e41952018-03-12 14:54:01 -07003460 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3462 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3463 return null;
3464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465
3466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 if (appType != TelephonyManager.APPTYPE_USIM
3469 && appType != TelephonyManager.APPTYPE_SIM) {
3470 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3471 return null;
3472 }
3473 Object response = sendRequest(
3474 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3475 if (response instanceof String[]) {
3476 return (String[]) response;
3477 }
3478 // Response is an Exception of some kind,
3479 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003480 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003481 } finally {
3482 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003483 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003484 }
3485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003486 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003487 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3489 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3494 if (response.payload == null) {
3495 return "";
3496 }
Evan Charltonc66da362014-05-16 14:06:40 -07003497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498 // Append the returned status code to the end of the response payload.
3499 String s = Integer.toHexString(
3500 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3501 s = IccUtils.bytesToHexString(response.payload) + s;
3502 return s;
3503 } finally {
3504 Binder.restoreCallingIdentity(identity);
3505 }
Evan Charltonc66da362014-05-16 14:06:40 -07003506 }
3507
Jake Hambye994d462014-02-03 13:10:13 -08003508 /**
3509 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3510 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3511 *
3512 * @param itemID the ID of the item to read
3513 * @return the NV item as a String, or null on error.
3514 */
3515 @Override
3516 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003517 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3519 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520
3521 final long identity = Binder.clearCallingIdentity();
3522 try {
3523 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003524 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003525 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3526 return value;
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Jake Hambye994d462014-02-03 13:10:13 -08003530 }
3531
3532 /**
3533 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3534 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3535 *
3536 * @param itemID the ID of the item to read
3537 * @param itemValue the value to write, as a String
3538 * @return true on success; false on any failure
3539 */
3540 @Override
3541 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003542 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3544 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3549 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003550 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3552 return success;
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
Jake Hambye994d462014-02-03 13:10:13 -08003556 }
3557
3558 /**
3559 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3560 * Used for device configuration by some CDMA operators.
3561 *
3562 * @param preferredRoamingList byte array containing the new PRL
3563 * @return true on success; false on any failure
3564 */
3565 @Override
3566 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3568 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569
3570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3573 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3574 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3575 return success;
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
Jake Hambye994d462014-02-03 13:10:13 -08003579 }
3580
3581 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003582 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003583 * Used for device configuration by some CDMA operators.
3584 *
chen xu6dac5ab2018-10-26 17:39:23 -07003585 * @param slotIndex - device slot.
3586 *
Jake Hambye994d462014-02-03 13:10:13 -08003587 * @return true on success; false on any failure
3588 */
3589 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003590 public boolean resetModemConfig(int slotIndex) {
3591 Phone phone = PhoneFactory.getPhone(slotIndex);
3592 if (phone != null) {
3593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3594 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
chen xu6dac5ab2018-10-26 17:39:23 -07003596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3599 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3600 return success;
3601 } finally {
3602 Binder.restoreCallingIdentity(identity);
3603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604 }
chen xu6dac5ab2018-10-26 17:39:23 -07003605 return false;
3606 }
3607
3608 /**
3609 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3610 *
3611 * @param slotIndex - device slot.
3612 *
3613 * @return true on success; false on any failure
3614 */
3615 @Override
3616 public boolean rebootModem(int slotIndex) {
3617 Phone phone = PhoneFactory.getPhone(slotIndex);
3618 if (phone != null) {
3619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3620 mApp, phone.getSubId(), "rebootModem");
3621
3622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3625 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3626 return success;
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
3630 }
3631 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003632 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003633
Svet Ganovb320e182015-04-16 12:30:10 -07003634 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003635 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003638 return new String[0];
3639 }
3640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003641 final long identity = Binder.clearCallingIdentity();
3642 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003643 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
Wink Saville36469e72014-06-11 15:17:00 -07003647 }
3648
Brad Ebinger51f743a2017-01-23 13:50:20 -08003649 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003650 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3651 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003652 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003653 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655
3656 final long identity = Binder.clearCallingIdentity();
3657 try {
3658 PhoneFactory.getImsResolver().enableIms(slotId);
3659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003662 }
3663
3664 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003665 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3666 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003667 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003668 public void disableIms(int slotId) {
3669 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003670
3671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 PhoneFactory.getImsResolver().disableIms(slotId);
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003677 }
3678
3679 /**
3680 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3681 * feature or {@link null} if the service is not available. If the feature is available, the
3682 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3683 */
3684 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003685 IImsServiceFeatureCallback callback) {
3686 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003694 }
3695
3696 /**
3697 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3698 * feature during emergency calling or {@link null} if the service is not available. If the
3699 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3700 * listener for feature updates.
3701 */
3702 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704
3705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003711 }
3712
Brad Ebinger5f64b052017-12-14 14:26:15 -08003713 /**
3714 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3715 * specified.
3716 */
3717 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3718 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003726 }
3727
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003728 /**
3729 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3730 * specified.
3731 */
3732 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3733 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3738 } finally {
3739 Binder.restoreCallingIdentity(identity);
3740 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003741 }
3742
Brad Ebinger884c07b2018-02-15 16:17:40 -08003743 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003744 * Sets the ImsService Package Name that Telephony will bind to.
3745 *
3746 * @param slotId the slot ID that the ImsService should bind for.
3747 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3748 * ImsService is the device default ImsService.
3749 * @param packageName The package name of the application that contains the ImsService to bind
3750 * to.
3751 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3752 * @hide
3753 */
3754 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003755 int[] subIds = SubscriptionManager.getSubId(slotId);
3756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3757 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3758 "setImsService");
3759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003760 final long identity = Binder.clearCallingIdentity();
3761 try {
3762 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3763 isCarrierImsService, packageName);
3764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003767 }
3768
3769 /**
3770 * Return the ImsService configuration.
3771 *
3772 * @param slotId The slot that the ImsService is associated with.
3773 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3774 * the device default.
3775 * @return the package name of the ImsService configuration.
3776 */
3777 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003778 int[] subIds = SubscriptionManager.getSubId(slotId);
3779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3780 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3781 "getImsService");
3782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783 final long identity = Binder.clearCallingIdentity();
3784 try {
3785 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3786 isCarrierImsService);
3787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003790 }
3791
Wink Saville36469e72014-06-11 15:17:00 -07003792 public void setImsRegistrationState(boolean registered) {
3793 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794
3795 final long identity = Binder.clearCallingIdentity();
3796 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003797 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 } finally {
3799 Binder.restoreCallingIdentity(identity);
3800 }
Wink Saville36469e72014-06-11 15:17:00 -07003801 }
3802
3803 /**
Stuart Scott54788802015-03-30 13:18:01 -07003804 * Set the network selection mode to automatic.
3805 *
3806 */
3807 @Override
3808 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3810 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811
Pengquan Menge92a50d2018-09-21 15:54:48 -07003812 if (!isActiveSubscription(subId)) {
3813 return;
3814 }
3815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 final long identity = Binder.clearCallingIdentity();
3817 try {
3818 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3819 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
3822 }
Stuart Scott54788802015-03-30 13:18:01 -07003823 }
3824
Pengquan Mengea84e042018-09-20 14:57:26 -07003825 /**
3826 * Ask the radio to connect to the input network and change selection mode to manual.
3827 *
3828 * @param subId the id of the subscription.
3829 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3830 * the operator to attach to.
3831 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3832 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3833 * normal network selection next time.
3834 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003835 */
3836 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003837 public boolean setNetworkSelectionModeManual(
3838 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3840 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003841
3842 if (!isActiveSubscription(subId)) {
3843 return false;
3844 }
3845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846 final long identity = Binder.clearCallingIdentity();
3847 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003848 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003849 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003850 if (DBG) {
3851 log("setNetworkSelectionModeManual: subId: " + subId
3852 + " operator: " + operatorInfo);
3853 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
3857 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003858 }
3859
3860 /**
3861 * Scans for available networks.
3862 */
3863 @Override
3864 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3866 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867
Pengquan Menga1bb6272018-09-06 09:59:22 -07003868 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869 try {
3870 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003871 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003876 }
3877
3878 /**
yinxub1bed742017-04-17 11:45:04 -07003879 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003880 *
yinxub1bed742017-04-17 11:45:04 -07003881 * @param subId id of the subscription
3882 * @param request contains the radio access networks with bands/channels to scan
3883 * @param messenger callback messenger for scan results or errors
3884 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003885 * @return the id of the requested scan which can be used to stop the scan.
3886 */
3887 @Override
3888 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3889 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3891 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892
3893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 return mNetworkScanRequestTracker.startNetworkScan(
3896 request, messenger, binder, getPhone(subId));
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
3899 }
yinxu504e1392017-04-12 16:03:22 -07003900 }
3901
3902 /**
3903 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003904 *
3905 * @param subId id of the subscription
3906 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003907 */
3908 @Override
3909 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3911 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912
3913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
3918 }
yinxu504e1392017-04-12 16:03:22 -07003919 }
3920
3921 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003922 * Get the calculated preferred network type.
3923 * Used for debugging incorrect network type.
3924 *
3925 * @return the preferred network type, defined in RILConstants.java.
3926 */
3927 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003928 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003929 final Phone defaultPhone = getDefaultPhone();
3930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3931 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003932 return RILConstants.PREFERRED_NETWORK_MODE;
3933 }
3934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003938 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
Junda Liu84d15a22014-07-02 11:21:04 -07003942 }
3943
3944 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003945 * Get the preferred network type.
3946 * Used for device configuration by some CDMA operators.
3947 *
3948 * @return the preferred network type, defined in RILConstants.java.
3949 */
3950 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003951 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08003952 TelephonyPermissions
3953 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
3954 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955
3956 final long identity = Binder.clearCallingIdentity();
3957 try {
3958 if (DBG) log("getPreferredNetworkType");
3959 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3960 int networkType = (result != null ? result[0] : -1);
3961 if (DBG) log("getPreferredNetworkType: " + networkType);
3962 return networkType;
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003966 }
3967
3968 /**
3969 * Set the preferred network type.
3970 * Used for device configuration by some CDMA operators.
3971 *
3972 * @param networkType the preferred network type, defined in RILConstants.java.
3973 * @return true on success; false on any failure.
3974 */
3975 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003976 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3978 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979
3980 final long identity = Binder.clearCallingIdentity();
3981 try {
3982 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3983 Boolean success = (Boolean) sendRequest(
3984 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3985 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3986 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003987 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003988 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3989 }
3990 return success;
3991 } finally {
3992 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003993 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003994 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003995
3996 /**
Junda Liu475951f2014-11-07 16:45:03 -08003997 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07003998 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003999 * tethering.
4000 *
4001 * @return 0: Not required. 1: required. 2: Not set.
4002 * @hide
4003 */
4004 @Override
4005 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004006 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007
4008 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004009 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004011 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004012 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07004013 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004014 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015 dunRequired = 1;
4016 }
4017 return dunRequired;
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004020 }
Junda Liu475951f2014-11-07 16:45:03 -08004021 }
4022
4023 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004024 * Set mobile data enabled
4025 * Used by the user through settings etc to turn on/off mobile data
4026 *
4027 * @param enable {@code true} turn turn data on, else {@code false}
4028 */
4029 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004030 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4032 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004033
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 int phoneId = mSubscriptionController.getPhoneId(subId);
4037 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4038 Phone phone = PhoneFactory.getPhone(phoneId);
4039 if (phone != null) {
4040 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004041 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004043 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004044 }
4045 } finally {
4046 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004047 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004048 }
4049
4050 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004051 * Get the user enabled state of Mobile Data.
4052 *
4053 * TODO: remove and use isUserDataEnabled.
4054 * This can't be removed now because some vendor codes
4055 * calls through ITelephony directly while they should
4056 * use TelephonyManager.
4057 *
4058 * @return true on enabled
4059 */
4060 @Override
4061 public boolean getDataEnabled(int subId) {
4062 return isUserDataEnabled(subId);
4063 }
4064
4065 /**
4066 * Get whether mobile data is enabled per user setting.
4067 *
4068 * There are other factors deciding whether mobile data is actually enabled, but they are
4069 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004070 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004071 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004072 *
4073 * @return {@code true} if data is enabled else {@code false}
4074 */
4075 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004076 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004077 try {
4078 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4079 null);
4080 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4082 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084
4085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 int phoneId = mSubscriptionController.getPhoneId(subId);
4088 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4089 Phone phone = PhoneFactory.getPhone(phoneId);
4090 if (phone != null) {
4091 boolean retVal = phone.isUserDataEnabled();
4092 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4093 return retVal;
4094 } else {
4095 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4096 return false;
4097 }
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004100 }
4101 }
4102
4103 /**
4104 * Get whether mobile data is enabled.
4105 *
4106 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4107 * whether mobile data is actually enabled.
4108 *
4109 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4110 *
4111 * @return {@code true} if data is enabled else {@code false}
4112 */
4113 @Override
4114 public boolean isDataEnabled(int subId) {
4115 try {
4116 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4117 null);
4118 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4120 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004121 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004122
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 int phoneId = mSubscriptionController.getPhoneId(subId);
4126 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4127 Phone phone = PhoneFactory.getPhone(phoneId);
4128 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004129 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004130 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4131 return retVal;
4132 } else {
4133 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4134 return false;
4135 }
4136 } finally {
4137 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004138 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004139 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004140
4141 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004142 public int getCarrierPrivilegeStatus(int subId) {
4143 final Phone phone = getPhone(subId);
4144 if (phone == null) {
4145 loge("getCarrierPrivilegeStatus: Invalid subId");
4146 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4147 }
4148 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004149 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004150 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004151 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4152 }
4153 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004154 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004155 }
Junda Liu29340342014-07-10 15:23:27 -07004156
4157 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004158 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4159 final Phone phone = getPhone(subId);
4160 if (phone == null) {
4161 loge("getCarrierPrivilegeStatus: Invalid subId");
4162 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4163 }
4164 UiccProfile profile =
4165 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4166 if (profile == null) {
4167 loge("getCarrierPrivilegeStatus: No UICC");
4168 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4169 }
4170 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4171 }
4172
4173 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004174 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004175 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004176 if (TextUtils.isEmpty(pkgName))
4177 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004178 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004179 if (card == null) {
4180 loge("checkCarrierPrivilegesForPackage: No UICC");
4181 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4182 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004183 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4184 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004185 }
4186
4187 @Override
4188 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004189 if (TextUtils.isEmpty(pkgName))
4190 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004191 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4192 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4193 UiccCard card = UiccController.getInstance().getUiccCard(i);
4194 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004195 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004196 continue;
4197 }
4198
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004199 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004200 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4201 break;
4202 }
4203 }
4204
4205 return result;
Junda Liu29340342014-07-10 15:23:27 -07004206 }
Derek Tan89e89d42014-07-08 17:00:10 -07004207
4208 @Override
Junda Liue64de782015-04-16 17:19:16 -07004209 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4210 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4211 loge("phoneId " + phoneId + " is not valid.");
4212 return null;
4213 }
4214 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004215 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004216 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004217 return null ;
4218 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004219 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004220 }
4221
Amith Yamasani6e118872016-02-19 12:53:51 -08004222 @Override
4223 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004224 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004225 List<String> privilegedPackages = new ArrayList<>();
4226 List<PackageInfo> packages = null;
4227 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4228 UiccCard card = UiccController.getInstance().getUiccCard(i);
4229 if (card == null) {
4230 // No UICC in that slot.
4231 continue;
4232 }
4233 if (card.hasCarrierPrivilegeRules()) {
4234 if (packages == null) {
4235 // Only check packages in user 0 for now
4236 packages = pm.getInstalledPackagesAsUser(
4237 PackageManager.MATCH_DISABLED_COMPONENTS
4238 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4239 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4240 }
4241 for (int p = packages.size() - 1; p >= 0; p--) {
4242 PackageInfo pkgInfo = packages.get(p);
4243 if (pkgInfo != null && pkgInfo.packageName != null
4244 && card.getCarrierPrivilegeStatus(pkgInfo)
4245 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4246 privilegedPackages.add(pkgInfo.packageName);
4247 }
4248 }
4249 }
4250 }
4251 return privilegedPackages;
4252 }
4253
Wink Savilleb564aae2014-10-23 10:18:09 -07004254 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004255 final Phone phone = getPhone(subId);
4256 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004257 if (card == null) {
4258 loge("getIccId: No UICC");
4259 return null;
4260 }
4261 String iccId = card.getIccId();
4262 if (TextUtils.isEmpty(iccId)) {
4263 loge("getIccId: ICC ID is null or empty.");
4264 return null;
4265 }
4266 return iccId;
4267 }
4268
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004269 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004270 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4271 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004272 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4273 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275 final long identity = Binder.clearCallingIdentity();
4276 try {
4277 final String iccId = getIccId(subId);
4278 final Phone phone = getPhone(subId);
4279 if (phone == null) {
4280 return false;
4281 }
4282 final String subscriberId = phone.getSubscriberId();
4283
4284 if (DBG_MERGE) {
4285 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4286 + subscriberId + " to " + number);
4287 }
4288
4289 if (TextUtils.isEmpty(iccId)) {
4290 return false;
4291 }
4292
4293 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4294
4295 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4296 if (alphaTag == null) {
4297 editor.remove(alphaTagPrefKey);
4298 } else {
4299 editor.putString(alphaTagPrefKey, alphaTag);
4300 }
4301
4302 // Record both the line number and IMSI for this ICCID, since we need to
4303 // track all merged IMSIs based on line number
4304 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4305 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4306 if (number == null) {
4307 editor.remove(numberPrefKey);
4308 editor.remove(subscriberPrefKey);
4309 } else {
4310 editor.putString(numberPrefKey, number);
4311 editor.putString(subscriberPrefKey, subscriberId);
4312 }
4313
4314 editor.commit();
4315 return true;
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004318 }
Derek Tan7226c842014-07-02 17:42:23 -07004319 }
4320
4321 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004322 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004323 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004325 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004326 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004327 return null;
4328 }
Derek Tan97ebb422014-09-05 16:55:38 -07004329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 final long identity = Binder.clearCallingIdentity();
4331 try {
4332 String iccId = getIccId(subId);
4333 if (iccId != null) {
4334 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4335 if (DBG_MERGE) {
4336 log("getLine1NumberForDisplay returning "
4337 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4338 }
4339 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004340 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4342 return null;
4343 } finally {
4344 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004345 }
Derek Tan7226c842014-07-02 17:42:23 -07004346 }
4347
4348 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004349 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004350 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004351 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004352 return null;
4353 }
Derek Tan97ebb422014-09-05 16:55:38 -07004354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 String iccId = getIccId(subId);
4358 if (iccId != null) {
4359 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4360 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4361 }
4362 return null;
4363 } finally {
4364 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004365 }
Derek Tan7226c842014-07-02 17:42:23 -07004366 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004367
4368 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004369 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004370 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4371 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004373 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4374 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004375 return null;
4376 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004377
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004378 final long identity = Binder.clearCallingIdentity();
4379 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004380 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381 final TelephonyManager tele = TelephonyManager.from(context);
4382 final SubscriptionManager sub = SubscriptionManager.from(context);
4383
4384 // Figure out what subscribers are currently active
4385 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4386 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4387 // the process, where TelephonyManager was instantiated.
4388 // Otherwise AppOps check will fail.
4389
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004390 final int[] subIds = sub.getActiveSubscriptionIdList();
4391 for (int subId : subIds) {
4392 activeSubscriberIds.add(tele.getSubscriberId(subId));
4393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004394
4395 // First pass, find a number override for an active subscriber
4396 String mergeNumber = null;
4397 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4398 for (String key : prefs.keySet()) {
4399 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4400 final String subscriberId = (String) prefs.get(key);
4401 if (activeSubscriberIds.contains(subscriberId)) {
4402 final String iccId = key.substring(
4403 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4404 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4405 mergeNumber = (String) prefs.get(numberKey);
4406 if (DBG_MERGE) {
4407 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4408 + " for active subscriber " + subscriberId);
4409 }
4410 if (!TextUtils.isEmpty(mergeNumber)) {
4411 break;
4412 }
4413 }
4414 }
4415 }
4416
4417 // Shortcut when no active merged subscribers
4418 if (TextUtils.isEmpty(mergeNumber)) {
4419 return null;
4420 }
4421
4422 // Second pass, find all subscribers under that line override
4423 final ArraySet<String> result = new ArraySet<>();
4424 for (String key : prefs.keySet()) {
4425 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4426 final String number = (String) prefs.get(key);
4427 if (mergeNumber.equals(number)) {
4428 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4429 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4430 final String subscriberId = (String) prefs.get(subscriberKey);
4431 if (!TextUtils.isEmpty(subscriberId)) {
4432 result.add(subscriberId);
4433 }
4434 }
4435 }
4436 }
4437
4438 final String[] resultArray = result.toArray(new String[result.size()]);
4439 Arrays.sort(resultArray);
4440 if (DBG_MERGE) {
4441 Slog.d(LOG_TAG,
4442 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4443 }
4444 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004445 } finally {
4446 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004447 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004448 }
4449
4450 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004451 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004452 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4453 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004454
4455 final long identity = Binder.clearCallingIdentity();
4456 try {
4457 final Phone phone = getPhone(subId);
4458 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4459 } finally {
4460 Binder.restoreCallingIdentity(identity);
4461 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004462 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004463
4464 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004465 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004466 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4467 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004468 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 final Phone phone = getPhone(subId);
4473 if (phone == null) {
4474 return false;
4475 }
4476 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4477 cdmaNonRoamingList);
4478 } finally {
4479 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004480 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004481 }
4482
4483 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004484 @Deprecated
4485 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4486 enforceModifyPermission();
4487
4488 int returnValue = 0;
4489 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004490 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004491 if(result.exception == null) {
4492 if (result.result != null) {
4493 byte[] responseData = (byte[])(result.result);
4494 if(responseData.length > oemResp.length) {
4495 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4496 responseData.length + "bytes. Buffer Size is " +
4497 oemResp.length + "bytes.");
4498 }
4499 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4500 returnValue = responseData.length;
4501 }
4502 } else {
4503 CommandException ex = (CommandException) result.exception;
4504 returnValue = ex.getCommandError().ordinal();
4505 if(returnValue > 0) returnValue *= -1;
4506 }
4507 } catch (RuntimeException e) {
4508 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4509 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4510 if(returnValue > 0) returnValue *= -1;
4511 }
4512
4513 return returnValue;
4514 }
4515
4516 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004517 public void setRadioCapability(RadioAccessFamily[] rafs) {
4518 try {
4519 ProxyController.getInstance().setRadioCapability(rafs);
4520 } catch (RuntimeException e) {
4521 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4522 }
4523 }
4524
4525 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004526 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004527 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004528 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004529 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004530 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004532 final long identity = Binder.clearCallingIdentity();
4533 try {
chen xub97461a2018-10-26 14:17:57 -07004534 TelephonyPermissions
4535 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4536 mApp, phone.getSubId(), "getRadioAccessFamily");
4537 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
chen xub97461a2018-10-26 14:17:57 -07004541 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004542 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004543
4544 @Override
4545 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004546 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004548
4549 final long identity = Binder.clearCallingIdentity();
4550 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004551 ImsManager.getInstance(defaultPhone.getContext(),
4552 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 } finally {
4554 Binder.restoreCallingIdentity(identity);
4555 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004556 }
4557
4558 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004559 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004560 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004562 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004563 return false;
4564 }
Svet Ganovb320e182015-04-16 12:30:10 -07004565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566 final long identity = Binder.clearCallingIdentity();
4567 try {
4568 // Check the user preference and the system-level IMS setting. Even if the user has
4569 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4570 // In the long run, we may instead need to check if there exists a connection service
4571 // which can support video calling.
4572 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004573 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 return imsManager.isVtEnabledByPlatform()
4575 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4576 && imsManager.isVtEnabledByUser();
4577 } finally {
4578 Binder.restoreCallingIdentity(identity);
4579 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004580 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004581
Andrew Leea1239f22015-03-02 17:44:07 -08004582 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004583 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4585 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4586 return false;
4587 }
4588
4589 final long identity = Binder.clearCallingIdentity();
4590 try {
4591 CarrierConfigManager configManager =
4592 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004593 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4595 } finally {
4596 Binder.restoreCallingIdentity(identity);
4597 }
Andrew Leea1239f22015-03-02 17:44:07 -08004598 }
4599
4600 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 public boolean isWorldPhone(int subId, String callingPackage) {
4602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4603 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4604 return false;
4605 }
4606
4607 final long identity = Binder.clearCallingIdentity();
4608 try {
4609 CarrierConfigManager configManager =
4610 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004611 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004612 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4613 } finally {
4614 Binder.restoreCallingIdentity(identity);
4615 }
Andrew Leea1239f22015-03-02 17:44:07 -08004616 }
4617
Andrew Lee9431b832015-03-09 18:46:45 -07004618 @Override
4619 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004620 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004621 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004622 }
4623
4624 @Override
4625 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 final long identity = Binder.clearCallingIdentity();
4627 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004628 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
Andrew Lee9431b832015-03-09 18:46:45 -07004632 }
4633
Hall Liuf6668912018-10-31 17:05:23 -07004634 /**
4635 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4636 * support for the feature and device firmware support.
4637 *
4638 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4639 */
4640 @Override
4641 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004643 final Phone phone = getPhone(subscriptionId);
4644 if (phone == null) {
4645 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4646 return false;
4647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004649 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4651 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004652 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 return isCarrierSupported && isDeviceSupported;
4654 } finally {
4655 Binder.restoreCallingIdentity(identity);
4656 }
Hall Liu98187582018-01-22 19:15:32 -08004657 }
4658
Hall Liuf6668912018-10-31 17:05:23 -07004659 /**
4660 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4661 * both also support RTT.
4662 */
4663 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 final long identity = Binder.clearCallingIdentity();
4665 try {
Hall Liuf6668912018-10-31 17:05:23 -07004666 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004667 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004668 } finally {
4669 Binder.restoreCallingIdentity(identity);
4670 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004671 }
4672
Sanket Padawe7310cc72015-01-14 09:53:20 -08004673 /**
4674 * Returns the unique device ID of phone, for example, the IMEI for
4675 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4676 *
4677 * <p>Requires Permission:
4678 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4679 */
4680 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004681 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004682 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004683 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004684 return null;
4685 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004686 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004687 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4688 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004689 return null;
4690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691
4692 final long identity = Binder.clearCallingIdentity();
4693 try {
4694 return phone.getDeviceId();
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004698 }
4699
Ping Sunc67b7c22016-03-02 19:16:45 +08004700 /**
4701 * {@hide}
4702 * Returns the IMS Registration Status on a particular subid
4703 *
4704 * @param subId
4705 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004706 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004707 Phone phone = getPhone(subId);
4708 if (phone != null) {
4709 return phone.isImsRegistered();
4710 } else {
4711 return false;
4712 }
4713 }
4714
Santos Cordon7a1885b2015-02-03 11:15:19 -08004715 @Override
4716 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 final long identity = Binder.clearCallingIdentity();
4718 try {
4719 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004723 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004724
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004725 /**
4726 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004727 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004728 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 Phone phone = getPhone(subId);
4732 if (phone != null) {
4733 return phone.isWifiCallingEnabled();
4734 } else {
4735 return false;
4736 }
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004739 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004740 }
4741
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004742 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004743 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004744 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004745 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746 final long identity = Binder.clearCallingIdentity();
4747 try {
4748 Phone phone = getPhone(subId);
4749 if (phone != null) {
4750 return phone.isVideoEnabled();
4751 } else {
4752 return false;
4753 }
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004756 }
4757 }
4758
4759 /**
4760 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4761 * defined in {@link ImsRegistrationImplBase}.
4762 */
4763 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004764 final long identity = Binder.clearCallingIdentity();
4765 try {
4766 Phone phone = getPhone(subId);
4767 if (phone != null) {
4768 return phone.getImsRegistrationTech();
4769 } else {
4770 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4771 }
4772 } finally {
4773 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004774 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004775 }
4776
Stuart Scott8eef64f2015-04-08 15:13:54 -07004777 @Override
4778 public void factoryReset(int subId) {
4779 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004780 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4781 return;
4782 }
4783
Svet Ganovcc087f82015-05-12 20:35:54 -07004784 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004785
Svet Ganovcc087f82015-05-12 20:35:54 -07004786 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004787 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4788 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004789 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004790 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004791 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004792 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4793 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004794 }
4795 } finally {
4796 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004797 }
4798 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004799
4800 @Override
4801 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802 final long identity = Binder.clearCallingIdentity();
4803 try {
4804 // We query all subscriptions instead of just the active ones, because
4805 // this might be called early on in the provisioning flow when the
4806 // subscriptions potentially aren't active yet.
4807 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4808 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004809 return null;
4810 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812 // This function may be called very early, say, from the setup wizard, at
4813 // which point we won't have a default subscription set. If that's the case
4814 // we just choose the first, which will be valid in "most cases".
4815 final int defaultSubId = getDefaultSubscription();
4816 SubscriptionInfo info = null;
4817 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4818 info = slist.get(0);
4819 } else {
4820 for (SubscriptionInfo item : slist) {
4821 if (item.getSubscriptionId() == defaultSubId) {
4822 info = item;
4823 break;
4824 }
4825 }
4826
4827 if (info == null) {
4828 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004829 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004830 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004831
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832 // Try and fetch the locale from the carrier properties or from the SIM language
4833 // preferences (EF-PL and EF-LI)...
4834 final int mcc = info.getMcc();
4835 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4836 String simLanguage = null;
4837 if (defaultPhone != null) {
4838 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4839 if (localeFromDefaultSim != null) {
4840 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4841 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4842 return localeFromDefaultSim.toLanguageTag();
4843 } else {
4844 simLanguage = localeFromDefaultSim.getLanguage();
4845 }
4846 }
4847 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004848
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 // The SIM language preferences only store a language (e.g. fr = French), not an
4850 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4851 // the SIM and carrier preferences does not include a country we add the country
4852 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004853 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 if (mccLocale != null) {
4855 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4856 return mccLocale.toLanguageTag();
4857 }
4858
4859 if (DBG) log("No locale found - returning null");
4860 return null;
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004864 }
4865
4866 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004867 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004868 }
4869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 /**
4871 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4872 */
4873 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004874 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004875 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004876
Chenjie Yu1ba97252018-01-11 18:16:20 -08004877 private final ModemActivityInfo mLastModemActivityInfo =
4878 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4879
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004880 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004881 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4882 * representing the state of the modem.
4883 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004884 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4885 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004886 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004887 */
4888 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004889 public void requestModemActivityInfo(ResultReceiver result) {
4890 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004891 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892
4893 final long identity = Binder.clearCallingIdentity();
4894 try {
4895 ModemActivityInfo ret = null;
4896 synchronized (mLastModemActivityInfo) {
4897 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4898 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004899 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004900 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004901 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4902 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004903 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
4904 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905 }
4906 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004907 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
4908 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 mLastModemActivityInfo.setIdleTimeMillis(
4910 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4911 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4912 mLastModemActivityInfo.setRxTimeMillis(
4913 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4914 mLastModemActivityInfo.setEnergyUsed(
4915 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4918 mLastModemActivityInfo.getSleepTimeMillis(),
4919 mLastModemActivityInfo.getIdleTimeMillis(),
4920 mLastModemActivityInfo.getTxTimeMillis(),
4921 mLastModemActivityInfo.getRxTimeMillis(),
4922 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 Bundle bundle = new Bundle();
4925 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4926 result.send(0, bundle);
4927 } finally {
4928 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004929 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004930 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004931
Siddharth Rayb8114062018-06-17 15:02:38 -07004932 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4933 // less than total activity duration.
4934 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4935 if (info == null) {
4936 return false;
4937 }
4938 int activityDurationMs =
4939 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4940 int totalTxTimeMs = 0;
4941 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4942 totalTxTimeMs += info.getTxTimeMillis()[i];
4943 }
4944 return (info.isValid()
4945 && (info.getSleepTimeMillis() <= activityDurationMs)
4946 && (info.getIdleTimeMillis() <= activityDurationMs)
4947 && (info.getRxTimeMillis() <= activityDurationMs)
4948 && (totalTxTimeMs <= activityDurationMs));
4949 }
4950
Jack Yu85bd38a2015-11-09 11:34:32 -08004951 /**
4952 * {@hide}
4953 * Returns the service state information on specified subscription.
4954 */
4955 @Override
4956 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004958 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004959 return null;
4960 }
4961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 final Phone phone = getPhone(subId);
4965 if (phone == null) {
4966 return null;
4967 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 return phone.getServiceState();
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004973 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004974
4975 /**
4976 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4977 *
4978 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4979 * voicemail ringtone.
4980 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4981 * PhoneAccount.
4982 */
4983 @Override
4984 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 final long identity = Binder.clearCallingIdentity();
4986 try {
4987 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4988 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004989 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004996 }
4997
4998 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004999 * Sets the per-account voicemail ringtone.
5000 *
5001 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5002 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5003 *
5004 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5005 * voicemail ringtone.
5006 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5007 * PhoneAccount.
5008 */
5009 @Override
5010 public void setVoicemailRingtoneUri(String callingPackage,
5011 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005012 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5014 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005015 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5017 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5018 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020
5021 final long identity = Binder.clearCallingIdentity();
5022 try {
5023 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5024 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005025 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 }
5027 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005030 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005031 }
5032
5033 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005034 * Returns whether vibration is set for voicemail notification in Phone settings.
5035 *
5036 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5037 * voicemail vibration setting.
5038 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5039 */
5040 @Override
5041 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 final long identity = Binder.clearCallingIdentity();
5043 try {
5044 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5045 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005046 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5050 } finally {
5051 Binder.restoreCallingIdentity(identity);
5052 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005053 }
5054
Youhan Wange64578a2016-05-02 15:32:42 -07005055 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005056 * Sets the per-account voicemail vibration.
5057 *
5058 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5059 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5060 *
5061 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5062 * voicemail vibration setting.
5063 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5064 * specific PhoneAccount.
5065 */
5066 @Override
5067 public void setVoicemailVibrationEnabled(String callingPackage,
5068 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005069 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005070 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5071 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005072 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5074 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5075 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005076 }
5077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5081 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005082 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 }
5084 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005087 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005088 }
5089
5090 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005091 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5092 *
5093 * @throws SecurityException if the caller does not have the required permission
5094 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005095 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005096 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005097 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005098 }
5099
5100 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005101 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5102 * permission.
5103 *
5104 * @throws SecurityException if the caller does not have the required permission
5105 */
5106 private void enforceSendSmsPermission() {
5107 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5108 }
5109
5110 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005111 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005112 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005113 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005114 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005115 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005119 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 if (componentName == null) {
5121 throw new SecurityException(
5122 "Caller not current active visual voicemail package[null]");
5123 }
5124 String vvmPackage = componentName.getPackageName();
5125 if (!callingPackage.equals(vvmPackage)) {
5126 throw new SecurityException("Caller not current active visual voicemail package["
5127 + vvmPackage + "]");
5128 }
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005131 }
5132 }
5133
5134 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005135 * Return the application ID for the app type.
5136 *
5137 * @param subId the subscription ID that this request applies to.
5138 * @param appType the uicc app type.
5139 * @return Application ID for specificied app type, or null if no uicc.
5140 */
5141 @Override
5142 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005143 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005144 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145
5146 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005147 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 if (phone == null) {
5149 return null;
5150 }
5151 String aid = null;
5152 try {
5153 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5154 .getApplicationByType(appType).getAid();
5155 } catch (Exception e) {
5156 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5157 }
5158 return aid;
5159 } finally {
5160 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005161 }
Youhan Wange64578a2016-05-02 15:32:42 -07005162 }
5163
Youhan Wang4001d252016-05-11 10:29:41 -07005164 /**
5165 * Return the Electronic Serial Number.
5166 *
5167 * @param subId the subscription ID that this request applies to.
5168 * @return ESN or null if error.
5169 */
5170 @Override
5171 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005172 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005173 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174
5175 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005176 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177 if (phone == null) {
5178 return null;
5179 }
5180 String esn = null;
5181 try {
5182 esn = phone.getEsn();
5183 } catch (Exception e) {
5184 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5185 }
5186 return esn;
5187 } finally {
5188 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005189 }
Youhan Wang4001d252016-05-11 10:29:41 -07005190 }
5191
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005192 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005193 * Return the Preferred Roaming List Version.
5194 *
5195 * @param subId the subscription ID that this request applies to.
5196 * @return PRLVersion or null if error.
5197 */
5198 @Override
5199 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005200 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005201 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202
5203 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005204 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 if (phone == null) {
5206 return null;
5207 }
5208 String cdmaPrlVersion = null;
5209 try {
5210 cdmaPrlVersion = phone.getCdmaPrlVersion();
5211 } catch (Exception e) {
5212 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5213 }
5214 return cdmaPrlVersion;
5215 } finally {
5216 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005217 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005218 }
5219
5220 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005221 * Get snapshot of Telephony histograms
5222 * @return List of Telephony histograms
5223 * @hide
5224 */
5225 @Override
5226 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5228 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229
5230 final long identity = Binder.clearCallingIdentity();
5231 try {
5232 return RIL.getTelephonyRILTimingHistograms();
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005236 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005237
5238 /**
5239 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005240 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005241 * Require system privileges. In the future we may add this to carrier APIs.
5242 *
5243 * @return The number of carriers set successfully, should match length of carriers
5244 */
5245 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005246 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005247 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005248 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005249
Meng Wang9b7c4e92017-02-17 11:41:27 -08005250 if (carriers == null) {
5251 throw new NullPointerException("carriers cannot be null");
5252 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 final long identity = Binder.clearCallingIdentity();
5255 try {
Michele85121de2018-12-19 15:25:20 -08005256 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5257 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005258 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5259 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 return retVal[0];
5261 } finally {
5262 Binder.restoreCallingIdentity(identity);
5263 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005264 }
5265
5266 /**
5267 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005268 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005269 * Require system privileges. In the future we may add this to carrier APIs.
5270 *
5271 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5272 * means all carriers are allowed.
5273 */
5274 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005275 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005276 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278
5279 final long identity = Binder.clearCallingIdentity();
5280 try {
Michele85121de2018-12-19 15:25:20 -08005281 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5282 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005283 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5284 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005288 }
5289
fionaxu59545b42016-05-25 15:53:37 -07005290 /**
5291 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5292 * @param subId the subscription ID that this action applies to.
5293 * @param enabled control enable or disable metered apns.
5294 * {@hide}
5295 */
5296 @Override
5297 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5298 enforceModifyPermission();
5299 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300
5301 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005302 if (phone == null) {
5303 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5304 return;
5305 }
5306 try {
5307 phone.carrierActionSetMeteredApnsEnabled(enabled);
5308 } catch (Exception e) {
5309 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310 } finally {
5311 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005312 }
5313 }
5314
5315 /**
5316 * Action set from carrier signalling broadcast receivers to enable/disable radio
5317 * @param subId the subscription ID that this action applies to.
5318 * @param enabled control enable or disable radio.
5319 * {@hide}
5320 */
5321 @Override
5322 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5323 enforceModifyPermission();
5324 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325
5326 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005327 if (phone == null) {
5328 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5329 return;
5330 }
5331 try {
5332 phone.carrierActionSetRadioEnabled(enabled);
5333 } catch (Exception e) {
5334 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 } finally {
5336 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005337 }
5338 }
5339
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005340 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005341 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5342 * network status based on which carrier apps could apply actions accordingly,
5343 * enable/disable default url handler for example.
5344 *
5345 * @param subId the subscription ID that this action applies to.
5346 * @param report control start/stop reporting the default network status.
5347 * {@hide}
5348 */
5349 @Override
5350 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5351 enforceModifyPermission();
5352 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353
5354 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005355 if (phone == null) {
5356 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5357 return;
5358 }
5359 try {
5360 phone.carrierActionReportDefaultNetworkStatus(report);
5361 } catch (Exception e) {
5362 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 } finally {
5364 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005365 }
5366 }
5367
5368 /**
fionaxud9622282017-07-17 17:51:30 -07005369 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5370 * @param subId the subscription ID that this action applies to.
5371 * {@hide}
5372 */
5373 @Override
5374 public void carrierActionResetAll(int subId) {
5375 enforceModifyPermission();
5376 final Phone phone = getPhone(subId);
5377 if (phone == null) {
5378 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5379 return;
5380 }
5381 try {
5382 phone.carrierActionResetAll();
5383 } catch (Exception e) {
5384 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5385 }
5386 }
5387
5388 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005389 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5390 * bug report is being generated.
5391 */
5392 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005393 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005394 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5395 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005396 writer.println("Permission Denial: can't dump Phone from pid="
5397 + Binder.getCallingPid()
5398 + ", uid=" + Binder.getCallingUid()
5399 + "without permission "
5400 + android.Manifest.permission.DUMP);
5401 return;
5402 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005403 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005404 }
Jack Yueb89b242016-06-22 13:27:47 -07005405
Brad Ebingerdac2f002018-04-03 15:17:52 -07005406 @Override
5407 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5408 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5409 throws RemoteException {
5410 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5411 }
5412
Jack Yueb89b242016-06-22 13:27:47 -07005413 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005414 * Get aggregated video call data usage since boot.
5415 *
5416 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5417 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005418 * {@hide}
5419 */
5420 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005421 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005422 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5423 null);
5424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 // NetworkStatsService keeps tracking the active network interface and identity. It
5428 // records the delta with the corresponding network identity.
5429 // We just return the total video call data usage snapshot since boot.
5430 Phone phone = getPhone(subId);
5431 if (phone != null) {
5432 return phone.getVtDataUsage(perUidStats);
5433 }
5434 return null;
5435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005437 }
Jack Yueb89b242016-06-22 13:27:47 -07005438 }
Jack Yu75ab2952016-07-08 14:29:33 -07005439
5440 /**
5441 * Policy control of data connection. Usually used when data limit is passed.
5442 * @param enabled True if enabling the data, otherwise disabling.
5443 * @param subId Subscription index
5444 * {@hide}
5445 */
5446 @Override
5447 public void setPolicyDataEnabled(boolean enabled, int subId) {
5448 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449
5450 final long identity = Binder.clearCallingIdentity();
5451 try {
5452 Phone phone = getPhone(subId);
5453 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005454 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455 }
5456 } finally {
5457 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005458 }
5459 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005460
5461 /**
5462 * Get Client request stats
5463 * @return List of Client Request Stats
5464 * @hide
5465 */
5466 @Override
5467 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005469 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005470 return null;
5471 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005472 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 final long identity = Binder.clearCallingIdentity();
5475 try {
5476 if (phone != null) {
5477 return phone.getClientRequestStats();
5478 }
5479
5480 return null;
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005484 }
5485
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005486 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005487 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005488 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005489 }
Jack Yueb4124c2017-02-16 15:32:43 -08005490
5491 /**
Grace Chen70990072017-03-24 17:21:30 -07005492 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005493 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005494 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005495 * @param state State of SIM (power down, power up, pass through)
5496 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5497 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5498 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005499 *
5500 **/
5501 @Override
Grace Chen70990072017-03-24 17:21:30 -07005502 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005503 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005504 Phone phone = PhoneFactory.getPhone(slotIndex);
5505
vagdeviaf9a5b92018-08-15 16:01:53 -07005506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005511 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 }
5513 } finally {
5514 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005515 }
5516 }
Shuo Qiandd210312017-04-12 22:11:33 +00005517
Tyler Gunn65d45c22017-06-05 11:22:26 -07005518 private boolean isUssdApiAllowed(int subId) {
5519 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005520 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005521 if (configManager == null) {
5522 return false;
5523 }
5524 PersistableBundle pb = configManager.getConfigForSubId(subId);
5525 if (pb == null) {
5526 return false;
5527 }
5528 return pb.getBoolean(
5529 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5530 }
5531
Shuo Qiandd210312017-04-12 22:11:33 +00005532 /**
5533 * Check if phone is in emergency callback mode
5534 * @return true if phone is in emergency callback mode
5535 * @param subId sub id
5536 */
goneil9c5f4872017-12-05 14:07:56 -08005537 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005538 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005539 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005540 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541
5542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 if (phone != null) {
5545 return phone.isInEcm();
5546 } else {
5547 return false;
5548 }
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005551 }
5552 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005553
5554 /**
5555 * Get the current signal strength information for the given subscription.
5556 * Because this information is not updated when the device is in a low power state
5557 * it should not be relied-upon to be current.
5558 * @param subId Subscription index
5559 * @return the most recent cached signal strength info from the modem
5560 */
5561 @Override
5562 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 final long identity = Binder.clearCallingIdentity();
5564 try {
5565 Phone p = getPhone(subId);
5566 if (p == null) {
5567 return null;
5568 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 return p.getSignalStrength();
5571 } finally {
5572 Binder.restoreCallingIdentity(identity);
5573 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005574 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005575
Pengquan Meng77b7f132018-08-22 14:49:57 -07005576 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005577 * Get the current modem radio state for the given slot.
5578 * @param slotIndex slot index.
5579 * @param callingPackage the name of the package making the call.
5580 * @return the current radio power state from the modem
5581 */
5582 @Override
5583 public int getRadioPowerState(int slotIndex, String callingPackage) {
5584 Phone phone = PhoneFactory.getPhone(slotIndex);
5585 if (phone != null) {
5586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5587 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5588 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5589 }
5590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 return phone.getRadioPowerState();
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
5597 }
5598 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5599 }
5600
5601 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005602 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5603 *
5604 * <p>Requires one of the following permissions:
5605 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5606 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5607 * privileges.
5608 *
5609 * @param subId subscription id
5610 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5611 * {@code false}.
5612 */
5613 @Override
5614 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005615 boolean isEnabled = false;
5616 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005617 try {
5618 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005619 null /* message */);
5620 Phone phone = getPhone(subId);
5621 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005622 } catch (Exception e) {
5623 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5624 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005625 } finally {
5626 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005627 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005628 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005629 }
5630
5631
5632 /**
5633 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5634 *
5635 * <p> Requires permission:
5636 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5637 * privileges.
5638 *
5639 * @param subId subscription id
5640 * @param isEnabled {@code true} means enable, {@code false} means disable.
5641 */
5642 @Override
5643 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5647 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005648
Pengquan Menga1bb6272018-09-06 09:59:22 -07005649 Phone phone = getPhone(subId);
5650 if (phone != null) {
5651 phone.setDataRoamingEnabled(isEnabled);
5652 }
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005655 }
5656 }
5657
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005658 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005659 public boolean isManualNetworkSelectionAllowed(int subId) {
5660 boolean isAllowed = true;
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5664 mApp, subId, "isManualNetworkSelectionAllowed");
5665 Phone phone = getPhone(subId);
5666 if (phone != null) {
5667 isAllowed = phone.isCspPlmnEnabled();
5668 }
5669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
5672 return isAllowed;
5673 }
5674
5675 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005676 public UiccCardInfo[] getUiccCardsInfo() {
5677 enforceReadPrivilegedPermission("getUiccCardsInfo");
5678
5679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5682 return cards.toArray(new UiccCardInfo[cards.size()]);
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
5686 }
5687
5688 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005689 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005690 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 final long identity = Binder.clearCallingIdentity();
5693 try {
5694 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5695 if (slots == null) {
5696 Rlog.i(LOG_TAG, "slots is null.");
5697 return null;
5698 }
5699
5700 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5701 for (int i = 0; i < slots.length; i++) {
5702 UiccSlot slot = slots[i];
5703 if (slot == null) {
5704 continue;
5705 }
5706
5707 String cardId;
5708 UiccCard card = slot.getUiccCard();
5709 if (card != null) {
5710 cardId = card.getCardId();
5711 } else {
5712 cardId = slot.getIccId();
5713 }
5714
5715 int cardState = 0;
5716 switch (slot.getCardState()) {
5717 case CARDSTATE_ABSENT:
5718 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5719 break;
5720 case CARDSTATE_PRESENT:
5721 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5722 break;
5723 case CARDSTATE_ERROR:
5724 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5725 break;
5726 case CARDSTATE_RESTRICTED:
5727 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5728 break;
5729 default:
5730 break;
5731
5732 }
5733
5734 infos[i] = new UiccSlotInfo(
5735 slot.isActive(),
5736 slot.isEuicc(),
5737 cardId,
5738 cardState,
5739 slot.getPhoneId(),
5740 slot.isExtendedApduSupported());
5741 }
5742 return infos;
5743 } finally {
5744 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005745 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005746 }
5747
5748 @Override
5749 public boolean switchSlots(int[] physicalSlots) {
5750 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751
5752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005758 }
Jack Yu4c988042018-02-27 15:30:01 -08005759
5760 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005761 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5763 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5764 return TelephonyManager.INVALID_CARD_ID;
5765 }
5766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 return UiccController.getInstance().getCardIdForDefaultEuicc();
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
5773 }
5774
5775 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005776 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5777 enforceModifyPermission();
5778 final Phone phone = getPhone(subId);
5779 if (phone == null) {
5780 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5781 return;
5782 }
5783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 final long identity = Binder.clearCallingIdentity();
5785 try {
5786 phone.setRadioIndicationUpdateMode(filters, mode);
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
5789 }
Jack Yu4c988042018-02-27 15:30:01 -08005790 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005791
5792 /**
goneil47ffb6e2018-04-06 15:40:58 -07005793 * A test API to reload the UICC profile.
5794 *
5795 * <p>Requires that the calling app has permission
5796 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5797 * @hide
5798 */
5799 @Override
5800 public void refreshUiccProfile(int subId) {
5801 enforceModifyPermission();
5802
5803 final long identity = Binder.clearCallingIdentity();
5804 try {
5805 Phone phone = getPhone(subId);
5806 if (phone == null) {
5807 return;
5808 }
5809 UiccCard uiccCard = phone.getUiccCard();
5810 if (uiccCard == null) {
5811 return;
5812 }
5813 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5814 if (uiccProfile == null) {
5815 return;
5816 }
5817 uiccProfile.refresh();
5818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
5821 }
5822
5823 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005824 * Returns false if the mobile data is disabled by default, otherwise return true.
5825 */
5826 private boolean getDefaultDataEnabled() {
5827 return "true".equalsIgnoreCase(
5828 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5829 }
5830
5831 /**
5832 * Returns true if the data roaming is enabled by default, i.e the system property
5833 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5834 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5835 */
5836 private boolean getDefaultDataRoamingEnabled(int subId) {
5837 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005838 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005839 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5840 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5841 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5842 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5843 return isDataRoamingEnabled;
5844 }
5845
5846 /**
5847 * Returns the default network type for the given {@code subId}, if the default network type is
5848 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5849 */
5850 private int getDefaultNetworkType(int subId) {
5851 return Integer.parseInt(
5852 TelephonyManager.getTelephonyProperty(
5853 mSubscriptionController.getPhoneId(subId),
5854 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5855 String.valueOf(Phone.PREFERRED_NT_MODE)));
5856 }
fionaxua13278b2018-03-21 00:08:13 -07005857
5858 @Override
5859 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5860 gid1, String gid2, String plmn, String spn) {
5861 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862
5863 final long identity = Binder.clearCallingIdentity();
5864 try {
5865 final Phone phone = getPhone(subId);
5866 if (phone == null) {
5867 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5868 return;
5869 }
5870 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5871 } finally {
5872 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005873 }
fionaxua13278b2018-03-21 00:08:13 -07005874 }
5875
5876 @Override
5877 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005878 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879
5880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 final Phone phone = getPhone(subId);
5883 if (phone == null) {
5884 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5885 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5886 }
5887 return phone.getCarrierIdListVersion();
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005890 }
fionaxua13278b2018-03-21 00:08:13 -07005891 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005892
5893 @Override
5894 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5896 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5897 return -1;
5898 }
5899
5900 final long identity = Binder.clearCallingIdentity();
5901 try {
5902 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
5906 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005907
5908 @Override
5909 public int getCdmaRoamingMode(int subId) {
5910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5911 mApp, subId, "getCdmaRoamingMode");
5912
5913 final long identity = Binder.clearCallingIdentity();
5914 try {
5915 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5916 } finally {
5917 Binder.restoreCallingIdentity(identity);
5918 }
5919 }
5920
5921 @Override
5922 public boolean setCdmaRoamingMode(int subId, int mode) {
5923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5924 mApp, subId, "setCdmaRoamingMode");
5925
5926 final long identity = Binder.clearCallingIdentity();
5927 try {
5928 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5929 } finally {
5930 Binder.restoreCallingIdentity(identity);
5931 }
5932 }
5933
5934 @Override
5935 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5937 mApp, subId, "setCdmaSubscriptionMode");
5938
5939 final long identity = Binder.clearCallingIdentity();
5940 try {
5941 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
5945 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005946
5947 private void ensureUserRunning(int userId) {
5948 if (!mUserManager.isUserRunning(userId)) {
5949 throw new IllegalStateException("User " + userId + " does not exist or not running");
5950 }
5951 }
5952
5953 /**
5954 * Returns a list of SMS apps on a given user.
5955 *
5956 * Only the shell user (UID 2000 or 0) can call it.
5957 * Target user must be running.
5958 */
5959 @Override
5960 public String[] getSmsApps(int userId) {
5961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5962 ensureUserRunning(userId);
5963
5964 final Collection<SmsApplicationData> apps =
5965 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5966
5967 String[] ret = new String[apps.size()];
5968 int i = 0;
5969 for (SmsApplicationData app : apps) {
5970 ret[i++] = app.mPackageName;
5971 }
5972 return ret;
5973 }
5974
5975 /**
5976 * Returns the default SMS app package name on a given user.
5977 *
5978 * Only the shell user (UID 2000 or 0) can call it.
5979 * Target user must be running.
5980 */
5981 @Override
5982 public String getDefaultSmsApp(int userId) {
5983 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5984 ensureUserRunning(userId);
5985
5986 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5987 /* updateIfNeeded= */ true, userId);
5988 return cn == null ? null : cn.getPackageName();
5989 }
5990
5991 /**
5992 * Set a package as the default SMS app on a given user.
5993 *
5994 * Only the shell user (UID 2000 or 0) can call it.
5995 * Target user must be running.
5996 */
5997 @Override
5998 public void setDefaultSmsApp(int userId, String packageName) {
5999 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6000 ensureUserRunning(userId);
6001
6002 boolean found = false;
6003 for (String pkg : getSmsApps(userId)) {
6004 if (TextUtils.equals(packageName, pkg)) {
6005 found = true;
6006 break;
6007 }
6008 }
6009 if (!found) {
6010 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6011 }
6012
6013 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6014 }
sqianc5eccab2018-10-19 18:46:41 -07006015
6016 @Override
6017 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6018 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6020 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6021 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6022 }
6023 final long identity = Binder.clearCallingIdentity();
6024 try {
sqian854d44b2018-12-12 16:48:18 -08006025 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6026 for (Phone phone: PhoneFactory.getPhones()) {
6027 if (phone.getEmergencyNumberTracker() != null
6028 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6029 emergencyNumberListInternal.put(
6030 phone.getSubId(),
6031 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6032 }
sqian11b7a0e2018-12-05 18:48:28 -08006033 }
sqian854d44b2018-12-12 16:48:18 -08006034 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
sqianc5eccab2018-10-19 18:46:41 -07006038 }
6039
6040 @Override
sqian11b7a0e2018-12-05 18:48:28 -08006041 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006042 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006043 if (!exactMatch) {
6044 TelephonyPermissions
6045 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006046 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006047 }
6048 final long identity = Binder.clearCallingIdentity();
6049 try {
sqian854d44b2018-12-12 16:48:18 -08006050 for (Phone phone: PhoneFactory.getPhones()) {
6051 if (phone.getEmergencyNumberTracker() != null
6052 && phone.getEmergencyNumberTracker() != null) {
6053 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6054 number, exactMatch)) {
6055 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006056 }
6057 }
sqian11b7a0e2018-12-05 18:48:28 -08006058 }
6059 return false;
6060 } finally {
6061 Binder.restoreCallingIdentity(identity);
6062 }
6063 }
6064
chen xud6b45bd2018-10-30 22:27:10 -07006065 @Override
6066 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6067 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6068 Phone phone = getPhone(subId);
6069 if (phone == null) {
6070 return null;
6071 }
6072 final long identity = Binder.clearCallingIdentity();
6073 try {
6074 UiccProfile profile = UiccController.getInstance()
6075 .getUiccProfileForPhone(phone.getPhoneId());
6076 if (profile != null) {
6077 return profile.getCertsFromCarrierPrivilegeAccessRules();
6078 }
6079 } finally {
6080 Binder.restoreCallingIdentity(identity);
6081 }
6082 return null;
6083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006084}