blob: 8a4c3d3e520dba6eeb70f13348382acf425cfa48 [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 Yu311536f2018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080087import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-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 Ebinger4c460712018-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 Ebinger4c460712018-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 xu02581692018-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 Chenf144d942018-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;
sqian2fff4a32018-11-05 14:18:37 -0800129import 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;
sqian2fff4a32018-11-05 14:18:37 -0800154import java.util.Collection;
sqian03bca152018-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 xu1cc0abe2018-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 Meng0c05b502018-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 xu1cc0abe2018-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 Chenf144d942018-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
vagdevie435a3e2018-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
vagdevie435a3e2018-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 }
vagdevie435a3e2018-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 Bakhshi2f2cc692018-12-11 15:15:39 -0800371 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
373 switch (msg.what) {
Pengquan Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-09-06 09:59:22 -0700389 request.result = true;
390 notifyRequester(request);
391 return;
392 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700393
Pengquan Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Bakhshi2f2cc692018-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 Meng0c05b502018-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 Bakhshi2f2cc692018-12-11 15:15:39 -0800653 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-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 Bakhshi2f2cc692018-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 xu1cc0abe2018-10-26 17:39:23 -0700671 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800672 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700673 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800674 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800675 break;
676
chen xu1cc0abe2018-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 Meng0c05b502018-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 Bakhshi2f2cc692018-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 Meng0c05b502018-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 Meng0c05b502018-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 Mengdd9ac822018-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 Bakhshi2f2cc692018-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 Meng0c05b502018-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 Bakhshi2f2cc692018-12-11 15:15:39 -0800844 defaultPhone.setAllowedCarriers(
Meng Wang1a7c35a2016-05-05 20:56:15 -0700845 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-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 Meng0c05b502018-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 Bakhshi2f2cc692018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 Meng0c05b502018-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 xu1cc0abe2018-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 Bakhshi2f2cc692018-12-11 15:15:39 -08001081 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001082 break;
chen xu1cc0abe2018-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 Meng0c05b502018-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 Meng0c05b502018-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);
vagdevie435a3e2018-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);
vagdevie435a3e2018-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 Bakhshi2f2cc692018-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 Bakhshi2f2cc692018-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 Bakhshi2f2cc692018-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();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001250 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001251 mTelephonySharedPreferences =
1252 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001253 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-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 Bakhshi2f2cc692018-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 Bakhshi2f2cc692018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08001349 if (!isValid) {
1350 return;
1351 }
Wink Saville08874612014-08-31 19:19:58 -07001352
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08001627 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001628 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Yu7a030e52018-12-13 11:51:28 -08001694 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Yu7a030e52018-12-13 11:51:28 -08001714 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08001726 final long identity = Binder.clearCallingIdentity();
1727 try {
1728 final Phone phone = getPhone(subId);
1729 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001730 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Bakhshi2f2cc692018-12-11 15:15:39 -08001820 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001821 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Bakhshi2f2cc692018-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 Bakhshi2f2cc692018-12-11 15:15:39 -08001972 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001973 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-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 Chend965c8b2018-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 Chend965c8b2018-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 Bakhshi2f2cc692018-12-11 15:15:39 -08002015 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002016 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-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 Chend965c8b2018-02-28 15:00:40 -08002032
2033 final long identity = Binder.clearCallingIdentity();
2034 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002035 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-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();
2048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2049 mApp, subId, callingPackage, "getImeiForSlot")) {
2050 return null;
2051 }
Malcolm Chend965c8b2018-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 Bakhshi2f2cc692018-12-11 15:15:39 -08002078
Jeff Davidson913390f2018-02-23 17:11:49 -08002079 int subId = phone.getSubId();
2080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2081 mApp, subId, callingPackage, "getMeidForSlot")) {
2082 return null;
2083 }
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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
calvinpaneed9ae82018-11-01 19:43:06 +08002146 @Override
chen xuc93cc282018-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 xu02581692018-11-11 19:03:44 -08002169 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002170 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2171 if (!isSubscriptionMccMnc) {
2172 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2173 }
chen xu02581692018-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 Bakhshi2f2cc692018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08002346
2347 final long identity = Binder.clearCallingIdentity();
2348 try {
2349 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002350 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002351 return phone.getLine1Number();
2352 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002353 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08002410 final long identity = Binder.clearCallingIdentity();
2411 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002412 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Bakhshi2f2cc692018-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 Chend965c8b2018-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 Bakhshi2f2cc692018-12-11 15:15:39 -08002449 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08002462
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002463 final long identity = Binder.clearCallingIdentity();
2464 try {
Nazanin Bakhshi2f2cc692018-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 Chend965c8b2018-02-28 15:00:40 -08002475
2476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002479 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002492 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-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 Chend965c8b2018-02-28 15:00:40 -08002502
2503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002506 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-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 Ebinger4c460712018-10-01 10:40:55 -07002514 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002515
2516 final long identity = Binder.clearCallingIdentity();
2517 try {
2518 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002519 mApp, subId);
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Ebinger4c460712018-10-01 10:40:55 -07002594 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002595
fionaxu0152e512016-11-14 13:36:14 -08002596 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-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 Ebinger4c460712018-10-01 10:40:55 -07002614 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002615
fionaxu0152e512016-11-14 13:36:14 -08002616 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Chend965c8b2018-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 Bakhshi2f2cc692018-12-11 15:15:39 -08002673 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002674 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-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 Chend965c8b2018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002684 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-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 Chend965c8b2018-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 Meng0c05b502018-09-06 09:59:22 -07002711 @Override
2712 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002713 if (!isActiveSubscription(subId)) {
2714 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2715 }
2716
Pengquan Meng0c05b502018-09-06 09:59:22 -07002717 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2718 }
2719
Brad Ebinger4c460712018-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 Ebinger4c460712018-10-01 10:40:55 -07002724 final long token = Binder.clearCallingIdentity();
2725 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002726 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002727 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-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 Ebinger4ae57f92019-01-09 16:51:30 -08002737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2738 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2739 }
2740 Binder.withCleanCallingIdentity(() -> {
2741 try {
2742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002743 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002744 .removeRegistrationCallbackForSubscription(c, subId);
2745 } catch (IllegalArgumentException e) {
2746 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2747 + "is inactive, ignoring unregister.");
2748 // If the subscription is no longer active, just return, since the callback
2749 // will already have been removed internally.
2750 }
2751 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002752 }
2753
2754 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002755 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2756 throws RemoteException {
2757 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2759 final long token = Binder.clearCallingIdentity();
2760 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002761 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002762 .addCapabilitiesCallbackForSubscription(c, subId);
2763 } finally {
2764 Binder.restoreCallingIdentity(token);
2765 }
2766 }
2767
2768 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002769 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2770 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002771
2772 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2773 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2774 }
2775 Binder.withCleanCallingIdentity(() -> {
2776 try {
2777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002778 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002779 .removeCapabilitiesCallbackForSubscription(c, subId);
2780 } catch (IllegalArgumentException e) {
2781 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2782 + "is inactive, ignoring unregister.");
2783 // If the subscription is no longer active, just return, since the callback
2784 // will already have been removed internally.
2785 }
2786 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002787 }
2788
2789 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002790 public boolean isCapable(int subId, int capability, int regTech) {
2791 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2793 final long token = Binder.clearCallingIdentity();
2794 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002795 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002796 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2797 } catch (ImsException e) {
2798 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2799 return false;
2800 } finally {
2801 Binder.restoreCallingIdentity(token);
2802 }
2803 }
2804
2805 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002806 public boolean isAvailable(int subId, int capability, int regTech) {
2807 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002808 final long token = Binder.clearCallingIdentity();
2809 try {
2810 Phone phone = getPhone(subId);
2811 if (phone == null) return false;
2812 return phone.isImsCapabilityAvailable(capability, regTech);
2813 } finally {
2814 Binder.restoreCallingIdentity(token);
2815 }
2816 }
2817
2818 @Override
2819 public boolean isAdvancedCallingSettingEnabled(int subId) {
2820 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2822 final long token = Binder.clearCallingIdentity();
2823 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002824 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002825 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2826 } finally {
2827 Binder.restoreCallingIdentity(token);
2828 }
2829 }
2830
2831 @Override
2832 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2834 "setAdvancedCallingSetting");
2835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002838 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002839 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
2842 }
2843 }
2844
2845 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002846 public boolean isVtSettingEnabled(int subId) {
2847 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002851 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002852 getSlotIndexOrException(subId)).isVtEnabledByUser();
2853 } finally {
2854 Binder.restoreCallingIdentity(identity);
2855 }
2856 }
2857
2858 @Override
2859 public void setVtSetting(int subId, boolean isEnabled) {
2860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2861 "setVtSetting");
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002865 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002866 } finally {
2867 Binder.restoreCallingIdentity(identity);
2868 }
2869 }
2870
2871 @Override
2872 public boolean isVoWiFiSettingEnabled(int subId) {
2873 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002877 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002878 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
2881 }
2882 }
2883
2884 @Override
2885 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2887 "setVoWiFiSetting");
2888 final long identity = Binder.clearCallingIdentity();
2889 try {
2890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002891 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002892 } finally {
2893 Binder.restoreCallingIdentity(identity);
2894 }
2895 }
2896
2897 @Override
2898 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2899 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002903 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002904 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
2907 }
2908 }
2909
2910 @Override
2911 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2913 "setVoWiFiRoamingSetting");
2914 final long identity = Binder.clearCallingIdentity();
2915 try {
2916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002917 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002918 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2919 } finally {
2920 Binder.restoreCallingIdentity(identity);
2921 }
2922 }
2923
2924 @Override
2925 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2927 "setVoWiFiNonPersistent");
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002931 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002932 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
2935 }
2936 }
2937
2938 @Override
2939 public int getVoWiFiModeSetting(int subId) {
2940 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2941 final long identity = Binder.clearCallingIdentity();
2942 try {
2943 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002944 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002945 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
2948 }
2949 }
2950
2951 @Override
2952 public void setVoWiFiModeSetting(int subId, int mode) {
2953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2954 "setVoWiFiModeSetting");
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002958 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002959 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2960 } finally {
2961 Binder.restoreCallingIdentity(identity);
2962 }
2963 }
2964
2965 @Override
2966 public int getVoWiFiRoamingModeSetting(int subId) {
2967 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002971 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002972 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
2975 }
2976 }
2977
2978 @Override
2979 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2981 "setVoWiFiRoamingModeSetting");
2982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002985 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002986 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
2990 }
2991
2992 @Override
2993 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2995 "setRttCapabilityEnabled");
2996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002999 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003000 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
3004 }
3005
3006 @Override
3007 public boolean isTtyOverVolteEnabled(int subId) {
3008 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003012 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003013 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
3016 }
3017 }
3018
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003019 @Override
3020 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3021 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003025 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003026 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003027 } finally {
3028 Binder.restoreCallingIdentity(identity);
3029 }
3030 }
3031
3032 @Override
3033 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3034 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3035 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003036 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3037 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3038 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003039 try {
3040 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003041 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003042 .removeProvisioningCallbackForSubscription(callback, subId);
3043 } catch (IllegalArgumentException e) {
3044 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3045 + "is inactive, ignoring unregister.");
3046 // If the subscription is no longer active, just return, since the callback will already
3047 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
3051 }
3052
3053 @Override
3054 public int getImsProvisioningInt(int subId, int key) {
3055 enforceReadPrivilegedPermission("getImsProvisioningInt");
3056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003059 return ImsManager.getInstance(mApp,
3060 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003061 } catch (ImsException e) {
3062 throw new IllegalArgumentException(e.getMessage());
3063 } finally {
3064 Binder.restoreCallingIdentity(identity);
3065 }
3066 }
3067
3068 @Override
3069 public String getImsProvisioningString(int subId, int key) {
3070 enforceReadPrivilegedPermission("getImsProvisioningString");
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003074 return ImsManager.getInstance(mApp,
3075 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003076 } catch (ImsException e) {
3077 throw new IllegalArgumentException(e.getMessage());
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
3081 }
3082
3083 @Override
3084 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3086 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003090 return ImsManager.getInstance(mApp,
3091 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003092 } catch (ImsException e) {
3093 throw new IllegalArgumentException(e.getMessage());
3094 } finally {
3095 Binder.restoreCallingIdentity(identity);
3096 }
3097 }
3098
3099 @Override
3100 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3102 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003106 return ImsManager.getInstance(mApp,
3107 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003108 } catch (ImsException e) {
3109 throw new IllegalArgumentException(e.getMessage());
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
3113 }
3114
Brad Ebinger4c460712018-10-01 10:40:55 -07003115 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3116 int slotId = SubscriptionManager.getSlotIndex(subId);
3117 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3118 throw new IllegalArgumentException("Invalid Subscription Id.");
3119 }
3120 return slotId;
3121 }
3122
Wink Saville36469e72014-06-11 15:17:00 -07003123 /**
3124 * Returns the network type for a subId
3125 */
3126 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003127 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003129 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003130 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3131 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003132
Malcolm Chend965c8b2018-02-28 15:00:40 -08003133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 final Phone phone = getPhone(subId);
3136 if (phone != null) {
3137 return phone.getServiceState().getDataNetworkType();
3138 } else {
3139 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3140 }
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 }
3145
3146 /**
3147 * Returns the data network type
3148 */
3149 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003150 public int getDataNetworkType(String callingPackage) {
3151 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003152 }
3153
3154 /**
3155 * Returns the data network type for a subId
3156 */
3157 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003158 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003160 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003161 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3162 }
3163
Malcolm Chend965c8b2018-02-28 15:00:40 -08003164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 final Phone phone = getPhone(subId);
3167 if (phone != null) {
3168 return phone.getServiceState().getDataNetworkType();
3169 } else {
3170 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3171 }
3172 } finally {
3173 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003175 }
3176
3177 /**
Wink Saville36469e72014-06-11 15:17:00 -07003178 * Returns the Voice network type for a subId
3179 */
3180 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003181 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003183 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003184 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3185 }
3186
Malcolm Chend965c8b2018-02-28 15:00:40 -08003187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 final Phone phone = getPhone(subId);
3190 if (phone != null) {
3191 return phone.getServiceState().getVoiceNetworkType();
3192 } else {
3193 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3194 }
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 }
3199
3200 /**
3201 * @return true if a ICC card is present
3202 */
3203 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003204 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003205 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3206 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003207 }
3208
3209 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003210 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003211 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003213 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 final Phone phone = PhoneFactory.getPhone(slotIndex);
3217 if (phone != null) {
3218 return phone.getIccCard().hasIccCard();
3219 } else {
3220 return false;
3221 }
3222 } finally {
3223 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003225 }
3226
3227 /**
3228 * Return if the current radio is LTE on CDMA. This
3229 * is a tri-state return value as for a period of time
3230 * the mode may be unknown.
3231 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003232 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003233 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003234 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003236 @Override
3237 public int getLteOnCdmaMode(String callingPackage) {
3238 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003239 }
3240
Sanket Padawe356d7632015-06-22 14:03:32 -07003241 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003242 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003244 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003245 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3246 }
3247
Malcolm Chend965c8b2018-02-28 15:00:40 -08003248 final long identity = Binder.clearCallingIdentity();
3249 try {
3250 final Phone phone = getPhone(subId);
3251 if (phone == null) {
3252 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3253 } else {
3254 return phone.getLteOnCdmaMode();
3255 }
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003258 }
Wink Saville36469e72014-06-11 15:17:00 -07003259 }
3260
Wink Saville36469e72014-06-11 15:17:00 -07003261 /**
3262 * {@hide}
3263 * Returns Default subId, 0 in the case of single standby.
3264 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003265 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003266 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003267 }
3268
Shishir Agrawala9f32182016-04-12 12:00:16 -07003269 private int getSlotForDefaultSubscription() {
3270 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3271 }
3272
Wink Savilleb564aae2014-10-23 10:18:09 -07003273 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003274 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003276
Pengquan Meng466e2482018-09-21 15:54:48 -07003277 private boolean isActiveSubscription(int subId) {
3278 return mSubscriptionController.isActiveSubId(subId);
3279 }
3280
Ihab Awadf2177b72013-11-25 13:33:23 -08003281 /**
3282 * @see android.telephony.TelephonyManager.WifiCallingChoices
3283 */
3284 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003285 final long identity = Binder.clearCallingIdentity();
3286 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003287 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003288 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3289 getWhenToMakeWifiCallsDefaultPreference());
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003293 }
3294
3295 /**
3296 * @see android.telephony.TelephonyManager.WifiCallingChoices
3297 */
3298 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003302 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003303 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3304 } finally {
3305 Binder.restoreCallingIdentity(identity);
3306 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003307 }
3308
Sailesh Nepald1e68152013-12-12 19:08:02 -08003309 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003310 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003311 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003312 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003313
Shishir Agrawal566b7612013-10-28 14:41:00 -07003314 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003315 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3316 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3318 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003320
Malcolm Chend965c8b2018-02-28 15:00:40 -08003321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 if (TextUtils.equals(ISDR_AID, aid)) {
3324 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003325 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3326 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003327 if (bestComponent == null
3328 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3329 loge("The calling package is not allowed to access ISD-R.");
3330 throw new SecurityException(
3331 "The calling package is not allowed to access ISD-R.");
3332 }
Derek Tan740e1672017-06-27 14:56:27 -07003333 }
Derek Tan740e1672017-06-27 14:56:27 -07003334
Malcolm Chend965c8b2018-02-28 15:00:40 -08003335 if (DBG) {
3336 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3337 }
3338 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3339 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3340 if (DBG) log("iccOpenLogicalChannel: " + response);
3341 return response;
3342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003345 }
3346
3347 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003348 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3350 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003351
Malcolm Chend965c8b2018-02-28 15:00:40 -08003352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3355 if (channel < 0) {
3356 return false;
3357 }
3358 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3359 if (DBG) log("iccCloseLogicalChannel: " + success);
3360 return success;
3361 } finally {
3362 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003363 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003364 }
3365
3366 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003367 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003368 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3370 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003371
Malcolm Chend965c8b2018-02-28 15:00:40 -08003372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 if (DBG) {
3375 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3376 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3377 + p3 + " data=" + data);
3378 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003379
Malcolm Chend965c8b2018-02-28 15:00:40 -08003380 if (channel < 0) {
3381 return "";
3382 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003383
Malcolm Chend965c8b2018-02-28 15:00:40 -08003384 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3385 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3386 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003387
Malcolm Chend965c8b2018-02-28 15:00:40 -08003388 // Append the returned status code to the end of the response payload.
3389 String s = Integer.toHexString(
3390 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3391 if (response.payload != null) {
3392 s = IccUtils.bytesToHexString(response.payload) + s;
3393 }
3394 return s;
3395 } finally {
3396 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003397 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003398 }
Jake Hambye994d462014-02-03 13:10:13 -08003399
Evan Charltonc66da362014-05-16 14:06:40 -07003400 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003401 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3402 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3404 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003405 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003406
Malcolm Chend965c8b2018-02-28 15:00:40 -08003407 final long identity = Binder.clearCallingIdentity();
3408 try {
3409 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3410 && TextUtils.equals(ISDR_AID, data)) {
3411 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003412 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3413 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003414 if (bestComponent == null
3415 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3416 loge("The calling package is not allowed to select ISD-R.");
3417 throw new SecurityException(
3418 "The calling package is not allowed to select ISD-R.");
3419 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003420 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003421
Malcolm Chend965c8b2018-02-28 15:00:40 -08003422 if (DBG) {
3423 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3424 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3425 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003426
Malcolm Chend965c8b2018-02-28 15:00:40 -08003427 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3428 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3429 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003430
Malcolm Chend965c8b2018-02-28 15:00:40 -08003431 // Append the returned status code to the end of the response payload.
3432 String s = Integer.toHexString(
3433 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3434 if (response.payload != null) {
3435 s = IccUtils.bytesToHexString(response.payload) + s;
3436 }
3437 return s;
3438 } finally {
3439 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003440 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003441 }
3442
3443 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003444 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003445 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3447 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003448
Malcolm Chend965c8b2018-02-28 15:00:40 -08003449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 if (DBG) {
3452 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3453 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3454 }
3455
3456 IccIoResult response =
3457 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3458 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3459 subId);
3460
3461 if (DBG) {
3462 log("Exchange SIM_IO [R]" + response);
3463 }
3464
3465 byte[] result = null;
3466 int length = 2;
3467 if (response.payload != null) {
3468 length = 2 + response.payload.length;
3469 result = new byte[length];
3470 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3471 } else {
3472 result = new byte[length];
3473 }
3474
3475 result[length - 1] = (byte) response.sw2;
3476 result[length - 2] = (byte) response.sw1;
3477 return result;
3478 } finally {
3479 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003480 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003481 }
3482
Nathan Haroldb3014052017-01-25 15:57:32 -08003483 /**
3484 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3485 * on a particular subscription
3486 */
sqianb6e41952018-03-12 14:54:01 -07003487 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3489 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3490 return null;
3491 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003492
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 if (appType != TelephonyManager.APPTYPE_USIM
3496 && appType != TelephonyManager.APPTYPE_SIM) {
3497 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3498 return null;
3499 }
3500 Object response = sendRequest(
3501 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3502 if (response instanceof String[]) {
3503 return (String[]) response;
3504 }
3505 // Response is an Exception of some kind,
3506 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003507 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003508 } finally {
3509 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003510 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003511 }
3512
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003513 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003514 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3516 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003517
Malcolm Chend965c8b2018-02-28 15:00:40 -08003518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3521 if (response.payload == null) {
3522 return "";
3523 }
Evan Charltonc66da362014-05-16 14:06:40 -07003524
Malcolm Chend965c8b2018-02-28 15:00:40 -08003525 // Append the returned status code to the end of the response payload.
3526 String s = Integer.toHexString(
3527 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3528 s = IccUtils.bytesToHexString(response.payload) + s;
3529 return s;
3530 } finally {
3531 Binder.restoreCallingIdentity(identity);
3532 }
Evan Charltonc66da362014-05-16 14:06:40 -07003533 }
3534
Jake Hambye994d462014-02-03 13:10:13 -08003535 /**
3536 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3537 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3538 *
3539 * @param itemID the ID of the item to read
3540 * @return the NV item as a String, or null on error.
3541 */
3542 @Override
3543 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3546 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003551 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003552 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3553 return value;
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
3556 }
Jake Hambye994d462014-02-03 13:10:13 -08003557 }
3558
3559 /**
3560 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3561 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3562 *
3563 * @param itemID the ID of the item to read
3564 * @param itemValue the value to write, as a String
3565 * @return true on success; false on any failure
3566 */
3567 @Override
3568 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003569 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3571 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3576 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003577 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003578 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3579 return success;
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
3582 }
Jake Hambye994d462014-02-03 13:10:13 -08003583 }
3584
3585 /**
3586 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3587 * Used for device configuration by some CDMA operators.
3588 *
3589 * @param preferredRoamingList byte array containing the new PRL
3590 * @return true on success; false on any failure
3591 */
3592 @Override
3593 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3595 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003596
3597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3600 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3601 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3602 return success;
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
Jake Hambye994d462014-02-03 13:10:13 -08003606 }
3607
3608 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003609 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003610 * Used for device configuration by some CDMA operators.
3611 *
chen xu1cc0abe2018-10-26 17:39:23 -07003612 * @param slotIndex - device slot.
3613 *
Jake Hambye994d462014-02-03 13:10:13 -08003614 * @return true on success; false on any failure
3615 */
3616 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003617 public boolean resetModemConfig(int slotIndex) {
3618 Phone phone = PhoneFactory.getPhone(slotIndex);
3619 if (phone != null) {
3620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3621 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003622
chen xu1cc0abe2018-10-26 17:39:23 -07003623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3626 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3627 return success;
3628 } finally {
3629 Binder.restoreCallingIdentity(identity);
3630 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003631 }
chen xu1cc0abe2018-10-26 17:39:23 -07003632 return false;
3633 }
3634
3635 /**
3636 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3637 *
3638 * @param slotIndex - device slot.
3639 *
3640 * @return true on success; false on any failure
3641 */
3642 @Override
3643 public boolean rebootModem(int slotIndex) {
3644 Phone phone = PhoneFactory.getPhone(slotIndex);
3645 if (phone != null) {
3646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3647 mApp, phone.getSubId(), "rebootModem");
3648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3652 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3653 return success;
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
3657 }
3658 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003659 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003660
Svet Ganovb320e182015-04-16 12:30:10 -07003661 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003662 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003664 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003665 return new String[0];
3666 }
3667
Malcolm Chend965c8b2018-02-28 15:00:40 -08003668 final long identity = Binder.clearCallingIdentity();
3669 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003670 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003671 } finally {
3672 Binder.restoreCallingIdentity(identity);
3673 }
Wink Saville36469e72014-06-11 15:17:00 -07003674 }
3675
Brad Ebinger51f743a2017-01-23 13:50:20 -08003676 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003677 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3678 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003679 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003680 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003681 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003682
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 PhoneFactory.getImsResolver().enableIms(slotId);
3686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003689 }
3690
3691 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003692 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3693 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003694 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003695 public void disableIms(int slotId) {
3696 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003697
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 PhoneFactory.getImsResolver().disableIms(slotId);
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003704 }
3705
3706 /**
3707 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3708 * feature or {@link null} if the service is not available. If the feature is available, the
3709 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3710 */
3711 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003712 IImsServiceFeatureCallback callback) {
3713 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003714
3715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003721 }
3722
3723 /**
3724 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3725 * feature during emergency calling or {@link null} if the service is not available. If the
3726 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3727 * listener for feature updates.
3728 */
3729 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3730 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003731
3732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3735 } finally {
3736 Binder.restoreCallingIdentity(identity);
3737 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003738 }
3739
Brad Ebinger5f64b052017-12-14 14:26:15 -08003740 /**
3741 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3742 * specified.
3743 */
3744 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3745 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003746
3747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003753 }
3754
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003755 /**
3756 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3757 * specified.
3758 */
3759 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3760 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003761
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3765 } finally {
3766 Binder.restoreCallingIdentity(identity);
3767 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003768 }
3769
Brad Ebinger884c07b2018-02-15 16:17:40 -08003770 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003771 * Sets the ImsService Package Name that Telephony will bind to.
3772 *
3773 * @param slotId the slot ID that the ImsService should bind for.
3774 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3775 * ImsService is the device default ImsService.
3776 * @param packageName The package name of the application that contains the ImsService to bind
3777 * to.
3778 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3779 * @hide
3780 */
3781 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003782 int[] subIds = SubscriptionManager.getSubId(slotId);
3783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3784 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3785 "setImsService");
3786
Malcolm Chend965c8b2018-02-28 15:00:40 -08003787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3790 isCarrierImsService, packageName);
3791 } finally {
3792 Binder.restoreCallingIdentity(identity);
3793 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003794 }
3795
3796 /**
3797 * Return the ImsService configuration.
3798 *
3799 * @param slotId The slot that the ImsService is associated with.
3800 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3801 * the device default.
3802 * @return the package name of the ImsService configuration.
3803 */
3804 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003805 int[] subIds = SubscriptionManager.getSubId(slotId);
3806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3807 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3808 "getImsService");
3809
Malcolm Chend965c8b2018-02-28 15:00:40 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3813 isCarrierImsService);
3814 } finally {
3815 Binder.restoreCallingIdentity(identity);
3816 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003817 }
3818
Wink Saville36469e72014-06-11 15:17:00 -07003819 public void setImsRegistrationState(boolean registered) {
3820 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003821
3822 final long identity = Binder.clearCallingIdentity();
3823 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003824 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003825 } finally {
3826 Binder.restoreCallingIdentity(identity);
3827 }
Wink Saville36469e72014-06-11 15:17:00 -07003828 }
3829
3830 /**
Stuart Scott54788802015-03-30 13:18:01 -07003831 * Set the network selection mode to automatic.
3832 *
3833 */
3834 @Override
3835 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3837 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003838
Pengquan Meng466e2482018-09-21 15:54:48 -07003839 if (!isActiveSubscription(subId)) {
3840 return;
3841 }
3842
Malcolm Chend965c8b2018-02-28 15:00:40 -08003843 final long identity = Binder.clearCallingIdentity();
3844 try {
3845 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3846 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
3849 }
Stuart Scott54788802015-03-30 13:18:01 -07003850 }
3851
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003852 /**
3853 * Ask the radio to connect to the input network and change selection mode to manual.
3854 *
3855 * @param subId the id of the subscription.
3856 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3857 * the operator to attach to.
3858 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3859 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3860 * normal network selection next time.
3861 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003862 */
3863 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003864 public boolean setNetworkSelectionModeManual(
3865 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3867 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003868
3869 if (!isActiveSubscription(subId)) {
3870 return false;
3871 }
3872
Malcolm Chend965c8b2018-02-28 15:00:40 -08003873 final long identity = Binder.clearCallingIdentity();
3874 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003875 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003876 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003877 if (DBG) {
3878 log("setNetworkSelectionModeManual: subId: " + subId
3879 + " operator: " + operatorInfo);
3880 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003881 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
3884 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003885 }
3886
3887 /**
3888 * Scans for available networks.
3889 */
3890 @Override
3891 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3893 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003894
Pengquan Meng0c05b502018-09-06 09:59:22 -07003895 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003896 try {
3897 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003898 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003899 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003900 } finally {
3901 Binder.restoreCallingIdentity(identity);
3902 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003903 }
3904
3905 /**
yinxub1bed742017-04-17 11:45:04 -07003906 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003907 *
yinxub1bed742017-04-17 11:45:04 -07003908 * @param subId id of the subscription
3909 * @param request contains the radio access networks with bands/channels to scan
3910 * @param messenger callback messenger for scan results or errors
3911 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003912 * @return the id of the requested scan which can be used to stop the scan.
3913 */
3914 @Override
3915 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3916 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3918 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003919
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 return mNetworkScanRequestTracker.startNetworkScan(
3923 request, messenger, binder, getPhone(subId));
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
3926 }
yinxu504e1392017-04-12 16:03:22 -07003927 }
3928
3929 /**
3930 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003931 *
3932 * @param subId id of the subscription
3933 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003934 */
3935 @Override
3936 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3938 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003939
3940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
yinxu504e1392017-04-12 16:03:22 -07003946 }
3947
3948 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003949 * Get the calculated preferred network type.
3950 * Used for debugging incorrect network type.
3951 *
3952 * @return the preferred network type, defined in RILConstants.java.
3953 */
3954 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003955 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003956 final Phone defaultPhone = getDefaultPhone();
3957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3958 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003959 return RILConstants.PREFERRED_NETWORK_MODE;
3960 }
3961
Malcolm Chend965c8b2018-02-28 15:00:40 -08003962 final long identity = Binder.clearCallingIdentity();
3963 try {
3964 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003965 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003966 } finally {
3967 Binder.restoreCallingIdentity(identity);
3968 }
Junda Liu84d15a22014-07-02 11:21:04 -07003969 }
3970
3971 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003972 * Get the preferred network type.
3973 * Used for device configuration by some CDMA operators.
3974 *
3975 * @return the preferred network type, defined in RILConstants.java.
3976 */
3977 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003978 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3980 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003981
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
3984 if (DBG) log("getPreferredNetworkType");
3985 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3986 int networkType = (result != null ? result[0] : -1);
3987 if (DBG) log("getPreferredNetworkType: " + networkType);
3988 return networkType;
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003992 }
3993
3994 /**
3995 * Set the preferred network type.
3996 * Used for device configuration by some CDMA operators.
3997 *
3998 * @param networkType the preferred network type, defined in RILConstants.java.
3999 * @return true on success; false on any failure.
4000 */
4001 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004002 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4004 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004005
4006 final long identity = Binder.clearCallingIdentity();
4007 try {
4008 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4009 Boolean success = (Boolean) sendRequest(
4010 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4011 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4012 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004013 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004014 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4015 }
4016 return success;
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004019 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004020 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004021
4022 /**
Junda Liu475951f2014-11-07 16:45:03 -08004023 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004024 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004025 * tethering.
4026 *
4027 * @return 0: Not required. 1: required. 2: Not set.
4028 * @hide
4029 */
4030 @Override
4031 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004032 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004033
4034 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004035 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004036 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004037 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004038 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004039 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004040 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004041 dunRequired = 1;
4042 }
4043 return dunRequired;
4044 } finally {
4045 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004046 }
Junda Liu475951f2014-11-07 16:45:03 -08004047 }
4048
4049 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004050 * Set mobile data enabled
4051 * Used by the user through settings etc to turn on/off mobile data
4052 *
4053 * @param enable {@code true} turn turn data on, else {@code false}
4054 */
4055 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004056 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4058 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004059
4060 final long identity = Binder.clearCallingIdentity();
4061 try {
4062 int phoneId = mSubscriptionController.getPhoneId(subId);
4063 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4064 Phone phone = PhoneFactory.getPhone(phoneId);
4065 if (phone != null) {
4066 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004067 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004068 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004069 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004070 }
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004073 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004074 }
4075
4076 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004077 * Get the user enabled state of Mobile Data.
4078 *
4079 * TODO: remove and use isUserDataEnabled.
4080 * This can't be removed now because some vendor codes
4081 * calls through ITelephony directly while they should
4082 * use TelephonyManager.
4083 *
4084 * @return true on enabled
4085 */
4086 @Override
4087 public boolean getDataEnabled(int subId) {
4088 return isUserDataEnabled(subId);
4089 }
4090
4091 /**
4092 * Get whether mobile data is enabled per user setting.
4093 *
4094 * There are other factors deciding whether mobile data is actually enabled, but they are
4095 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004096 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004097 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004098 *
4099 * @return {@code true} if data is enabled else {@code false}
4100 */
4101 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004102 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004103 try {
4104 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4105 null);
4106 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4108 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004109 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004110
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 int phoneId = mSubscriptionController.getPhoneId(subId);
4114 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4115 Phone phone = PhoneFactory.getPhone(phoneId);
4116 if (phone != null) {
4117 boolean retVal = phone.isUserDataEnabled();
4118 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4119 return retVal;
4120 } else {
4121 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4122 return false;
4123 }
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004126 }
4127 }
4128
4129 /**
4130 * Get whether mobile data is enabled.
4131 *
4132 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4133 * whether mobile data is actually enabled.
4134 *
4135 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4136 *
4137 * @return {@code true} if data is enabled else {@code false}
4138 */
4139 @Override
4140 public boolean isDataEnabled(int subId) {
4141 try {
4142 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4143 null);
4144 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4146 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004147 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004148
4149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 int phoneId = mSubscriptionController.getPhoneId(subId);
4152 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4153 Phone phone = PhoneFactory.getPhone(phoneId);
4154 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004155 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004156 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4157 return retVal;
4158 } else {
4159 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4160 return false;
4161 }
4162 } finally {
4163 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004164 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004165 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004166
4167 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004168 public int getCarrierPrivilegeStatus(int subId) {
4169 final Phone phone = getPhone(subId);
4170 if (phone == null) {
4171 loge("getCarrierPrivilegeStatus: Invalid subId");
4172 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4173 }
4174 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004175 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004176 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004177 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4178 }
4179 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004180 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004181 }
Junda Liu29340342014-07-10 15:23:27 -07004182
4183 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004184 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4185 final Phone phone = getPhone(subId);
4186 if (phone == null) {
4187 loge("getCarrierPrivilegeStatus: Invalid subId");
4188 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4189 }
4190 UiccProfile profile =
4191 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4192 if (profile == null) {
4193 loge("getCarrierPrivilegeStatus: No UICC");
4194 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4195 }
4196 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4197 }
4198
4199 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004200 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004201 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004202 if (TextUtils.isEmpty(pkgName))
4203 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004204 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004205 if (card == null) {
4206 loge("checkCarrierPrivilegesForPackage: No UICC");
4207 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4208 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004209 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4210 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004211 }
4212
4213 @Override
4214 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004215 if (TextUtils.isEmpty(pkgName))
4216 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004217 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4218 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4219 UiccCard card = UiccController.getInstance().getUiccCard(i);
4220 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004221 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004222 continue;
4223 }
4224
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004225 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004226 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4227 break;
4228 }
4229 }
4230
4231 return result;
Junda Liu29340342014-07-10 15:23:27 -07004232 }
Derek Tan89e89d42014-07-08 17:00:10 -07004233
4234 @Override
Junda Liue64de782015-04-16 17:19:16 -07004235 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4236 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4237 loge("phoneId " + phoneId + " is not valid.");
4238 return null;
4239 }
4240 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004241 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004242 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004243 return null ;
4244 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004245 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004246 }
4247
Amith Yamasani6e118872016-02-19 12:53:51 -08004248 @Override
4249 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004250 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004251 List<String> privilegedPackages = new ArrayList<>();
4252 List<PackageInfo> packages = null;
4253 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4254 UiccCard card = UiccController.getInstance().getUiccCard(i);
4255 if (card == null) {
4256 // No UICC in that slot.
4257 continue;
4258 }
4259 if (card.hasCarrierPrivilegeRules()) {
4260 if (packages == null) {
4261 // Only check packages in user 0 for now
4262 packages = pm.getInstalledPackagesAsUser(
4263 PackageManager.MATCH_DISABLED_COMPONENTS
4264 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4265 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4266 }
4267 for (int p = packages.size() - 1; p >= 0; p--) {
4268 PackageInfo pkgInfo = packages.get(p);
4269 if (pkgInfo != null && pkgInfo.packageName != null
4270 && card.getCarrierPrivilegeStatus(pkgInfo)
4271 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4272 privilegedPackages.add(pkgInfo.packageName);
4273 }
4274 }
4275 }
4276 }
4277 return privilegedPackages;
4278 }
4279
Wink Savilleb564aae2014-10-23 10:18:09 -07004280 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004281 final Phone phone = getPhone(subId);
4282 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004283 if (card == null) {
4284 loge("getIccId: No UICC");
4285 return null;
4286 }
4287 String iccId = card.getIccId();
4288 if (TextUtils.isEmpty(iccId)) {
4289 loge("getIccId: ICC ID is null or empty.");
4290 return null;
4291 }
4292 return iccId;
4293 }
4294
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004295 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004296 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4297 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004298 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4299 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004300
Malcolm Chend965c8b2018-02-28 15:00:40 -08004301 final long identity = Binder.clearCallingIdentity();
4302 try {
4303 final String iccId = getIccId(subId);
4304 final Phone phone = getPhone(subId);
4305 if (phone == null) {
4306 return false;
4307 }
4308 final String subscriberId = phone.getSubscriberId();
4309
4310 if (DBG_MERGE) {
4311 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4312 + subscriberId + " to " + number);
4313 }
4314
4315 if (TextUtils.isEmpty(iccId)) {
4316 return false;
4317 }
4318
4319 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4320
4321 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4322 if (alphaTag == null) {
4323 editor.remove(alphaTagPrefKey);
4324 } else {
4325 editor.putString(alphaTagPrefKey, alphaTag);
4326 }
4327
4328 // Record both the line number and IMSI for this ICCID, since we need to
4329 // track all merged IMSIs based on line number
4330 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4331 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4332 if (number == null) {
4333 editor.remove(numberPrefKey);
4334 editor.remove(subscriberPrefKey);
4335 } else {
4336 editor.putString(numberPrefKey, number);
4337 editor.putString(subscriberPrefKey, subscriberId);
4338 }
4339
4340 editor.commit();
4341 return true;
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004344 }
Derek Tan7226c842014-07-02 17:42:23 -07004345 }
4346
4347 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004348 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004349 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004350 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004351 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004352 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004353 return null;
4354 }
Derek Tan97ebb422014-09-05 16:55:38 -07004355
Malcolm Chend965c8b2018-02-28 15:00:40 -08004356 final long identity = Binder.clearCallingIdentity();
4357 try {
4358 String iccId = getIccId(subId);
4359 if (iccId != null) {
4360 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4361 if (DBG_MERGE) {
4362 log("getLine1NumberForDisplay returning "
4363 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4364 }
4365 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004366 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004367 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4368 return null;
4369 } finally {
4370 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004371 }
Derek Tan7226c842014-07-02 17:42:23 -07004372 }
4373
4374 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004375 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004377 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004378 return null;
4379 }
Derek Tan97ebb422014-09-05 16:55:38 -07004380
Malcolm Chend965c8b2018-02-28 15:00:40 -08004381 final long identity = Binder.clearCallingIdentity();
4382 try {
4383 String iccId = getIccId(subId);
4384 if (iccId != null) {
4385 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4386 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4387 }
4388 return null;
4389 } finally {
4390 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004391 }
Derek Tan7226c842014-07-02 17:42:23 -07004392 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004393
4394 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004395 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004396 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4397 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004398 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004399 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4400 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004401 return null;
4402 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004403
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004404 final long identity = Binder.clearCallingIdentity();
4405 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004406 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004407 final TelephonyManager tele = TelephonyManager.from(context);
4408 final SubscriptionManager sub = SubscriptionManager.from(context);
4409
4410 // Figure out what subscribers are currently active
4411 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4412 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4413 // the process, where TelephonyManager was instantiated.
4414 // Otherwise AppOps check will fail.
4415
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004416 final int[] subIds = sub.getActiveSubscriptionIdList();
4417 for (int subId : subIds) {
4418 activeSubscriberIds.add(tele.getSubscriberId(subId));
4419 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004420
4421 // First pass, find a number override for an active subscriber
4422 String mergeNumber = null;
4423 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4424 for (String key : prefs.keySet()) {
4425 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4426 final String subscriberId = (String) prefs.get(key);
4427 if (activeSubscriberIds.contains(subscriberId)) {
4428 final String iccId = key.substring(
4429 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4430 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4431 mergeNumber = (String) prefs.get(numberKey);
4432 if (DBG_MERGE) {
4433 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4434 + " for active subscriber " + subscriberId);
4435 }
4436 if (!TextUtils.isEmpty(mergeNumber)) {
4437 break;
4438 }
4439 }
4440 }
4441 }
4442
4443 // Shortcut when no active merged subscribers
4444 if (TextUtils.isEmpty(mergeNumber)) {
4445 return null;
4446 }
4447
4448 // Second pass, find all subscribers under that line override
4449 final ArraySet<String> result = new ArraySet<>();
4450 for (String key : prefs.keySet()) {
4451 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4452 final String number = (String) prefs.get(key);
4453 if (mergeNumber.equals(number)) {
4454 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4455 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4456 final String subscriberId = (String) prefs.get(subscriberKey);
4457 if (!TextUtils.isEmpty(subscriberId)) {
4458 result.add(subscriberId);
4459 }
4460 }
4461 }
4462 }
4463
4464 final String[] resultArray = result.toArray(new String[result.size()]);
4465 Arrays.sort(resultArray);
4466 if (DBG_MERGE) {
4467 Slog.d(LOG_TAG,
4468 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4469 }
4470 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004473 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004474 }
4475
4476 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004477 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004478 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4479 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004480
4481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 final Phone phone = getPhone(subId);
4484 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004488 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004489
4490 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004491 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004492 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4493 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004494 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004495
4496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 final Phone phone = getPhone(subId);
4499 if (phone == null) {
4500 return false;
4501 }
4502 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4503 cdmaNonRoamingList);
4504 } finally {
4505 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004506 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004507 }
4508
4509 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004510 @Deprecated
4511 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4512 enforceModifyPermission();
4513
4514 int returnValue = 0;
4515 try {
vagdevie435a3e2018-08-15 16:01:53 -07004516 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004517 if(result.exception == null) {
4518 if (result.result != null) {
4519 byte[] responseData = (byte[])(result.result);
4520 if(responseData.length > oemResp.length) {
4521 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4522 responseData.length + "bytes. Buffer Size is " +
4523 oemResp.length + "bytes.");
4524 }
4525 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4526 returnValue = responseData.length;
4527 }
4528 } else {
4529 CommandException ex = (CommandException) result.exception;
4530 returnValue = ex.getCommandError().ordinal();
4531 if(returnValue > 0) returnValue *= -1;
4532 }
4533 } catch (RuntimeException e) {
4534 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4535 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4536 if(returnValue > 0) returnValue *= -1;
4537 }
4538
4539 return returnValue;
4540 }
4541
4542 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004543 public void setRadioCapability(RadioAccessFamily[] rafs) {
4544 try {
4545 ProxyController.getInstance().setRadioCapability(rafs);
4546 } catch (RuntimeException e) {
4547 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4548 }
4549 }
4550
4551 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004552 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004553 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004554 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004555 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004556 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004557 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004558 final long identity = Binder.clearCallingIdentity();
4559 try {
chen xufeeed752018-10-26 14:17:57 -07004560 TelephonyPermissions
4561 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4562 mApp, phone.getSubId(), "getRadioAccessFamily");
4563 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004564 } finally {
4565 Binder.restoreCallingIdentity(identity);
4566 }
chen xufeeed752018-10-26 14:17:57 -07004567 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004568 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004569
4570 @Override
4571 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004572 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004573 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004574
4575 final long identity = Binder.clearCallingIdentity();
4576 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004577 ImsManager.getInstance(defaultPhone.getContext(),
4578 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004582 }
4583
4584 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004585 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004586 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004588 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004589 return false;
4590 }
Svet Ganovb320e182015-04-16 12:30:10 -07004591
Malcolm Chend965c8b2018-02-28 15:00:40 -08004592 final long identity = Binder.clearCallingIdentity();
4593 try {
4594 // Check the user preference and the system-level IMS setting. Even if the user has
4595 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4596 // In the long run, we may instead need to check if there exists a connection service
4597 // which can support video calling.
4598 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004599 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004600 return imsManager.isVtEnabledByPlatform()
4601 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4602 && imsManager.isVtEnabledByUser();
4603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004606 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004607
Andrew Leea1239f22015-03-02 17:44:07 -08004608 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004609 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4611 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4612 return false;
4613 }
4614
4615 final long identity = Binder.clearCallingIdentity();
4616 try {
4617 CarrierConfigManager configManager =
4618 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004619 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004620 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
Andrew Leea1239f22015-03-02 17:44:07 -08004624 }
4625
4626 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004627 public boolean isWorldPhone(int subId, String callingPackage) {
4628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4629 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4630 return false;
4631 }
4632
4633 final long identity = Binder.clearCallingIdentity();
4634 try {
4635 CarrierConfigManager configManager =
4636 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004637 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004638 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
Andrew Leea1239f22015-03-02 17:44:07 -08004642 }
4643
Andrew Lee9431b832015-03-09 18:46:45 -07004644 @Override
4645 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004646 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004647 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004648 }
4649
4650 @Override
4651 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004652 final long identity = Binder.clearCallingIdentity();
4653 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004654 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
Andrew Lee9431b832015-03-09 18:46:45 -07004658 }
4659
Hall Liuf6668912018-10-31 17:05:23 -07004660 /**
4661 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4662 * support for the feature and device firmware support.
4663 *
4664 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4665 */
4666 @Override
4667 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004668 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004669 final Phone phone = getPhone(subscriptionId);
4670 if (phone == null) {
4671 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4672 return false;
4673 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004674 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004675 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004676 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4677 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004678 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004679 return isCarrierSupported && isDeviceSupported;
4680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
Hall Liu98187582018-01-22 19:15:32 -08004683 }
4684
Hall Liuf6668912018-10-31 17:05:23 -07004685 /**
4686 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4687 * both also support RTT.
4688 */
4689 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004690 final long identity = Binder.clearCallingIdentity();
4691 try {
Hall Liuf6668912018-10-31 17:05:23 -07004692 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004693 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004697 }
4698
Sanket Padawe7310cc72015-01-14 09:53:20 -08004699 /**
4700 * Returns the unique device ID of phone, for example, the IMEI for
4701 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4702 *
4703 * <p>Requires Permission:
4704 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4705 */
4706 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004707 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004708 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004709 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004710 return null;
4711 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004712 int subId = phone.getSubId();
4713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4714 mApp, subId, callingPackage, "getDeviceId")) {
4715 return null;
4716 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004717
4718 final long identity = Binder.clearCallingIdentity();
4719 try {
4720 return phone.getDeviceId();
4721 } finally {
4722 Binder.restoreCallingIdentity(identity);
4723 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004724 }
4725
Ping Sunc67b7c22016-03-02 19:16:45 +08004726 /**
4727 * {@hide}
4728 * Returns the IMS Registration Status on a particular subid
4729 *
4730 * @param subId
4731 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004732 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004733 Phone phone = getPhone(subId);
4734 if (phone != null) {
4735 return phone.isImsRegistered();
4736 } else {
4737 return false;
4738 }
4739 }
4740
Santos Cordon7a1885b2015-02-03 11:15:19 -08004741 @Override
4742 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004743 final long identity = Binder.clearCallingIdentity();
4744 try {
4745 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4746 } finally {
4747 Binder.restoreCallingIdentity(identity);
4748 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004749 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004750
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004751 /**
4752 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004753 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004754 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004755 final long identity = Binder.clearCallingIdentity();
4756 try {
4757 Phone phone = getPhone(subId);
4758 if (phone != null) {
4759 return phone.isWifiCallingEnabled();
4760 } else {
4761 return false;
4762 }
4763 } finally {
4764 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004765 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004766 }
4767
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004768 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004769 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004770 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004771 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004772 final long identity = Binder.clearCallingIdentity();
4773 try {
4774 Phone phone = getPhone(subId);
4775 if (phone != null) {
4776 return phone.isVideoEnabled();
4777 } else {
4778 return false;
4779 }
4780 } finally {
4781 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004782 }
4783 }
4784
4785 /**
4786 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4787 * defined in {@link ImsRegistrationImplBase}.
4788 */
4789 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004790 final long identity = Binder.clearCallingIdentity();
4791 try {
4792 Phone phone = getPhone(subId);
4793 if (phone != null) {
4794 return phone.getImsRegistrationTech();
4795 } else {
4796 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4797 }
4798 } finally {
4799 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004800 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004801 }
4802
Stuart Scott8eef64f2015-04-08 15:13:54 -07004803 @Override
4804 public void factoryReset(int subId) {
4805 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004806 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4807 return;
4808 }
4809
Svet Ganovcc087f82015-05-12 20:35:54 -07004810 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004811
Svet Ganovcc087f82015-05-12 20:35:54 -07004812 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004813 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4814 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004815 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004816 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004817 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004818 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4819 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004820 }
4821 } finally {
4822 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004823 }
4824 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004825
4826 @Override
4827 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004828 final long identity = Binder.clearCallingIdentity();
4829 try {
4830 // We query all subscriptions instead of just the active ones, because
4831 // this might be called early on in the provisioning flow when the
4832 // subscriptions potentially aren't active yet.
4833 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4834 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004835 return null;
4836 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004837
Malcolm Chend965c8b2018-02-28 15:00:40 -08004838 // This function may be called very early, say, from the setup wizard, at
4839 // which point we won't have a default subscription set. If that's the case
4840 // we just choose the first, which will be valid in "most cases".
4841 final int defaultSubId = getDefaultSubscription();
4842 SubscriptionInfo info = null;
4843 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4844 info = slist.get(0);
4845 } else {
4846 for (SubscriptionInfo item : slist) {
4847 if (item.getSubscriptionId() == defaultSubId) {
4848 info = item;
4849 break;
4850 }
4851 }
4852
4853 if (info == null) {
4854 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004855 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004856 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004857
Malcolm Chend965c8b2018-02-28 15:00:40 -08004858 // Try and fetch the locale from the carrier properties or from the SIM language
4859 // preferences (EF-PL and EF-LI)...
4860 final int mcc = info.getMcc();
4861 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4862 String simLanguage = null;
4863 if (defaultPhone != null) {
4864 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4865 if (localeFromDefaultSim != null) {
4866 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4867 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4868 return localeFromDefaultSim.toLanguageTag();
4869 } else {
4870 simLanguage = localeFromDefaultSim.getLanguage();
4871 }
4872 }
4873 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004874
Malcolm Chend965c8b2018-02-28 15:00:40 -08004875 // The SIM language preferences only store a language (e.g. fr = French), not an
4876 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4877 // the SIM and carrier preferences does not include a country we add the country
4878 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004879 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004880 if (mccLocale != null) {
4881 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4882 return mccLocale.toLanguageTag();
4883 }
4884
4885 if (DBG) log("No locale found - returning null");
4886 return null;
4887 } finally {
4888 Binder.restoreCallingIdentity(identity);
4889 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004890 }
4891
4892 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004893 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004894 }
4895
Malcolm Chend965c8b2018-02-28 15:00:40 -08004896 /**
4897 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4898 */
4899 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004900 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004901 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004902
Chenjie Yu1ba97252018-01-11 18:16:20 -08004903 private final ModemActivityInfo mLastModemActivityInfo =
4904 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4905
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004906 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004907 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4908 * representing the state of the modem.
4909 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004910 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4911 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004912 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004913 */
4914 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004915 public void requestModemActivityInfo(ResultReceiver result) {
4916 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004917 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004918
4919 final long identity = Binder.clearCallingIdentity();
4920 try {
4921 ModemActivityInfo ret = null;
4922 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004923 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4924 CMD_GET_MODEM_ACTIVITY_INFO,
4925 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004926 if (isModemActivityInfoValid(info)) {
4927 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4928 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4929 mergedTxTimeMs[i] =
4930 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4931 }
4932 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4933 mLastModemActivityInfo.setSleepTimeMillis(
4934 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4935 mLastModemActivityInfo.setIdleTimeMillis(
4936 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4937 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4938 mLastModemActivityInfo.setRxTimeMillis(
4939 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4940 mLastModemActivityInfo.setEnergyUsed(
4941 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004942 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004943 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4944 mLastModemActivityInfo.getSleepTimeMillis(),
4945 mLastModemActivityInfo.getIdleTimeMillis(),
4946 mLastModemActivityInfo.getTxTimeMillis(),
4947 mLastModemActivityInfo.getRxTimeMillis(),
4948 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004949 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004950 Bundle bundle = new Bundle();
4951 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4952 result.send(0, bundle);
4953 } finally {
4954 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004955 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004956 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004957
Siddharth Rayf5d29552018-06-17 15:02:38 -07004958 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4959 // less than total activity duration.
4960 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4961 if (info == null) {
4962 return false;
4963 }
4964 int activityDurationMs =
4965 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4966 int totalTxTimeMs = 0;
4967 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4968 totalTxTimeMs += info.getTxTimeMillis()[i];
4969 }
4970 return (info.isValid()
4971 && (info.getSleepTimeMillis() <= activityDurationMs)
4972 && (info.getIdleTimeMillis() <= activityDurationMs)
4973 && (info.getRxTimeMillis() <= activityDurationMs)
4974 && (totalTxTimeMs <= activityDurationMs));
4975 }
4976
Jack Yu85bd38a2015-11-09 11:34:32 -08004977 /**
4978 * {@hide}
4979 * Returns the service state information on specified subscription.
4980 */
4981 @Override
4982 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004984 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004985 return null;
4986 }
4987
Malcolm Chend965c8b2018-02-28 15:00:40 -08004988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 final Phone phone = getPhone(subId);
4991 if (phone == null) {
4992 return null;
4993 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004994
Malcolm Chend965c8b2018-02-28 15:00:40 -08004995 return phone.getServiceState();
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004999 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005000
5001 /**
5002 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5003 *
5004 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5005 * voicemail ringtone.
5006 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5007 * PhoneAccount.
5008 */
5009 @Override
5010 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005011 final long identity = Binder.clearCallingIdentity();
5012 try {
5013 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5014 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005015 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005016 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005017
Malcolm Chend965c8b2018-02-28 15:00:40 -08005018 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5019 } finally {
5020 Binder.restoreCallingIdentity(identity);
5021 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005022 }
5023
5024 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005025 * Sets the per-account voicemail ringtone.
5026 *
5027 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5028 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5029 *
5030 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5031 * voicemail ringtone.
5032 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5033 * PhoneAccount.
5034 */
5035 @Override
5036 public void setVoicemailRingtoneUri(String callingPackage,
5037 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005038 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5040 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005041 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5043 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5044 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005045 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005046
5047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5050 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005051 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005052 }
5053 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005056 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005057 }
5058
5059 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005060 * Returns whether vibration is set for voicemail notification in Phone settings.
5061 *
5062 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5063 * voicemail vibration setting.
5064 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5065 */
5066 @Override
5067 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5071 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005072 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005073 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005074
Malcolm Chend965c8b2018-02-28 15:00:40 -08005075 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5076 } finally {
5077 Binder.restoreCallingIdentity(identity);
5078 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005079 }
5080
Youhan Wange64578a2016-05-02 15:32:42 -07005081 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005082 * Sets the per-account voicemail vibration.
5083 *
5084 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5085 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5086 *
5087 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5088 * voicemail vibration setting.
5089 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5090 * specific PhoneAccount.
5091 */
5092 @Override
5093 public void setVoicemailVibrationEnabled(String callingPackage,
5094 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005095 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005096 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5097 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005098 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5100 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5101 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005102 }
5103
Malcolm Chend965c8b2018-02-28 15:00:40 -08005104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5107 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005108 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005109 }
5110 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5111 } finally {
5112 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005113 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005114 }
5115
5116 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005117 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5118 *
5119 * @throws SecurityException if the caller does not have the required permission
5120 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005121 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005122 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005123 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005124 }
5125
5126 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005127 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5128 * permission.
5129 *
5130 * @throws SecurityException if the caller does not have the required permission
5131 */
5132 private void enforceSendSmsPermission() {
5133 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5134 }
5135
5136 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005137 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005138 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005139 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005140 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005141 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005145 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005146 if (componentName == null) {
5147 throw new SecurityException(
5148 "Caller not current active visual voicemail package[null]");
5149 }
5150 String vvmPackage = componentName.getPackageName();
5151 if (!callingPackage.equals(vvmPackage)) {
5152 throw new SecurityException("Caller not current active visual voicemail package["
5153 + vvmPackage + "]");
5154 }
5155 } finally {
5156 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005157 }
5158 }
5159
5160 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005161 * Return the application ID for the app type.
5162 *
5163 * @param subId the subscription ID that this request applies to.
5164 * @param appType the uicc app type.
5165 * @return Application ID for specificied app type, or null if no uicc.
5166 */
5167 @Override
5168 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005169 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005170 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005171
5172 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005173 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005174 if (phone == null) {
5175 return null;
5176 }
5177 String aid = null;
5178 try {
5179 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5180 .getApplicationByType(appType).getAid();
5181 } catch (Exception e) {
5182 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5183 }
5184 return aid;
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005187 }
Youhan Wange64578a2016-05-02 15:32:42 -07005188 }
5189
Youhan Wang4001d252016-05-11 10:29:41 -07005190 /**
5191 * Return the Electronic Serial Number.
5192 *
5193 * @param subId the subscription ID that this request applies to.
5194 * @return ESN or null if error.
5195 */
5196 @Override
5197 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005198 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005199 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005200
5201 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005202 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005203 if (phone == null) {
5204 return null;
5205 }
5206 String esn = null;
5207 try {
5208 esn = phone.getEsn();
5209 } catch (Exception e) {
5210 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5211 }
5212 return esn;
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005215 }
Youhan Wang4001d252016-05-11 10:29:41 -07005216 }
5217
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005218 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005219 * Return the Preferred Roaming List Version.
5220 *
5221 * @param subId the subscription ID that this request applies to.
5222 * @return PRLVersion or null if error.
5223 */
5224 @Override
5225 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005226 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005227 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005228
5229 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005230 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005231 if (phone == null) {
5232 return null;
5233 }
5234 String cdmaPrlVersion = null;
5235 try {
5236 cdmaPrlVersion = phone.getCdmaPrlVersion();
5237 } catch (Exception e) {
5238 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5239 }
5240 return cdmaPrlVersion;
5241 } finally {
5242 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005243 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005244 }
5245
5246 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005247 * Get snapshot of Telephony histograms
5248 * @return List of Telephony histograms
5249 * @hide
5250 */
5251 @Override
5252 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5254 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005255
5256 final long identity = Binder.clearCallingIdentity();
5257 try {
5258 return RIL.getTelephonyRILTimingHistograms();
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005262 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005263
5264 /**
5265 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005266 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005267 * Require system privileges. In the future we may add this to carrier APIs.
5268 *
5269 * @return The number of carriers set successfully, should match length of carriers
5270 */
5271 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005272 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005273 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005275
Meng Wang9b7c4e92017-02-17 11:41:27 -08005276 if (carriers == null) {
5277 throw new NullPointerException("carriers cannot be null");
5278 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005279
Malcolm Chend965c8b2018-02-28 15:00:40 -08005280 final long identity = Binder.clearCallingIdentity();
5281 try {
Michele85121de2018-12-19 15:25:20 -08005282 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5283 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdevie435a3e2018-08-15 16:01:53 -07005284 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5285 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005286 return retVal[0];
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005290 }
5291
5292 /**
5293 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005294 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005295 * Require system privileges. In the future we may add this to carrier APIs.
5296 *
5297 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5298 * means all carriers are allowed.
5299 */
5300 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005301 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005302 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005303 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005304
5305 final long identity = Binder.clearCallingIdentity();
5306 try {
Michele85121de2018-12-19 15:25:20 -08005307 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5308 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdevie435a3e2018-08-15 16:01:53 -07005309 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5310 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005314 }
5315
fionaxu59545b42016-05-25 15:53:37 -07005316 /**
5317 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5318 * @param subId the subscription ID that this action applies to.
5319 * @param enabled control enable or disable metered apns.
5320 * {@hide}
5321 */
5322 @Override
5323 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5324 enforceModifyPermission();
5325 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005326
5327 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005328 if (phone == null) {
5329 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5330 return;
5331 }
5332 try {
5333 phone.carrierActionSetMeteredApnsEnabled(enabled);
5334 } catch (Exception e) {
5335 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005336 } finally {
5337 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005338 }
5339 }
5340
5341 /**
5342 * Action set from carrier signalling broadcast receivers to enable/disable radio
5343 * @param subId the subscription ID that this action applies to.
5344 * @param enabled control enable or disable radio.
5345 * {@hide}
5346 */
5347 @Override
5348 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5349 enforceModifyPermission();
5350 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005351
5352 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005353 if (phone == null) {
5354 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5355 return;
5356 }
5357 try {
5358 phone.carrierActionSetRadioEnabled(enabled);
5359 } catch (Exception e) {
5360 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005361 } finally {
5362 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005363 }
5364 }
5365
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005366 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005367 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5368 * network status based on which carrier apps could apply actions accordingly,
5369 * enable/disable default url handler for example.
5370 *
5371 * @param subId the subscription ID that this action applies to.
5372 * @param report control start/stop reporting the default network status.
5373 * {@hide}
5374 */
5375 @Override
5376 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5377 enforceModifyPermission();
5378 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005379
5380 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005381 if (phone == null) {
5382 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5383 return;
5384 }
5385 try {
5386 phone.carrierActionReportDefaultNetworkStatus(report);
5387 } catch (Exception e) {
5388 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005389 } finally {
5390 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005391 }
5392 }
5393
5394 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005395 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5396 * bug report is being generated.
5397 */
5398 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005399 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005400 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5401 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005402 writer.println("Permission Denial: can't dump Phone from pid="
5403 + Binder.getCallingPid()
5404 + ", uid=" + Binder.getCallingUid()
5405 + "without permission "
5406 + android.Manifest.permission.DUMP);
5407 return;
5408 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005409 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005410 }
Jack Yueb89b242016-06-22 13:27:47 -07005411
Brad Ebingerdac2f002018-04-03 15:17:52 -07005412 @Override
5413 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5414 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5415 throws RemoteException {
5416 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5417 }
5418
Jack Yueb89b242016-06-22 13:27:47 -07005419 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005420 * Get aggregated video call data usage since boot.
5421 *
5422 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5423 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005424 * {@hide}
5425 */
5426 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005427 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5429 null);
5430
Malcolm Chend965c8b2018-02-28 15:00:40 -08005431 final long identity = Binder.clearCallingIdentity();
5432 try {
5433 // NetworkStatsService keeps tracking the active network interface and identity. It
5434 // records the delta with the corresponding network identity.
5435 // We just return the total video call data usage snapshot since boot.
5436 Phone phone = getPhone(subId);
5437 if (phone != null) {
5438 return phone.getVtDataUsage(perUidStats);
5439 }
5440 return null;
5441 } finally {
5442 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005443 }
Jack Yueb89b242016-06-22 13:27:47 -07005444 }
Jack Yu75ab2952016-07-08 14:29:33 -07005445
5446 /**
5447 * Policy control of data connection. Usually used when data limit is passed.
5448 * @param enabled True if enabling the data, otherwise disabling.
5449 * @param subId Subscription index
5450 * {@hide}
5451 */
5452 @Override
5453 public void setPolicyDataEnabled(boolean enabled, int subId) {
5454 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005455
5456 final long identity = Binder.clearCallingIdentity();
5457 try {
5458 Phone phone = getPhone(subId);
5459 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005460 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005461 }
5462 } finally {
5463 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005464 }
5465 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005466
5467 /**
5468 * Get Client request stats
5469 * @return List of Client Request Stats
5470 * @hide
5471 */
5472 @Override
5473 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005475 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005476 return null;
5477 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005478 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005479
Malcolm Chend965c8b2018-02-28 15:00:40 -08005480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 if (phone != null) {
5483 return phone.getClientRequestStats();
5484 }
5485
5486 return null;
5487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005490 }
5491
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005492 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005493 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005494 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005495 }
Jack Yueb4124c2017-02-16 15:32:43 -08005496
5497 /**
Grace Chen70990072017-03-24 17:21:30 -07005498 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005499 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005500 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005501 * @param state State of SIM (power down, power up, pass through)
5502 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5503 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5504 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005505 *
5506 **/
5507 @Override
Grace Chen70990072017-03-24 17:21:30 -07005508 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005509 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005510 Phone phone = PhoneFactory.getPhone(slotIndex);
5511
vagdevie435a3e2018-08-15 16:01:53 -07005512 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5513
Malcolm Chend965c8b2018-02-28 15:00:40 -08005514 final long identity = Binder.clearCallingIdentity();
5515 try {
5516 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005517 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005518 }
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005521 }
5522 }
Shuo Qiandd210312017-04-12 22:11:33 +00005523
Tyler Gunn65d45c22017-06-05 11:22:26 -07005524 private boolean isUssdApiAllowed(int subId) {
5525 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005526 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005527 if (configManager == null) {
5528 return false;
5529 }
5530 PersistableBundle pb = configManager.getConfigForSubId(subId);
5531 if (pb == null) {
5532 return false;
5533 }
5534 return pb.getBoolean(
5535 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5536 }
5537
Shuo Qiandd210312017-04-12 22:11:33 +00005538 /**
5539 * Check if phone is in emergency callback mode
5540 * @return true if phone is in emergency callback mode
5541 * @param subId sub id
5542 */
goneil9c5f4872017-12-05 14:07:56 -08005543 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005544 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005545 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005546 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005547
5548 final long identity = Binder.clearCallingIdentity();
5549 try {
5550 if (phone != null) {
5551 return phone.isInEcm();
5552 } else {
5553 return false;
5554 }
5555 } finally {
5556 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005557 }
5558 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005559
5560 /**
5561 * Get the current signal strength information for the given subscription.
5562 * Because this information is not updated when the device is in a low power state
5563 * it should not be relied-upon to be current.
5564 * @param subId Subscription index
5565 * @return the most recent cached signal strength info from the modem
5566 */
5567 @Override
5568 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005569 final long identity = Binder.clearCallingIdentity();
5570 try {
5571 Phone p = getPhone(subId);
5572 if (p == null) {
5573 return null;
5574 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005575
Malcolm Chend965c8b2018-02-28 15:00:40 -08005576 return p.getSignalStrength();
5577 } finally {
5578 Binder.restoreCallingIdentity(identity);
5579 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005580 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005581
Pengquan Meng9140aec2018-08-22 14:49:57 -07005582 /**
chen xu907e5a22018-10-11 13:21:04 -07005583 * Get the current modem radio state for the given slot.
5584 * @param slotIndex slot index.
5585 * @param callingPackage the name of the package making the call.
5586 * @return the current radio power state from the modem
5587 */
5588 @Override
5589 public int getRadioPowerState(int slotIndex, String callingPackage) {
5590 Phone phone = PhoneFactory.getPhone(slotIndex);
5591 if (phone != null) {
5592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5593 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5594 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5595 }
5596
5597 final long identity = Binder.clearCallingIdentity();
5598 try {
5599 return phone.getRadioPowerState();
5600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
5603 }
5604 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5605 }
5606
5607 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005608 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5609 *
5610 * <p>Requires one of the following permissions:
5611 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5612 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5613 * privileges.
5614 *
5615 * @param subId subscription id
5616 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5617 * {@code false}.
5618 */
5619 @Override
5620 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005621 boolean isEnabled = false;
5622 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005623 try {
5624 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005625 null /* message */);
5626 Phone phone = getPhone(subId);
5627 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005628 } catch (Exception e) {
5629 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5630 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005631 } finally {
5632 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005633 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005634 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005635 }
5636
5637
5638 /**
5639 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5640 *
5641 * <p> Requires permission:
5642 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5643 * privileges.
5644 *
5645 * @param subId subscription id
5646 * @param isEnabled {@code true} means enable, {@code false} means disable.
5647 */
5648 @Override
5649 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005650 final long identity = Binder.clearCallingIdentity();
5651 try {
5652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5653 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005654
Pengquan Meng0c05b502018-09-06 09:59:22 -07005655 Phone phone = getPhone(subId);
5656 if (phone != null) {
5657 phone.setDataRoamingEnabled(isEnabled);
5658 }
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005661 }
5662 }
5663
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005664 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005665 public boolean isManualNetworkSelectionAllowed(int subId) {
5666 boolean isAllowed = true;
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5670 mApp, subId, "isManualNetworkSelectionAllowed");
5671 Phone phone = getPhone(subId);
5672 if (phone != null) {
5673 isAllowed = phone.isCspPlmnEnabled();
5674 }
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
5678 return isAllowed;
5679 }
5680
5681 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005682 public UiccCardInfo[] getUiccCardsInfo() {
5683 enforceReadPrivilegedPermission("getUiccCardsInfo");
5684
5685 final long identity = Binder.clearCallingIdentity();
5686 try {
5687 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5688 return cards.toArray(new UiccCardInfo[cards.size()]);
5689 } finally {
5690 Binder.restoreCallingIdentity(identity);
5691 }
5692 }
5693
5694 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005695 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005696 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005697
Malcolm Chend965c8b2018-02-28 15:00:40 -08005698 final long identity = Binder.clearCallingIdentity();
5699 try {
5700 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5701 if (slots == null) {
5702 Rlog.i(LOG_TAG, "slots is null.");
5703 return null;
5704 }
5705
5706 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5707 for (int i = 0; i < slots.length; i++) {
5708 UiccSlot slot = slots[i];
5709 if (slot == null) {
5710 continue;
5711 }
5712
5713 String cardId;
5714 UiccCard card = slot.getUiccCard();
5715 if (card != null) {
5716 cardId = card.getCardId();
5717 } else {
5718 cardId = slot.getIccId();
5719 }
5720
5721 int cardState = 0;
5722 switch (slot.getCardState()) {
5723 case CARDSTATE_ABSENT:
5724 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5725 break;
5726 case CARDSTATE_PRESENT:
5727 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5728 break;
5729 case CARDSTATE_ERROR:
5730 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5731 break;
5732 case CARDSTATE_RESTRICTED:
5733 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5734 break;
5735 default:
5736 break;
5737
5738 }
5739
5740 infos[i] = new UiccSlotInfo(
5741 slot.isActive(),
5742 slot.isEuicc(),
5743 cardId,
5744 cardState,
5745 slot.getPhoneId(),
5746 slot.isExtendedApduSupported());
5747 }
5748 return infos;
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005751 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005752 }
5753
5754 @Override
5755 public boolean switchSlots(int[] physicalSlots) {
5756 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005757
5758 final long identity = Binder.clearCallingIdentity();
5759 try {
5760 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5761 } finally {
5762 Binder.restoreCallingIdentity(identity);
5763 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005764 }
Jack Yu4c988042018-02-27 15:30:01 -08005765
5766 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005767 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5769 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5770 return TelephonyManager.INVALID_CARD_ID;
5771 }
5772
5773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 return UiccController.getInstance().getCardIdForDefaultEuicc();
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
5779 }
5780
5781 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005782 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5783 enforceModifyPermission();
5784 final Phone phone = getPhone(subId);
5785 if (phone == null) {
5786 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5787 return;
5788 }
5789
Malcolm Chend965c8b2018-02-28 15:00:40 -08005790 final long identity = Binder.clearCallingIdentity();
5791 try {
5792 phone.setRadioIndicationUpdateMode(filters, mode);
5793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
Jack Yu4c988042018-02-27 15:30:01 -08005796 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005797
5798 /**
goneil47ffb6e2018-04-06 15:40:58 -07005799 * A test API to reload the UICC profile.
5800 *
5801 * <p>Requires that the calling app has permission
5802 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5803 * @hide
5804 */
5805 @Override
5806 public void refreshUiccProfile(int subId) {
5807 enforceModifyPermission();
5808
5809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 Phone phone = getPhone(subId);
5812 if (phone == null) {
5813 return;
5814 }
5815 UiccCard uiccCard = phone.getUiccCard();
5816 if (uiccCard == null) {
5817 return;
5818 }
5819 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5820 if (uiccProfile == null) {
5821 return;
5822 }
5823 uiccProfile.refresh();
5824 } finally {
5825 Binder.restoreCallingIdentity(identity);
5826 }
5827 }
5828
5829 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005830 * Returns false if the mobile data is disabled by default, otherwise return true.
5831 */
5832 private boolean getDefaultDataEnabled() {
5833 return "true".equalsIgnoreCase(
5834 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5835 }
5836
5837 /**
5838 * Returns true if the data roaming is enabled by default, i.e the system property
5839 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5840 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5841 */
5842 private boolean getDefaultDataRoamingEnabled(int subId) {
5843 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005844 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005845 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5846 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5847 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5848 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5849 return isDataRoamingEnabled;
5850 }
5851
5852 /**
5853 * Returns the default network type for the given {@code subId}, if the default network type is
5854 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5855 */
5856 private int getDefaultNetworkType(int subId) {
5857 return Integer.parseInt(
5858 TelephonyManager.getTelephonyProperty(
5859 mSubscriptionController.getPhoneId(subId),
5860 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5861 String.valueOf(Phone.PREFERRED_NT_MODE)));
5862 }
fionaxua13278b2018-03-21 00:08:13 -07005863
5864 @Override
5865 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5866 gid1, String gid2, String plmn, String spn) {
5867 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005868
5869 final long identity = Binder.clearCallingIdentity();
5870 try {
5871 final Phone phone = getPhone(subId);
5872 if (phone == null) {
5873 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5874 return;
5875 }
5876 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5877 } finally {
5878 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005879 }
fionaxua13278b2018-03-21 00:08:13 -07005880 }
5881
5882 @Override
5883 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005884 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005885
5886 final long identity = Binder.clearCallingIdentity();
5887 try {
5888 final Phone phone = getPhone(subId);
5889 if (phone == null) {
5890 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5891 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5892 }
5893 return phone.getCarrierIdListVersion();
5894 } finally {
5895 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005896 }
fionaxua13278b2018-03-21 00:08:13 -07005897 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005898
5899 @Override
5900 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5901 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5902 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5903 return -1;
5904 }
5905
5906 final long identity = Binder.clearCallingIdentity();
5907 try {
5908 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
5912 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005913
5914 @Override
5915 public int getCdmaRoamingMode(int subId) {
5916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5917 mApp, subId, "getCdmaRoamingMode");
5918
5919 final long identity = Binder.clearCallingIdentity();
5920 try {
5921 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
5925 }
5926
5927 @Override
5928 public boolean setCdmaRoamingMode(int subId, int mode) {
5929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5930 mApp, subId, "setCdmaRoamingMode");
5931
5932 final long identity = Binder.clearCallingIdentity();
5933 try {
5934 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5935 } finally {
5936 Binder.restoreCallingIdentity(identity);
5937 }
5938 }
5939
5940 @Override
5941 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5943 mApp, subId, "setCdmaSubscriptionMode");
5944
5945 final long identity = Binder.clearCallingIdentity();
5946 try {
5947 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
5951 }
chen xu7ee67862018-10-30 22:27:10 -07005952
sqian2fff4a32018-11-05 14:18:37 -08005953 private void ensureUserRunning(int userId) {
5954 if (!mUserManager.isUserRunning(userId)) {
5955 throw new IllegalStateException("User " + userId + " does not exist or not running");
5956 }
5957 }
5958
5959 /**
5960 * Returns a list of SMS apps on a given user.
5961 *
5962 * Only the shell user (UID 2000 or 0) can call it.
5963 * Target user must be running.
5964 */
5965 @Override
5966 public String[] getSmsApps(int userId) {
5967 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5968 ensureUserRunning(userId);
5969
5970 final Collection<SmsApplicationData> apps =
5971 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5972
5973 String[] ret = new String[apps.size()];
5974 int i = 0;
5975 for (SmsApplicationData app : apps) {
5976 ret[i++] = app.mPackageName;
5977 }
5978 return ret;
5979 }
5980
5981 /**
5982 * Returns the default SMS app package name on a given user.
5983 *
5984 * Only the shell user (UID 2000 or 0) can call it.
5985 * Target user must be running.
5986 */
5987 @Override
5988 public String getDefaultSmsApp(int userId) {
5989 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5990 ensureUserRunning(userId);
5991
5992 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5993 /* updateIfNeeded= */ true, userId);
5994 return cn == null ? null : cn.getPackageName();
5995 }
5996
5997 /**
5998 * Set a package as the default SMS app on a given user.
5999 *
6000 * Only the shell user (UID 2000 or 0) can call it.
6001 * Target user must be running.
6002 */
6003 @Override
6004 public void setDefaultSmsApp(int userId, String packageName) {
6005 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6006 ensureUserRunning(userId);
6007
6008 boolean found = false;
6009 for (String pkg : getSmsApps(userId)) {
6010 if (TextUtils.equals(packageName, pkg)) {
6011 found = true;
6012 break;
6013 }
6014 }
6015 if (!found) {
6016 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6017 }
6018
6019 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6020 }
6021
chen xu7ee67862018-10-30 22:27:10 -07006022 @Override
sqian04b86072018-11-07 14:02:21 -08006023 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6024 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6026 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6027 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6028 }
6029 final long identity = Binder.clearCallingIdentity();
6030 try {
sqian991b35e2018-12-12 16:48:18 -08006031 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6032 for (Phone phone: PhoneFactory.getPhones()) {
6033 if (phone.getEmergencyNumberTracker() != null
6034 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6035 emergencyNumberListInternal.put(
6036 phone.getSubId(),
6037 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6038 }
sqian03bca152018-12-05 18:48:28 -08006039 }
sqian991b35e2018-12-12 16:48:18 -08006040 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006041 } finally {
6042 Binder.restoreCallingIdentity(identity);
6043 }
sqian04b86072018-11-07 14:02:21 -08006044 }
6045
6046 @Override
sqian03bca152018-12-05 18:48:28 -08006047 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6048 final Phone defaultPhone = getDefaultPhone();
6049 if (!exactMatch) {
6050 TelephonyPermissions
6051 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6052 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6053 }
6054 final long identity = Binder.clearCallingIdentity();
6055 try {
sqian991b35e2018-12-12 16:48:18 -08006056 for (Phone phone: PhoneFactory.getPhones()) {
6057 if (phone.getEmergencyNumberTracker() != null
6058 && phone.getEmergencyNumberTracker() != null) {
6059 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6060 number, exactMatch)) {
6061 return true;
sqian03bca152018-12-05 18:48:28 -08006062 }
6063 }
sqian03bca152018-12-05 18:48:28 -08006064 }
6065 return false;
6066 } finally {
6067 Binder.restoreCallingIdentity(identity);
6068 }
6069 }
6070
6071 private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListInternal() {
6072 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6073
6074 for (Phone phone: PhoneFactory.getPhones()) {
6075 if (phone.getEmergencyNumberTracker() != null
6076 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6077 emergencyNumberListInternal.put(
6078 phone.getSubId(),
6079 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6080 }
6081 }
6082 return emergencyNumberListInternal;
6083 }
6084
6085 private List<EmergencyNumber> getEmergencyNumberListFromEccList(int subscriptionId) {
6086 SubscriptionManager sm = (SubscriptionManager) mApp.getSystemService(
6087 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6088 List<EmergencyNumber> emergencyNumberList = new ArrayList<>();
6089 int slotId = sm.getSlotIndex(subscriptionId);
6090
6091 String ecclist = (slotId <= 0) ? "ril.ecclist" : ("ril.ecclist" + slotId);
6092 String emergencyNumbers = SystemProperties.get(ecclist, "");
6093 if (TextUtils.isEmpty(emergencyNumbers)) {
6094 // then read-only ecclist property since old RIL only uses this
6095 emergencyNumbers = SystemProperties.get("ro.ril.ecclist");
6096 }
6097 if (!TextUtils.isEmpty(emergencyNumbers)) {
6098 // searches through the comma-separated list for a match,
6099 // return true if one is found.
6100 for (String emergencyNum : emergencyNumbers.split(",")) {
6101 emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "",
6102 EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0));
6103 }
6104 }
6105 emergencyNumbers = ((slotId < 0) ? "112,911,000,08,110,118,119,999" : "112,911");
6106 for (String emergencyNum : emergencyNumbers.split(",")) {
6107 emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "",
6108 EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0));
6109 }
6110 EmergencyNumber.mergeSameNumbersInEmergencyNumberList(emergencyNumberList);
6111 return emergencyNumberList;
6112 }
6113
6114 /**
6115 * Get Emergency number list based on EccList. This util is used for solving backward
6116 * compatibility if device does not support the 1.4 IRadioIndication HAL that reports
6117 * emergency number list.
6118 *
6119 * @return Map including the key as the active subscription ID (Note: if there is no active
6120 * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId})
6121 * and the value as the list of {@link EmergencyNumber}.
6122 */
6123 private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListFromEccList() {
6124 Map<Integer, List<EmergencyNumber>> results = new HashMap<>();
6125 SubscriptionManager sm = (SubscriptionManager) mApp.getSystemService(
6126 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6127 int[] activeSubscriptionIds = sm.getActiveSubscriptionIdList();
6128
6129 if (activeSubscriptionIds.length == 0) {
6130 int defaultSubscriptionId = getDefaultSubscription();
6131 results.put(defaultSubscriptionId,
6132 getEmergencyNumberListFromEccList(defaultSubscriptionId));
6133 } else {
6134 for (int activeSubscriptionId : activeSubscriptionIds) {
6135 results.put(activeSubscriptionId,
6136 getEmergencyNumberListFromEccList(activeSubscriptionId));
6137 }
6138 }
6139 return results;
sqian04b86072018-11-07 14:02:21 -08006140 }
6141
6142 @Override
chen xu7ee67862018-10-30 22:27:10 -07006143 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6144 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6145 Phone phone = getPhone(subId);
6146 if (phone == null) {
6147 return null;
6148 }
6149 final long identity = Binder.clearCallingIdentity();
6150 try {
6151 UiccProfile profile = UiccController.getInstance()
6152 .getUiccProfileForPhone(phone.getPhoneId());
6153 if (profile != null) {
6154 return profile.getCertsFromCarrierPrivilegeAccessRules();
6155 }
6156 } finally {
6157 Binder.restoreCallingIdentity(identity);
6158 }
6159 return null;
6160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006161}