blob: 6d3a6da033876cdec169b4be2a056b0a2254add9 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070055import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
87import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070089import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080090import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070091import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080092import android.telephony.ims.aidl.IImsMmTelFeature;
93import android.telephony.ims.aidl.IImsRcsFeature;
94import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070095import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080096import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800100import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800102
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700104import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800105import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700107import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700108import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800109import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800113import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800115import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700116import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100117import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700118import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700121import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800122import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700123import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700124import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700125import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700126import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700127import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700129import com.android.internal.telephony.SmsApplication;
130import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800131import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800132import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700133import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700134import com.android.internal.telephony.uicc.IccIoResult;
135import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800136import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700137import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800138import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800140import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000141import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700142import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800143import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700144import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800145import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700146import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700147import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800148
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700149import java.io.FileDescriptor;
150import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800151import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800153import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700154import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800155import java.util.HashMap;
Jake Hambye994d462014-02-03 13:10:13 -0800156import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100157import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159
160/**
161 * Implementation of the ITelephony interface.
162 */
Santos Cordon117fee72014-05-16 17:56:12 -0700163public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 private static final String LOG_TAG = "PhoneInterfaceManager";
165 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
166 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168
169 // Message codes used with mMainThreadHandler
170 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700171 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
172 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173 private static final int CMD_OPEN_CHANNEL = 9;
174 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
175 private static final int CMD_CLOSE_CHANNEL = 11;
176 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800177 private static final int CMD_NV_READ_ITEM = 13;
178 private static final int EVENT_NV_READ_ITEM_DONE = 14;
179 private static final int CMD_NV_WRITE_ITEM = 15;
180 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
181 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
182 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700183 private static final int CMD_RESET_MODEM_CONFIG = 19;
184 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800185 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
186 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
187 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
188 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800189 private static final int CMD_SEND_ENVELOPE = 25;
190 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000191 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
192 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700193 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
194 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
195 private static final int CMD_EXCHANGE_SIM_IO = 31;
196 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800197 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
198 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700199 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
200 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700201 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
202 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700203 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
204 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
205 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
206 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700207 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
208 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
209 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
210 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700211 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800212 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
213 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000214 private static final int CMD_SWITCH_SLOTS = 50;
215 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700216 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
217 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
218 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
219 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
220 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
221 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
222 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
223 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700224 private static final int CMD_GET_ALL_CELL_INFO = 60;
225 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
226 private static final int CMD_GET_CELL_LOCATION = 62;
227 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700228 private static final int CMD_MODEM_REBOOT = 64;
229 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700230 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
231 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800232 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
233 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800235 // Parameters of select command.
236 private static final int SELECT_COMMAND = 0xA4;
237 private static final int SELECT_P1 = 0x04;
238 private static final int SELECT_P2 = 0;
239 private static final int SELECT_P3 = 0x10;
240
Pengquan Meng85728fb2018-03-12 16:31:21 -0700241 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
242 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
243 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
244
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 /** The singleton instance. */
246 private static PhoneInterfaceManager sInstance;
247
Wink Saville3ab207e2014-11-20 13:07:20 -0800248 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800249 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700250 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800251 private AppOpsManager mAppOps;
252 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800253 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800254 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700255 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256
Derek Tan97ebb422014-09-05 16:55:38 -0700257 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
258 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800259 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700260
Derek Tan740e1672017-06-27 14:56:27 -0700261 // The AID of ISD-R.
262 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
263
yinxub1bed742017-04-17 11:45:04 -0700264 private NetworkScanRequestTracker mNetworkScanRequestTracker;
265
David Kelly5e06a7f2018-03-12 14:10:59 +0000266 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
267 private static final int MANUFACTURER_CODE_LENGTH = 8;
268
Derek Tan89e89d42014-07-08 17:00:10 -0700269 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700270 * A request object to use for transmitting data to an ICC.
271 */
272 private static final class IccAPDUArgument {
273 public int channel, cla, command, p1, p2, p3;
274 public String data;
275
276 public IccAPDUArgument(int channel, int cla, int command,
277 int p1, int p2, int p3, String data) {
278 this.channel = channel;
279 this.cla = cla;
280 this.command = command;
281 this.p1 = p1;
282 this.p2 = p2;
283 this.p3 = p3;
284 this.data = data;
285 }
286 }
287
288 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700289 * A request object to use for transmitting data to an ICC.
290 */
291 private static final class ManualNetworkSelectionArgument {
292 public OperatorInfo operatorInfo;
293 public boolean persistSelection;
294
295 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
296 this.operatorInfo = operatorInfo;
297 this.persistSelection = persistSelection;
298 }
299 }
300
301 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
303 * request after sending. The main thread will notify the request when it is complete.
304 */
305 private static final class MainThreadRequest {
306 /** The argument to use for the request */
307 public Object argument;
308 /** The result of the request that is run on the main thread */
309 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800310 // The subscriber id that this request applies to. Defaults to
311 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
312 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313
Nathan Harold92bed182018-10-12 18:16:49 -0700314 // In cases where subId is unavailable, the caller needs to specify the phone.
315 public Phone phone;
316
vagdeviaf9a5b92018-08-15 16:01:53 -0700317 public WorkSource workSource;
318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 public MainThreadRequest(Object argument) {
320 this.argument = argument;
321 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800322
Nathan Harold92bed182018-10-12 18:16:49 -0700323 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
324 this.argument = argument;
325 if (phone != null) {
326 this.phone = phone;
327 }
328 this.workSource = workSource;
329 }
330
vagdeviaf9a5b92018-08-15 16:01:53 -0700331 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800332 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800333 if (subId != null) {
334 this.subId = subId;
335 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700336 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 }
339
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800340 private static final class IncomingThirdPartyCallArgs {
341 public final ComponentName component;
342 public final String callId;
343 public final String callerDisplayName;
344
345 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
346 String callerDisplayName) {
347 this.component = component;
348 this.callId = callId;
349 this.callerDisplayName = callerDisplayName;
350 }
351 }
352
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 /**
354 * A handler that processes messages on the main thread in the phone process. Since many
355 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
356 * inbound binder threads to the main thread in the phone process. The Binder thread
357 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
358 * on, which will be notified when the operation completes and will contain the result of the
359 * request.
360 *
361 * <p>If a MainThreadRequest object is provided in the msg.obj field,
362 * note that request.result must be set to something non-null for the calling thread to
363 * unblock.
364 */
365 private final class MainThreadHandler extends Handler {
366 @Override
367 public void handleMessage(Message msg) {
368 MainThreadRequest request;
369 Message onCompleted;
370 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800371 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700372 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800373 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
375 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700376 case CMD_HANDLE_USSD_REQUEST: {
377 request = (MainThreadRequest) msg.obj;
378 final Phone phone = getPhoneFromRequest(request);
379 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
380 String ussdRequest = ussdObject.first;
381 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700382
Pengquan Menga1bb6272018-09-06 09:59:22 -0700383 if (!isUssdApiAllowed(request.subId)) {
384 // Carrier does not support use of this API, return failure.
385 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
386 UssdResponse response = new UssdResponse(ussdRequest, null);
387 Bundle returnData = new Bundle();
388 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
389 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700390
Pengquan Menga1bb6272018-09-06 09:59:22 -0700391 request.result = true;
392 notifyRequester(request);
393 return;
394 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700395
Pengquan Menga1bb6272018-09-06 09:59:22 -0700396 try {
397 request.result = phone != null
398 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
399 } catch (CallStateException cse) {
400 request.result = false;
401 }
402 // Wake up the requesting thread
403 notifyRequester(request);
404 break;
pkanwar32d516d2016-10-14 19:37:38 -0700405 }
406
Yorke Lee716f67e2015-06-17 15:39:16 -0700407 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700409 final Phone phone = getPhoneFromRequest(request);
410 request.result = phone != null ?
411 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
412 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700414 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800421 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 if (uiccCard == null) {
423 loge("iccTransmitApduLogicalChannel: No UICC");
424 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700425 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
428 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700430 iccArgument.channel, iccArgument.cla, iccArgument.command,
431 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700433 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 break;
435
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 ar = (AsyncResult) msg.obj;
438 request = (MainThreadRequest) ar.userObj;
439 if (ar.exception == null && ar.result != null) {
440 request.result = ar.result;
441 } else {
442 request.result = new IccIoResult(0x6F, 0, (byte[])null);
443 if (ar.result == null) {
444 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800445 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800447 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 } else {
449 loge("iccTransmitApduLogicalChannel: Unknown exception");
450 }
451 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 break;
454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
456 request = (MainThreadRequest) msg.obj;
457 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800458 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 if (uiccCard == null) {
460 loge("iccTransmitApduBasicChannel: No UICC");
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 } else {
464 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
465 request);
466 uiccCard.iccTransmitApduBasicChannel(
467 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
468 iccArgument.p3, iccArgument.data, onCompleted);
469 }
470 break;
471
472 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
473 ar = (AsyncResult) msg.obj;
474 request = (MainThreadRequest) ar.userObj;
475 if (ar.exception == null && ar.result != null) {
476 request.result = ar.result;
477 } else {
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
479 if (ar.result == null) {
480 loge("iccTransmitApduBasicChannel: Empty response");
481 } else if (ar.exception instanceof CommandException) {
482 loge("iccTransmitApduBasicChannel: CommandException: " +
483 ar.exception);
484 } else {
485 loge("iccTransmitApduBasicChannel: Unknown exception");
486 }
487 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 break;
490
491 case CMD_EXCHANGE_SIM_IO:
492 request = (MainThreadRequest) msg.obj;
493 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800494 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 if (uiccCard == null) {
496 loge("iccExchangeSimIO: No UICC");
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700498 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 } else {
500 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
501 request);
502 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
503 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
504 iccArgument.data, onCompleted);
505 }
506 break;
507
508 case EVENT_EXCHANGE_SIM_IO_DONE:
509 ar = (AsyncResult) msg.obj;
510 request = (MainThreadRequest) ar.userObj;
511 if (ar.exception == null && ar.result != null) {
512 request.result = ar.result;
513 } else {
514 request.result = new IccIoResult(0x6f, 0, (byte[])null);
515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 break;
518
Derek Tan4d5e5c12014-02-04 11:54:58 -0800519 case CMD_SEND_ENVELOPE:
520 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 if (uiccCard == null) {
523 loge("sendEnvelopeWithStatus: No UICC");
524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 } else {
527 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
528 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
529 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 break;
531
532 case EVENT_SEND_ENVELOPE_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("sendEnvelopeWithStatus: Empty response");
541 } else if (ar.exception instanceof CommandException) {
542 loge("sendEnvelopeWithStatus: CommandException: " +
543 ar.exception);
544 } else {
545 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
546 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 break;
550
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 case CMD_OPEN_CHANNEL:
552 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800553 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800554 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 if (uiccCard == null) {
556 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800557 request.result = new IccOpenLogicalChannelResponse(-1,
558 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 } else {
561 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800562 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
563 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
567 case EVENT_OPEN_CHANNEL_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 int[] result = (int[]) ar.result;
573 int channelId = result[0];
574 byte[] selectResponse = null;
575 if (result.length > 1) {
576 selectResponse = new byte[result.length - 1];
577 for (int i = 1; i < result.length; ++i) {
578 selectResponse[i - 1] = (byte) result[i];
579 }
580 }
581 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 if (ar.result == null) {
585 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 if (ar.exception != null) {
588 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
589 }
590
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700591 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700592 if (ar.exception instanceof CommandException) {
593 CommandException.Error error =
594 ((CommandException) (ar.exception)).getCommandError();
595 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700597 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700598 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 }
600 }
601 openChannelResp = new IccOpenLogicalChannelResponse(
602 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700604 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
608 case CMD_CLOSE_CHANNEL:
609 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800610 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 if (uiccCard == null) {
612 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900613 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 } else {
616 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
617 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
618 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 break;
620
621 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800622 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
623 break;
624
625 case CMD_NV_READ_ITEM:
626 request = (MainThreadRequest) msg.obj;
627 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800628 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
629 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800630 break;
631
632 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 ar = (AsyncResult) msg.obj;
634 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800635 if (ar.exception == null && ar.result != null) {
636 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800638 request.result = "";
639 if (ar.result == null) {
640 loge("nvReadItem: Empty response");
641 } else if (ar.exception instanceof CommandException) {
642 loge("nvReadItem: CommandException: " +
643 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800645 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
647 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
Jake Hambye994d462014-02-03 13:10:13 -0800651 case CMD_NV_WRITE_ITEM:
652 request = (MainThreadRequest) msg.obj;
653 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
654 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800655 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700656 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800657 break;
658
659 case EVENT_NV_WRITE_ITEM_DONE:
660 handleNullReturnEvent(msg, "nvWriteItem");
661 break;
662
663 case CMD_NV_WRITE_CDMA_PRL:
664 request = (MainThreadRequest) msg.obj;
665 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800666 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800667 break;
668
669 case EVENT_NV_WRITE_CDMA_PRL_DONE:
670 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
671 break;
672
chen xu6dac5ab2018-10-26 17:39:23 -0700673 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800674 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700675 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800676 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800677 break;
678
chen xu6dac5ab2018-10-26 17:39:23 -0700679 case EVENT_RESET_MODEM_CONFIG_DONE:
680 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800681 break;
682
Jake Hamby7c27be32014-03-03 13:25:59 -0800683 case CMD_GET_PREFERRED_NETWORK_TYPE:
684 request = (MainThreadRequest) msg.obj;
685 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700686 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 break;
688
689 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
690 ar = (AsyncResult) msg.obj;
691 request = (MainThreadRequest) ar.userObj;
692 if (ar.exception == null && ar.result != null) {
693 request.result = ar.result; // Integer
694 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800695 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800696 if (ar.result == null) {
697 loge("getPreferredNetworkType: Empty response");
698 } else if (ar.exception instanceof CommandException) {
699 loge("getPreferredNetworkType: CommandException: " +
700 ar.exception);
701 } else {
702 loge("getPreferredNetworkType: Unknown exception");
703 }
704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 break;
707
708 case CMD_SET_PREFERRED_NETWORK_TYPE:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
711 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700712 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 break;
714
715 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
716 handleNullReturnEvent(msg, "setPreferredNetworkType");
717 break;
718
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000719 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
720 request = (MainThreadRequest)msg.obj;
721 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800722 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000723 break;
724
725 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
726 ar = (AsyncResult)msg.obj;
727 request = (MainThreadRequest)ar.userObj;
728 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000730 break;
731
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800732 case CMD_SET_VOICEMAIL_NUMBER:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
735 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800736 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
737 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800738 break;
739
740 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
741 handleNullReturnEvent(msg, "setVoicemailNumber");
742 break;
743
Stuart Scott54788802015-03-30 13:18:01 -0700744 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
745 request = (MainThreadRequest) msg.obj;
746 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
747 request);
748 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
749 break;
750
751 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
752 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
753 break;
754
Shishir Agrawal302c8692015-06-19 13:49:39 -0700755 case CMD_PERFORM_NETWORK_SCAN:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
758 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
759 break;
760
761 case EVENT_PERFORM_NETWORK_SCAN_DONE:
762 ar = (AsyncResult) msg.obj;
763 request = (MainThreadRequest) ar.userObj;
764 CellNetworkScanResult cellScanResult;
765 if (ar.exception == null && ar.result != null) {
766 cellScanResult = new CellNetworkScanResult(
767 CellNetworkScanResult.STATUS_SUCCESS,
768 (List<OperatorInfo>) ar.result);
769 } else {
770 if (ar.result == null) {
771 loge("getCellNetworkScanResults: Empty response");
772 }
773 if (ar.exception != null) {
774 loge("getCellNetworkScanResults: Exception: " + ar.exception);
775 }
776 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
777 if (ar.exception instanceof CommandException) {
778 CommandException.Error error =
779 ((CommandException) (ar.exception)).getCommandError();
780 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
781 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
782 } else if (error == CommandException.Error.GENERIC_FAILURE) {
783 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
784 }
785 }
786 cellScanResult = new CellNetworkScanResult(errorCode, null);
787 }
788 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700789 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 break;
791
792 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
793 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700794 ManualNetworkSelectionArgument selArg =
795 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
797 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700798 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
799 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700800 break;
801
802 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 if (ar.exception == null) {
806 request.result = true;
807 } else {
808 request.result = false;
809 loge("setNetworkSelectionModeManual " + ar.exception);
810 }
811 notifyRequester(request);
812 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700813 break;
814
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700815 case CMD_GET_MODEM_ACTIVITY_INFO:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800818 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700819 break;
820
821 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null && ar.result != null) {
825 request.result = ar.result;
826 } else {
827 if (ar.result == null) {
828 loge("queryModemActivityInfo: Empty response");
829 } else if (ar.exception instanceof CommandException) {
830 loge("queryModemActivityInfo: CommandException: " +
831 ar.exception);
832 } else {
833 loge("queryModemActivityInfo: Unknown exception");
834 }
835 }
Amit Mahajand4766222016-01-28 15:28:28 -0800836 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
837 if (request.result == null) {
838 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
839 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700840 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700841 break;
842
Meng Wang1a7c35a2016-05-05 20:56:15 -0700843 case CMD_SET_ALLOWED_CARRIERS:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800846 defaultPhone.setAllowedCarriers(
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700848 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700849 break;
850
851 case EVENT_SET_ALLOWED_CARRIERS_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 if (ar.result == null) {
858 loge("setAllowedCarriers: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("setAllowedCarriers: CommandException: " +
861 ar.exception);
862 } else {
863 loge("setAllowedCarriers: Unknown exception");
864 }
865 }
866 // Result cannot be null. Return -1 on error.
867 if (request.result == null) {
868 request.result = new int[]{-1};
869 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700870 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700871 break;
872
873 case CMD_GET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800876 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 break;
878
879 case EVENT_GET_ALLOWED_CARRIERS_DONE:
880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
882 if (ar.exception == null && ar.result != null) {
883 request.result = ar.result;
884 } else {
885 if (ar.result == null) {
886 loge("getAllowedCarriers: Empty response");
887 } else if (ar.exception instanceof CommandException) {
888 loge("getAllowedCarriers: CommandException: " +
889 ar.exception);
890 } else {
891 loge("getAllowedCarriers: Unknown exception");
892 }
893 }
894 // Result cannot be null. Return empty list of CarrierIdentifier.
895 if (request.result == null) {
896 request.result = new ArrayList<CarrierIdentifier>(0);
897 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700898 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700899 break;
900
Nathan Haroldb3014052017-01-25 15:57:32 -0800901 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
902 ar = (AsyncResult) msg.obj;
903 request = (MainThreadRequest) ar.userObj;
904 if (ar.exception == null && ar.result != null) {
905 request.result = ar.result;
906 } else {
907 request.result = new IllegalArgumentException(
908 "Failed to retrieve Forbidden Plmns");
909 if (ar.result == null) {
910 loge("getForbiddenPlmns: Empty response");
911 } else {
912 loge("getForbiddenPlmns: Unknown exception");
913 }
914 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700915 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800916 break;
917
918 case CMD_GET_FORBIDDEN_PLMNS:
919 request = (MainThreadRequest) msg.obj;
920 uiccCard = getUiccCardFromRequest(request);
921 if (uiccCard == null) {
922 loge("getForbiddenPlmns() UiccCard is null");
923 request.result = new IllegalArgumentException(
924 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700925 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800926 break;
927 }
928 Integer appType = (Integer) request.argument;
929 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
930 if (uiccApp == null) {
931 loge("getForbiddenPlmns() no app with specified type -- "
932 + appType);
933 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700934 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800935 break;
936 } else {
937 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
938 + " specified type -- " + appType);
939 }
940 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
941 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
942 onCompleted);
943 break;
944
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000945 case CMD_SWITCH_SLOTS:
946 request = (MainThreadRequest) msg.obj;
947 int[] physicalSlots = (int[]) request.argument;
948 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
949 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
950 break;
951
952 case EVENT_SWITCH_SLOTS_DONE:
953 ar = (AsyncResult) msg.obj;
954 request = (MainThreadRequest) ar.userObj;
955 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
957 break;
958 case CMD_GET_NETWORK_SELECTION_MODE:
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
961 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
962 break;
963
964 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 if (ar.exception != null) {
968 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
969 } else {
970 int mode = ((int[]) ar.result)[0];
971 if (mode == 0) {
972 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
973 } else {
974 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
975 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000976 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700977 notifyRequester(request);
978 break;
979 case CMD_GET_CDMA_ROAMING_MODE:
980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
982 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
983 break;
984 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception != null) {
988 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
989 } else {
990 request.result = ((int[]) ar.result)[0];
991 }
992 notifyRequester(request);
993 break;
994 case CMD_SET_CDMA_ROAMING_MODE:
995 request = (MainThreadRequest) msg.obj;
996 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
997 int mode = (int) request.argument;
998 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
999 break;
1000 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1001 ar = (AsyncResult) msg.obj;
1002 request = (MainThreadRequest) ar.userObj;
1003 request.result = ar.exception == null;
1004 notifyRequester(request);
1005 break;
1006 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1009 int subscriptionMode = (int) request.argument;
1010 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1011 break;
1012 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 request.result = ar.exception == null;
1016 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001017 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 case CMD_GET_ALL_CELL_INFO:
1019 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001020 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001021 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001022 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001023 case EVENT_GET_ALL_CELL_INFO_DONE:
1024 ar = (AsyncResult) msg.obj;
1025 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001026 // If a timeout occurs, the response will be null
1027 request.result = (ar.exception == null && ar.result != null)
1028 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001029 synchronized (request) {
1030 request.notifyAll();
1031 }
1032 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001033 case CMD_REQUEST_CELL_INFO_UPDATE:
1034 request = (MainThreadRequest) msg.obj;
1035 request.phone.requestCellInfoUpdate(request.workSource,
1036 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1037 break;
1038 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
1041 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1042 try {
1043 if (ar.exception != null) {
1044 // something went wrong... the response is null
1045 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1046 cb.onCellInfo(null);
1047 } else if (ar.result == null) {
1048 // timeout occurred, so force the result to non-null "empty"
1049 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1050 cb.onCellInfo(new ArrayList<CellInfo>());
1051 } else {
1052 // use the result as returned
1053 cb.onCellInfo((List<CellInfo>) ar.result);
1054 }
1055 } catch (RemoteException re) {
1056 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1057 }
1058 break;
1059 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 request = (MainThreadRequest) msg.obj;
1061 WorkSource ws = (WorkSource) request.argument;
1062 Phone phone = getPhoneFromRequest(request);
1063 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1064 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null) {
1069 request.result = ar.result;
1070 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001071 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001072 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1073 ? new CdmaCellLocation() : new GsmCellLocation();
1074 }
1075
1076 synchronized (request) {
1077 request.notifyAll();
1078 }
1079 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001080 case CMD_MODEM_REBOOT:
1081 request = (MainThreadRequest) msg.obj;
1082 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001083 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001084 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001085 case EVENT_CMD_MODEM_REBOOT_DONE:
1086 handleNullReturnEvent(msg, "rebootModem");
1087 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001088 case CMD_REQUEST_ENABLE_MODEM:
1089 request = (MainThreadRequest) msg.obj;
1090 boolean enable = (boolean) request.argument;
1091 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1092 PhoneConfigurationManager.getInstance()
1093 .enablePhone(request.phone, enable, onCompleted);
1094 break;
1095 case EVENT_ENABLE_MODEM_DONE:
1096 ar = (AsyncResult) msg.obj;
1097 request = (MainThreadRequest) ar.userObj;
1098 request.result = (ar.exception == null);
1099 notifyRequester(request);
1100 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001101 default:
1102 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1103 break;
1104 }
1105 }
Jake Hambye994d462014-02-03 13:10:13 -08001106
Pengquan Menga1bb6272018-09-06 09:59:22 -07001107 private void notifyRequester(MainThreadRequest request) {
1108 synchronized (request) {
1109 request.notifyAll();
1110 }
1111 }
1112
Jake Hambye994d462014-02-03 13:10:13 -08001113 private void handleNullReturnEvent(Message msg, String command) {
1114 AsyncResult ar = (AsyncResult) msg.obj;
1115 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1116 if (ar.exception == null) {
1117 request.result = true;
1118 } else {
1119 request.result = false;
1120 if (ar.exception instanceof CommandException) {
1121 loge(command + ": CommandException: " + ar.exception);
1122 } else {
1123 loge(command + ": Unknown exception");
1124 }
1125 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001126 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001128 }
1129
1130 /**
1131 * Posts the specified command to be executed on the main thread,
1132 * waits for the request to complete, and returns the result.
1133 * @see #sendRequestAsync
1134 */
1135 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001136 return sendRequest(
1137 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001138 }
1139
1140 /**
1141 * Posts the specified command to be executed on the main thread,
1142 * waits for the request to complete, and returns the result.
1143 * @see #sendRequestAsync
1144 */
1145 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1146 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001147 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001148 }
1149
1150 /**
1151 * Posts the specified command to be executed on the main thread,
1152 * waits for the request to complete, and returns the result.
1153 * @see #sendRequestAsync
1154 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001155 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001156 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001157 }
1158
1159 /**
1160 * Posts the specified command to be executed on the main thread,
1161 * waits for the request to complete, and returns the result.
1162 * @see #sendRequestAsync
1163 */
Nathan Harold92bed182018-10-12 18:16:49 -07001164 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1165 return sendRequest(command, argument, subId, null, workSource);
1166 }
1167
1168 /**
1169 * Posts the specified command to be executed on the main thread,
1170 * waits for the request to complete, and returns the result.
1171 * @see #sendRequestAsync
1172 */
1173 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1174 return sendRequest(
1175 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1176 }
1177
1178 /**
1179 * Posts the specified command to be executed on the main thread,
1180 * waits for the request to complete, and returns the result.
1181 * @see #sendRequestAsync
1182 */
1183 private Object sendRequest(
1184 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001185 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1186 throw new RuntimeException("This method will deadlock if called from the main thread.");
1187 }
1188
Nathan Harold92bed182018-10-12 18:16:49 -07001189 MainThreadRequest request = null;
1190 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1191 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1192 } else if (phone != null) {
1193 request = new MainThreadRequest(argument, phone, workSource);
1194 } else {
1195 request = new MainThreadRequest(argument, subId, workSource);
1196 }
1197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001198 Message msg = mMainThreadHandler.obtainMessage(command, request);
1199 msg.sendToTarget();
1200
1201 // Wait for the request to complete
1202 synchronized (request) {
1203 while (request.result == null) {
1204 try {
1205 request.wait();
1206 } catch (InterruptedException e) {
1207 // Do nothing, go back and wait until the request is complete
1208 }
1209 }
1210 }
1211 return request.result;
1212 }
1213
1214 /**
1215 * Asynchronous ("fire and forget") version of sendRequest():
1216 * Posts the specified command to be executed on the main thread, and
1217 * returns immediately.
1218 * @see #sendRequest
1219 */
1220 private void sendRequestAsync(int command) {
1221 mMainThreadHandler.sendEmptyMessage(command);
1222 }
1223
1224 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001225 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001226 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001227 */
1228 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001229 sendRequestAsync(command, argument, null, null);
1230 }
1231
1232 /**
1233 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1234 * @see {@link #sendRequest(int,Object)}
1235 */
1236 private void sendRequestAsync(
1237 int command, Object argument, Phone phone, WorkSource workSource) {
1238 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001239 Message msg = mMainThreadHandler.obtainMessage(command, request);
1240 msg.sendToTarget();
1241 }
1242
1243 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 * Initialize the singleton PhoneInterfaceManager instance.
1245 * This is only done once, at startup, from PhoneApp.onCreate().
1246 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001247 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 synchronized (PhoneInterfaceManager.class) {
1249 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001250 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 } else {
1252 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1253 }
1254 return sInstance;
1255 }
1256 }
1257
1258 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001259 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001262 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1264 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001265 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001266 mTelephonySharedPreferences =
1267 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001268 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001269 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001270
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271 publish();
1272 }
1273
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001274 private Phone getDefaultPhone() {
1275 Phone thePhone = getPhone(getDefaultSubscription());
1276 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1277 }
1278
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 private void publish() {
1280 if (DBG) log("publish: " + this);
1281
1282 ServiceManager.addService("phone", this);
1283 }
1284
Stuart Scott584921c2015-01-15 17:10:34 -08001285 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001286 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001287 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001288 }
1289
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001290 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1291 Phone phone = getPhoneFromRequest(request);
1292 return phone == null ? null :
1293 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1294 }
1295
Wink Saville36469e72014-06-11 15:17:00 -07001296 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001297 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001298 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300
1301 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001302 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001303 }
1304
Wink Savilleb564aae2014-10-23 10:18:09 -07001305 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 if (DBG) log("dial: " + number);
1307 // No permission check needed here: This is just a wrapper around the
1308 // ACTION_DIAL intent, which is available to any app since it puts up
1309 // the UI before it does anything.
1310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001311 final long identity = Binder.clearCallingIdentity();
1312 try {
1313 String url = createTelUrl(number);
1314 if (url == null) {
1315 return;
1316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001318 // PENDING: should we just silently fail if phone is offhook or ringing?
1319 PhoneConstants.State state = mCM.getState(subId);
1320 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1321 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1322 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1323 mApp.startActivity(intent);
1324 }
1325 } finally {
1326 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 }
1328 }
1329
1330 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001331 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001332 }
1333
Wink Savilleb564aae2014-10-23 10:18:09 -07001334 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 if (DBG) log("call: " + number);
1336
1337 // This is just a wrapper around the ACTION_CALL intent, but we still
1338 // need to do a permission check since we're calling startActivity()
1339 // from the context of the phone app.
1340 enforceCallPermission();
1341
1342 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1343 != AppOpsManager.MODE_ALLOWED) {
1344 return;
1345 }
1346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001347 final long identity = Binder.clearCallingIdentity();
1348 try {
1349 String url = createTelUrl(number);
1350 if (url == null) {
1351 return;
1352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001354 boolean isValid = false;
1355 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1356 if (slist != null) {
1357 for (SubscriptionInfo subInfoRecord : slist) {
1358 if (subInfoRecord.getSubscriptionId() == subId) {
1359 isValid = true;
1360 break;
1361 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001362 }
Wink Saville08874612014-08-31 19:19:58 -07001363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001364 if (!isValid) {
1365 return;
1366 }
Wink Saville08874612014-08-31 19:19:58 -07001367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001368 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1369 intent.putExtra(SUBSCRIPTION_KEY, subId);
1370 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1371 mApp.startActivity(intent);
1372 } finally {
1373 Binder.restoreCallingIdentity(identity);
1374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 }
1376
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001378 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001379 }
1380
Wink Savilleb564aae2014-10-23 10:18:09 -07001381 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001382 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001383 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1384 }
1385
1386 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001387 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001388 }
1389
Wink Savilleb564aae2014-10-23 10:18:09 -07001390 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001391 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001392 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1393 }
1394
1395 /** {@hide} */
1396 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001397 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001398 }
1399
Wink Savilleb564aae2014-10-23 10:18:09 -07001400 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001402
1403 final long identity = Binder.clearCallingIdentity();
1404 try {
1405 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1406 checkSimPin.start();
1407 return checkSimPin.unlockSim(null, pin);
1408 } finally {
1409 Binder.restoreCallingIdentity(identity);
1410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 }
1412
Wink Saville9de0f752013-10-22 19:04:03 -07001413 /** {@hide} */
1414 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001415 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001416 }
1417
Wink Savilleb564aae2014-10-23 10:18:09 -07001418 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001420
1421 final long identity = Binder.clearCallingIdentity();
1422 try {
1423 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1424 checkSimPuk.start();
1425 return checkSimPuk.unlockSim(puk, pin);
1426 } finally {
1427 Binder.restoreCallingIdentity(identity);
1428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429 }
1430
1431 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001432 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433 * a synchronous one.
1434 */
1435 private static class UnlockSim extends Thread {
1436
1437 private final IccCard mSimCard;
1438
1439 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001440 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1441 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
1443 // For replies from SimCard interface
1444 private Handler mHandler;
1445
1446 // For async handler to identify request type
1447 private static final int SUPPLY_PIN_COMPLETE = 100;
1448
1449 public UnlockSim(IccCard simCard) {
1450 mSimCard = simCard;
1451 }
1452
1453 @Override
1454 public void run() {
1455 Looper.prepare();
1456 synchronized (UnlockSim.this) {
1457 mHandler = new Handler() {
1458 @Override
1459 public void handleMessage(Message msg) {
1460 AsyncResult ar = (AsyncResult) msg.obj;
1461 switch (msg.what) {
1462 case SUPPLY_PIN_COMPLETE:
1463 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1464 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001465 mRetryCount = msg.arg1;
1466 if (ar.exception != null) {
1467 if (ar.exception instanceof CommandException &&
1468 ((CommandException)(ar.exception)).getCommandError()
1469 == CommandException.Error.PASSWORD_INCORRECT) {
1470 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1471 } else {
1472 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1473 }
1474 } else {
1475 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477 mDone = true;
1478 UnlockSim.this.notifyAll();
1479 }
1480 break;
1481 }
1482 }
1483 };
1484 UnlockSim.this.notifyAll();
1485 }
1486 Looper.loop();
1487 }
1488
1489 /*
1490 * Use PIN or PUK to unlock SIM card
1491 *
1492 * If PUK is null, unlock SIM card with PIN
1493 *
1494 * If PUK is not null, unlock SIM card with PUK and set PIN code
1495 */
Wink Saville9de0f752013-10-22 19:04:03 -07001496 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497
1498 while (mHandler == null) {
1499 try {
1500 wait();
1501 } catch (InterruptedException e) {
1502 Thread.currentThread().interrupt();
1503 }
1504 }
1505 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1506
1507 if (puk == null) {
1508 mSimCard.supplyPin(pin, callback);
1509 } else {
1510 mSimCard.supplyPuk(puk, pin, callback);
1511 }
1512
1513 while (!mDone) {
1514 try {
1515 Log.d(LOG_TAG, "wait for done");
1516 wait();
1517 } catch (InterruptedException e) {
1518 // Restore the interrupted status
1519 Thread.currentThread().interrupt();
1520 }
1521 }
1522 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001523 int[] resultArray = new int[2];
1524 resultArray[0] = mResult;
1525 resultArray[1] = mRetryCount;
1526 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 }
1528 }
1529
1530 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001531 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001532
1533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 // No permission check needed here: this call is harmless, and it's
1537 // needed for the ServiceState.requestStateUpdate() call (which is
1538 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001539 final long identity = Binder.clearCallingIdentity();
1540 try {
1541 final Phone phone = getPhone(subId);
1542 if (phone != null) {
1543 phone.updateServiceLocation();
1544 }
1545 } finally {
1546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 }
1549
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001550 @Override
1551 public boolean isRadioOn(String callingPackage) {
1552 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001553 }
1554
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001555 @Override
1556 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001558 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001559 return false;
1560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001561
1562 final long identity = Binder.clearCallingIdentity();
1563 try {
1564 return isRadioOnForSubscriber(subId);
1565 } finally {
1566 Binder.restoreCallingIdentity(identity);
1567 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001568 }
1569
1570 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001571 final long identity = Binder.clearCallingIdentity();
1572 try {
1573 final Phone phone = getPhone(subId);
1574 if (phone != null) {
1575 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1576 } else {
1577 return false;
1578 }
1579 } finally {
1580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 }
1583
1584 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001585 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 }
Wink Saville36469e72014-06-11 15:17:00 -07001587
Wink Savilleb564aae2014-10-23 10:18:09 -07001588 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001590
1591 final long identity = Binder.clearCallingIdentity();
1592 try {
1593 final Phone phone = getPhone(subId);
1594 if (phone != null) {
1595 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1596 }
1597 } finally {
1598 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 }
Wink Saville36469e72014-06-11 15:17:00 -07001600 }
1601
1602 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001603 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001604 }
1605
Wink Savilleb564aae2014-10-23 10:18:09 -07001606 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001608
1609 final long identity = Binder.clearCallingIdentity();
1610 try {
1611 final Phone phone = getPhone(subId);
1612 if (phone == null) {
1613 return false;
1614 }
1615 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1616 toggleRadioOnOffForSubscriber(subId);
1617 }
1618 return true;
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
Wink Saville36469e72014-06-11 15:17:00 -07001623
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001624 public boolean needMobileRadioShutdown() {
1625 /*
1626 * If any of the Radios are available, it will need to be
1627 * shutdown. So return true if any Radio is available.
1628 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001629 final long identity = Binder.clearCallingIdentity();
1630 try {
1631 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1632 Phone phone = PhoneFactory.getPhone(i);
1633 if (phone != null && phone.isRadioAvailable()) return true;
1634 }
1635 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1636 return false;
1637 } finally {
1638 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001639 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001640 }
1641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001642 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001643 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001644 enforceModifyPermission();
1645
1646 final long identity = Binder.clearCallingIdentity();
1647 try {
1648 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1649 logv("Shutting down Phone " + i);
1650 shutdownRadioUsingPhoneId(i);
1651 }
1652 } finally {
1653 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001654 }
1655 }
1656
1657 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001658 Phone phone = PhoneFactory.getPhone(phoneId);
1659 if (phone != null && phone.isRadioAvailable()) {
1660 phone.shutdownRadio();
1661 }
1662 }
1663
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001666
1667 final long identity = Binder.clearCallingIdentity();
1668 try {
1669 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1670 if (defaultPhone != null) {
1671 defaultPhone.setRadioPower(turnOn);
1672 return true;
1673 } else {
1674 loge("There's no default phone.");
1675 return false;
1676 }
1677 } finally {
1678 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001679 }
Wink Saville36469e72014-06-11 15:17:00 -07001680 }
1681
Wink Savilleb564aae2014-10-23 10:18:09 -07001682 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001684
1685 final long identity = Binder.clearCallingIdentity();
1686 try {
1687 final Phone phone = getPhone(subId);
1688 if (phone != null) {
1689 phone.setRadioPower(turnOn);
1690 return true;
1691 } else {
1692 return false;
1693 }
1694 } finally {
1695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 }
1698
Wink Saville36469e72014-06-11 15:17:00 -07001699 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 public boolean enableDataConnectivity() {
1702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001703
1704 final long identity = Binder.clearCallingIdentity();
1705 try {
1706 int subId = mSubscriptionController.getDefaultDataSubId();
1707 final Phone phone = getPhone(subId);
1708 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001709 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001710 return true;
1711 } else {
1712 return false;
1713 }
1714 } finally {
1715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 }
1718
Wink Saville36469e72014-06-11 15:17:00 -07001719 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 public boolean disableDataConnectivity() {
1722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723
1724 final long identity = Binder.clearCallingIdentity();
1725 try {
1726 int subId = mSubscriptionController.getDefaultDataSubId();
1727 final Phone phone = getPhone(subId);
1728 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001729 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001730 return true;
1731 } 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
Sanket Padawe356d7632015-06-22 14:03:32 -07001739 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001740 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001741 final long identity = Binder.clearCallingIdentity();
1742 try {
1743 final Phone phone = getPhone(subId);
1744 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001745 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746 } else {
1747 return false;
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
1753
1754 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001755 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
pkanwarae03a6b2016-11-06 20:37:09 -08001758 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001759 enforceCallPermission();
1760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1764 return;
1765 }
1766 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1767 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1768 } finally {
1769 Binder.restoreCallingIdentity(identity);
1770 }
pkanwar32d516d2016-10-14 19:37:38 -07001771 };
1772
Wink Savilleb564aae2014-10-23 10:18:09 -07001773 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1779 return false;
1780 }
1781 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1782 } finally {
1783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001788 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001789 }
1790
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001791 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 Phone phone = PhoneFactory.getPhone(slotIndex);
1795 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1796 PhoneConstantConversions.convertCallState(phone.getState());
1797 } finally {
1798 Binder.restoreCallingIdentity(identity);
1799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 }
1801
Sanket Padawe356d7632015-06-22 14:03:32 -07001802 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001804 final long identity = Binder.clearCallingIdentity();
1805 try {
1806 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1807 if (phone != null) {
1808 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1809 } else {
1810 return PhoneConstantConversions.convertDataState(
1811 PhoneConstants.DataState.DISCONNECTED);
1812 }
1813 } finally {
1814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 }
1817
Sanket Padawe356d7632015-06-22 14:03:32 -07001818 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1823 if (phone != null) {
1824 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1825 } else {
1826 return TelephonyManager.DATA_ACTIVITY_NONE;
1827 }
1828 } finally {
1829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
1832
1833 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001834 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001835 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001836 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001837 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1838 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001839 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001842 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001843 final long identity = Binder.clearCallingIdentity();
1844 try {
1845 if (DBG_LOC) log("getCellLocation: is active user");
1846 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001847 int subId = mSubscriptionController.getDefaultDataSubId();
1848 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1849 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001850 return data;
1851 } finally {
1852 Binder.restoreCallingIdentity(identity);
1853 }
Svetoslav64fad262015-04-14 14:35:21 -07001854 }
1855
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001857 public String getNetworkCountryIsoForPhone(int phoneId) {
1858 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1859 // registered cell info, so return a NULL country instead.
1860 final long identity = Binder.clearCallingIdentity();
1861 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001862 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1863 // Get default phone in this case.
1864 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1865 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001866 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001867 // Todo: fix this when we can get the actual cellular network info when the device
1868 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001869 if (TelephonyManager.NETWORK_TYPE_IWLAN
1870 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1871 return "";
1872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001873 Phone phone = PhoneFactory.getPhone(phoneId);
1874 if (phone != null) {
1875 ServiceStateTracker sst = phone.getServiceStateTracker();
1876 if (sst != null) {
1877 LocaleTracker lt = sst.getLocaleTracker();
1878 if (lt != null) {
1879 return lt.getCurrentCountry();
1880 }
1881 }
1882 }
1883 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001884 } finally {
1885 Binder.restoreCallingIdentity(identity);
1886 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001887 }
1888
1889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001891 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001895 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 mApp.enforceCallingOrSelfPermission(
1897 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898
1899 final long identity = Binder.clearCallingIdentity();
1900 try {
1901 final Phone phone = getPhone(subId);
1902 if (phone != null) {
1903 phone.enableLocationUpdates();
1904 }
1905 } finally {
1906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 }
1909
1910 @Override
1911 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001912 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001913 }
1914
Sanket Padawe356d7632015-06-22 14:03:32 -07001915 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001916 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 mApp.enforceCallingOrSelfPermission(
1918 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001919
1920 final long identity = Binder.clearCallingIdentity();
1921 try {
1922 final Phone phone = getPhone(subId);
1923 if (phone != null) {
1924 phone.disableLocationUpdates();
1925 }
1926 } finally {
1927 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 }
1930
Nathan Harold31d7ff32018-10-15 20:20:30 -07001931 /**
1932 * Returns the target SDK version number for a given package name.
1933 *
1934 * @return target SDK if the package is found or INT_MAX.
1935 */
1936 private int getTargetSdk(String packageName) {
1937 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001938 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1939 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001940 if (ai != null) return ai.targetSdkVersion;
1941 } catch (PackageManager.NameNotFoundException unexpected) {
1942 }
1943 return Integer.MAX_VALUE;
1944 }
1945
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 @Override
1947 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001948 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1949 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001950 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1951 throw new SecurityException(
1952 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1953 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001954
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1956 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1957 return null;
1958 }
Svetoslav64fad262015-04-14 14:35:21 -07001959
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001960 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961
Nathan Haroldf180aac2018-06-01 18:43:55 -07001962 List<CellInfo> info = getAllCellInfo(callingPackage);
1963 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964
Nathan Haroldf180aac2018-06-01 18:43:55 -07001965 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1966 for (CellInfo ci : info) {
1967 if (ci instanceof CellInfoGsm) {
1968 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1969 } else if (ci instanceof CellInfoWcdma) {
1970 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1971 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001973 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001976 private List<CellInfo> getCachedCellInfo() {
1977 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1978 for (Phone phone : PhoneFactory.getPhones()) {
1979 List<CellInfo> info = phone.getAllCellInfo();
1980 if (info != null) cellInfos.addAll(info);
1981 }
1982 return cellInfos;
1983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984
1985 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001986 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001987 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001988 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001989 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001990 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001991 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 }
1993
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001994 final int targetSdk = getTargetSdk(callingPackage);
1995 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1996 return getCachedCellInfo();
1997 }
1998
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001999 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001 final long identity = Binder.clearCallingIdentity();
2002 try {
2003 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2004 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002005 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002006 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002007 if (info != null) cellInfos.addAll(info);
2008 }
2009 return cellInfos;
2010 } finally {
2011 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 }
2013 }
2014
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002015 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002016 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2017 requestCellInfoUpdateInternal(
2018 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2019 }
2020
2021 @Override
2022 public void requestCellInfoUpdateWithWorkSource(
2023 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2024 enforceModifyPermission();
2025 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2026 }
2027
2028 private void requestCellInfoUpdateInternal(
2029 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002030 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002031 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002032 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2033 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002034 return;
2035 }
2036
2037 final Phone phone = getPhone(subId);
2038 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2039
2040 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2041 }
2042
2043 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002045 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002046 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002047
2048 final long identity = Binder.clearCallingIdentity();
2049 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002050 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002051 } finally {
2052 Binder.restoreCallingIdentity(identity);
2053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 }
2055
Shishir Agrawala9f32182016-04-12 12:00:16 -07002056 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002057 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002058 Phone phone = PhoneFactory.getPhone(slotIndex);
2059 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002060 return null;
2061 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002062 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002063 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2064 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002065 return null;
2066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002067
2068 final long identity = Binder.clearCallingIdentity();
2069 try {
2070 return phone.getImei();
2071 } finally {
2072 Binder.restoreCallingIdentity(identity);
2073 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002074 }
2075
2076 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002077 public String getTypeAllocationCodeForSlot(int slotIndex) {
2078 Phone phone = PhoneFactory.getPhone(slotIndex);
2079 String tac = null;
2080 if (phone != null) {
2081 String imei = phone.getImei();
2082 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2083 }
2084 return tac;
2085 }
2086
2087 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002088 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002089 Phone phone = PhoneFactory.getPhone(slotIndex);
2090 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002091 return null;
2092 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002093
Jeff Davidson913390f2018-02-23 17:11:49 -08002094 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002095 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2096 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002097 return null;
2098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099
2100 final long identity = Binder.clearCallingIdentity();
2101 try {
2102 return phone.getMeid();
2103 } finally {
2104 Binder.restoreCallingIdentity(identity);
2105 }
Jack Yu2af8d712017-03-15 17:14:14 -07002106 }
2107
2108 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002109 public String getManufacturerCodeForSlot(int slotIndex) {
2110 Phone phone = PhoneFactory.getPhone(slotIndex);
2111 String manufacturerCode = null;
2112 if (phone != null) {
2113 String meid = phone.getMeid();
2114 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2115 }
2116 return manufacturerCode;
2117 }
2118
2119 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002120 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002121 Phone phone = PhoneFactory.getPhone(slotIndex);
2122 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002123 return null;
2124 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002125 int subId = phone.getSubId();
2126 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2127 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2128 return null;
2129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002130
2131 final long identity = Binder.clearCallingIdentity();
2132 try {
2133 return phone.getDeviceSvn();
2134 } finally {
2135 Binder.restoreCallingIdentity(identity);
2136 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002137 }
2138
fionaxu43304da2017-11-27 22:51:16 -08002139 @Override
2140 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002141 final long identity = Binder.clearCallingIdentity();
2142 try {
2143 final Phone phone = getPhone(subId);
2144 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
2147 }
fionaxu43304da2017-11-27 22:51:16 -08002148 }
2149
2150 @Override
2151 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152 final long identity = Binder.clearCallingIdentity();
2153 try {
2154 final Phone phone = getPhone(subId);
2155 return phone == null ? null : phone.getCarrierName();
2156 } finally {
2157 Binder.restoreCallingIdentity(identity);
2158 }
fionaxu43304da2017-11-27 22:51:16 -08002159 }
2160
calvinpanffe225e2018-11-01 19:43:06 +08002161 @Override
chen xu25637222018-11-04 17:17:00 -08002162 public int getSubscriptionPreciseCarrierId(int subId) {
2163 final long identity = Binder.clearCallingIdentity();
2164 try {
2165 final Phone phone = getPhone(subId);
2166 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2167 : phone.getPreciseCarrierId();
2168 } finally {
2169 Binder.restoreCallingIdentity(identity);
2170 }
2171 }
2172
2173 @Override
2174 public String getSubscriptionPreciseCarrierName(int subId) {
2175 final long identity = Binder.clearCallingIdentity();
2176 try {
2177 final Phone phone = getPhone(subId);
2178 return phone == null ? null : phone.getPreciseCarrierName();
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
2181 }
2182 }
2183
chen xu651eec72018-11-11 19:03:44 -08002184 @Override
chen xu864e11c2018-12-06 22:10:03 -08002185 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2186 if (!isSubscriptionMccMnc) {
2187 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2188 }
chen xu651eec72018-11-11 19:03:44 -08002189 final Phone phone = PhoneFactory.getPhone(slotIndex);
2190 if (phone == null) {
2191 return TelephonyManager.UNKNOWN_CARRIER_ID;
2192 }
2193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2196 } finally {
2197 Binder.restoreCallingIdentity(identity);
2198 }
2199 }
2200
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 //
2202 // Internal helper methods.
2203 //
2204
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002205 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2207 *
2208 * @throws SecurityException if the caller does not have the required permission
2209 */
2210 private void enforceModifyPermission() {
2211 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2212 }
2213
2214 /**
2215 * Make sure the caller has the CALL_PHONE permission.
2216 *
2217 * @throws SecurityException if the caller does not have the required permission
2218 */
2219 private void enforceCallPermission() {
2220 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2221 }
2222
Stuart Scott8eef64f2015-04-08 15:13:54 -07002223 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002224 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002225 "ConnectivityService");
2226 }
2227
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 private String createTelUrl(String number) {
2229 if (TextUtils.isEmpty(number)) {
2230 return null;
2231 }
2232
Jake Hambye994d462014-02-03 13:10:13 -08002233 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235
Ihab Awadf9e92732013-12-05 18:02:52 -08002236 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2238 }
2239
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002240 private static void logv(String msg) {
2241 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2242 }
2243
Ihab Awadf9e92732013-12-05 18:02:52 -08002244 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2246 }
2247
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002248 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002250 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002251 }
2252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002254 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 final Phone phone = PhoneFactory.getPhone(slotIndex);
2258 if (phone == null) {
2259 return PhoneConstants.PHONE_TYPE_NONE;
2260 } else {
2261 return phone.getPhoneType();
2262 }
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
2268 /**
2269 * Returns the CDMA ERI icon index to display
2270 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002271 @Override
2272 public int getCdmaEriIconIndex(String callingPackage) {
2273 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002274 }
2275
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002277 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002279 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002280 return -1;
2281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282
2283 final long identity = Binder.clearCallingIdentity();
2284 try {
2285 final Phone phone = getPhone(subId);
2286 if (phone != null) {
2287 return phone.getCdmaEriIconIndex();
2288 } else {
2289 return -1;
2290 }
2291 } finally {
2292 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
2296 /**
2297 * Returns the CDMA ERI icon mode,
2298 * 0 - ON
2299 * 1 - FLASHING
2300 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 @Override
2302 public int getCdmaEriIconMode(String callingPackage) {
2303 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002307 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002309 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002310 return -1;
2311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 final Phone phone = getPhone(subId);
2316 if (phone != null) {
2317 return phone.getCdmaEriIconMode();
2318 } else {
2319 return -1;
2320 }
2321 } finally {
2322 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 }
2325
2326 /**
2327 * Returns the CDMA ERI text,
2328 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002329 @Override
2330 public String getCdmaEriText(String callingPackage) {
2331 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002332 }
2333
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002335 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002337 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002338 return null;
2339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340
2341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 final Phone phone = getPhone(subId);
2344 if (phone != null) {
2345 return phone.getCdmaEriText();
2346 } else {
2347 return null;
2348 }
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 }
2353
2354 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002355 * Returns the CDMA MDN.
2356 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002357 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002358 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2360 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002361
2362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002365 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002366 return phone.getLine1Number();
2367 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002368 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369 return null;
2370 }
2371 } finally {
2372 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002373 }
2374 }
2375
2376 /**
2377 * Returns the CDMA MIN.
2378 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002379 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002380 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2382 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002383
2384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 final Phone phone = getPhone(subId);
2387 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2388 return phone.getCdmaMin();
2389 } else {
2390 return null;
2391 }
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002394 }
2395 }
2396
Hall Liud892bec2018-11-30 14:51:45 -08002397 @Override
2398 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2399 INumberVerificationCallback callback, String callingPackage) {
2400 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2401 != PERMISSION_GRANTED) {
2402 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2403 }
2404 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2405
2406 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2407 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2408 throw new SecurityException("Calling package must be configured in the device config");
2409 }
2410
2411 if (range == null) {
2412 throw new NullPointerException("Range must be non-null");
2413 }
2414
2415 timeoutMillis = Math.min(timeoutMillis,
2416 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2417
2418 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2419 }
2420
Junda Liuca05d5d2014-08-14 22:36:34 -07002421 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 * Returns true if CDMA provisioning needs to run.
2423 */
2424 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425 final long identity = Binder.clearCallingIdentity();
2426 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002427 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002428 } finally {
2429 Binder.restoreCallingIdentity(identity);
2430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
2433 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002434 * Sets the voice mail number of a given subId.
2435 */
2436 @Override
2437 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002438 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002439
2440 final long identity = Binder.clearCallingIdentity();
2441 try {
2442 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2443 new Pair<String, String>(alphaTag, number), new Integer(subId));
2444 return success;
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
2447 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002448 }
2449
Ta-wei Yen87c49842016-05-13 21:19:52 -07002450 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002451 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002453 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002454 if (!TextUtils.equals(callingPackage, systemDialer)) {
2455 throw new SecurityException("caller must be system dialer");
2456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457
2458 final long identity = Binder.clearCallingIdentity();
2459 try {
2460 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2461 if (phoneAccountHandle == null) {
2462 return null;
2463 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002464 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465 } finally {
2466 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002467 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002468 }
2469
2470 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002471 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002474 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002475 return null;
2476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002478 final long identity = Binder.clearCallingIdentity();
2479 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002480 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002481 } finally {
2482 Binder.restoreCallingIdentity(identity);
2483 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002484 }
2485
2486 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002487 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2488 VisualVoicemailSmsFilterSettings settings) {
2489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002494 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495 } finally {
2496 Binder.restoreCallingIdentity(identity);
2497 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002498 }
2499
2500 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002501 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002507 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002511 }
2512
2513 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002514 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2515 String callingPackage, int subId) {
2516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517
2518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002521 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522 } finally {
2523 Binder.restoreCallingIdentity(identity);
2524 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002525 }
2526
2527 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002528 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002529 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002534 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535 } finally {
2536 Binder.restoreCallingIdentity(identity);
2537 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002538 }
2539
2540 @Override
2541 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2542 String number, int port, String text, PendingIntent sentIntent) {
2543 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002544 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002545 enforceSendSmsPermission();
2546 // Make the calls as the phone process.
2547 final long identity = Binder.clearCallingIdentity();
2548 try {
2549 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2550 if (port == 0) {
2551 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2552 sentIntent, null, false);
2553 } else {
2554 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2555 smsManager.sendDataMessageWithSelfPermissions(number, null,
2556 (short) port, data, sentIntent, null);
2557 }
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
2560 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002561 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002562 /**
fionaxu0152e512016-11-14 13:36:14 -08002563 * Sets the voice activation state of a given subId.
2564 */
2565 @Override
2566 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2568 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone phone = getPhone(subId);
2573 if (phone != null) {
2574 phone.setVoiceActivationState(activationState);
2575 } else {
2576 loge("setVoiceActivationState fails with invalid subId: " + subId);
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002580 }
2581 }
2582
2583 /**
2584 * Sets the data activation state of a given subId.
2585 */
2586 @Override
2587 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2589 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590
2591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 final Phone phone = getPhone(subId);
2594 if (phone != null) {
2595 phone.setDataActivationState(activationState);
2596 } else {
2597 loge("setVoiceActivationState fails with invalid subId: " + subId);
2598 }
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002601 }
2602 }
2603
2604 /**
2605 * Returns the voice activation state of a given subId.
2606 */
2607 @Override
2608 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002609 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610
fionaxu0152e512016-11-14 13:36:14 -08002611 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 if (phone != null) {
2615 return phone.getVoiceActivationState();
2616 } else {
2617 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002621 }
2622 }
2623
2624 /**
2625 * Returns the data activation state of a given subId.
2626 */
2627 @Override
2628 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002629 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630
fionaxu0152e512016-11-14 13:36:14 -08002631 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632 final long identity = Binder.clearCallingIdentity();
2633 try {
2634 if (phone != null) {
2635 return phone.getDataActivationState();
2636 } else {
2637 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2638 }
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002641 }
2642 }
2643
2644 /**
Wink Saville36469e72014-06-11 15:17:00 -07002645 * Returns the unread count of voicemails for a subId
2646 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002647 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002648 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2650 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2651 return 0;
2652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 final Phone phone = getPhone(subId);
2656 if (phone != null) {
2657 return phone.getVoiceMessageCount();
2658 } else {
2659 return 0;
2660 }
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002663 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 }
2665
2666 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002667 * returns true, if the device is in a state where both voice and data
2668 * are supported simultaneously. This can change based on location or network condition.
2669 */
2670 @Override
2671 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672 final long identity = Binder.clearCallingIdentity();
2673 try {
2674 final Phone phone = getPhone(subId);
2675 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
2678 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002679 }
2680
2681 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002682 * Send the dialer code if called from the current default dialer or the caller has
2683 * carrier privilege.
2684 * @param inputCode The dialer code to send
2685 */
2686 @Override
2687 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002688 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002689 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002690 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2691 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002692 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002693 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2694 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002699 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700 } finally {
2701 Binder.restoreCallingIdentity(identity);
2702 }
fionaxu235cc5e2017-03-06 22:25:57 -08002703 }
2704
2705 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002706 * Returns the data network type.
2707 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 *
2709 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2710 */
2711 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002712 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 final Phone phone = getPhone(getDefaultSubscription());
2716 if (phone != null) {
2717 return phone.getServiceState().getDataNetworkType();
2718 } else {
2719 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2720 }
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002723 }
Wink Saville36469e72014-06-11 15:17:00 -07002724 }
2725
Pengquan Menga1bb6272018-09-06 09:59:22 -07002726 @Override
2727 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002728 if (!isActiveSubscription(subId)) {
2729 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2730 }
2731
Pengquan Menga1bb6272018-09-06 09:59:22 -07002732 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2733 }
2734
Brad Ebinger35c841c2018-10-01 10:40:55 -07002735 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002736 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2737 throws RemoteException {
2738 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2740 final long token = Binder.clearCallingIdentity();
2741 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002742 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002743 .addRegistrationCallbackForSubscription(c, subId);
2744 } finally {
2745 Binder.restoreCallingIdentity(token);
2746 }
2747 }
2748
2749 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002750 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2751 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002752 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2753 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002754 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002755 .removeRegistrationCallbackForSubscription(c, subId));
2756 }
2757
2758 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002759 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2760 throws RemoteException {
2761 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002762 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2763 final long token = Binder.clearCallingIdentity();
2764 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002765 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002766 .addCapabilitiesCallbackForSubscription(c, subId);
2767 } finally {
2768 Binder.restoreCallingIdentity(token);
2769 }
2770 }
2771
2772 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002773 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2774 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002775 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2776 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002777 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002778 .removeCapabilitiesCallbackForSubscription(c, subId));
2779 }
2780
2781 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002782 public boolean isCapable(int subId, int capability, int regTech) {
2783 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002784 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2785 final long token = Binder.clearCallingIdentity();
2786 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002787 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002788 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2789 } catch (ImsException e) {
2790 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2791 return false;
2792 } finally {
2793 Binder.restoreCallingIdentity(token);
2794 }
2795 }
2796
2797 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002798 public boolean isAvailable(int subId, int capability, int regTech) {
2799 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002800 final long token = Binder.clearCallingIdentity();
2801 try {
2802 Phone phone = getPhone(subId);
2803 if (phone == null) return false;
2804 return phone.isImsCapabilityAvailable(capability, regTech);
2805 } finally {
2806 Binder.restoreCallingIdentity(token);
2807 }
2808 }
2809
2810 @Override
2811 public boolean isAdvancedCallingSettingEnabled(int subId) {
2812 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2813 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2814 final long token = Binder.clearCallingIdentity();
2815 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002816 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002817 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2818 } finally {
2819 Binder.restoreCallingIdentity(token);
2820 }
2821 }
2822
2823 @Override
2824 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2826 "setAdvancedCallingSetting");
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002830 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002831 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
2834 }
2835 }
2836
2837 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002838 public boolean isVtSettingEnabled(int subId) {
2839 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002843 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002844 getSlotIndexOrException(subId)).isVtEnabledByUser();
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
2848 }
2849
2850 @Override
2851 public void setVtSetting(int subId, boolean isEnabled) {
2852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2853 "setVtSetting");
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002857 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002858 } finally {
2859 Binder.restoreCallingIdentity(identity);
2860 }
2861 }
2862
2863 @Override
2864 public boolean isVoWiFiSettingEnabled(int subId) {
2865 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2866 final long identity = Binder.clearCallingIdentity();
2867 try {
2868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002869 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002870 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
2873 }
2874 }
2875
2876 @Override
2877 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2879 "setVoWiFiSetting");
2880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002883 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002884 } finally {
2885 Binder.restoreCallingIdentity(identity);
2886 }
2887 }
2888
2889 @Override
2890 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2891 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002895 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002896 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
2899 }
2900 }
2901
2902 @Override
2903 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2905 "setVoWiFiRoamingSetting");
2906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002909 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002910 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
2913 }
2914 }
2915
2916 @Override
2917 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2919 "setVoWiFiNonPersistent");
2920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002923 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002924 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
2927 }
2928 }
2929
2930 @Override
2931 public int getVoWiFiModeSetting(int subId) {
2932 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002937 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
2941 }
2942
2943 @Override
2944 public void setVoWiFiModeSetting(int subId, int mode) {
2945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2946 "setVoWiFiModeSetting");
2947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002950 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002951 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
2954 }
2955 }
2956
2957 @Override
2958 public int getVoWiFiRoamingModeSetting(int subId) {
2959 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002963 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002964 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
2967 }
2968 }
2969
2970 @Override
2971 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2973 "setVoWiFiRoamingModeSetting");
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002977 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002978 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
2985 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2987 "setRttCapabilityEnabled");
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002991 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
2998 @Override
2999 public boolean isTtyOverVolteEnabled(int subId) {
3000 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003005 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003011 @Override
3012 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3013 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003017 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003018 .getConfigInterface().addConfigCallback(callback);
3019 } catch (ImsException e) {
3020 throw new IllegalArgumentException(e.getMessage());
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
3024 }
3025
3026 @Override
3027 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3028 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003032 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003033 .getConfigInterface().removeConfigCallback(callback);
3034 } catch (ImsException e) {
3035 throw new IllegalArgumentException(e.getMessage());
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
3039 }
3040
3041 @Override
3042 public int getImsProvisioningInt(int subId, int key) {
3043 enforceReadPrivilegedPermission("getImsProvisioningInt");
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003047 return ImsManager.getInstance(mApp,
3048 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(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 String getImsProvisioningString(int subId, int key) {
3058 enforceReadPrivilegedPermission("getImsProvisioningString");
3059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003062 return ImsManager.getInstance(mApp,
3063 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003064 } catch (ImsException e) {
3065 throw new IllegalArgumentException(e.getMessage());
3066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
3069 }
3070
3071 @Override
3072 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3074 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003078 return ImsManager.getInstance(mApp,
3079 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003080 } catch (ImsException e) {
3081 throw new IllegalArgumentException(e.getMessage());
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
3084 }
3085 }
3086
3087 @Override
3088 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3090 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003094 return ImsManager.getInstance(mApp,
3095 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003096 } catch (ImsException e) {
3097 throw new IllegalArgumentException(e.getMessage());
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
3101 }
3102
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3104 int slotId = SubscriptionManager.getSlotIndex(subId);
3105 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3106 throw new IllegalArgumentException("Invalid Subscription Id.");
3107 }
3108 return slotId;
3109 }
3110
Wink Saville36469e72014-06-11 15:17:00 -07003111 /**
3112 * Returns the network type for a subId
3113 */
3114 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003115 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003117 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003118 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3119 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121 final long identity = Binder.clearCallingIdentity();
3122 try {
3123 final Phone phone = getPhone(subId);
3124 if (phone != null) {
3125 return phone.getServiceState().getDataNetworkType();
3126 } else {
3127 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3128 }
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
3133
3134 /**
3135 * Returns the data network type
3136 */
3137 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003138 public int getDataNetworkType(String callingPackage) {
3139 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003140 }
3141
3142 /**
3143 * Returns the data network type for a subId
3144 */
3145 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003146 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003148 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003149 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3150 }
3151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 final Phone phone = getPhone(subId);
3155 if (phone != null) {
3156 return phone.getServiceState().getDataNetworkType();
3157 } else {
3158 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3159 }
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003163 }
3164
3165 /**
Wink Saville36469e72014-06-11 15:17:00 -07003166 * Returns the Voice network type for a subId
3167 */
3168 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003169 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003171 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003172 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3173 }
3174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 final Phone phone = getPhone(subId);
3178 if (phone != null) {
3179 return phone.getServiceState().getVoiceNetworkType();
3180 } else {
3181 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3182 }
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 }
3187
3188 /**
3189 * @return true if a ICC card is present
3190 */
3191 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003192 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003193 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3194 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003195 }
3196
3197 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003198 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003199 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003200 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003201 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 final Phone phone = PhoneFactory.getPhone(slotIndex);
3205 if (phone != null) {
3206 return phone.getIccCard().hasIccCard();
3207 } else {
3208 return false;
3209 }
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 }
3214
3215 /**
3216 * Return if the current radio is LTE on CDMA. This
3217 * is a tri-state return value as for a period of time
3218 * the mode may be unknown.
3219 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003220 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003222 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003223 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003224 @Override
3225 public int getLteOnCdmaMode(String callingPackage) {
3226 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003227 }
3228
Sanket Padawe356d7632015-06-22 14:03:32 -07003229 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003230 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003232 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003233 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3234 }
3235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 final Phone phone = getPhone(subId);
3239 if (phone == null) {
3240 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3241 } else {
3242 return phone.getLteOnCdmaMode();
3243 }
3244 } finally {
3245 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003246 }
Wink Saville36469e72014-06-11 15:17:00 -07003247 }
3248
Wink Saville36469e72014-06-11 15:17:00 -07003249 /**
3250 * {@hide}
3251 * Returns Default subId, 0 in the case of single standby.
3252 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003253 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003254 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003255 }
3256
Shishir Agrawala9f32182016-04-12 12:00:16 -07003257 private int getSlotForDefaultSubscription() {
3258 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3259 }
3260
Wink Savilleb564aae2014-10-23 10:18:09 -07003261 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003262 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003264
Pengquan Menge92a50d2018-09-21 15:54:48 -07003265 private boolean isActiveSubscription(int subId) {
3266 return mSubscriptionController.isActiveSubId(subId);
3267 }
3268
Ihab Awadf2177b72013-11-25 13:33:23 -08003269 /**
3270 * @see android.telephony.TelephonyManager.WifiCallingChoices
3271 */
3272 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273 final long identity = Binder.clearCallingIdentity();
3274 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003275 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3277 getWhenToMakeWifiCallsDefaultPreference());
3278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003281 }
3282
3283 /**
3284 * @see android.telephony.TelephonyManager.WifiCallingChoices
3285 */
3286 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003290 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003295 }
3296
Sailesh Nepald1e68152013-12-12 19:08:02 -08003297 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003298 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003299 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003300 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003301
Shishir Agrawal566b7612013-10-28 14:41:00 -07003302 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003303 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3304 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3306 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 if (TextUtils.equals(ISDR_AID, aid)) {
3312 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003313 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3314 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 if (bestComponent == null
3316 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3317 loge("The calling package is not allowed to access ISD-R.");
3318 throw new SecurityException(
3319 "The calling package is not allowed to access ISD-R.");
3320 }
Derek Tan740e1672017-06-27 14:56:27 -07003321 }
Derek Tan740e1672017-06-27 14:56:27 -07003322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003323 if (DBG) {
3324 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3325 }
3326 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3327 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3328 if (DBG) log("iccOpenLogicalChannel: " + response);
3329 return response;
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003333 }
3334
3335 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003336 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3338 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3343 if (channel < 0) {
3344 return false;
3345 }
3346 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3347 if (DBG) log("iccCloseLogicalChannel: " + success);
3348 return success;
3349 } finally {
3350 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003352 }
3353
3354 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003355 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003356 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3358 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 if (DBG) {
3363 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3364 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3365 + p3 + " data=" + data);
3366 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003368 if (channel < 0) {
3369 return "";
3370 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003372 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3373 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3374 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376 // Append the returned status code to the end of the response payload.
3377 String s = Integer.toHexString(
3378 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3379 if (response.payload != null) {
3380 s = IccUtils.bytesToHexString(response.payload) + s;
3381 }
3382 return s;
3383 } finally {
3384 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003385 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003386 }
Jake Hambye994d462014-02-03 13:10:13 -08003387
Evan Charltonc66da362014-05-16 14:06:40 -07003388 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003389 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3390 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3392 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3398 && TextUtils.equals(ISDR_AID, data)) {
3399 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003400 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3401 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402 if (bestComponent == null
3403 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3404 loge("The calling package is not allowed to select ISD-R.");
3405 throw new SecurityException(
3406 "The calling package is not allowed to select ISD-R.");
3407 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003408 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003410 if (DBG) {
3411 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3412 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3413 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003415 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3416 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3417 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 // Append the returned status code to the end of the response payload.
3420 String s = Integer.toHexString(
3421 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3422 if (response.payload != null) {
3423 s = IccUtils.bytesToHexString(response.payload) + s;
3424 }
3425 return s;
3426 } finally {
3427 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003428 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003429 }
3430
3431 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003432 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003433 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3435 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 if (DBG) {
3440 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3441 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3442 }
3443
3444 IccIoResult response =
3445 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3446 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3447 subId);
3448
3449 if (DBG) {
3450 log("Exchange SIM_IO [R]" + response);
3451 }
3452
3453 byte[] result = null;
3454 int length = 2;
3455 if (response.payload != null) {
3456 length = 2 + response.payload.length;
3457 result = new byte[length];
3458 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3459 } else {
3460 result = new byte[length];
3461 }
3462
3463 result[length - 1] = (byte) response.sw2;
3464 result[length - 2] = (byte) response.sw1;
3465 return result;
3466 } finally {
3467 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003468 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003469 }
3470
Nathan Haroldb3014052017-01-25 15:57:32 -08003471 /**
3472 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3473 * on a particular subscription
3474 */
sqianb6e41952018-03-12 14:54:01 -07003475 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3477 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3478 return null;
3479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 if (appType != TelephonyManager.APPTYPE_USIM
3484 && appType != TelephonyManager.APPTYPE_SIM) {
3485 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3486 return null;
3487 }
3488 Object response = sendRequest(
3489 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3490 if (response instanceof String[]) {
3491 return (String[]) response;
3492 }
3493 // Response is an Exception of some kind,
3494 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003495 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496 } finally {
3497 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003498 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003499 }
3500
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003501 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003502 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3504 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506 final long identity = Binder.clearCallingIdentity();
3507 try {
3508 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3509 if (response.payload == null) {
3510 return "";
3511 }
Evan Charltonc66da362014-05-16 14:06:40 -07003512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003513 // Append the returned status code to the end of the response payload.
3514 String s = Integer.toHexString(
3515 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3516 s = IccUtils.bytesToHexString(response.payload) + s;
3517 return s;
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
3520 }
Evan Charltonc66da362014-05-16 14:06:40 -07003521 }
3522
Jake Hambye994d462014-02-03 13:10:13 -08003523 /**
3524 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3525 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3526 *
3527 * @param itemID the ID of the item to read
3528 * @return the NV item as a String, or null on error.
3529 */
3530 @Override
3531 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003532 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3534 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535
3536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003539 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3541 return value;
3542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
Jake Hambye994d462014-02-03 13:10:13 -08003545 }
3546
3547 /**
3548 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3549 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3550 *
3551 * @param itemID the ID of the item to read
3552 * @param itemValue the value to write, as a String
3553 * @return true on success; false on any failure
3554 */
3555 @Override
3556 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003557 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3559 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3564 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003565 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3567 return success;
3568 } finally {
3569 Binder.restoreCallingIdentity(identity);
3570 }
Jake Hambye994d462014-02-03 13:10:13 -08003571 }
3572
3573 /**
3574 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3575 * Used for device configuration by some CDMA operators.
3576 *
3577 * @param preferredRoamingList byte array containing the new PRL
3578 * @return true on success; false on any failure
3579 */
3580 @Override
3581 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3583 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584
3585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3588 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3589 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3590 return success;
3591 } finally {
3592 Binder.restoreCallingIdentity(identity);
3593 }
Jake Hambye994d462014-02-03 13:10:13 -08003594 }
3595
3596 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003597 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003598 * Used for device configuration by some CDMA operators.
3599 *
chen xu6dac5ab2018-10-26 17:39:23 -07003600 * @param slotIndex - device slot.
3601 *
Jake Hambye994d462014-02-03 13:10:13 -08003602 * @return true on success; false on any failure
3603 */
3604 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003605 public boolean resetModemConfig(int slotIndex) {
3606 Phone phone = PhoneFactory.getPhone(slotIndex);
3607 if (phone != null) {
3608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3609 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610
chen xu6dac5ab2018-10-26 17:39:23 -07003611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3614 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3615 return success;
3616 } finally {
3617 Binder.restoreCallingIdentity(identity);
3618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619 }
chen xu6dac5ab2018-10-26 17:39:23 -07003620 return false;
3621 }
3622
3623 /**
3624 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3625 *
3626 * @param slotIndex - device slot.
3627 *
3628 * @return true on success; false on any failure
3629 */
3630 @Override
3631 public boolean rebootModem(int slotIndex) {
3632 Phone phone = PhoneFactory.getPhone(slotIndex);
3633 if (phone != null) {
3634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3635 mApp, phone.getSubId(), "rebootModem");
3636
3637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3640 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3641 return success;
3642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
3645 }
3646 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003647 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003648
Svet Ganovb320e182015-04-16 12:30:10 -07003649 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003650 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003653 return new String[0];
3654 }
3655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656 final long identity = Binder.clearCallingIdentity();
3657 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003658 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
Wink Saville36469e72014-06-11 15:17:00 -07003662 }
3663
Brad Ebinger51f743a2017-01-23 13:50:20 -08003664 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003665 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3666 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003667 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003668 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003669 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003670
3671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 PhoneFactory.getImsResolver().enableIms(slotId);
3674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003677 }
3678
3679 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003680 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3681 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003682 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003683 public void disableIms(int slotId) {
3684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 PhoneFactory.getImsResolver().disableIms(slotId);
3689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003692 }
3693
3694 /**
3695 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3696 * feature or {@link null} if the service is not available. If the feature is available, the
3697 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3698 */
3699 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003700 IImsServiceFeatureCallback callback) {
3701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003709 }
3710
3711 /**
3712 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3713 * feature during emergency calling or {@link null} if the service is not available. If the
3714 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3715 * listener for feature updates.
3716 */
3717 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3718 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003726 }
3727
Brad Ebinger5f64b052017-12-14 14:26:15 -08003728 /**
3729 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3730 * specified.
3731 */
3732 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3733 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3738 } finally {
3739 Binder.restoreCallingIdentity(identity);
3740 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003741 }
3742
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003743 /**
3744 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3745 * specified.
3746 */
3747 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749
3750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3753 } finally {
3754 Binder.restoreCallingIdentity(identity);
3755 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003756 }
3757
Brad Ebinger884c07b2018-02-15 16:17:40 -08003758 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003759 * Sets the ImsService Package Name that Telephony will bind to.
3760 *
3761 * @param slotId the slot ID that the ImsService should bind for.
3762 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3763 * ImsService is the device default ImsService.
3764 * @param packageName The package name of the application that contains the ImsService to bind
3765 * to.
3766 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3767 * @hide
3768 */
3769 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003770 int[] subIds = SubscriptionManager.getSubId(slotId);
3771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3772 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3773 "setImsService");
3774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3778 isCarrierImsService, packageName);
3779 } finally {
3780 Binder.restoreCallingIdentity(identity);
3781 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003782 }
3783
3784 /**
3785 * Return the ImsService configuration.
3786 *
3787 * @param slotId The slot that the ImsService is associated with.
3788 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3789 * the device default.
3790 * @return the package name of the ImsService configuration.
3791 */
3792 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003793 int[] subIds = SubscriptionManager.getSubId(slotId);
3794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3795 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3796 "getImsService");
3797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3801 isCarrierImsService);
3802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003805 }
3806
Wink Saville36469e72014-06-11 15:17:00 -07003807 public void setImsRegistrationState(boolean registered) {
3808 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809
3810 final long identity = Binder.clearCallingIdentity();
3811 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003812 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
Wink Saville36469e72014-06-11 15:17:00 -07003816 }
3817
3818 /**
Stuart Scott54788802015-03-30 13:18:01 -07003819 * Set the network selection mode to automatic.
3820 *
3821 */
3822 @Override
3823 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3825 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826
Pengquan Menge92a50d2018-09-21 15:54:48 -07003827 if (!isActiveSubscription(subId)) {
3828 return;
3829 }
3830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3834 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
3837 }
Stuart Scott54788802015-03-30 13:18:01 -07003838 }
3839
Pengquan Mengea84e042018-09-20 14:57:26 -07003840 /**
3841 * Ask the radio to connect to the input network and change selection mode to manual.
3842 *
3843 * @param subId the id of the subscription.
3844 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3845 * the operator to attach to.
3846 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3847 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3848 * normal network selection next time.
3849 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003850 */
3851 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003852 public boolean setNetworkSelectionModeManual(
3853 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3855 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003856
3857 if (!isActiveSubscription(subId)) {
3858 return false;
3859 }
3860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003863 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003865 if (DBG) {
3866 log("setNetworkSelectionModeManual: subId: " + subId
3867 + " operator: " + operatorInfo);
3868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
3872 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003873 }
3874
3875 /**
3876 * Scans for available networks.
3877 */
3878 @Override
3879 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3881 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882
Pengquan Menga1bb6272018-09-06 09:59:22 -07003883 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884 try {
3885 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003886 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888 } finally {
3889 Binder.restoreCallingIdentity(identity);
3890 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003891 }
3892
3893 /**
yinxub1bed742017-04-17 11:45:04 -07003894 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003895 *
yinxub1bed742017-04-17 11:45:04 -07003896 * @param subId id of the subscription
3897 * @param request contains the radio access networks with bands/channels to scan
3898 * @param messenger callback messenger for scan results or errors
3899 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003900 * @return the id of the requested scan which can be used to stop the scan.
3901 */
3902 @Override
3903 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3904 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3906 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003907
3908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 return mNetworkScanRequestTracker.startNetworkScan(
3911 request, messenger, binder, getPhone(subId));
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
3914 }
yinxu504e1392017-04-12 16:03:22 -07003915 }
3916
3917 /**
3918 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003919 *
3920 * @param subId id of the subscription
3921 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003922 */
3923 @Override
3924 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3926 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
3933 }
yinxu504e1392017-04-12 16:03:22 -07003934 }
3935
3936 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003937 * Get the calculated preferred network type.
3938 * Used for debugging incorrect network type.
3939 *
3940 * @return the preferred network type, defined in RILConstants.java.
3941 */
3942 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003943 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003944 final Phone defaultPhone = getDefaultPhone();
3945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3946 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003947 return RILConstants.PREFERRED_NETWORK_MODE;
3948 }
3949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 final long identity = Binder.clearCallingIdentity();
3951 try {
3952 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003953 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954 } finally {
3955 Binder.restoreCallingIdentity(identity);
3956 }
Junda Liu84d15a22014-07-02 11:21:04 -07003957 }
3958
3959 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003960 * Get the preferred network type.
3961 * Used for device configuration by some CDMA operators.
3962 *
3963 * @return the preferred network type, defined in RILConstants.java.
3964 */
3965 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003966 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08003967 TelephonyPermissions
3968 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
3969 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970
3971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 if (DBG) log("getPreferredNetworkType");
3974 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3975 int networkType = (result != null ? result[0] : -1);
3976 if (DBG) log("getPreferredNetworkType: " + networkType);
3977 return networkType;
3978 } finally {
3979 Binder.restoreCallingIdentity(identity);
3980 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003981 }
3982
3983 /**
3984 * Set the preferred network type.
3985 * Used for device configuration by some CDMA operators.
3986 *
3987 * @param networkType the preferred network type, defined in RILConstants.java.
3988 * @return true on success; false on any failure.
3989 */
3990 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003991 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3993 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994
3995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3998 Boolean success = (Boolean) sendRequest(
3999 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4000 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4001 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004002 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004003 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4004 }
4005 return success;
4006 } finally {
4007 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004008 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004009 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004010
4011 /**
Junda Liu475951f2014-11-07 16:45:03 -08004012 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07004013 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004014 * tethering.
4015 *
4016 * @return 0: Not required. 1: required. 2: Not set.
4017 * @hide
4018 */
4019 @Override
4020 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004022
4023 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004024 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004026 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07004028 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004029 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030 dunRequired = 1;
4031 }
4032 return dunRequired;
4033 } finally {
4034 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004035 }
Junda Liu475951f2014-11-07 16:45:03 -08004036 }
4037
4038 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004039 * Set mobile data enabled
4040 * Used by the user through settings etc to turn on/off mobile data
4041 *
4042 * @param enable {@code true} turn turn data on, else {@code false}
4043 */
4044 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004045 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4047 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 int phoneId = mSubscriptionController.getPhoneId(subId);
4052 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4053 Phone phone = PhoneFactory.getPhone(phoneId);
4054 if (phone != null) {
4055 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004056 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004057 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004058 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 }
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004062 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004063 }
4064
4065 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004066 * Get the user enabled state of Mobile Data.
4067 *
4068 * TODO: remove and use isUserDataEnabled.
4069 * This can't be removed now because some vendor codes
4070 * calls through ITelephony directly while they should
4071 * use TelephonyManager.
4072 *
4073 * @return true on enabled
4074 */
4075 @Override
4076 public boolean getDataEnabled(int subId) {
4077 return isUserDataEnabled(subId);
4078 }
4079
4080 /**
4081 * Get whether mobile data is enabled per user setting.
4082 *
4083 * There are other factors deciding whether mobile data is actually enabled, but they are
4084 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004085 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004086 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004087 *
4088 * @return {@code true} if data is enabled else {@code false}
4089 */
4090 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004091 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004092 try {
4093 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4094 null);
4095 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4097 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099
4100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 int phoneId = mSubscriptionController.getPhoneId(subId);
4103 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4104 Phone phone = PhoneFactory.getPhone(phoneId);
4105 if (phone != null) {
4106 boolean retVal = phone.isUserDataEnabled();
4107 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4108 return retVal;
4109 } else {
4110 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4111 return false;
4112 }
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004115 }
4116 }
4117
4118 /**
4119 * Get whether mobile data is enabled.
4120 *
4121 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4122 * whether mobile data is actually enabled.
4123 *
4124 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4125 *
4126 * @return {@code true} if data is enabled else {@code false}
4127 */
4128 @Override
4129 public boolean isDataEnabled(int subId) {
4130 try {
4131 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4132 null);
4133 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4135 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 int phoneId = mSubscriptionController.getPhoneId(subId);
4141 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4142 Phone phone = PhoneFactory.getPhone(phoneId);
4143 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004144 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4146 return retVal;
4147 } else {
4148 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4149 return false;
4150 }
4151 } finally {
4152 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004153 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004154 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004155
4156 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004157 public int getCarrierPrivilegeStatus(int subId) {
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 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004164 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004165 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004166 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4167 }
4168 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004169 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004170 }
Junda Liu29340342014-07-10 15:23:27 -07004171
4172 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004173 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4174 final Phone phone = getPhone(subId);
4175 if (phone == null) {
4176 loge("getCarrierPrivilegeStatus: Invalid subId");
4177 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4178 }
4179 UiccProfile profile =
4180 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4181 if (profile == null) {
4182 loge("getCarrierPrivilegeStatus: No UICC");
4183 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4184 }
4185 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4186 }
4187
4188 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004189 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004190 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004191 if (TextUtils.isEmpty(pkgName))
4192 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004193 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004194 if (card == null) {
4195 loge("checkCarrierPrivilegesForPackage: No UICC");
4196 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4197 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004198 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4199 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004200 }
4201
4202 @Override
4203 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004204 if (TextUtils.isEmpty(pkgName))
4205 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004206 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4207 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4208 UiccCard card = UiccController.getInstance().getUiccCard(i);
4209 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004210 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004211 continue;
4212 }
4213
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004214 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004215 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4216 break;
4217 }
4218 }
4219
4220 return result;
Junda Liu29340342014-07-10 15:23:27 -07004221 }
Derek Tan89e89d42014-07-08 17:00:10 -07004222
4223 @Override
Junda Liue64de782015-04-16 17:19:16 -07004224 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4225 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4226 loge("phoneId " + phoneId + " is not valid.");
4227 return null;
4228 }
4229 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004230 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004231 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004232 return null ;
4233 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004234 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004235 }
4236
Amith Yamasani6e118872016-02-19 12:53:51 -08004237 @Override
4238 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004239 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004240 List<String> privilegedPackages = new ArrayList<>();
4241 List<PackageInfo> packages = null;
4242 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4243 UiccCard card = UiccController.getInstance().getUiccCard(i);
4244 if (card == null) {
4245 // No UICC in that slot.
4246 continue;
4247 }
4248 if (card.hasCarrierPrivilegeRules()) {
4249 if (packages == null) {
4250 // Only check packages in user 0 for now
4251 packages = pm.getInstalledPackagesAsUser(
4252 PackageManager.MATCH_DISABLED_COMPONENTS
4253 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4254 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4255 }
4256 for (int p = packages.size() - 1; p >= 0; p--) {
4257 PackageInfo pkgInfo = packages.get(p);
4258 if (pkgInfo != null && pkgInfo.packageName != null
4259 && card.getCarrierPrivilegeStatus(pkgInfo)
4260 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4261 privilegedPackages.add(pkgInfo.packageName);
4262 }
4263 }
4264 }
4265 }
4266 return privilegedPackages;
4267 }
4268
Wink Savilleb564aae2014-10-23 10:18:09 -07004269 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004270 final Phone phone = getPhone(subId);
4271 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004272 if (card == null) {
4273 loge("getIccId: No UICC");
4274 return null;
4275 }
4276 String iccId = card.getIccId();
4277 if (TextUtils.isEmpty(iccId)) {
4278 loge("getIccId: ICC ID is null or empty.");
4279 return null;
4280 }
4281 return iccId;
4282 }
4283
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004284 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004285 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4286 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004287 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4288 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 final String iccId = getIccId(subId);
4293 final Phone phone = getPhone(subId);
4294 if (phone == null) {
4295 return false;
4296 }
4297 final String subscriberId = phone.getSubscriberId();
4298
4299 if (DBG_MERGE) {
4300 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4301 + subscriberId + " to " + number);
4302 }
4303
4304 if (TextUtils.isEmpty(iccId)) {
4305 return false;
4306 }
4307
4308 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4309
4310 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4311 if (alphaTag == null) {
4312 editor.remove(alphaTagPrefKey);
4313 } else {
4314 editor.putString(alphaTagPrefKey, alphaTag);
4315 }
4316
4317 // Record both the line number and IMSI for this ICCID, since we need to
4318 // track all merged IMSIs based on line number
4319 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4320 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4321 if (number == null) {
4322 editor.remove(numberPrefKey);
4323 editor.remove(subscriberPrefKey);
4324 } else {
4325 editor.putString(numberPrefKey, number);
4326 editor.putString(subscriberPrefKey, subscriberId);
4327 }
4328
4329 editor.commit();
4330 return true;
4331 } finally {
4332 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004333 }
Derek Tan7226c842014-07-02 17:42:23 -07004334 }
4335
4336 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004337 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004338 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004340 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004341 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004342 return null;
4343 }
Derek Tan97ebb422014-09-05 16:55:38 -07004344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 String iccId = getIccId(subId);
4348 if (iccId != null) {
4349 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4350 if (DBG_MERGE) {
4351 log("getLine1NumberForDisplay returning "
4352 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4353 }
4354 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4357 return null;
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004360 }
Derek Tan7226c842014-07-02 17:42:23 -07004361 }
4362
4363 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004364 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004366 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004367 return null;
4368 }
Derek Tan97ebb422014-09-05 16:55:38 -07004369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370 final long identity = Binder.clearCallingIdentity();
4371 try {
4372 String iccId = getIccId(subId);
4373 if (iccId != null) {
4374 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4375 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4376 }
4377 return null;
4378 } finally {
4379 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004380 }
Derek Tan7226c842014-07-02 17:42:23 -07004381 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004382
4383 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004384 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004385 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4386 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004388 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4389 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004390 return null;
4391 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004392
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004393 final long identity = Binder.clearCallingIdentity();
4394 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004395 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396 final TelephonyManager tele = TelephonyManager.from(context);
4397 final SubscriptionManager sub = SubscriptionManager.from(context);
4398
4399 // Figure out what subscribers are currently active
4400 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4401 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4402 // the process, where TelephonyManager was instantiated.
4403 // Otherwise AppOps check will fail.
4404
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004405 final int[] subIds = sub.getActiveSubscriptionIdList();
4406 for (int subId : subIds) {
4407 activeSubscriberIds.add(tele.getSubscriberId(subId));
4408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409
4410 // First pass, find a number override for an active subscriber
4411 String mergeNumber = null;
4412 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4413 for (String key : prefs.keySet()) {
4414 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4415 final String subscriberId = (String) prefs.get(key);
4416 if (activeSubscriberIds.contains(subscriberId)) {
4417 final String iccId = key.substring(
4418 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4419 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4420 mergeNumber = (String) prefs.get(numberKey);
4421 if (DBG_MERGE) {
4422 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4423 + " for active subscriber " + subscriberId);
4424 }
4425 if (!TextUtils.isEmpty(mergeNumber)) {
4426 break;
4427 }
4428 }
4429 }
4430 }
4431
4432 // Shortcut when no active merged subscribers
4433 if (TextUtils.isEmpty(mergeNumber)) {
4434 return null;
4435 }
4436
4437 // Second pass, find all subscribers under that line override
4438 final ArraySet<String> result = new ArraySet<>();
4439 for (String key : prefs.keySet()) {
4440 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4441 final String number = (String) prefs.get(key);
4442 if (mergeNumber.equals(number)) {
4443 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4444 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4445 final String subscriberId = (String) prefs.get(subscriberKey);
4446 if (!TextUtils.isEmpty(subscriberId)) {
4447 result.add(subscriberId);
4448 }
4449 }
4450 }
4451 }
4452
4453 final String[] resultArray = result.toArray(new String[result.size()]);
4454 Arrays.sort(resultArray);
4455 if (DBG_MERGE) {
4456 Slog.d(LOG_TAG,
4457 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4458 }
4459 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004460 } finally {
4461 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004462 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004463 }
4464
4465 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004466 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004467 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4468 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 final Phone phone = getPhone(subId);
4473 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4474 } finally {
4475 Binder.restoreCallingIdentity(identity);
4476 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004477 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004478
4479 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004480 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004481 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4482 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004483 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004484
4485 final long identity = Binder.clearCallingIdentity();
4486 try {
4487 final Phone phone = getPhone(subId);
4488 if (phone == null) {
4489 return false;
4490 }
4491 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4492 cdmaNonRoamingList);
4493 } finally {
4494 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004495 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004496 }
4497
4498 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004499 @Deprecated
4500 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4501 enforceModifyPermission();
4502
4503 int returnValue = 0;
4504 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004505 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004506 if(result.exception == null) {
4507 if (result.result != null) {
4508 byte[] responseData = (byte[])(result.result);
4509 if(responseData.length > oemResp.length) {
4510 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4511 responseData.length + "bytes. Buffer Size is " +
4512 oemResp.length + "bytes.");
4513 }
4514 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4515 returnValue = responseData.length;
4516 }
4517 } else {
4518 CommandException ex = (CommandException) result.exception;
4519 returnValue = ex.getCommandError().ordinal();
4520 if(returnValue > 0) returnValue *= -1;
4521 }
4522 } catch (RuntimeException e) {
4523 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4524 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4525 if(returnValue > 0) returnValue *= -1;
4526 }
4527
4528 return returnValue;
4529 }
4530
4531 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004532 public void setRadioCapability(RadioAccessFamily[] rafs) {
4533 try {
4534 ProxyController.getInstance().setRadioCapability(rafs);
4535 } catch (RuntimeException e) {
4536 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4537 }
4538 }
4539
4540 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004541 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004542 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004543 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004544 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004545 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004547 final long identity = Binder.clearCallingIdentity();
4548 try {
chen xub97461a2018-10-26 14:17:57 -07004549 TelephonyPermissions
4550 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4551 mApp, phone.getSubId(), "getRadioAccessFamily");
4552 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 } finally {
4554 Binder.restoreCallingIdentity(identity);
4555 }
chen xub97461a2018-10-26 14:17:57 -07004556 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004557 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004558
4559 @Override
4560 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004561 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004562 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563
4564 final long identity = Binder.clearCallingIdentity();
4565 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004566 ImsManager.getInstance(defaultPhone.getContext(),
4567 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 } finally {
4569 Binder.restoreCallingIdentity(identity);
4570 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004571 }
4572
4573 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004574 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004575 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004577 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004578 return false;
4579 }
Svet Ganovb320e182015-04-16 12:30:10 -07004580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 final long identity = Binder.clearCallingIdentity();
4582 try {
4583 // Check the user preference and the system-level IMS setting. Even if the user has
4584 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4585 // In the long run, we may instead need to check if there exists a connection service
4586 // which can support video calling.
4587 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004588 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 return imsManager.isVtEnabledByPlatform()
4590 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4591 && imsManager.isVtEnabledByUser();
4592 } finally {
4593 Binder.restoreCallingIdentity(identity);
4594 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004595 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004596
Andrew Leea1239f22015-03-02 17:44:07 -08004597 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4600 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4601 return false;
4602 }
4603
4604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 CarrierConfigManager configManager =
4607 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004608 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4610 } finally {
4611 Binder.restoreCallingIdentity(identity);
4612 }
Andrew Leea1239f22015-03-02 17:44:07 -08004613 }
4614
4615 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 public boolean isWorldPhone(int subId, String callingPackage) {
4617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4618 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4619 return false;
4620 }
4621
4622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 CarrierConfigManager configManager =
4625 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004626 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4628 } finally {
4629 Binder.restoreCallingIdentity(identity);
4630 }
Andrew Leea1239f22015-03-02 17:44:07 -08004631 }
4632
Andrew Lee9431b832015-03-09 18:46:45 -07004633 @Override
4634 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004635 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004636 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004637 }
4638
4639 @Override
4640 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 final long identity = Binder.clearCallingIdentity();
4642 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004643 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644 } finally {
4645 Binder.restoreCallingIdentity(identity);
4646 }
Andrew Lee9431b832015-03-09 18:46:45 -07004647 }
4648
Hall Liuf6668912018-10-31 17:05:23 -07004649 /**
4650 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4651 * support for the feature and device firmware support.
4652 *
4653 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4654 */
4655 @Override
4656 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004658 final Phone phone = getPhone(subscriptionId);
4659 if (phone == null) {
4660 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4661 return false;
4662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004664 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4666 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004667 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004668 return isCarrierSupported && isDeviceSupported;
4669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
Hall Liu98187582018-01-22 19:15:32 -08004672 }
4673
Hall Liuf6668912018-10-31 17:05:23 -07004674 /**
4675 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4676 * both also support RTT.
4677 */
4678 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679 final long identity = Binder.clearCallingIdentity();
4680 try {
Hall Liuf6668912018-10-31 17:05:23 -07004681 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004682 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 } finally {
4684 Binder.restoreCallingIdentity(identity);
4685 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004686 }
4687
Sanket Padawe7310cc72015-01-14 09:53:20 -08004688 /**
4689 * Returns the unique device ID of phone, for example, the IMEI for
4690 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4691 *
4692 * <p>Requires Permission:
4693 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4694 */
4695 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004696 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004697 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004698 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004699 return null;
4700 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004701 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004702 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4703 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004704 return null;
4705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706
4707 final long identity = Binder.clearCallingIdentity();
4708 try {
4709 return phone.getDeviceId();
4710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004713 }
4714
Ping Sunc67b7c22016-03-02 19:16:45 +08004715 /**
4716 * {@hide}
4717 * Returns the IMS Registration Status on a particular subid
4718 *
4719 * @param subId
4720 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004721 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004722 Phone phone = getPhone(subId);
4723 if (phone != null) {
4724 return phone.isImsRegistered();
4725 } else {
4726 return false;
4727 }
4728 }
4729
Santos Cordon7a1885b2015-02-03 11:15:19 -08004730 @Override
4731 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004738 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004739
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004740 /**
4741 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004742 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004743 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
4746 Phone phone = getPhone(subId);
4747 if (phone != null) {
4748 return phone.isWifiCallingEnabled();
4749 } else {
4750 return false;
4751 }
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004754 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004755 }
4756
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004757 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004758 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004759 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004760 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 final long identity = Binder.clearCallingIdentity();
4762 try {
4763 Phone phone = getPhone(subId);
4764 if (phone != null) {
4765 return phone.isVideoEnabled();
4766 } else {
4767 return false;
4768 }
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004771 }
4772 }
4773
4774 /**
4775 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4776 * defined in {@link ImsRegistrationImplBase}.
4777 */
4778 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 final long identity = Binder.clearCallingIdentity();
4780 try {
4781 Phone phone = getPhone(subId);
4782 if (phone != null) {
4783 return phone.getImsRegistrationTech();
4784 } else {
4785 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4786 }
4787 } finally {
4788 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004789 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004790 }
4791
Stuart Scott8eef64f2015-04-08 15:13:54 -07004792 @Override
4793 public void factoryReset(int subId) {
4794 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004795 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4796 return;
4797 }
4798
Svet Ganovcc087f82015-05-12 20:35:54 -07004799 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004800
Svet Ganovcc087f82015-05-12 20:35:54 -07004801 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004802 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4803 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004804 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004805 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004806 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004807 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4808 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004809 }
4810 } finally {
4811 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004812 }
4813 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004814
4815 @Override
4816 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 final long identity = Binder.clearCallingIdentity();
4818 try {
4819 // We query all subscriptions instead of just the active ones, because
4820 // this might be called early on in the provisioning flow when the
4821 // subscriptions potentially aren't active yet.
4822 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4823 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004824 return null;
4825 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827 // This function may be called very early, say, from the setup wizard, at
4828 // which point we won't have a default subscription set. If that's the case
4829 // we just choose the first, which will be valid in "most cases".
4830 final int defaultSubId = getDefaultSubscription();
4831 SubscriptionInfo info = null;
4832 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4833 info = slist.get(0);
4834 } else {
4835 for (SubscriptionInfo item : slist) {
4836 if (item.getSubscriptionId() == defaultSubId) {
4837 info = item;
4838 break;
4839 }
4840 }
4841
4842 if (info == null) {
4843 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004844 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004845 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 // Try and fetch the locale from the carrier properties or from the SIM language
4848 // preferences (EF-PL and EF-LI)...
4849 final int mcc = info.getMcc();
4850 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4851 String simLanguage = null;
4852 if (defaultPhone != null) {
4853 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4854 if (localeFromDefaultSim != null) {
4855 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4856 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4857 return localeFromDefaultSim.toLanguageTag();
4858 } else {
4859 simLanguage = localeFromDefaultSim.getLanguage();
4860 }
4861 }
4862 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864 // The SIM language preferences only store a language (e.g. fr = French), not an
4865 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4866 // the SIM and carrier preferences does not include a country we add the country
4867 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004868 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 if (mccLocale != null) {
4870 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4871 return mccLocale.toLanguageTag();
4872 }
4873
4874 if (DBG) log("No locale found - returning null");
4875 return null;
4876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004879 }
4880
4881 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004882 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004883 }
4884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004885 /**
4886 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4887 */
4888 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004889 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004890 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004891
Chenjie Yu1ba97252018-01-11 18:16:20 -08004892 private final ModemActivityInfo mLastModemActivityInfo =
4893 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4894
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004895 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004896 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4897 * representing the state of the modem.
4898 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004899 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4900 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004901 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004902 */
4903 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004904 public void requestModemActivityInfo(ResultReceiver result) {
4905 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004906 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907
4908 final long identity = Binder.clearCallingIdentity();
4909 try {
4910 ModemActivityInfo ret = null;
4911 synchronized (mLastModemActivityInfo) {
4912 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4913 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004914 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004915 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4917 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004918 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
4919 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004920 }
4921 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004922 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
4923 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 mLastModemActivityInfo.setIdleTimeMillis(
4925 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4926 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4927 mLastModemActivityInfo.setRxTimeMillis(
4928 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4929 mLastModemActivityInfo.setEnergyUsed(
4930 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4933 mLastModemActivityInfo.getSleepTimeMillis(),
4934 mLastModemActivityInfo.getIdleTimeMillis(),
4935 mLastModemActivityInfo.getTxTimeMillis(),
4936 mLastModemActivityInfo.getRxTimeMillis(),
4937 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 Bundle bundle = new Bundle();
4940 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4941 result.send(0, bundle);
4942 } finally {
4943 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004944 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004945 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004946
Siddharth Rayb8114062018-06-17 15:02:38 -07004947 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4948 // less than total activity duration.
4949 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4950 if (info == null) {
4951 return false;
4952 }
4953 int activityDurationMs =
4954 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4955 int totalTxTimeMs = 0;
4956 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4957 totalTxTimeMs += info.getTxTimeMillis()[i];
4958 }
4959 return (info.isValid()
4960 && (info.getSleepTimeMillis() <= activityDurationMs)
4961 && (info.getIdleTimeMillis() <= activityDurationMs)
4962 && (info.getRxTimeMillis() <= activityDurationMs)
4963 && (totalTxTimeMs <= activityDurationMs));
4964 }
4965
Jack Yu85bd38a2015-11-09 11:34:32 -08004966 /**
4967 * {@hide}
4968 * Returns the service state information on specified subscription.
4969 */
4970 @Override
4971 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004973 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004974 return null;
4975 }
4976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 final Phone phone = getPhone(subId);
4980 if (phone == null) {
4981 return null;
4982 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 return phone.getServiceState();
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004988 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004989
4990 /**
4991 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4992 *
4993 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4994 * voicemail ringtone.
4995 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4996 * PhoneAccount.
4997 */
4998 @Override
4999 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 final long identity = Binder.clearCallingIdentity();
5001 try {
5002 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5003 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005004 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005011 }
5012
5013 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005014 * Sets the per-account voicemail ringtone.
5015 *
5016 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5017 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5018 *
5019 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5020 * voicemail ringtone.
5021 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5022 * PhoneAccount.
5023 */
5024 @Override
5025 public void setVoicemailRingtoneUri(String callingPackage,
5026 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005027 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005028 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5029 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005030 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5032 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5033 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035
5036 final long identity = Binder.clearCallingIdentity();
5037 try {
5038 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5039 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005040 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 }
5042 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005045 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005046 }
5047
5048 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005049 * Returns whether vibration is set for voicemail notification in Phone settings.
5050 *
5051 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5052 * voicemail vibration setting.
5053 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5054 */
5055 @Override
5056 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 final long identity = Binder.clearCallingIdentity();
5058 try {
5059 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5060 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005061 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005068 }
5069
Youhan Wange64578a2016-05-02 15:32:42 -07005070 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005071 * Sets the per-account voicemail vibration.
5072 *
5073 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5074 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5075 *
5076 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5077 * voicemail vibration setting.
5078 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5079 * specific PhoneAccount.
5080 */
5081 @Override
5082 public void setVoicemailVibrationEnabled(String callingPackage,
5083 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005084 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005085 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5086 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005087 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5089 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5090 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005091 }
5092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5096 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005097 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 }
5099 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005102 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005103 }
5104
5105 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005106 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5107 *
5108 * @throws SecurityException if the caller does not have the required permission
5109 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005110 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005111 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005112 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005113 }
5114
5115 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005116 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5117 * permission.
5118 *
5119 * @throws SecurityException if the caller does not have the required permission
5120 */
5121 private void enforceSendSmsPermission() {
5122 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5123 }
5124
5125 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005126 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005127 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005128 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005129 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005130 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 final long identity = Binder.clearCallingIdentity();
5132 try {
5133 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005134 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 if (componentName == null) {
5136 throw new SecurityException(
5137 "Caller not current active visual voicemail package[null]");
5138 }
5139 String vvmPackage = componentName.getPackageName();
5140 if (!callingPackage.equals(vvmPackage)) {
5141 throw new SecurityException("Caller not current active visual voicemail package["
5142 + vvmPackage + "]");
5143 }
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005146 }
5147 }
5148
5149 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005150 * Return the application ID for the app type.
5151 *
5152 * @param subId the subscription ID that this request applies to.
5153 * @param appType the uicc app type.
5154 * @return Application ID for specificied app type, or null if no uicc.
5155 */
5156 @Override
5157 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005158 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005159 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160
5161 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005162 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 if (phone == null) {
5164 return null;
5165 }
5166 String aid = null;
5167 try {
5168 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5169 .getApplicationByType(appType).getAid();
5170 } catch (Exception e) {
5171 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5172 }
5173 return aid;
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005176 }
Youhan Wange64578a2016-05-02 15:32:42 -07005177 }
5178
Youhan Wang4001d252016-05-11 10:29:41 -07005179 /**
5180 * Return the Electronic Serial Number.
5181 *
5182 * @param subId the subscription ID that this request applies to.
5183 * @return ESN or null if error.
5184 */
5185 @Override
5186 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005187 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005188 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189
5190 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005191 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 if (phone == null) {
5193 return null;
5194 }
5195 String esn = null;
5196 try {
5197 esn = phone.getEsn();
5198 } catch (Exception e) {
5199 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5200 }
5201 return esn;
5202 } finally {
5203 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005204 }
Youhan Wang4001d252016-05-11 10:29:41 -07005205 }
5206
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005207 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005208 * Return the Preferred Roaming List Version.
5209 *
5210 * @param subId the subscription ID that this request applies to.
5211 * @return PRLVersion or null if error.
5212 */
5213 @Override
5214 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005215 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005216 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217
5218 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005219 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 if (phone == null) {
5221 return null;
5222 }
5223 String cdmaPrlVersion = null;
5224 try {
5225 cdmaPrlVersion = phone.getCdmaPrlVersion();
5226 } catch (Exception e) {
5227 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5228 }
5229 return cdmaPrlVersion;
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005232 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005233 }
5234
5235 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005236 * Get snapshot of Telephony histograms
5237 * @return List of Telephony histograms
5238 * @hide
5239 */
5240 @Override
5241 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5243 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244
5245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 return RIL.getTelephonyRILTimingHistograms();
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005251 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005252
5253 /**
5254 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005255 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005256 * Require system privileges. In the future we may add this to carrier APIs.
5257 *
5258 * @return The number of carriers set successfully, should match length of carriers
5259 */
5260 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005261 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005262 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005264
Meng Wang9b7c4e92017-02-17 11:41:27 -08005265 if (carriers == null) {
5266 throw new NullPointerException("carriers cannot be null");
5267 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 final long identity = Binder.clearCallingIdentity();
5270 try {
Michele85121de2018-12-19 15:25:20 -08005271 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5272 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005273 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5274 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 return retVal[0];
5276 } finally {
5277 Binder.restoreCallingIdentity(identity);
5278 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005279 }
5280
5281 /**
5282 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005283 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005284 * Require system privileges. In the future we may add this to carrier APIs.
5285 *
5286 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5287 * means all carriers are allowed.
5288 */
5289 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005290 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005291 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005292 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293
5294 final long identity = Binder.clearCallingIdentity();
5295 try {
Michele85121de2018-12-19 15:25:20 -08005296 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5297 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005298 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5299 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005303 }
5304
fionaxu59545b42016-05-25 15:53:37 -07005305 /**
5306 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5307 * @param subId the subscription ID that this action applies to.
5308 * @param enabled control enable or disable metered apns.
5309 * {@hide}
5310 */
5311 @Override
5312 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5313 enforceModifyPermission();
5314 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315
5316 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005317 if (phone == null) {
5318 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5319 return;
5320 }
5321 try {
5322 phone.carrierActionSetMeteredApnsEnabled(enabled);
5323 } catch (Exception e) {
5324 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 } finally {
5326 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005327 }
5328 }
5329
5330 /**
5331 * Action set from carrier signalling broadcast receivers to enable/disable radio
5332 * @param subId the subscription ID that this action applies to.
5333 * @param enabled control enable or disable radio.
5334 * {@hide}
5335 */
5336 @Override
5337 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5338 enforceModifyPermission();
5339 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340
5341 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005342 if (phone == null) {
5343 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5344 return;
5345 }
5346 try {
5347 phone.carrierActionSetRadioEnabled(enabled);
5348 } catch (Exception e) {
5349 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 } finally {
5351 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005352 }
5353 }
5354
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005355 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005356 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5357 * network status based on which carrier apps could apply actions accordingly,
5358 * enable/disable default url handler for example.
5359 *
5360 * @param subId the subscription ID that this action applies to.
5361 * @param report control start/stop reporting the default network status.
5362 * {@hide}
5363 */
5364 @Override
5365 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5366 enforceModifyPermission();
5367 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368
5369 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005370 if (phone == null) {
5371 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5372 return;
5373 }
5374 try {
5375 phone.carrierActionReportDefaultNetworkStatus(report);
5376 } catch (Exception e) {
5377 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 } finally {
5379 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005380 }
5381 }
5382
5383 /**
fionaxud9622282017-07-17 17:51:30 -07005384 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5385 * @param subId the subscription ID that this action applies to.
5386 * {@hide}
5387 */
5388 @Override
5389 public void carrierActionResetAll(int subId) {
5390 enforceModifyPermission();
5391 final Phone phone = getPhone(subId);
5392 if (phone == null) {
5393 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5394 return;
5395 }
5396 try {
5397 phone.carrierActionResetAll();
5398 } catch (Exception e) {
5399 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5400 }
5401 }
5402
5403 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005404 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5405 * bug report is being generated.
5406 */
5407 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005408 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005409 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5410 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005411 writer.println("Permission Denial: can't dump Phone from pid="
5412 + Binder.getCallingPid()
5413 + ", uid=" + Binder.getCallingUid()
5414 + "without permission "
5415 + android.Manifest.permission.DUMP);
5416 return;
5417 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005418 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005419 }
Jack Yueb89b242016-06-22 13:27:47 -07005420
Brad Ebingerdac2f002018-04-03 15:17:52 -07005421 @Override
5422 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5423 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5424 throws RemoteException {
5425 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5426 }
5427
Jack Yueb89b242016-06-22 13:27:47 -07005428 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005429 * Get aggregated video call data usage since boot.
5430 *
5431 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5432 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005433 * {@hide}
5434 */
5435 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005436 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005437 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5438 null);
5439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 final long identity = Binder.clearCallingIdentity();
5441 try {
5442 // NetworkStatsService keeps tracking the active network interface and identity. It
5443 // records the delta with the corresponding network identity.
5444 // We just return the total video call data usage snapshot since boot.
5445 Phone phone = getPhone(subId);
5446 if (phone != null) {
5447 return phone.getVtDataUsage(perUidStats);
5448 }
5449 return null;
5450 } finally {
5451 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005452 }
Jack Yueb89b242016-06-22 13:27:47 -07005453 }
Jack Yu75ab2952016-07-08 14:29:33 -07005454
5455 /**
5456 * Policy control of data connection. Usually used when data limit is passed.
5457 * @param enabled True if enabling the data, otherwise disabling.
5458 * @param subId Subscription index
5459 * {@hide}
5460 */
5461 @Override
5462 public void setPolicyDataEnabled(boolean enabled, int subId) {
5463 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 Phone phone = getPhone(subId);
5468 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005469 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 }
5471 } finally {
5472 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005473 }
5474 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005475
5476 /**
5477 * Get Client request stats
5478 * @return List of Client Request Stats
5479 * @hide
5480 */
5481 @Override
5482 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005484 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005485 return null;
5486 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005487 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 final long identity = Binder.clearCallingIdentity();
5490 try {
5491 if (phone != null) {
5492 return phone.getClientRequestStats();
5493 }
5494
5495 return null;
5496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005499 }
5500
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005501 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005502 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005503 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005504 }
Jack Yueb4124c2017-02-16 15:32:43 -08005505
5506 /**
Grace Chen70990072017-03-24 17:21:30 -07005507 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005508 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005509 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005510 * @param state State of SIM (power down, power up, pass through)
5511 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5512 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5513 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005514 *
5515 **/
5516 @Override
Grace Chen70990072017-03-24 17:21:30 -07005517 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005518 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005519 Phone phone = PhoneFactory.getPhone(slotIndex);
5520
vagdeviaf9a5b92018-08-15 16:01:53 -07005521 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005526 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 }
5528 } finally {
5529 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005530 }
5531 }
Shuo Qiandd210312017-04-12 22:11:33 +00005532
Tyler Gunn65d45c22017-06-05 11:22:26 -07005533 private boolean isUssdApiAllowed(int subId) {
5534 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005535 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005536 if (configManager == null) {
5537 return false;
5538 }
5539 PersistableBundle pb = configManager.getConfigForSubId(subId);
5540 if (pb == null) {
5541 return false;
5542 }
5543 return pb.getBoolean(
5544 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5545 }
5546
Shuo Qiandd210312017-04-12 22:11:33 +00005547 /**
5548 * Check if phone is in emergency callback mode
5549 * @return true if phone is in emergency callback mode
5550 * @param subId sub id
5551 */
goneil9c5f4872017-12-05 14:07:56 -08005552 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005553 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005554 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005555 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556
5557 final long identity = Binder.clearCallingIdentity();
5558 try {
5559 if (phone != null) {
5560 return phone.isInEcm();
5561 } else {
5562 return false;
5563 }
5564 } finally {
5565 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005566 }
5567 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005568
5569 /**
5570 * Get the current signal strength information for the given subscription.
5571 * Because this information is not updated when the device is in a low power state
5572 * it should not be relied-upon to be current.
5573 * @param subId Subscription index
5574 * @return the most recent cached signal strength info from the modem
5575 */
5576 @Override
5577 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 Phone p = getPhone(subId);
5581 if (p == null) {
5582 return null;
5583 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 return p.getSignalStrength();
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
5588 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005589 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005590
Pengquan Meng77b7f132018-08-22 14:49:57 -07005591 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005592 * Get the current modem radio state for the given slot.
5593 * @param slotIndex slot index.
5594 * @param callingPackage the name of the package making the call.
5595 * @return the current radio power state from the modem
5596 */
5597 @Override
5598 public int getRadioPowerState(int slotIndex, String callingPackage) {
5599 Phone phone = PhoneFactory.getPhone(slotIndex);
5600 if (phone != null) {
5601 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5602 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5603 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5604 }
5605
5606 final long identity = Binder.clearCallingIdentity();
5607 try {
5608 return phone.getRadioPowerState();
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
5611 }
5612 }
5613 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5614 }
5615
5616 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005617 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5618 *
5619 * <p>Requires one of the following permissions:
5620 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5621 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5622 * privileges.
5623 *
5624 * @param subId subscription id
5625 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5626 * {@code false}.
5627 */
5628 @Override
5629 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005630 boolean isEnabled = false;
5631 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005632 try {
5633 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005634 null /* message */);
5635 Phone phone = getPhone(subId);
5636 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005637 } catch (Exception e) {
5638 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5639 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005640 } finally {
5641 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005643 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005644 }
5645
5646
5647 /**
5648 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5649 *
5650 * <p> Requires permission:
5651 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5652 * privileges.
5653 *
5654 * @param subId subscription id
5655 * @param isEnabled {@code true} means enable, {@code false} means disable.
5656 */
5657 @Override
5658 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5662 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005663
Pengquan Menga1bb6272018-09-06 09:59:22 -07005664 Phone phone = getPhone(subId);
5665 if (phone != null) {
5666 phone.setDataRoamingEnabled(isEnabled);
5667 }
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005670 }
5671 }
5672
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005673 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005674 public boolean isManualNetworkSelectionAllowed(int subId) {
5675 boolean isAllowed = true;
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5679 mApp, subId, "isManualNetworkSelectionAllowed");
5680 Phone phone = getPhone(subId);
5681 if (phone != null) {
5682 isAllowed = phone.isCspPlmnEnabled();
5683 }
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
5687 return isAllowed;
5688 }
5689
5690 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005691 public UiccCardInfo[] getUiccCardsInfo() {
5692 enforceReadPrivilegedPermission("getUiccCardsInfo");
5693
5694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5697 return cards.toArray(new UiccCardInfo[cards.size()]);
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
5701 }
5702
5703 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005704 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005705 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 final long identity = Binder.clearCallingIdentity();
5708 try {
5709 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5710 if (slots == null) {
5711 Rlog.i(LOG_TAG, "slots is null.");
5712 return null;
5713 }
5714
5715 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5716 for (int i = 0; i < slots.length; i++) {
5717 UiccSlot slot = slots[i];
5718 if (slot == null) {
5719 continue;
5720 }
5721
5722 String cardId;
5723 UiccCard card = slot.getUiccCard();
5724 if (card != null) {
5725 cardId = card.getCardId();
5726 } else {
5727 cardId = slot.getIccId();
5728 }
5729
5730 int cardState = 0;
5731 switch (slot.getCardState()) {
5732 case CARDSTATE_ABSENT:
5733 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5734 break;
5735 case CARDSTATE_PRESENT:
5736 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5737 break;
5738 case CARDSTATE_ERROR:
5739 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5740 break;
5741 case CARDSTATE_RESTRICTED:
5742 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5743 break;
5744 default:
5745 break;
5746
5747 }
5748
5749 infos[i] = new UiccSlotInfo(
5750 slot.isActive(),
5751 slot.isEuicc(),
5752 cardId,
5753 cardState,
5754 slot.getPhoneId(),
5755 slot.isExtendedApduSupported());
5756 }
5757 return infos;
5758 } finally {
5759 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005760 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005761 }
5762
5763 @Override
5764 public boolean switchSlots(int[] physicalSlots) {
5765 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766
5767 final long identity = Binder.clearCallingIdentity();
5768 try {
5769 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005773 }
Jack Yu4c988042018-02-27 15:30:01 -08005774
5775 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005776 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5778 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5779 return TelephonyManager.INVALID_CARD_ID;
5780 }
5781
5782 final long identity = Binder.clearCallingIdentity();
5783 try {
5784 return UiccController.getInstance().getCardIdForDefaultEuicc();
5785 } finally {
5786 Binder.restoreCallingIdentity(identity);
5787 }
5788 }
5789
5790 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005791 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5792 enforceModifyPermission();
5793 final Phone phone = getPhone(subId);
5794 if (phone == null) {
5795 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5796 return;
5797 }
5798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 phone.setRadioIndicationUpdateMode(filters, mode);
5802 } finally {
5803 Binder.restoreCallingIdentity(identity);
5804 }
Jack Yu4c988042018-02-27 15:30:01 -08005805 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005806
5807 /**
goneil47ffb6e2018-04-06 15:40:58 -07005808 * A test API to reload the UICC profile.
5809 *
5810 * <p>Requires that the calling app has permission
5811 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5812 * @hide
5813 */
5814 @Override
5815 public void refreshUiccProfile(int subId) {
5816 enforceModifyPermission();
5817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 Phone phone = getPhone(subId);
5821 if (phone == null) {
5822 return;
5823 }
5824 UiccCard uiccCard = phone.getUiccCard();
5825 if (uiccCard == null) {
5826 return;
5827 }
5828 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5829 if (uiccProfile == null) {
5830 return;
5831 }
5832 uiccProfile.refresh();
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
5836 }
5837
5838 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005839 * Returns false if the mobile data is disabled by default, otherwise return true.
5840 */
5841 private boolean getDefaultDataEnabled() {
5842 return "true".equalsIgnoreCase(
5843 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5844 }
5845
5846 /**
5847 * Returns true if the data roaming is enabled by default, i.e the system property
5848 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5849 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5850 */
5851 private boolean getDefaultDataRoamingEnabled(int subId) {
5852 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005853 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005854 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5855 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5856 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5857 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5858 return isDataRoamingEnabled;
5859 }
5860
5861 /**
5862 * Returns the default network type for the given {@code subId}, if the default network type is
5863 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5864 */
5865 private int getDefaultNetworkType(int subId) {
5866 return Integer.parseInt(
5867 TelephonyManager.getTelephonyProperty(
5868 mSubscriptionController.getPhoneId(subId),
5869 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5870 String.valueOf(Phone.PREFERRED_NT_MODE)));
5871 }
fionaxua13278b2018-03-21 00:08:13 -07005872
5873 @Override
5874 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5875 gid1, String gid2, String plmn, String spn) {
5876 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877
5878 final long identity = Binder.clearCallingIdentity();
5879 try {
5880 final Phone phone = getPhone(subId);
5881 if (phone == null) {
5882 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5883 return;
5884 }
5885 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5886 } finally {
5887 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005888 }
fionaxua13278b2018-03-21 00:08:13 -07005889 }
5890
5891 @Override
5892 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005893 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894
5895 final long identity = Binder.clearCallingIdentity();
5896 try {
5897 final Phone phone = getPhone(subId);
5898 if (phone == null) {
5899 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5900 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5901 }
5902 return phone.getCarrierIdListVersion();
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005905 }
fionaxua13278b2018-03-21 00:08:13 -07005906 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005907
5908 @Override
5909 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5910 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5911 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5912 return -1;
5913 }
5914
5915 final long identity = Binder.clearCallingIdentity();
5916 try {
5917 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5918 } finally {
5919 Binder.restoreCallingIdentity(identity);
5920 }
5921 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005922
5923 @Override
5924 public int getCdmaRoamingMode(int subId) {
5925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5926 mApp, subId, "getCdmaRoamingMode");
5927
5928 final long identity = Binder.clearCallingIdentity();
5929 try {
5930 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
5934 }
5935
5936 @Override
5937 public boolean setCdmaRoamingMode(int subId, int mode) {
5938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5939 mApp, subId, "setCdmaRoamingMode");
5940
5941 final long identity = Binder.clearCallingIdentity();
5942 try {
5943 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
5947 }
5948
5949 @Override
5950 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5952 mApp, subId, "setCdmaSubscriptionMode");
5953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
5960 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005961
5962 private void ensureUserRunning(int userId) {
5963 if (!mUserManager.isUserRunning(userId)) {
5964 throw new IllegalStateException("User " + userId + " does not exist or not running");
5965 }
5966 }
5967
5968 /**
5969 * Returns a list of SMS apps on a given user.
5970 *
5971 * Only the shell user (UID 2000 or 0) can call it.
5972 * Target user must be running.
5973 */
5974 @Override
5975 public String[] getSmsApps(int userId) {
5976 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5977 ensureUserRunning(userId);
5978
5979 final Collection<SmsApplicationData> apps =
5980 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5981
5982 String[] ret = new String[apps.size()];
5983 int i = 0;
5984 for (SmsApplicationData app : apps) {
5985 ret[i++] = app.mPackageName;
5986 }
5987 return ret;
5988 }
5989
5990 /**
5991 * Returns the default SMS app package name on a given user.
5992 *
5993 * Only the shell user (UID 2000 or 0) can call it.
5994 * Target user must be running.
5995 */
5996 @Override
5997 public String getDefaultSmsApp(int userId) {
5998 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5999 ensureUserRunning(userId);
6000
6001 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6002 /* updateIfNeeded= */ true, userId);
6003 return cn == null ? null : cn.getPackageName();
6004 }
6005
6006 /**
6007 * Set a package as the default SMS app on a given user.
6008 *
6009 * Only the shell user (UID 2000 or 0) can call it.
6010 * Target user must be running.
6011 */
6012 @Override
6013 public void setDefaultSmsApp(int userId, String packageName) {
6014 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6015 ensureUserRunning(userId);
6016
6017 boolean found = false;
6018 for (String pkg : getSmsApps(userId)) {
6019 if (TextUtils.equals(packageName, pkg)) {
6020 found = true;
6021 break;
6022 }
6023 }
6024 if (!found) {
6025 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6026 }
6027
6028 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6029 }
sqianc5eccab2018-10-19 18:46:41 -07006030
6031 @Override
6032 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6033 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6035 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6036 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6037 }
6038 final long identity = Binder.clearCallingIdentity();
6039 try {
sqian854d44b2018-12-12 16:48:18 -08006040 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6041 for (Phone phone: PhoneFactory.getPhones()) {
6042 if (phone.getEmergencyNumberTracker() != null
6043 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6044 emergencyNumberListInternal.put(
6045 phone.getSubId(),
6046 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6047 }
sqian11b7a0e2018-12-05 18:48:28 -08006048 }
sqian854d44b2018-12-12 16:48:18 -08006049 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006050 } finally {
6051 Binder.restoreCallingIdentity(identity);
6052 }
sqianc5eccab2018-10-19 18:46:41 -07006053 }
6054
6055 @Override
sqian11b7a0e2018-12-05 18:48:28 -08006056 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006057 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006058 if (!exactMatch) {
6059 TelephonyPermissions
6060 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006061 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006062 }
6063 final long identity = Binder.clearCallingIdentity();
6064 try {
sqian854d44b2018-12-12 16:48:18 -08006065 for (Phone phone: PhoneFactory.getPhones()) {
6066 if (phone.getEmergencyNumberTracker() != null
6067 && phone.getEmergencyNumberTracker() != null) {
6068 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6069 number, exactMatch)) {
6070 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006071 }
6072 }
sqian11b7a0e2018-12-05 18:48:28 -08006073 }
6074 return false;
6075 } finally {
6076 Binder.restoreCallingIdentity(identity);
6077 }
6078 }
6079
chen xud6b45bd2018-10-30 22:27:10 -07006080 @Override
6081 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6082 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6083 Phone phone = getPhone(subId);
6084 if (phone == null) {
6085 return null;
6086 }
6087 final long identity = Binder.clearCallingIdentity();
6088 try {
6089 UiccProfile profile = UiccController.getInstance()
6090 .getUiccProfileForPhone(phone.getPhoneId());
6091 if (profile != null) {
6092 return profile.getCertsFromCarrierPrivilegeAccessRules();
6093 }
6094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
6097 return null;
6098 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006099
6100 /**
6101 * Enable or disable a modem stack.
6102 */
6103 @Override
6104 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6105 enforceModifyPermission();
6106
6107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 Phone phone = PhoneFactory.getPhone(slotIndex);
6110 if (phone == null) {
6111 return false;
6112 } else {
6113 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6114 }
6115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
6118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006119}