blob: 7b7eb0f78290797deebd4d818fbe502e7c6a6e0e [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 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2725 final long token = Binder.clearCallingIdentity();
2726 try {
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 Ebinger4c460712018-10-01 10:40:55 -07002737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2738 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002739 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002740 .removeRegistrationCallbackForSubscription(c, subId));
2741 }
2742
2743 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002744 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2745 throws RemoteException {
2746 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002747 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2748 final long token = Binder.clearCallingIdentity();
2749 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002750 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002751 .addCapabilitiesCallbackForSubscription(c, subId);
2752 } finally {
2753 Binder.restoreCallingIdentity(token);
2754 }
2755 }
2756
2757 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002758 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2759 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002760 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2761 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002762 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002763 .removeCapabilitiesCallbackForSubscription(c, subId));
2764 }
2765
2766 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002767 public boolean isCapable(int subId, int capability, int regTech) {
2768 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002769 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2770 final long token = Binder.clearCallingIdentity();
2771 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002772 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002773 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2774 } catch (ImsException e) {
2775 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2776 return false;
2777 } finally {
2778 Binder.restoreCallingIdentity(token);
2779 }
2780 }
2781
2782 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002783 public boolean isAvailable(int subId, int capability, int regTech) {
2784 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002785 final long token = Binder.clearCallingIdentity();
2786 try {
2787 Phone phone = getPhone(subId);
2788 if (phone == null) return false;
2789 return phone.isImsCapabilityAvailable(capability, regTech);
2790 } finally {
2791 Binder.restoreCallingIdentity(token);
2792 }
2793 }
2794
2795 @Override
2796 public boolean isAdvancedCallingSettingEnabled(int subId) {
2797 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2798 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2799 final long token = Binder.clearCallingIdentity();
2800 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002801 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002802 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2803 } finally {
2804 Binder.restoreCallingIdentity(token);
2805 }
2806 }
2807
2808 @Override
2809 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2811 "setAdvancedCallingSetting");
2812 final long identity = Binder.clearCallingIdentity();
2813 try {
2814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002815 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002816 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2817 } finally {
2818 Binder.restoreCallingIdentity(identity);
2819 }
2820 }
2821
2822 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002823 public boolean isVtSettingEnabled(int subId) {
2824 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002828 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002829 getSlotIndexOrException(subId)).isVtEnabledByUser();
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
2832 }
2833 }
2834
2835 @Override
2836 public void setVtSetting(int subId, boolean isEnabled) {
2837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2838 "setVtSetting");
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002842 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002843 } finally {
2844 Binder.restoreCallingIdentity(identity);
2845 }
2846 }
2847
2848 @Override
2849 public boolean isVoWiFiSettingEnabled(int subId) {
2850 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002854 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002855 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
2859 }
2860
2861 @Override
2862 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2864 "setVoWiFiSetting");
2865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002868 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002869 } finally {
2870 Binder.restoreCallingIdentity(identity);
2871 }
2872 }
2873
2874 @Override
2875 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2876 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
2879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002880 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002881 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
2885 }
2886
2887 @Override
2888 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2890 "setVoWiFiRoamingSetting");
2891 final long identity = Binder.clearCallingIdentity();
2892 try {
2893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002894 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002895 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
2898 }
2899 }
2900
2901 @Override
2902 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2904 "setVoWiFiNonPersistent");
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002908 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002909 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
2912 }
2913 }
2914
2915 @Override
2916 public int getVoWiFiModeSetting(int subId) {
2917 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002921 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002922 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2923 } finally {
2924 Binder.restoreCallingIdentity(identity);
2925 }
2926 }
2927
2928 @Override
2929 public void setVoWiFiModeSetting(int subId, int mode) {
2930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2931 "setVoWiFiModeSetting");
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002935 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002936 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
2940 }
2941
2942 @Override
2943 public int getVoWiFiRoamingModeSetting(int subId) {
2944 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2945 final long identity = Binder.clearCallingIdentity();
2946 try {
2947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002948 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002949 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
2952 }
2953 }
2954
2955 @Override
2956 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2958 "setVoWiFiRoamingModeSetting");
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002962 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002963 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
2967 }
2968
2969 @Override
2970 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2972 "setRttCapabilityEnabled");
2973 final long identity = Binder.clearCallingIdentity();
2974 try {
2975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002976 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002977 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
2983 @Override
2984 public boolean isTtyOverVolteEnabled(int subId) {
2985 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002989 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002990 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
2994 }
2995
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002996 @Override
2997 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2998 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003002 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003003 .getConfigInterface().addConfigCallback(callback);
3004 } catch (ImsException e) {
3005 throw new IllegalArgumentException(e.getMessage());
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
3011 @Override
3012 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3013 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003017 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003018 .getConfigInterface().removeConfigCallback(callback);
3019 } catch (ImsException e) {
3020 throw new IllegalArgumentException(e.getMessage());
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
3024 }
3025
3026 @Override
3027 public int getImsProvisioningInt(int subId, int key) {
3028 enforceReadPrivilegedPermission("getImsProvisioningInt");
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003032 return ImsManager.getInstance(mApp,
3033 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003034 } catch (ImsException e) {
3035 throw new IllegalArgumentException(e.getMessage());
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
3039 }
3040
3041 @Override
3042 public String getImsProvisioningString(int subId, int key) {
3043 enforceReadPrivilegedPermission("getImsProvisioningString");
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003047 return ImsManager.getInstance(mApp,
3048 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003049 } catch (ImsException e) {
3050 throw new IllegalArgumentException(e.getMessage());
3051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
3054 }
3055
3056 @Override
3057 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3059 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003063 return ImsManager.getInstance(mApp,
3064 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003065 } catch (ImsException e) {
3066 throw new IllegalArgumentException(e.getMessage());
3067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
3070 }
3071
3072 @Override
3073 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3075 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003079 return ImsManager.getInstance(mApp,
3080 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003081 } catch (ImsException e) {
3082 throw new IllegalArgumentException(e.getMessage());
3083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
3086 }
3087
Brad Ebinger4c460712018-10-01 10:40:55 -07003088 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3089 int slotId = SubscriptionManager.getSlotIndex(subId);
3090 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3091 throw new IllegalArgumentException("Invalid Subscription Id.");
3092 }
3093 return slotId;
3094 }
3095
Wink Saville36469e72014-06-11 15:17:00 -07003096 /**
3097 * Returns the network type for a subId
3098 */
3099 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003100 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003102 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003103 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3104 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003105
Malcolm Chend965c8b2018-02-28 15:00:40 -08003106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 final Phone phone = getPhone(subId);
3109 if (phone != null) {
3110 return phone.getServiceState().getDataNetworkType();
3111 } else {
3112 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3113 }
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 }
3118
3119 /**
3120 * Returns the data network type
3121 */
3122 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003123 public int getDataNetworkType(String callingPackage) {
3124 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003125 }
3126
3127 /**
3128 * Returns the data network type for a subId
3129 */
3130 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003131 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003133 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003134 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3135 }
3136
Malcolm Chend965c8b2018-02-28 15:00:40 -08003137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 final Phone phone = getPhone(subId);
3140 if (phone != null) {
3141 return phone.getServiceState().getDataNetworkType();
3142 } else {
3143 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3144 }
3145 } finally {
3146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 }
3149
3150 /**
Wink Saville36469e72014-06-11 15:17:00 -07003151 * Returns the Voice network type for a subId
3152 */
3153 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003154 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003155 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003156 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003157 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3158 }
3159
Malcolm Chend965c8b2018-02-28 15:00:40 -08003160 final long identity = Binder.clearCallingIdentity();
3161 try {
3162 final Phone phone = getPhone(subId);
3163 if (phone != null) {
3164 return phone.getServiceState().getVoiceNetworkType();
3165 } else {
3166 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3167 }
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 }
3172
3173 /**
3174 * @return true if a ICC card is present
3175 */
3176 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003177 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003178 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3179 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003180 }
3181
3182 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003183 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003184 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003186 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 final Phone phone = PhoneFactory.getPhone(slotIndex);
3190 if (phone != null) {
3191 return phone.getIccCard().hasIccCard();
3192 } else {
3193 return false;
3194 }
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 }
3199
3200 /**
3201 * Return if the current radio is LTE on CDMA. This
3202 * is a tri-state return value as for a period of time
3203 * the mode may be unknown.
3204 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003205 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003207 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003209 @Override
3210 public int getLteOnCdmaMode(String callingPackage) {
3211 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003212 }
3213
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003215 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003217 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003218 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3219 }
3220
Malcolm Chend965c8b2018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 final Phone phone = getPhone(subId);
3224 if (phone == null) {
3225 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3226 } else {
3227 return phone.getLteOnCdmaMode();
3228 }
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 }
Wink Saville36469e72014-06-11 15:17:00 -07003232 }
3233
Wink Saville36469e72014-06-11 15:17:00 -07003234 /**
3235 * {@hide}
3236 * Returns Default subId, 0 in the case of single standby.
3237 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003238 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003239 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003240 }
3241
Shishir Agrawala9f32182016-04-12 12:00:16 -07003242 private int getSlotForDefaultSubscription() {
3243 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3244 }
3245
Wink Savilleb564aae2014-10-23 10:18:09 -07003246 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003247 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003249
Pengquan Meng466e2482018-09-21 15:54:48 -07003250 private boolean isActiveSubscription(int subId) {
3251 return mSubscriptionController.isActiveSubId(subId);
3252 }
3253
Ihab Awadf2177b72013-11-25 13:33:23 -08003254 /**
3255 * @see android.telephony.TelephonyManager.WifiCallingChoices
3256 */
3257 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003258 final long identity = Binder.clearCallingIdentity();
3259 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003260 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003261 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3262 getWhenToMakeWifiCallsDefaultPreference());
3263 } finally {
3264 Binder.restoreCallingIdentity(identity);
3265 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003266 }
3267
3268 /**
3269 * @see android.telephony.TelephonyManager.WifiCallingChoices
3270 */
3271 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003272 final long identity = Binder.clearCallingIdentity();
3273 try {
3274 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003275 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003276 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003280 }
3281
Sailesh Nepald1e68152013-12-12 19:08:02 -08003282 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003283 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003284 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003285 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003286
Shishir Agrawal566b7612013-10-28 14:41:00 -07003287 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003288 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3289 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003292 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003293
Malcolm Chend965c8b2018-02-28 15:00:40 -08003294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 if (TextUtils.equals(ISDR_AID, aid)) {
3297 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003298 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3299 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003300 if (bestComponent == null
3301 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3302 loge("The calling package is not allowed to access ISD-R.");
3303 throw new SecurityException(
3304 "The calling package is not allowed to access ISD-R.");
3305 }
Derek Tan740e1672017-06-27 14:56:27 -07003306 }
Derek Tan740e1672017-06-27 14:56:27 -07003307
Malcolm Chend965c8b2018-02-28 15:00:40 -08003308 if (DBG) {
3309 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3310 }
3311 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3312 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3313 if (DBG) log("iccOpenLogicalChannel: " + response);
3314 return response;
3315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003318 }
3319
3320 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003321 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3323 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003324
Malcolm Chend965c8b2018-02-28 15:00:40 -08003325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3328 if (channel < 0) {
3329 return false;
3330 }
3331 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3332 if (DBG) log("iccCloseLogicalChannel: " + success);
3333 return success;
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003337 }
3338
3339 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003340 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003341 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3343 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003344
Malcolm Chend965c8b2018-02-28 15:00:40 -08003345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 if (DBG) {
3348 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3349 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3350 + p3 + " data=" + data);
3351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003352
Malcolm Chend965c8b2018-02-28 15:00:40 -08003353 if (channel < 0) {
3354 return "";
3355 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003356
Malcolm Chend965c8b2018-02-28 15:00:40 -08003357 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3358 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3359 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003360
Malcolm Chend965c8b2018-02-28 15:00:40 -08003361 // Append the returned status code to the end of the response payload.
3362 String s = Integer.toHexString(
3363 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3364 if (response.payload != null) {
3365 s = IccUtils.bytesToHexString(response.payload) + s;
3366 }
3367 return s;
3368 } finally {
3369 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003370 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003371 }
Jake Hambye994d462014-02-03 13:10:13 -08003372
Evan Charltonc66da362014-05-16 14:06:40 -07003373 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003374 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3375 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3377 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003378 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003379
Malcolm Chend965c8b2018-02-28 15:00:40 -08003380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3383 && TextUtils.equals(ISDR_AID, data)) {
3384 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003385 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3386 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003387 if (bestComponent == null
3388 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3389 loge("The calling package is not allowed to select ISD-R.");
3390 throw new SecurityException(
3391 "The calling package is not allowed to select ISD-R.");
3392 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003393 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003394
Malcolm Chend965c8b2018-02-28 15:00:40 -08003395 if (DBG) {
3396 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3397 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3398 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003399
Malcolm Chend965c8b2018-02-28 15:00:40 -08003400 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3401 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3402 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003403
Malcolm Chend965c8b2018-02-28 15:00:40 -08003404 // Append the returned status code to the end of the response payload.
3405 String s = Integer.toHexString(
3406 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3407 if (response.payload != null) {
3408 s = IccUtils.bytesToHexString(response.payload) + s;
3409 }
3410 return s;
3411 } finally {
3412 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003413 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003414 }
3415
3416 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003417 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003418 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3420 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003421
Malcolm Chend965c8b2018-02-28 15:00:40 -08003422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 if (DBG) {
3425 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3426 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3427 }
3428
3429 IccIoResult response =
3430 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3431 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3432 subId);
3433
3434 if (DBG) {
3435 log("Exchange SIM_IO [R]" + response);
3436 }
3437
3438 byte[] result = null;
3439 int length = 2;
3440 if (response.payload != null) {
3441 length = 2 + response.payload.length;
3442 result = new byte[length];
3443 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3444 } else {
3445 result = new byte[length];
3446 }
3447
3448 result[length - 1] = (byte) response.sw2;
3449 result[length - 2] = (byte) response.sw1;
3450 return result;
3451 } finally {
3452 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003453 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003454 }
3455
Nathan Haroldb3014052017-01-25 15:57:32 -08003456 /**
3457 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3458 * on a particular subscription
3459 */
sqianb6e41952018-03-12 14:54:01 -07003460 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3462 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3463 return null;
3464 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003465
3466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 if (appType != TelephonyManager.APPTYPE_USIM
3469 && appType != TelephonyManager.APPTYPE_SIM) {
3470 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3471 return null;
3472 }
3473 Object response = sendRequest(
3474 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3475 if (response instanceof String[]) {
3476 return (String[]) response;
3477 }
3478 // Response is an Exception of some kind,
3479 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003480 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003481 } finally {
3482 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003483 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003484 }
3485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003486 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003487 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3489 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003490
Malcolm Chend965c8b2018-02-28 15:00:40 -08003491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3494 if (response.payload == null) {
3495 return "";
3496 }
Evan Charltonc66da362014-05-16 14:06:40 -07003497
Malcolm Chend965c8b2018-02-28 15:00:40 -08003498 // Append the returned status code to the end of the response payload.
3499 String s = Integer.toHexString(
3500 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3501 s = IccUtils.bytesToHexString(response.payload) + s;
3502 return s;
3503 } finally {
3504 Binder.restoreCallingIdentity(identity);
3505 }
Evan Charltonc66da362014-05-16 14:06:40 -07003506 }
3507
Jake Hambye994d462014-02-03 13:10:13 -08003508 /**
3509 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3510 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3511 *
3512 * @param itemID the ID of the item to read
3513 * @return the NV item as a String, or null on error.
3514 */
3515 @Override
3516 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003517 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3519 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003520
3521 final long identity = Binder.clearCallingIdentity();
3522 try {
3523 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003524 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003525 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3526 return value;
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Jake Hambye994d462014-02-03 13:10:13 -08003530 }
3531
3532 /**
3533 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3534 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3535 *
3536 * @param itemID the ID of the item to read
3537 * @param itemValue the value to write, as a String
3538 * @return true on success; false on any failure
3539 */
3540 @Override
3541 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003542 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3544 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3549 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003550 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003551 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3552 return success;
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
Jake Hambye994d462014-02-03 13:10:13 -08003556 }
3557
3558 /**
3559 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3560 * Used for device configuration by some CDMA operators.
3561 *
3562 * @param preferredRoamingList byte array containing the new PRL
3563 * @return true on success; false on any failure
3564 */
3565 @Override
3566 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3568 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003569
3570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3573 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3574 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3575 return success;
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
Jake Hambye994d462014-02-03 13:10:13 -08003579 }
3580
3581 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003582 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003583 * Used for device configuration by some CDMA operators.
3584 *
chen xu1cc0abe2018-10-26 17:39:23 -07003585 * @param slotIndex - device slot.
3586 *
Jake Hambye994d462014-02-03 13:10:13 -08003587 * @return true on success; false on any failure
3588 */
3589 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003590 public boolean resetModemConfig(int slotIndex) {
3591 Phone phone = PhoneFactory.getPhone(slotIndex);
3592 if (phone != null) {
3593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3594 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003595
chen xu1cc0abe2018-10-26 17:39:23 -07003596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3599 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3600 return success;
3601 } finally {
3602 Binder.restoreCallingIdentity(identity);
3603 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003604 }
chen xu1cc0abe2018-10-26 17:39:23 -07003605 return false;
3606 }
3607
3608 /**
3609 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3610 *
3611 * @param slotIndex - device slot.
3612 *
3613 * @return true on success; false on any failure
3614 */
3615 @Override
3616 public boolean rebootModem(int slotIndex) {
3617 Phone phone = PhoneFactory.getPhone(slotIndex);
3618 if (phone != null) {
3619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3620 mApp, phone.getSubId(), "rebootModem");
3621
3622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3625 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3626 return success;
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
3630 }
3631 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003632 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003633
Svet Ganovb320e182015-04-16 12:30:10 -07003634 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003635 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003637 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003638 return new String[0];
3639 }
3640
Malcolm Chend965c8b2018-02-28 15:00:40 -08003641 final long identity = Binder.clearCallingIdentity();
3642 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003643 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
Wink Saville36469e72014-06-11 15:17:00 -07003647 }
3648
Brad Ebinger51f743a2017-01-23 13:50:20 -08003649 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003650 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3651 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003652 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003653 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003654 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003655
3656 final long identity = Binder.clearCallingIdentity();
3657 try {
3658 PhoneFactory.getImsResolver().enableIms(slotId);
3659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003662 }
3663
3664 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003665 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3666 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003667 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003668 public void disableIms(int slotId) {
3669 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003670
3671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 PhoneFactory.getImsResolver().disableIms(slotId);
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003677 }
3678
3679 /**
3680 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3681 * feature or {@link null} if the service is not available. If the feature is available, the
3682 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3683 */
3684 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003685 IImsServiceFeatureCallback callback) {
3686 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003687
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003694 }
3695
3696 /**
3697 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3698 * feature during emergency calling or {@link null} if the service is not available. If the
3699 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3700 * listener for feature updates.
3701 */
3702 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3703 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003704
3705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003711 }
3712
Brad Ebinger5f64b052017-12-14 14:26:15 -08003713 /**
3714 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3715 * specified.
3716 */
3717 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3718 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003719
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003726 }
3727
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003728 /**
3729 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3730 * specified.
3731 */
3732 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3733 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3738 } finally {
3739 Binder.restoreCallingIdentity(identity);
3740 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003741 }
3742
Brad Ebinger884c07b2018-02-15 16:17:40 -08003743 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003744 * Sets the ImsService Package Name that Telephony will bind to.
3745 *
3746 * @param slotId the slot ID that the ImsService should bind for.
3747 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3748 * ImsService is the device default ImsService.
3749 * @param packageName The package name of the application that contains the ImsService to bind
3750 * to.
3751 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3752 * @hide
3753 */
3754 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003755 int[] subIds = SubscriptionManager.getSubId(slotId);
3756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3757 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3758 "setImsService");
3759
Malcolm Chend965c8b2018-02-28 15:00:40 -08003760 final long identity = Binder.clearCallingIdentity();
3761 try {
3762 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3763 isCarrierImsService, packageName);
3764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003767 }
3768
3769 /**
3770 * Return the ImsService configuration.
3771 *
3772 * @param slotId The slot that the ImsService is associated with.
3773 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3774 * the device default.
3775 * @return the package name of the ImsService configuration.
3776 */
3777 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003778 int[] subIds = SubscriptionManager.getSubId(slotId);
3779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3780 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3781 "getImsService");
3782
Malcolm Chend965c8b2018-02-28 15:00:40 -08003783 final long identity = Binder.clearCallingIdentity();
3784 try {
3785 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3786 isCarrierImsService);
3787 } finally {
3788 Binder.restoreCallingIdentity(identity);
3789 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003790 }
3791
Wink Saville36469e72014-06-11 15:17:00 -07003792 public void setImsRegistrationState(boolean registered) {
3793 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003794
3795 final long identity = Binder.clearCallingIdentity();
3796 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003797 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003798 } finally {
3799 Binder.restoreCallingIdentity(identity);
3800 }
Wink Saville36469e72014-06-11 15:17:00 -07003801 }
3802
3803 /**
Stuart Scott54788802015-03-30 13:18:01 -07003804 * Set the network selection mode to automatic.
3805 *
3806 */
3807 @Override
3808 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3810 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003811
Pengquan Meng466e2482018-09-21 15:54:48 -07003812 if (!isActiveSubscription(subId)) {
3813 return;
3814 }
3815
Malcolm Chend965c8b2018-02-28 15:00:40 -08003816 final long identity = Binder.clearCallingIdentity();
3817 try {
3818 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3819 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
3822 }
Stuart Scott54788802015-03-30 13:18:01 -07003823 }
3824
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003825 /**
3826 * Ask the radio to connect to the input network and change selection mode to manual.
3827 *
3828 * @param subId the id of the subscription.
3829 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3830 * the operator to attach to.
3831 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3832 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3833 * normal network selection next time.
3834 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003835 */
3836 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003837 public boolean setNetworkSelectionModeManual(
3838 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3840 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003841
3842 if (!isActiveSubscription(subId)) {
3843 return false;
3844 }
3845
Malcolm Chend965c8b2018-02-28 15:00:40 -08003846 final long identity = Binder.clearCallingIdentity();
3847 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003848 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003849 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003850 if (DBG) {
3851 log("setNetworkSelectionModeManual: subId: " + subId
3852 + " operator: " + operatorInfo);
3853 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003854 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3855 } finally {
3856 Binder.restoreCallingIdentity(identity);
3857 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003858 }
3859
3860 /**
3861 * Scans for available networks.
3862 */
3863 @Override
3864 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3866 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003867
Pengquan Meng0c05b502018-09-06 09:59:22 -07003868 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003869 try {
3870 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003871 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003872 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003876 }
3877
3878 /**
yinxub1bed742017-04-17 11:45:04 -07003879 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003880 *
yinxub1bed742017-04-17 11:45:04 -07003881 * @param subId id of the subscription
3882 * @param request contains the radio access networks with bands/channels to scan
3883 * @param messenger callback messenger for scan results or errors
3884 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003885 * @return the id of the requested scan which can be used to stop the scan.
3886 */
3887 @Override
3888 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3889 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3891 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003892
3893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 return mNetworkScanRequestTracker.startNetworkScan(
3896 request, messenger, binder, getPhone(subId));
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
3899 }
yinxu504e1392017-04-12 16:03:22 -07003900 }
3901
3902 /**
3903 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003904 *
3905 * @param subId id of the subscription
3906 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003907 */
3908 @Override
3909 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3911 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003912
3913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3916 } finally {
3917 Binder.restoreCallingIdentity(identity);
3918 }
yinxu504e1392017-04-12 16:03:22 -07003919 }
3920
3921 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003922 * Get the calculated preferred network type.
3923 * Used for debugging incorrect network type.
3924 *
3925 * @return the preferred network type, defined in RILConstants.java.
3926 */
3927 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003928 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003929 final Phone defaultPhone = getDefaultPhone();
3930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3931 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003932 return RILConstants.PREFERRED_NETWORK_MODE;
3933 }
3934
Malcolm Chend965c8b2018-02-28 15:00:40 -08003935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003938 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
Junda Liu84d15a22014-07-02 11:21:04 -07003942 }
3943
3944 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003945 * Get the preferred network type.
3946 * Used for device configuration by some CDMA operators.
3947 *
3948 * @return the preferred network type, defined in RILConstants.java.
3949 */
3950 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003951 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3953 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003954
3955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 if (DBG) log("getPreferredNetworkType");
3958 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3959 int networkType = (result != null ? result[0] : -1);
3960 if (DBG) log("getPreferredNetworkType: " + networkType);
3961 return networkType;
3962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003965 }
3966
3967 /**
3968 * Set the preferred network type.
3969 * Used for device configuration by some CDMA operators.
3970 *
3971 * @param networkType the preferred network type, defined in RILConstants.java.
3972 * @return true on success; false on any failure.
3973 */
3974 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003975 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3977 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003978
3979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3982 Boolean success = (Boolean) sendRequest(
3983 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3984 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3985 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003986 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003987 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3988 }
3989 return success;
3990 } finally {
3991 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003992 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003993 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003994
3995 /**
Junda Liu475951f2014-11-07 16:45:03 -08003996 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003997 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003998 * tethering.
3999 *
4000 * @return 0: Not required. 1: required. 2: Not set.
4001 * @hide
4002 */
4003 @Override
4004 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004005 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004006
4007 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004008 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004009 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004010 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004011 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004012 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004013 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004014 dunRequired = 1;
4015 }
4016 return dunRequired;
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004019 }
Junda Liu475951f2014-11-07 16:45:03 -08004020 }
4021
4022 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004023 * Set mobile data enabled
4024 * Used by the user through settings etc to turn on/off mobile data
4025 *
4026 * @param enable {@code true} turn turn data on, else {@code false}
4027 */
4028 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004029 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4031 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004032
4033 final long identity = Binder.clearCallingIdentity();
4034 try {
4035 int phoneId = mSubscriptionController.getPhoneId(subId);
4036 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4037 Phone phone = PhoneFactory.getPhone(phoneId);
4038 if (phone != null) {
4039 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004040 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004041 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004042 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004043 }
4044 } finally {
4045 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004046 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004047 }
4048
4049 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004050 * Get the user enabled state of Mobile Data.
4051 *
4052 * TODO: remove and use isUserDataEnabled.
4053 * This can't be removed now because some vendor codes
4054 * calls through ITelephony directly while they should
4055 * use TelephonyManager.
4056 *
4057 * @return true on enabled
4058 */
4059 @Override
4060 public boolean getDataEnabled(int subId) {
4061 return isUserDataEnabled(subId);
4062 }
4063
4064 /**
4065 * Get whether mobile data is enabled per user setting.
4066 *
4067 * There are other factors deciding whether mobile data is actually enabled, but they are
4068 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004069 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004070 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004071 *
4072 * @return {@code true} if data is enabled else {@code false}
4073 */
4074 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004075 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004076 try {
4077 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4078 null);
4079 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4081 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004082 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004083
4084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 int phoneId = mSubscriptionController.getPhoneId(subId);
4087 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4088 Phone phone = PhoneFactory.getPhone(phoneId);
4089 if (phone != null) {
4090 boolean retVal = phone.isUserDataEnabled();
4091 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4092 return retVal;
4093 } else {
4094 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4095 return false;
4096 }
4097 } finally {
4098 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004099 }
4100 }
4101
4102 /**
4103 * Get whether mobile data is enabled.
4104 *
4105 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4106 * whether mobile data is actually enabled.
4107 *
4108 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4109 *
4110 * @return {@code true} if data is enabled else {@code false}
4111 */
4112 @Override
4113 public boolean isDataEnabled(int subId) {
4114 try {
4115 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4116 null);
4117 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4119 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004120 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004121
4122 final long identity = Binder.clearCallingIdentity();
4123 try {
4124 int phoneId = mSubscriptionController.getPhoneId(subId);
4125 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4126 Phone phone = PhoneFactory.getPhone(phoneId);
4127 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004128 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004129 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4130 return retVal;
4131 } else {
4132 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4133 return false;
4134 }
4135 } finally {
4136 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004137 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004138 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004139
4140 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004141 public int getCarrierPrivilegeStatus(int subId) {
4142 final Phone phone = getPhone(subId);
4143 if (phone == null) {
4144 loge("getCarrierPrivilegeStatus: Invalid subId");
4145 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4146 }
4147 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004148 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004149 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004150 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4151 }
4152 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004153 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004154 }
Junda Liu29340342014-07-10 15:23:27 -07004155
4156 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004157 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4158 final Phone phone = getPhone(subId);
4159 if (phone == null) {
4160 loge("getCarrierPrivilegeStatus: Invalid subId");
4161 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4162 }
4163 UiccProfile profile =
4164 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4165 if (profile == null) {
4166 loge("getCarrierPrivilegeStatus: No UICC");
4167 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4168 }
4169 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4170 }
4171
4172 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004173 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004174 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004175 if (TextUtils.isEmpty(pkgName))
4176 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004177 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004178 if (card == null) {
4179 loge("checkCarrierPrivilegesForPackage: No UICC");
4180 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4181 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004182 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4183 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004184 }
4185
4186 @Override
4187 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004188 if (TextUtils.isEmpty(pkgName))
4189 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004190 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4191 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4192 UiccCard card = UiccController.getInstance().getUiccCard(i);
4193 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004194 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004195 continue;
4196 }
4197
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004198 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004199 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4200 break;
4201 }
4202 }
4203
4204 return result;
Junda Liu29340342014-07-10 15:23:27 -07004205 }
Derek Tan89e89d42014-07-08 17:00:10 -07004206
4207 @Override
Junda Liue64de782015-04-16 17:19:16 -07004208 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4209 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4210 loge("phoneId " + phoneId + " is not valid.");
4211 return null;
4212 }
4213 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004214 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004215 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004216 return null ;
4217 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004218 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004219 }
4220
Amith Yamasani6e118872016-02-19 12:53:51 -08004221 @Override
4222 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004223 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004224 List<String> privilegedPackages = new ArrayList<>();
4225 List<PackageInfo> packages = null;
4226 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4227 UiccCard card = UiccController.getInstance().getUiccCard(i);
4228 if (card == null) {
4229 // No UICC in that slot.
4230 continue;
4231 }
4232 if (card.hasCarrierPrivilegeRules()) {
4233 if (packages == null) {
4234 // Only check packages in user 0 for now
4235 packages = pm.getInstalledPackagesAsUser(
4236 PackageManager.MATCH_DISABLED_COMPONENTS
4237 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4238 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4239 }
4240 for (int p = packages.size() - 1; p >= 0; p--) {
4241 PackageInfo pkgInfo = packages.get(p);
4242 if (pkgInfo != null && pkgInfo.packageName != null
4243 && card.getCarrierPrivilegeStatus(pkgInfo)
4244 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4245 privilegedPackages.add(pkgInfo.packageName);
4246 }
4247 }
4248 }
4249 }
4250 return privilegedPackages;
4251 }
4252
Wink Savilleb564aae2014-10-23 10:18:09 -07004253 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004254 final Phone phone = getPhone(subId);
4255 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004256 if (card == null) {
4257 loge("getIccId: No UICC");
4258 return null;
4259 }
4260 String iccId = card.getIccId();
4261 if (TextUtils.isEmpty(iccId)) {
4262 loge("getIccId: ICC ID is null or empty.");
4263 return null;
4264 }
4265 return iccId;
4266 }
4267
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004268 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004269 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4270 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004271 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4272 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004273
Malcolm Chend965c8b2018-02-28 15:00:40 -08004274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 final String iccId = getIccId(subId);
4277 final Phone phone = getPhone(subId);
4278 if (phone == null) {
4279 return false;
4280 }
4281 final String subscriberId = phone.getSubscriberId();
4282
4283 if (DBG_MERGE) {
4284 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4285 + subscriberId + " to " + number);
4286 }
4287
4288 if (TextUtils.isEmpty(iccId)) {
4289 return false;
4290 }
4291
4292 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4293
4294 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4295 if (alphaTag == null) {
4296 editor.remove(alphaTagPrefKey);
4297 } else {
4298 editor.putString(alphaTagPrefKey, alphaTag);
4299 }
4300
4301 // Record both the line number and IMSI for this ICCID, since we need to
4302 // track all merged IMSIs based on line number
4303 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4304 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4305 if (number == null) {
4306 editor.remove(numberPrefKey);
4307 editor.remove(subscriberPrefKey);
4308 } else {
4309 editor.putString(numberPrefKey, number);
4310 editor.putString(subscriberPrefKey, subscriberId);
4311 }
4312
4313 editor.commit();
4314 return true;
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004317 }
Derek Tan7226c842014-07-02 17:42:23 -07004318 }
4319
4320 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004321 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004322 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004324 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004325 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004326 return null;
4327 }
Derek Tan97ebb422014-09-05 16:55:38 -07004328
Malcolm Chend965c8b2018-02-28 15:00:40 -08004329 final long identity = Binder.clearCallingIdentity();
4330 try {
4331 String iccId = getIccId(subId);
4332 if (iccId != null) {
4333 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4334 if (DBG_MERGE) {
4335 log("getLine1NumberForDisplay returning "
4336 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4337 }
4338 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004339 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004340 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4341 return null;
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004344 }
Derek Tan7226c842014-07-02 17:42:23 -07004345 }
4346
4347 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004348 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004349 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004350 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004351 return null;
4352 }
Derek Tan97ebb422014-09-05 16:55:38 -07004353
Malcolm Chend965c8b2018-02-28 15:00:40 -08004354 final long identity = Binder.clearCallingIdentity();
4355 try {
4356 String iccId = getIccId(subId);
4357 if (iccId != null) {
4358 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4359 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4360 }
4361 return null;
4362 } finally {
4363 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004364 }
Derek Tan7226c842014-07-02 17:42:23 -07004365 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004366
4367 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004368 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004369 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4370 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004372 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4373 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004374 return null;
4375 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004376
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004377 final long identity = Binder.clearCallingIdentity();
4378 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004379 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004380 final TelephonyManager tele = TelephonyManager.from(context);
4381 final SubscriptionManager sub = SubscriptionManager.from(context);
4382
4383 // Figure out what subscribers are currently active
4384 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4385 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4386 // the process, where TelephonyManager was instantiated.
4387 // Otherwise AppOps check will fail.
4388
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004389 final int[] subIds = sub.getActiveSubscriptionIdList();
4390 for (int subId : subIds) {
4391 activeSubscriberIds.add(tele.getSubscriberId(subId));
4392 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004393
4394 // First pass, find a number override for an active subscriber
4395 String mergeNumber = null;
4396 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4397 for (String key : prefs.keySet()) {
4398 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4399 final String subscriberId = (String) prefs.get(key);
4400 if (activeSubscriberIds.contains(subscriberId)) {
4401 final String iccId = key.substring(
4402 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4403 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4404 mergeNumber = (String) prefs.get(numberKey);
4405 if (DBG_MERGE) {
4406 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4407 + " for active subscriber " + subscriberId);
4408 }
4409 if (!TextUtils.isEmpty(mergeNumber)) {
4410 break;
4411 }
4412 }
4413 }
4414 }
4415
4416 // Shortcut when no active merged subscribers
4417 if (TextUtils.isEmpty(mergeNumber)) {
4418 return null;
4419 }
4420
4421 // Second pass, find all subscribers under that line override
4422 final ArraySet<String> result = new ArraySet<>();
4423 for (String key : prefs.keySet()) {
4424 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4425 final String number = (String) prefs.get(key);
4426 if (mergeNumber.equals(number)) {
4427 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4428 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4429 final String subscriberId = (String) prefs.get(subscriberKey);
4430 if (!TextUtils.isEmpty(subscriberId)) {
4431 result.add(subscriberId);
4432 }
4433 }
4434 }
4435 }
4436
4437 final String[] resultArray = result.toArray(new String[result.size()]);
4438 Arrays.sort(resultArray);
4439 if (DBG_MERGE) {
4440 Slog.d(LOG_TAG,
4441 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4442 }
4443 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004444 } finally {
4445 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004446 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004447 }
4448
4449 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004450 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004451 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4452 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004453
4454 final long identity = Binder.clearCallingIdentity();
4455 try {
4456 final Phone phone = getPhone(subId);
4457 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4458 } finally {
4459 Binder.restoreCallingIdentity(identity);
4460 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004461 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004462
4463 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004464 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004465 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4466 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004467 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004468
4469 final long identity = Binder.clearCallingIdentity();
4470 try {
4471 final Phone phone = getPhone(subId);
4472 if (phone == null) {
4473 return false;
4474 }
4475 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4476 cdmaNonRoamingList);
4477 } finally {
4478 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004479 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004480 }
4481
4482 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004483 @Deprecated
4484 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4485 enforceModifyPermission();
4486
4487 int returnValue = 0;
4488 try {
vagdevie435a3e2018-08-15 16:01:53 -07004489 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004490 if(result.exception == null) {
4491 if (result.result != null) {
4492 byte[] responseData = (byte[])(result.result);
4493 if(responseData.length > oemResp.length) {
4494 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4495 responseData.length + "bytes. Buffer Size is " +
4496 oemResp.length + "bytes.");
4497 }
4498 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4499 returnValue = responseData.length;
4500 }
4501 } else {
4502 CommandException ex = (CommandException) result.exception;
4503 returnValue = ex.getCommandError().ordinal();
4504 if(returnValue > 0) returnValue *= -1;
4505 }
4506 } catch (RuntimeException e) {
4507 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4508 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4509 if(returnValue > 0) returnValue *= -1;
4510 }
4511
4512 return returnValue;
4513 }
4514
4515 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004516 public void setRadioCapability(RadioAccessFamily[] rafs) {
4517 try {
4518 ProxyController.getInstance().setRadioCapability(rafs);
4519 } catch (RuntimeException e) {
4520 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4521 }
4522 }
4523
4524 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004525 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004526 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004527 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004528 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004529 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004530 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004531 final long identity = Binder.clearCallingIdentity();
4532 try {
chen xufeeed752018-10-26 14:17:57 -07004533 TelephonyPermissions
4534 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4535 mApp, phone.getSubId(), "getRadioAccessFamily");
4536 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
chen xufeeed752018-10-26 14:17:57 -07004540 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004541 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004542
4543 @Override
4544 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004545 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004546 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004547
4548 final long identity = Binder.clearCallingIdentity();
4549 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004550 ImsManager.getInstance(defaultPhone.getContext(),
4551 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004552 } finally {
4553 Binder.restoreCallingIdentity(identity);
4554 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004555 }
4556
4557 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004558 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004559 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004561 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004562 return false;
4563 }
Svet Ganovb320e182015-04-16 12:30:10 -07004564
Malcolm Chend965c8b2018-02-28 15:00:40 -08004565 final long identity = Binder.clearCallingIdentity();
4566 try {
4567 // Check the user preference and the system-level IMS setting. Even if the user has
4568 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4569 // In the long run, we may instead need to check if there exists a connection service
4570 // which can support video calling.
4571 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004572 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004573 return imsManager.isVtEnabledByPlatform()
4574 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4575 && imsManager.isVtEnabledByUser();
4576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004579 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004580
Andrew Leea1239f22015-03-02 17:44:07 -08004581 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004582 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4584 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4585 return false;
4586 }
4587
4588 final long identity = Binder.clearCallingIdentity();
4589 try {
4590 CarrierConfigManager configManager =
4591 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004592 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004593 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4594 } finally {
4595 Binder.restoreCallingIdentity(identity);
4596 }
Andrew Leea1239f22015-03-02 17:44:07 -08004597 }
4598
4599 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004600 public boolean isWorldPhone(int subId, String callingPackage) {
4601 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4602 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4603 return false;
4604 }
4605
4606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 CarrierConfigManager configManager =
4609 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004610 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004611 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4612 } finally {
4613 Binder.restoreCallingIdentity(identity);
4614 }
Andrew Leea1239f22015-03-02 17:44:07 -08004615 }
4616
Andrew Lee9431b832015-03-09 18:46:45 -07004617 @Override
4618 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004619 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004620 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004621 }
4622
4623 @Override
4624 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004625 final long identity = Binder.clearCallingIdentity();
4626 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004627 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004628 } finally {
4629 Binder.restoreCallingIdentity(identity);
4630 }
Andrew Lee9431b832015-03-09 18:46:45 -07004631 }
4632
Hall Liuf6668912018-10-31 17:05:23 -07004633 /**
4634 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4635 * support for the feature and device firmware support.
4636 *
4637 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4638 */
4639 @Override
4640 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004641 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004642 final Phone phone = getPhone(subscriptionId);
4643 if (phone == null) {
4644 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4645 return false;
4646 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004647 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004648 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004649 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4650 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004651 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004652 return isCarrierSupported && isDeviceSupported;
4653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
Hall Liu98187582018-01-22 19:15:32 -08004656 }
4657
Hall Liuf6668912018-10-31 17:05:23 -07004658 /**
4659 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4660 * both also support RTT.
4661 */
4662 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004663 final long identity = Binder.clearCallingIdentity();
4664 try {
Hall Liuf6668912018-10-31 17:05:23 -07004665 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004666 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004667 } finally {
4668 Binder.restoreCallingIdentity(identity);
4669 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004670 }
4671
Sanket Padawe7310cc72015-01-14 09:53:20 -08004672 /**
4673 * Returns the unique device ID of phone, for example, the IMEI for
4674 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4675 *
4676 * <p>Requires Permission:
4677 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4678 */
4679 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004680 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004681 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004682 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004683 return null;
4684 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004685 int subId = phone.getSubId();
4686 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4687 mApp, subId, callingPackage, "getDeviceId")) {
4688 return null;
4689 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004690
4691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 return phone.getDeviceId();
4694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004697 }
4698
Ping Sunc67b7c22016-03-02 19:16:45 +08004699 /**
4700 * {@hide}
4701 * Returns the IMS Registration Status on a particular subid
4702 *
4703 * @param subId
4704 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004705 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004706 Phone phone = getPhone(subId);
4707 if (phone != null) {
4708 return phone.isImsRegistered();
4709 } else {
4710 return false;
4711 }
4712 }
4713
Santos Cordon7a1885b2015-02-03 11:15:19 -08004714 @Override
4715 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004716 final long identity = Binder.clearCallingIdentity();
4717 try {
4718 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4719 } finally {
4720 Binder.restoreCallingIdentity(identity);
4721 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004722 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004723
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004724 /**
4725 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004726 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004727 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004728 final long identity = Binder.clearCallingIdentity();
4729 try {
4730 Phone phone = getPhone(subId);
4731 if (phone != null) {
4732 return phone.isWifiCallingEnabled();
4733 } else {
4734 return false;
4735 }
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004738 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004739 }
4740
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004741 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004742 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004743 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004744 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004745 final long identity = Binder.clearCallingIdentity();
4746 try {
4747 Phone phone = getPhone(subId);
4748 if (phone != null) {
4749 return phone.isVideoEnabled();
4750 } else {
4751 return false;
4752 }
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004755 }
4756 }
4757
4758 /**
4759 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4760 * defined in {@link ImsRegistrationImplBase}.
4761 */
4762 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004763 final long identity = Binder.clearCallingIdentity();
4764 try {
4765 Phone phone = getPhone(subId);
4766 if (phone != null) {
4767 return phone.getImsRegistrationTech();
4768 } else {
4769 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4770 }
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004773 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004774 }
4775
Stuart Scott8eef64f2015-04-08 15:13:54 -07004776 @Override
4777 public void factoryReset(int subId) {
4778 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004779 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4780 return;
4781 }
4782
Svet Ganovcc087f82015-05-12 20:35:54 -07004783 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004784
Svet Ganovcc087f82015-05-12 20:35:54 -07004785 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004786 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4787 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004788 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004789 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004790 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004791 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4792 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004793 }
4794 } finally {
4795 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004796 }
4797 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004798
4799 @Override
4800 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004801 final long identity = Binder.clearCallingIdentity();
4802 try {
4803 // We query all subscriptions instead of just the active ones, because
4804 // this might be called early on in the provisioning flow when the
4805 // subscriptions potentially aren't active yet.
4806 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4807 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004808 return null;
4809 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004810
Malcolm Chend965c8b2018-02-28 15:00:40 -08004811 // This function may be called very early, say, from the setup wizard, at
4812 // which point we won't have a default subscription set. If that's the case
4813 // we just choose the first, which will be valid in "most cases".
4814 final int defaultSubId = getDefaultSubscription();
4815 SubscriptionInfo info = null;
4816 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4817 info = slist.get(0);
4818 } else {
4819 for (SubscriptionInfo item : slist) {
4820 if (item.getSubscriptionId() == defaultSubId) {
4821 info = item;
4822 break;
4823 }
4824 }
4825
4826 if (info == null) {
4827 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004828 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004829 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004830
Malcolm Chend965c8b2018-02-28 15:00:40 -08004831 // Try and fetch the locale from the carrier properties or from the SIM language
4832 // preferences (EF-PL and EF-LI)...
4833 final int mcc = info.getMcc();
4834 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4835 String simLanguage = null;
4836 if (defaultPhone != null) {
4837 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4838 if (localeFromDefaultSim != null) {
4839 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4840 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4841 return localeFromDefaultSim.toLanguageTag();
4842 } else {
4843 simLanguage = localeFromDefaultSim.getLanguage();
4844 }
4845 }
4846 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004847
Malcolm Chend965c8b2018-02-28 15:00:40 -08004848 // The SIM language preferences only store a language (e.g. fr = French), not an
4849 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4850 // the SIM and carrier preferences does not include a country we add the country
4851 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004852 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004853 if (mccLocale != null) {
4854 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4855 return mccLocale.toLanguageTag();
4856 }
4857
4858 if (DBG) log("No locale found - returning null");
4859 return null;
4860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004863 }
4864
4865 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004866 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004867 }
4868
Malcolm Chend965c8b2018-02-28 15:00:40 -08004869 /**
4870 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4871 */
4872 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004873 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004874 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004875
Chenjie Yu1ba97252018-01-11 18:16:20 -08004876 private final ModemActivityInfo mLastModemActivityInfo =
4877 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4878
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004879 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004880 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4881 * representing the state of the modem.
4882 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004883 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4884 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004885 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004886 */
4887 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004888 public void requestModemActivityInfo(ResultReceiver result) {
4889 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004890 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004891
4892 final long identity = Binder.clearCallingIdentity();
4893 try {
4894 ModemActivityInfo ret = null;
4895 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004896 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4897 CMD_GET_MODEM_ACTIVITY_INFO,
4898 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004899 if (isModemActivityInfoValid(info)) {
4900 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4901 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4902 mergedTxTimeMs[i] =
4903 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4904 }
4905 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4906 mLastModemActivityInfo.setSleepTimeMillis(
4907 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4908 mLastModemActivityInfo.setIdleTimeMillis(
4909 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4910 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4911 mLastModemActivityInfo.setRxTimeMillis(
4912 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4913 mLastModemActivityInfo.setEnergyUsed(
4914 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004915 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004916 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4917 mLastModemActivityInfo.getSleepTimeMillis(),
4918 mLastModemActivityInfo.getIdleTimeMillis(),
4919 mLastModemActivityInfo.getTxTimeMillis(),
4920 mLastModemActivityInfo.getRxTimeMillis(),
4921 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004922 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004923 Bundle bundle = new Bundle();
4924 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4925 result.send(0, bundle);
4926 } finally {
4927 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004928 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004929 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004930
Siddharth Rayf5d29552018-06-17 15:02:38 -07004931 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4932 // less than total activity duration.
4933 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4934 if (info == null) {
4935 return false;
4936 }
4937 int activityDurationMs =
4938 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4939 int totalTxTimeMs = 0;
4940 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4941 totalTxTimeMs += info.getTxTimeMillis()[i];
4942 }
4943 return (info.isValid()
4944 && (info.getSleepTimeMillis() <= activityDurationMs)
4945 && (info.getIdleTimeMillis() <= activityDurationMs)
4946 && (info.getRxTimeMillis() <= activityDurationMs)
4947 && (totalTxTimeMs <= activityDurationMs));
4948 }
4949
Jack Yu85bd38a2015-11-09 11:34:32 -08004950 /**
4951 * {@hide}
4952 * Returns the service state information on specified subscription.
4953 */
4954 @Override
4955 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004957 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004958 return null;
4959 }
4960
Malcolm Chend965c8b2018-02-28 15:00:40 -08004961 final long identity = Binder.clearCallingIdentity();
4962 try {
4963 final Phone phone = getPhone(subId);
4964 if (phone == null) {
4965 return null;
4966 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004967
Malcolm Chend965c8b2018-02-28 15:00:40 -08004968 return phone.getServiceState();
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004972 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004973
4974 /**
4975 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4976 *
4977 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4978 * voicemail ringtone.
4979 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4980 * PhoneAccount.
4981 */
4982 @Override
4983 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004984 final long identity = Binder.clearCallingIdentity();
4985 try {
4986 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4987 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004988 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004989 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004990
Malcolm Chend965c8b2018-02-28 15:00:40 -08004991 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4992 } finally {
4993 Binder.restoreCallingIdentity(identity);
4994 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004995 }
4996
4997 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004998 * Sets the per-account voicemail ringtone.
4999 *
5000 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5001 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5002 *
5003 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5004 * voicemail ringtone.
5005 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5006 * PhoneAccount.
5007 */
5008 @Override
5009 public void setVoicemailRingtoneUri(String callingPackage,
5010 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005011 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005012 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5013 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005014 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5016 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5017 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005018 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005019
5020 final long identity = Binder.clearCallingIdentity();
5021 try {
5022 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5023 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005024 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005025 }
5026 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5027 } finally {
5028 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005029 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005030 }
5031
5032 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005033 * Returns whether vibration is set for voicemail notification in Phone settings.
5034 *
5035 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5036 * voicemail vibration setting.
5037 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5038 */
5039 @Override
5040 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005041 final long identity = Binder.clearCallingIdentity();
5042 try {
5043 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5044 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005045 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005046 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005047
Malcolm Chend965c8b2018-02-28 15:00:40 -08005048 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005052 }
5053
Youhan Wange64578a2016-05-02 15:32:42 -07005054 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005055 * Sets the per-account voicemail vibration.
5056 *
5057 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5058 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5059 *
5060 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5061 * voicemail vibration setting.
5062 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5063 * specific PhoneAccount.
5064 */
5065 @Override
5066 public void setVoicemailVibrationEnabled(String callingPackage,
5067 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005068 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005069 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5070 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005071 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5073 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5074 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005075 }
5076
Malcolm Chend965c8b2018-02-28 15:00:40 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5080 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005081 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005082 }
5083 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5084 } finally {
5085 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005086 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005087 }
5088
5089 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005090 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5091 *
5092 * @throws SecurityException if the caller does not have the required permission
5093 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005094 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005095 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005096 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005097 }
5098
5099 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005100 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5101 * permission.
5102 *
5103 * @throws SecurityException if the caller does not have the required permission
5104 */
5105 private void enforceSendSmsPermission() {
5106 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5107 }
5108
5109 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005110 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005111 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005112 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005113 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005114 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005118 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005119 if (componentName == null) {
5120 throw new SecurityException(
5121 "Caller not current active visual voicemail package[null]");
5122 }
5123 String vvmPackage = componentName.getPackageName();
5124 if (!callingPackage.equals(vvmPackage)) {
5125 throw new SecurityException("Caller not current active visual voicemail package["
5126 + vvmPackage + "]");
5127 }
5128 } finally {
5129 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005130 }
5131 }
5132
5133 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005134 * Return the application ID for the app type.
5135 *
5136 * @param subId the subscription ID that this request applies to.
5137 * @param appType the uicc app type.
5138 * @return Application ID for specificied app type, or null if no uicc.
5139 */
5140 @Override
5141 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005142 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005143 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005144
5145 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005146 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005147 if (phone == null) {
5148 return null;
5149 }
5150 String aid = null;
5151 try {
5152 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5153 .getApplicationByType(appType).getAid();
5154 } catch (Exception e) {
5155 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5156 }
5157 return aid;
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005160 }
Youhan Wange64578a2016-05-02 15:32:42 -07005161 }
5162
Youhan Wang4001d252016-05-11 10:29:41 -07005163 /**
5164 * Return the Electronic Serial Number.
5165 *
5166 * @param subId the subscription ID that this request applies to.
5167 * @return ESN or null if error.
5168 */
5169 @Override
5170 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005171 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005172 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005173
5174 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005175 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005176 if (phone == null) {
5177 return null;
5178 }
5179 String esn = null;
5180 try {
5181 esn = phone.getEsn();
5182 } catch (Exception e) {
5183 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5184 }
5185 return esn;
5186 } finally {
5187 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005188 }
Youhan Wang4001d252016-05-11 10:29:41 -07005189 }
5190
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005191 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005192 * Return the Preferred Roaming List Version.
5193 *
5194 * @param subId the subscription ID that this request applies to.
5195 * @return PRLVersion or null if error.
5196 */
5197 @Override
5198 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005199 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005200 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005201
5202 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005203 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005204 if (phone == null) {
5205 return null;
5206 }
5207 String cdmaPrlVersion = null;
5208 try {
5209 cdmaPrlVersion = phone.getCdmaPrlVersion();
5210 } catch (Exception e) {
5211 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5212 }
5213 return cdmaPrlVersion;
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005216 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005217 }
5218
5219 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005220 * Get snapshot of Telephony histograms
5221 * @return List of Telephony histograms
5222 * @hide
5223 */
5224 @Override
5225 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5227 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005228
5229 final long identity = Binder.clearCallingIdentity();
5230 try {
5231 return RIL.getTelephonyRILTimingHistograms();
5232 } finally {
5233 Binder.restoreCallingIdentity(identity);
5234 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005235 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005236
5237 /**
5238 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005239 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005240 * Require system privileges. In the future we may add this to carrier APIs.
5241 *
5242 * @return The number of carriers set successfully, should match length of carriers
5243 */
5244 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005245 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005246 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005247 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005248
Meng Wang9b7c4e92017-02-17 11:41:27 -08005249 if (carriers == null) {
5250 throw new NullPointerException("carriers cannot be null");
5251 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005252
Malcolm Chend965c8b2018-02-28 15:00:40 -08005253 final long identity = Binder.clearCallingIdentity();
5254 try {
Michele85121de2018-12-19 15:25:20 -08005255 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5256 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdevie435a3e2018-08-15 16:01:53 -07005257 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5258 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005259 return retVal[0];
5260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005263 }
5264
5265 /**
5266 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005267 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005268 * Require system privileges. In the future we may add this to carrier APIs.
5269 *
5270 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5271 * means all carriers are allowed.
5272 */
5273 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005274 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005275 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005276 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005277
5278 final long identity = Binder.clearCallingIdentity();
5279 try {
Michele85121de2018-12-19 15:25:20 -08005280 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5281 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdevie435a3e2018-08-15 16:01:53 -07005282 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5283 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005287 }
5288
fionaxu59545b42016-05-25 15:53:37 -07005289 /**
5290 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5291 * @param subId the subscription ID that this action applies to.
5292 * @param enabled control enable or disable metered apns.
5293 * {@hide}
5294 */
5295 @Override
5296 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5297 enforceModifyPermission();
5298 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005299
5300 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005301 if (phone == null) {
5302 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5303 return;
5304 }
5305 try {
5306 phone.carrierActionSetMeteredApnsEnabled(enabled);
5307 } catch (Exception e) {
5308 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005309 } finally {
5310 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005311 }
5312 }
5313
5314 /**
5315 * Action set from carrier signalling broadcast receivers to enable/disable radio
5316 * @param subId the subscription ID that this action applies to.
5317 * @param enabled control enable or disable radio.
5318 * {@hide}
5319 */
5320 @Override
5321 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5322 enforceModifyPermission();
5323 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005324
5325 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005326 if (phone == null) {
5327 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5328 return;
5329 }
5330 try {
5331 phone.carrierActionSetRadioEnabled(enabled);
5332 } catch (Exception e) {
5333 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005334 } finally {
5335 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005336 }
5337 }
5338
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005339 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005340 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5341 * network status based on which carrier apps could apply actions accordingly,
5342 * enable/disable default url handler for example.
5343 *
5344 * @param subId the subscription ID that this action applies to.
5345 * @param report control start/stop reporting the default network status.
5346 * {@hide}
5347 */
5348 @Override
5349 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5350 enforceModifyPermission();
5351 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005352
5353 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005354 if (phone == null) {
5355 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5356 return;
5357 }
5358 try {
5359 phone.carrierActionReportDefaultNetworkStatus(report);
5360 } catch (Exception e) {
5361 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005364 }
5365 }
5366
5367 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005368 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5369 * bug report is being generated.
5370 */
5371 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005372 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005373 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5374 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005375 writer.println("Permission Denial: can't dump Phone from pid="
5376 + Binder.getCallingPid()
5377 + ", uid=" + Binder.getCallingUid()
5378 + "without permission "
5379 + android.Manifest.permission.DUMP);
5380 return;
5381 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005382 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005383 }
Jack Yueb89b242016-06-22 13:27:47 -07005384
Brad Ebingerdac2f002018-04-03 15:17:52 -07005385 @Override
5386 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5387 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5388 throws RemoteException {
5389 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5390 }
5391
Jack Yueb89b242016-06-22 13:27:47 -07005392 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005393 * Get aggregated video call data usage since boot.
5394 *
5395 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5396 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005397 * {@hide}
5398 */
5399 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005400 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005401 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5402 null);
5403
Malcolm Chend965c8b2018-02-28 15:00:40 -08005404 final long identity = Binder.clearCallingIdentity();
5405 try {
5406 // NetworkStatsService keeps tracking the active network interface and identity. It
5407 // records the delta with the corresponding network identity.
5408 // We just return the total video call data usage snapshot since boot.
5409 Phone phone = getPhone(subId);
5410 if (phone != null) {
5411 return phone.getVtDataUsage(perUidStats);
5412 }
5413 return null;
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005416 }
Jack Yueb89b242016-06-22 13:27:47 -07005417 }
Jack Yu75ab2952016-07-08 14:29:33 -07005418
5419 /**
5420 * Policy control of data connection. Usually used when data limit is passed.
5421 * @param enabled True if enabling the data, otherwise disabling.
5422 * @param subId Subscription index
5423 * {@hide}
5424 */
5425 @Override
5426 public void setPolicyDataEnabled(boolean enabled, int subId) {
5427 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005428
5429 final long identity = Binder.clearCallingIdentity();
5430 try {
5431 Phone phone = getPhone(subId);
5432 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005433 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005434 }
5435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005437 }
5438 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005439
5440 /**
5441 * Get Client request stats
5442 * @return List of Client Request Stats
5443 * @hide
5444 */
5445 @Override
5446 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005448 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005449 return null;
5450 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005451 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005452
Malcolm Chend965c8b2018-02-28 15:00:40 -08005453 final long identity = Binder.clearCallingIdentity();
5454 try {
5455 if (phone != null) {
5456 return phone.getClientRequestStats();
5457 }
5458
5459 return null;
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005463 }
5464
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005465 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005466 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005467 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005468 }
Jack Yueb4124c2017-02-16 15:32:43 -08005469
5470 /**
Grace Chen70990072017-03-24 17:21:30 -07005471 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005472 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005473 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005474 * @param state State of SIM (power down, power up, pass through)
5475 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5476 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5477 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005478 *
5479 **/
5480 @Override
Grace Chen70990072017-03-24 17:21:30 -07005481 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005482 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005483 Phone phone = PhoneFactory.getPhone(slotIndex);
5484
vagdevie435a3e2018-08-15 16:01:53 -07005485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5486
Malcolm Chend965c8b2018-02-28 15:00:40 -08005487 final long identity = Binder.clearCallingIdentity();
5488 try {
5489 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005490 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005491 }
5492 } finally {
5493 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005494 }
5495 }
Shuo Qiandd210312017-04-12 22:11:33 +00005496
Tyler Gunn65d45c22017-06-05 11:22:26 -07005497 private boolean isUssdApiAllowed(int subId) {
5498 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005499 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005500 if (configManager == null) {
5501 return false;
5502 }
5503 PersistableBundle pb = configManager.getConfigForSubId(subId);
5504 if (pb == null) {
5505 return false;
5506 }
5507 return pb.getBoolean(
5508 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5509 }
5510
Shuo Qiandd210312017-04-12 22:11:33 +00005511 /**
5512 * Check if phone is in emergency callback mode
5513 * @return true if phone is in emergency callback mode
5514 * @param subId sub id
5515 */
goneil9c5f4872017-12-05 14:07:56 -08005516 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005517 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005518 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005519 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005520
5521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 if (phone != null) {
5524 return phone.isInEcm();
5525 } else {
5526 return false;
5527 }
5528 } finally {
5529 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005530 }
5531 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005532
5533 /**
5534 * Get the current signal strength information for the given subscription.
5535 * Because this information is not updated when the device is in a low power state
5536 * it should not be relied-upon to be current.
5537 * @param subId Subscription index
5538 * @return the most recent cached signal strength info from the modem
5539 */
5540 @Override
5541 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 Phone p = getPhone(subId);
5545 if (p == null) {
5546 return null;
5547 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005548
Malcolm Chend965c8b2018-02-28 15:00:40 -08005549 return p.getSignalStrength();
5550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005553 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005554
Pengquan Meng9140aec2018-08-22 14:49:57 -07005555 /**
chen xu907e5a22018-10-11 13:21:04 -07005556 * Get the current modem radio state for the given slot.
5557 * @param slotIndex slot index.
5558 * @param callingPackage the name of the package making the call.
5559 * @return the current radio power state from the modem
5560 */
5561 @Override
5562 public int getRadioPowerState(int slotIndex, String callingPackage) {
5563 Phone phone = PhoneFactory.getPhone(slotIndex);
5564 if (phone != null) {
5565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5566 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5567 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5568 }
5569
5570 final long identity = Binder.clearCallingIdentity();
5571 try {
5572 return phone.getRadioPowerState();
5573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
5576 }
5577 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5578 }
5579
5580 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005581 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5582 *
5583 * <p>Requires one of the following permissions:
5584 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5585 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5586 * privileges.
5587 *
5588 * @param subId subscription id
5589 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5590 * {@code false}.
5591 */
5592 @Override
5593 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005594 boolean isEnabled = false;
5595 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005596 try {
5597 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005598 null /* message */);
5599 Phone phone = getPhone(subId);
5600 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005601 } catch (Exception e) {
5602 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5603 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005606 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005607 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005608 }
5609
5610
5611 /**
5612 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5613 *
5614 * <p> Requires permission:
5615 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5616 * privileges.
5617 *
5618 * @param subId subscription id
5619 * @param isEnabled {@code true} means enable, {@code false} means disable.
5620 */
5621 @Override
5622 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005623 final long identity = Binder.clearCallingIdentity();
5624 try {
5625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005627
Pengquan Meng0c05b502018-09-06 09:59:22 -07005628 Phone phone = getPhone(subId);
5629 if (phone != null) {
5630 phone.setDataRoamingEnabled(isEnabled);
5631 }
5632 } finally {
5633 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005634 }
5635 }
5636
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005637 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005638 public boolean isManualNetworkSelectionAllowed(int subId) {
5639 boolean isAllowed = true;
5640 final long identity = Binder.clearCallingIdentity();
5641 try {
5642 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5643 mApp, subId, "isManualNetworkSelectionAllowed");
5644 Phone phone = getPhone(subId);
5645 if (phone != null) {
5646 isAllowed = phone.isCspPlmnEnabled();
5647 }
5648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
5651 return isAllowed;
5652 }
5653
5654 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005655 public UiccCardInfo[] getUiccCardsInfo() {
5656 enforceReadPrivilegedPermission("getUiccCardsInfo");
5657
5658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5661 return cards.toArray(new UiccCardInfo[cards.size()]);
5662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
5665 }
5666
5667 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005668 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005669 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005670
Malcolm Chend965c8b2018-02-28 15:00:40 -08005671 final long identity = Binder.clearCallingIdentity();
5672 try {
5673 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5674 if (slots == null) {
5675 Rlog.i(LOG_TAG, "slots is null.");
5676 return null;
5677 }
5678
5679 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5680 for (int i = 0; i < slots.length; i++) {
5681 UiccSlot slot = slots[i];
5682 if (slot == null) {
5683 continue;
5684 }
5685
5686 String cardId;
5687 UiccCard card = slot.getUiccCard();
5688 if (card != null) {
5689 cardId = card.getCardId();
5690 } else {
5691 cardId = slot.getIccId();
5692 }
5693
5694 int cardState = 0;
5695 switch (slot.getCardState()) {
5696 case CARDSTATE_ABSENT:
5697 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5698 break;
5699 case CARDSTATE_PRESENT:
5700 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5701 break;
5702 case CARDSTATE_ERROR:
5703 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5704 break;
5705 case CARDSTATE_RESTRICTED:
5706 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5707 break;
5708 default:
5709 break;
5710
5711 }
5712
5713 infos[i] = new UiccSlotInfo(
5714 slot.isActive(),
5715 slot.isEuicc(),
5716 cardId,
5717 cardState,
5718 slot.getPhoneId(),
5719 slot.isExtendedApduSupported());
5720 }
5721 return infos;
5722 } finally {
5723 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005724 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005725 }
5726
5727 @Override
5728 public boolean switchSlots(int[] physicalSlots) {
5729 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005730
5731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5734 } finally {
5735 Binder.restoreCallingIdentity(identity);
5736 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005737 }
Jack Yu4c988042018-02-27 15:30:01 -08005738
5739 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005740 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5742 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5743 return TelephonyManager.INVALID_CARD_ID;
5744 }
5745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 return UiccController.getInstance().getCardIdForDefaultEuicc();
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
5752 }
5753
5754 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005755 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5756 enforceModifyPermission();
5757 final Phone phone = getPhone(subId);
5758 if (phone == null) {
5759 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5760 return;
5761 }
5762
Malcolm Chend965c8b2018-02-28 15:00:40 -08005763 final long identity = Binder.clearCallingIdentity();
5764 try {
5765 phone.setRadioIndicationUpdateMode(filters, mode);
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
Jack Yu4c988042018-02-27 15:30:01 -08005769 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005770
5771 /**
goneil47ffb6e2018-04-06 15:40:58 -07005772 * A test API to reload the UICC profile.
5773 *
5774 * <p>Requires that the calling app has permission
5775 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5776 * @hide
5777 */
5778 @Override
5779 public void refreshUiccProfile(int subId) {
5780 enforceModifyPermission();
5781
5782 final long identity = Binder.clearCallingIdentity();
5783 try {
5784 Phone phone = getPhone(subId);
5785 if (phone == null) {
5786 return;
5787 }
5788 UiccCard uiccCard = phone.getUiccCard();
5789 if (uiccCard == null) {
5790 return;
5791 }
5792 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5793 if (uiccProfile == null) {
5794 return;
5795 }
5796 uiccProfile.refresh();
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
5800 }
5801
5802 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005803 * Returns false if the mobile data is disabled by default, otherwise return true.
5804 */
5805 private boolean getDefaultDataEnabled() {
5806 return "true".equalsIgnoreCase(
5807 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5808 }
5809
5810 /**
5811 * Returns true if the data roaming is enabled by default, i.e the system property
5812 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5813 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5814 */
5815 private boolean getDefaultDataRoamingEnabled(int subId) {
5816 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005817 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005818 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5819 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5820 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5821 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5822 return isDataRoamingEnabled;
5823 }
5824
5825 /**
5826 * Returns the default network type for the given {@code subId}, if the default network type is
5827 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5828 */
5829 private int getDefaultNetworkType(int subId) {
5830 return Integer.parseInt(
5831 TelephonyManager.getTelephonyProperty(
5832 mSubscriptionController.getPhoneId(subId),
5833 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5834 String.valueOf(Phone.PREFERRED_NT_MODE)));
5835 }
fionaxua13278b2018-03-21 00:08:13 -07005836
5837 @Override
5838 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5839 gid1, String gid2, String plmn, String spn) {
5840 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005841
5842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 final Phone phone = getPhone(subId);
5845 if (phone == null) {
5846 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5847 return;
5848 }
5849 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005852 }
fionaxua13278b2018-03-21 00:08:13 -07005853 }
5854
5855 @Override
5856 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005857 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005858
5859 final long identity = Binder.clearCallingIdentity();
5860 try {
5861 final Phone phone = getPhone(subId);
5862 if (phone == null) {
5863 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5864 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5865 }
5866 return phone.getCarrierIdListVersion();
5867 } finally {
5868 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005869 }
fionaxua13278b2018-03-21 00:08:13 -07005870 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005871
5872 @Override
5873 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5875 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5876 return -1;
5877 }
5878
5879 final long identity = Binder.clearCallingIdentity();
5880 try {
5881 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
5885 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005886
5887 @Override
5888 public int getCdmaRoamingMode(int subId) {
5889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5890 mApp, subId, "getCdmaRoamingMode");
5891
5892 final long identity = Binder.clearCallingIdentity();
5893 try {
5894 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
5898 }
5899
5900 @Override
5901 public boolean setCdmaRoamingMode(int subId, int mode) {
5902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5903 mApp, subId, "setCdmaRoamingMode");
5904
5905 final long identity = Binder.clearCallingIdentity();
5906 try {
5907 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5908 } finally {
5909 Binder.restoreCallingIdentity(identity);
5910 }
5911 }
5912
5913 @Override
5914 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5916 mApp, subId, "setCdmaSubscriptionMode");
5917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
5924 }
chen xu7ee67862018-10-30 22:27:10 -07005925
sqian2fff4a32018-11-05 14:18:37 -08005926 private void ensureUserRunning(int userId) {
5927 if (!mUserManager.isUserRunning(userId)) {
5928 throw new IllegalStateException("User " + userId + " does not exist or not running");
5929 }
5930 }
5931
5932 /**
5933 * Returns a list of SMS apps on a given user.
5934 *
5935 * Only the shell user (UID 2000 or 0) can call it.
5936 * Target user must be running.
5937 */
5938 @Override
5939 public String[] getSmsApps(int userId) {
5940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5941 ensureUserRunning(userId);
5942
5943 final Collection<SmsApplicationData> apps =
5944 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5945
5946 String[] ret = new String[apps.size()];
5947 int i = 0;
5948 for (SmsApplicationData app : apps) {
5949 ret[i++] = app.mPackageName;
5950 }
5951 return ret;
5952 }
5953
5954 /**
5955 * Returns the default SMS app package name on a given user.
5956 *
5957 * Only the shell user (UID 2000 or 0) can call it.
5958 * Target user must be running.
5959 */
5960 @Override
5961 public String getDefaultSmsApp(int userId) {
5962 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5963 ensureUserRunning(userId);
5964
5965 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5966 /* updateIfNeeded= */ true, userId);
5967 return cn == null ? null : cn.getPackageName();
5968 }
5969
5970 /**
5971 * Set a package as the default SMS app on a given user.
5972 *
5973 * Only the shell user (UID 2000 or 0) can call it.
5974 * Target user must be running.
5975 */
5976 @Override
5977 public void setDefaultSmsApp(int userId, String packageName) {
5978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5979 ensureUserRunning(userId);
5980
5981 boolean found = false;
5982 for (String pkg : getSmsApps(userId)) {
5983 if (TextUtils.equals(packageName, pkg)) {
5984 found = true;
5985 break;
5986 }
5987 }
5988 if (!found) {
5989 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5990 }
5991
5992 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5993 }
5994
chen xu7ee67862018-10-30 22:27:10 -07005995 @Override
sqian04b86072018-11-07 14:02:21 -08005996 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5997 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08005998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5999 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6000 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6001 }
6002 final long identity = Binder.clearCallingIdentity();
6003 try {
sqian991b35e2018-12-12 16:48:18 -08006004 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6005 for (Phone phone: PhoneFactory.getPhones()) {
6006 if (phone.getEmergencyNumberTracker() != null
6007 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6008 emergencyNumberListInternal.put(
6009 phone.getSubId(),
6010 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6011 }
sqian03bca152018-12-05 18:48:28 -08006012 }
sqian991b35e2018-12-12 16:48:18 -08006013 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006014 } finally {
6015 Binder.restoreCallingIdentity(identity);
6016 }
sqian04b86072018-11-07 14:02:21 -08006017 }
6018
6019 @Override
sqian03bca152018-12-05 18:48:28 -08006020 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6021 final Phone defaultPhone = getDefaultPhone();
6022 if (!exactMatch) {
6023 TelephonyPermissions
6024 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6025 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6026 }
6027 final long identity = Binder.clearCallingIdentity();
6028 try {
sqian991b35e2018-12-12 16:48:18 -08006029 for (Phone phone: PhoneFactory.getPhones()) {
6030 if (phone.getEmergencyNumberTracker() != null
6031 && phone.getEmergencyNumberTracker() != null) {
6032 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6033 number, exactMatch)) {
6034 return true;
sqian03bca152018-12-05 18:48:28 -08006035 }
6036 }
sqian03bca152018-12-05 18:48:28 -08006037 }
6038 return false;
6039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
6042 }
6043
6044 private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListInternal() {
6045 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6046
6047 for (Phone phone: PhoneFactory.getPhones()) {
6048 if (phone.getEmergencyNumberTracker() != null
6049 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6050 emergencyNumberListInternal.put(
6051 phone.getSubId(),
6052 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6053 }
6054 }
6055 return emergencyNumberListInternal;
6056 }
6057
6058 private List<EmergencyNumber> getEmergencyNumberListFromEccList(int subscriptionId) {
6059 SubscriptionManager sm = (SubscriptionManager) mApp.getSystemService(
6060 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6061 List<EmergencyNumber> emergencyNumberList = new ArrayList<>();
6062 int slotId = sm.getSlotIndex(subscriptionId);
6063
6064 String ecclist = (slotId <= 0) ? "ril.ecclist" : ("ril.ecclist" + slotId);
6065 String emergencyNumbers = SystemProperties.get(ecclist, "");
6066 if (TextUtils.isEmpty(emergencyNumbers)) {
6067 // then read-only ecclist property since old RIL only uses this
6068 emergencyNumbers = SystemProperties.get("ro.ril.ecclist");
6069 }
6070 if (!TextUtils.isEmpty(emergencyNumbers)) {
6071 // searches through the comma-separated list for a match,
6072 // return true if one is found.
6073 for (String emergencyNum : emergencyNumbers.split(",")) {
6074 emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "",
6075 EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0));
6076 }
6077 }
6078 emergencyNumbers = ((slotId < 0) ? "112,911,000,08,110,118,119,999" : "112,911");
6079 for (String emergencyNum : emergencyNumbers.split(",")) {
6080 emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "",
6081 EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0));
6082 }
6083 EmergencyNumber.mergeSameNumbersInEmergencyNumberList(emergencyNumberList);
6084 return emergencyNumberList;
6085 }
6086
6087 /**
6088 * Get Emergency number list based on EccList. This util is used for solving backward
6089 * compatibility if device does not support the 1.4 IRadioIndication HAL that reports
6090 * emergency number list.
6091 *
6092 * @return Map including the key as the active subscription ID (Note: if there is no active
6093 * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId})
6094 * and the value as the list of {@link EmergencyNumber}.
6095 */
6096 private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListFromEccList() {
6097 Map<Integer, List<EmergencyNumber>> results = new HashMap<>();
6098 SubscriptionManager sm = (SubscriptionManager) mApp.getSystemService(
6099 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6100 int[] activeSubscriptionIds = sm.getActiveSubscriptionIdList();
6101
6102 if (activeSubscriptionIds.length == 0) {
6103 int defaultSubscriptionId = getDefaultSubscription();
6104 results.put(defaultSubscriptionId,
6105 getEmergencyNumberListFromEccList(defaultSubscriptionId));
6106 } else {
6107 for (int activeSubscriptionId : activeSubscriptionIds) {
6108 results.put(activeSubscriptionId,
6109 getEmergencyNumberListFromEccList(activeSubscriptionId));
6110 }
6111 }
6112 return results;
sqian04b86072018-11-07 14:02:21 -08006113 }
6114
6115 @Override
chen xu7ee67862018-10-30 22:27:10 -07006116 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6117 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6118 Phone phone = getPhone(subId);
6119 if (phone == null) {
6120 return null;
6121 }
6122 final long identity = Binder.clearCallingIdentity();
6123 try {
6124 UiccProfile profile = UiccController.getInstance()
6125 .getUiccProfileForPhone(phone.getPhoneId());
6126 if (profile != null) {
6127 return profile.getCertsFromCarrierPrivilegeAccessRules();
6128 }
6129 } finally {
6130 Binder.restoreCallingIdentity(identity);
6131 }
6132 return null;
6133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006134}