blob: 743de334180e3ec82fc795ca43b372df6df20198 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070055import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080087import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070089import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080090import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070091import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080092import android.telephony.ims.aidl.IImsMmTelFeature;
93import android.telephony.ims.aidl.IImsRcsFeature;
94import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070095import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080096import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800100import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800102
Brad Ebinger4c460712018-10-01 10:40:55 -0700103import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700104import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800105import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700107import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700108import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800109import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800113import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800115import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700116import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100117import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700118import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700121import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800122import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700123import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700124import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700125import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700126import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700127import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800129import com.android.internal.telephony.SmsApplication;
130import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800131import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800132import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700133import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700134import com.android.internal.telephony.uicc.IccIoResult;
135import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800136import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700137import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800138import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800140import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000141import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700142import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800143import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700144import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800145import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700146import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700147import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800148
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700149import java.io.FileDescriptor;
150import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800151import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800153import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800154import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800155import java.util.HashMap;
Jake Hambye994d462014-02-03 13:10:13 -0800156import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100157import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159
160/**
161 * Implementation of the ITelephony interface.
162 */
Santos Cordon117fee72014-05-16 17:56:12 -0700163public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 private static final String LOG_TAG = "PhoneInterfaceManager";
165 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
166 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168
169 // Message codes used with mMainThreadHandler
170 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700171 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
172 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173 private static final int CMD_OPEN_CHANNEL = 9;
174 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
175 private static final int CMD_CLOSE_CHANNEL = 11;
176 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800177 private static final int CMD_NV_READ_ITEM = 13;
178 private static final int EVENT_NV_READ_ITEM_DONE = 14;
179 private static final int CMD_NV_WRITE_ITEM = 15;
180 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
181 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
182 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700183 private static final int CMD_RESET_MODEM_CONFIG = 19;
184 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800185 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
186 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
187 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
188 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800189 private static final int CMD_SEND_ENVELOPE = 25;
190 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000191 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
192 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700193 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
194 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
195 private static final int CMD_EXCHANGE_SIM_IO = 31;
196 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800197 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
198 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700199 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
200 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700201 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
202 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700203 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
204 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
205 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
206 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700207 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
208 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
209 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
210 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700211 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800212 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
213 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000214 private static final int CMD_SWITCH_SLOTS = 50;
215 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700216 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
217 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
218 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
219 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
220 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
221 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
222 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
223 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700224 private static final int CMD_GET_ALL_CELL_INFO = 60;
225 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
226 private static final int CMD_GET_CELL_LOCATION = 62;
227 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700228 private static final int CMD_MODEM_REBOOT = 64;
229 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700230 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
231 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800233 // Parameters of select command.
234 private static final int SELECT_COMMAND = 0xA4;
235 private static final int SELECT_P1 = 0x04;
236 private static final int SELECT_P2 = 0;
237 private static final int SELECT_P3 = 0x10;
238
Pengquan Meng85728fb2018-03-12 16:31:21 -0700239 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
240 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
241 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
242
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 /** The singleton instance. */
244 private static PhoneInterfaceManager sInstance;
245
Wink Saville3ab207e2014-11-20 13:07:20 -0800246 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800247 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700248 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800249 private AppOpsManager mAppOps;
250 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800251 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800252 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700253 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
Derek Tan97ebb422014-09-05 16:55:38 -0700255 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
256 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700258
Derek Tan740e1672017-06-27 14:56:27 -0700259 // The AID of ISD-R.
260 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
261
yinxub1bed742017-04-17 11:45:04 -0700262 private NetworkScanRequestTracker mNetworkScanRequestTracker;
263
David Kelly5e06a7f2018-03-12 14:10:59 +0000264 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
265 private static final int MANUFACTURER_CODE_LENGTH = 8;
266
Derek Tan89e89d42014-07-08 17:00:10 -0700267 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700268 * A request object to use for transmitting data to an ICC.
269 */
270 private static final class IccAPDUArgument {
271 public int channel, cla, command, p1, p2, p3;
272 public String data;
273
274 public IccAPDUArgument(int channel, int cla, int command,
275 int p1, int p2, int p3, String data) {
276 this.channel = channel;
277 this.cla = cla;
278 this.command = command;
279 this.p1 = p1;
280 this.p2 = p2;
281 this.p3 = p3;
282 this.data = data;
283 }
284 }
285
286 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700287 * A request object to use for transmitting data to an ICC.
288 */
289 private static final class ManualNetworkSelectionArgument {
290 public OperatorInfo operatorInfo;
291 public boolean persistSelection;
292
293 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
294 this.operatorInfo = operatorInfo;
295 this.persistSelection = persistSelection;
296 }
297 }
298
299 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
301 * request after sending. The main thread will notify the request when it is complete.
302 */
303 private static final class MainThreadRequest {
304 /** The argument to use for the request */
305 public Object argument;
306 /** The result of the request that is run on the main thread */
307 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800308 // The subscriber id that this request applies to. Defaults to
309 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
310 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Nathan Harold92bed182018-10-12 18:16:49 -0700312 // In cases where subId is unavailable, the caller needs to specify the phone.
313 public Phone phone;
314
vagdevie435a3e2018-08-15 16:01:53 -0700315 public WorkSource workSource;
316
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317 public MainThreadRequest(Object argument) {
318 this.argument = argument;
319 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800320
Nathan Harold92bed182018-10-12 18:16:49 -0700321 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
322 this.argument = argument;
323 if (phone != null) {
324 this.phone = phone;
325 }
326 this.workSource = workSource;
327 }
328
vagdevie435a3e2018-08-15 16:01:53 -0700329 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800330 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800331 if (subId != null) {
332 this.subId = subId;
333 }
vagdevie435a3e2018-08-15 16:01:53 -0700334 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 }
337
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800338 private static final class IncomingThirdPartyCallArgs {
339 public final ComponentName component;
340 public final String callId;
341 public final String callerDisplayName;
342
343 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
344 String callerDisplayName) {
345 this.component = component;
346 this.callId = callId;
347 this.callerDisplayName = callerDisplayName;
348 }
349 }
350
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 /**
352 * A handler that processes messages on the main thread in the phone process. Since many
353 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
354 * inbound binder threads to the main thread in the phone process. The Binder thread
355 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
356 * on, which will be notified when the operation completes and will contain the result of the
357 * request.
358 *
359 * <p>If a MainThreadRequest object is provided in the msg.obj field,
360 * note that request.result must be set to something non-null for the calling thread to
361 * unblock.
362 */
363 private final class MainThreadHandler extends Handler {
364 @Override
365 public void handleMessage(Message msg) {
366 MainThreadRequest request;
367 Message onCompleted;
368 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800369 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700370 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800371 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
373 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700374 case CMD_HANDLE_USSD_REQUEST: {
375 request = (MainThreadRequest) msg.obj;
376 final Phone phone = getPhoneFromRequest(request);
377 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
378 String ussdRequest = ussdObject.first;
379 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700380
Pengquan Meng0c05b502018-09-06 09:59:22 -0700381 if (!isUssdApiAllowed(request.subId)) {
382 // Carrier does not support use of this API, return failure.
383 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
384 UssdResponse response = new UssdResponse(ussdRequest, null);
385 Bundle returnData = new Bundle();
386 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
387 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700388
Pengquan Meng0c05b502018-09-06 09:59:22 -0700389 request.result = true;
390 notifyRequester(request);
391 return;
392 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700393
Pengquan Meng0c05b502018-09-06 09:59:22 -0700394 try {
395 request.result = phone != null
396 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
397 } catch (CallStateException cse) {
398 request.result = false;
399 }
400 // Wake up the requesting thread
401 notifyRequester(request);
402 break;
pkanwar32d516d2016-10-14 19:37:38 -0700403 }
404
Yorke Lee716f67e2015-06-17 15:39:16 -0700405 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700407 final Phone phone = getPhoneFromRequest(request);
408 request.result = phone != null ?
409 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
410 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700412 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800419 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700420 if (uiccCard == null) {
421 loge("iccTransmitApduLogicalChannel: No UICC");
422 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700423 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700424 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
426 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 iccArgument.channel, iccArgument.cla, iccArgument.command,
429 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 break;
433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 ar = (AsyncResult) msg.obj;
436 request = (MainThreadRequest) ar.userObj;
437 if (ar.exception == null && ar.result != null) {
438 request.result = ar.result;
439 } else {
440 request.result = new IccIoResult(0x6F, 0, (byte[])null);
441 if (ar.result == null) {
442 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800443 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800445 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 } else {
447 loge("iccTransmitApduLogicalChannel: Unknown exception");
448 }
449 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700450 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 break;
452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
454 request = (MainThreadRequest) msg.obj;
455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduBasicChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700460 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 } else {
462 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
463 request);
464 uiccCard.iccTransmitApduBasicChannel(
465 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
466 iccArgument.p3, iccArgument.data, onCompleted);
467 }
468 break;
469
470 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
471 ar = (AsyncResult) msg.obj;
472 request = (MainThreadRequest) ar.userObj;
473 if (ar.exception == null && ar.result != null) {
474 request.result = ar.result;
475 } else {
476 request.result = new IccIoResult(0x6F, 0, (byte[])null);
477 if (ar.result == null) {
478 loge("iccTransmitApduBasicChannel: Empty response");
479 } else if (ar.exception instanceof CommandException) {
480 loge("iccTransmitApduBasicChannel: CommandException: " +
481 ar.exception);
482 } else {
483 loge("iccTransmitApduBasicChannel: Unknown exception");
484 }
485 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700486 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 break;
488
489 case CMD_EXCHANGE_SIM_IO:
490 request = (MainThreadRequest) msg.obj;
491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 if (uiccCard == null) {
494 loge("iccExchangeSimIO: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 } else {
498 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
499 request);
500 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
501 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
502 iccArgument.data, onCompleted);
503 }
504 break;
505
506 case EVENT_EXCHANGE_SIM_IO_DONE:
507 ar = (AsyncResult) msg.obj;
508 request = (MainThreadRequest) ar.userObj;
509 if (ar.exception == null && ar.result != null) {
510 request.result = ar.result;
511 } else {
512 request.result = new IccIoResult(0x6f, 0, (byte[])null);
513 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 break;
516
Derek Tan4d5e5c12014-02-04 11:54:58 -0800517 case CMD_SEND_ENVELOPE:
518 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800519 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700520 if (uiccCard == null) {
521 loge("sendEnvelopeWithStatus: No UICC");
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700524 } else {
525 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
526 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
527 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800528 break;
529
530 case EVENT_SEND_ENVELOPE_DONE:
531 ar = (AsyncResult) msg.obj;
532 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700533 if (ar.exception == null && ar.result != null) {
534 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
537 if (ar.result == null) {
538 loge("sendEnvelopeWithStatus: Empty response");
539 } else if (ar.exception instanceof CommandException) {
540 loge("sendEnvelopeWithStatus: CommandException: " +
541 ar.exception);
542 } else {
543 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
544 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700546 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 break;
548
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 case CMD_OPEN_CHANNEL:
550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800552 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800555 request.result = new IccOpenLogicalChannelResponse(-1,
556 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 } else {
559 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800560 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
561 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 break;
564
565 case EVENT_OPEN_CHANNEL_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 int[] result = (int[]) ar.result;
571 int channelId = result[0];
572 byte[] selectResponse = null;
573 if (result.length > 1) {
574 selectResponse = new byte[result.length - 1];
575 for (int i = 1; i < result.length; ++i) {
576 selectResponse[i - 1] = (byte) result[i];
577 }
578 }
579 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700580 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 if (ar.result == null) {
583 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 if (ar.exception != null) {
586 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
587 }
588
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700589 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700590 if (ar.exception instanceof CommandException) {
591 CommandException.Error error =
592 ((CommandException) (ar.exception)).getCommandError();
593 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700595 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 }
598 }
599 openChannelResp = new IccOpenLogicalChannelResponse(
600 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700602 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 break;
605
606 case CMD_CLOSE_CHANNEL:
607 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800608 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700609 if (uiccCard == null) {
610 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900611 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700613 } else {
614 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
615 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
616 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 break;
618
619 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800620 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
621 break;
622
623 case CMD_NV_READ_ITEM:
624 request = (MainThreadRequest) msg.obj;
625 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800626 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
627 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800628 break;
629
630 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800636 request.result = "";
637 if (ar.result == null) {
638 loge("nvReadItem: Empty response");
639 } else if (ar.exception instanceof CommandException) {
640 loge("nvReadItem: CommandException: " +
641 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800643 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
645 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
Jake Hambye994d462014-02-03 13:10:13 -0800649 case CMD_NV_WRITE_ITEM:
650 request = (MainThreadRequest) msg.obj;
651 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
652 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800653 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700654 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800655 break;
656
657 case EVENT_NV_WRITE_ITEM_DONE:
658 handleNullReturnEvent(msg, "nvWriteItem");
659 break;
660
661 case CMD_NV_WRITE_CDMA_PRL:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800664 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800665 break;
666
667 case EVENT_NV_WRITE_CDMA_PRL_DONE:
668 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
669 break;
670
chen xu1cc0abe2018-10-26 17:39:23 -0700671 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800672 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700673 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800674 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800675 break;
676
chen xu1cc0abe2018-10-26 17:39:23 -0700677 case EVENT_RESET_MODEM_CONFIG_DONE:
678 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800679 break;
680
Jake Hamby7c27be32014-03-03 13:25:59 -0800681 case CMD_GET_PREFERRED_NETWORK_TYPE:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700684 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800685 break;
686
687 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
688 ar = (AsyncResult) msg.obj;
689 request = (MainThreadRequest) ar.userObj;
690 if (ar.exception == null && ar.result != null) {
691 request.result = ar.result; // Integer
692 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800693 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800694 if (ar.result == null) {
695 loge("getPreferredNetworkType: Empty response");
696 } else if (ar.exception instanceof CommandException) {
697 loge("getPreferredNetworkType: CommandException: " +
698 ar.exception);
699 } else {
700 loge("getPreferredNetworkType: Unknown exception");
701 }
702 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700703 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case CMD_SET_PREFERRED_NETWORK_TYPE:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
709 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700710 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 break;
712
713 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
714 handleNullReturnEvent(msg, "setPreferredNetworkType");
715 break;
716
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000717 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
718 request = (MainThreadRequest)msg.obj;
719 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800720 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000721 break;
722
723 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
724 ar = (AsyncResult)msg.obj;
725 request = (MainThreadRequest)ar.userObj;
726 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700727 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000728 break;
729
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800730 case CMD_SET_VOICEMAIL_NUMBER:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
733 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800734 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
735 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800736 break;
737
738 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
739 handleNullReturnEvent(msg, "setVoicemailNumber");
740 break;
741
Stuart Scott54788802015-03-30 13:18:01 -0700742 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
745 request);
746 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
747 break;
748
749 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
750 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
751 break;
752
Shishir Agrawal302c8692015-06-19 13:49:39 -0700753 case CMD_PERFORM_NETWORK_SCAN:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
756 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
757 break;
758
759 case EVENT_PERFORM_NETWORK_SCAN_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
762 CellNetworkScanResult cellScanResult;
763 if (ar.exception == null && ar.result != null) {
764 cellScanResult = new CellNetworkScanResult(
765 CellNetworkScanResult.STATUS_SUCCESS,
766 (List<OperatorInfo>) ar.result);
767 } else {
768 if (ar.result == null) {
769 loge("getCellNetworkScanResults: Empty response");
770 }
771 if (ar.exception != null) {
772 loge("getCellNetworkScanResults: Exception: " + ar.exception);
773 }
774 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
775 if (ar.exception instanceof CommandException) {
776 CommandException.Error error =
777 ((CommandException) (ar.exception)).getCommandError();
778 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
779 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
780 } else if (error == CommandException.Error.GENERIC_FAILURE) {
781 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
782 }
783 }
784 cellScanResult = new CellNetworkScanResult(errorCode, null);
785 }
786 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700787 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700788 break;
789
790 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
791 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700792 ManualNetworkSelectionArgument selArg =
793 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
795 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700796 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
797 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 break;
799
800 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700801 ar = (AsyncResult) msg.obj;
802 request = (MainThreadRequest) ar.userObj;
803 if (ar.exception == null) {
804 request.result = true;
805 } else {
806 request.result = false;
807 loge("setNetworkSelectionModeManual " + ar.exception);
808 }
809 notifyRequester(request);
810 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700811 break;
812
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700813 case CMD_GET_MODEM_ACTIVITY_INFO:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800816 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700817 break;
818
819 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null && ar.result != null) {
823 request.result = ar.result;
824 } else {
825 if (ar.result == null) {
826 loge("queryModemActivityInfo: Empty response");
827 } else if (ar.exception instanceof CommandException) {
828 loge("queryModemActivityInfo: CommandException: " +
829 ar.exception);
830 } else {
831 loge("queryModemActivityInfo: Unknown exception");
832 }
833 }
Amit Mahajand4766222016-01-28 15:28:28 -0800834 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
835 if (request.result == null) {
836 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
837 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700838 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 break;
840
Meng Wang1a7c35a2016-05-05 20:56:15 -0700841 case CMD_SET_ALLOWED_CARRIERS:
842 request = (MainThreadRequest) msg.obj;
843 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800844 defaultPhone.setAllowedCarriers(
Meng Wang1a7c35a2016-05-05 20:56:15 -0700845 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700846 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 break;
848
849 case EVENT_SET_ALLOWED_CARRIERS_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result;
854 } else {
855 if (ar.result == null) {
856 loge("setAllowedCarriers: Empty response");
857 } else if (ar.exception instanceof CommandException) {
858 loge("setAllowedCarriers: CommandException: " +
859 ar.exception);
860 } else {
861 loge("setAllowedCarriers: Unknown exception");
862 }
863 }
864 // Result cannot be null. Return -1 on error.
865 if (request.result == null) {
866 request.result = new int[]{-1};
867 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700868 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 break;
870
871 case CMD_GET_ALLOWED_CARRIERS:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800874 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 break;
876
877 case EVENT_GET_ALLOWED_CARRIERS_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result;
882 } else {
883 if (ar.result == null) {
884 loge("getAllowedCarriers: Empty response");
885 } else if (ar.exception instanceof CommandException) {
886 loge("getAllowedCarriers: CommandException: " +
887 ar.exception);
888 } else {
889 loge("getAllowedCarriers: Unknown exception");
890 }
891 }
892 // Result cannot be null. Return empty list of CarrierIdentifier.
893 if (request.result == null) {
894 request.result = new ArrayList<CarrierIdentifier>(0);
895 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700896 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 break;
898
Nathan Haroldb3014052017-01-25 15:57:32 -0800899 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
900 ar = (AsyncResult) msg.obj;
901 request = (MainThreadRequest) ar.userObj;
902 if (ar.exception == null && ar.result != null) {
903 request.result = ar.result;
904 } else {
905 request.result = new IllegalArgumentException(
906 "Failed to retrieve Forbidden Plmns");
907 if (ar.result == null) {
908 loge("getForbiddenPlmns: Empty response");
909 } else {
910 loge("getForbiddenPlmns: Unknown exception");
911 }
912 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700913 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800914 break;
915
916 case CMD_GET_FORBIDDEN_PLMNS:
917 request = (MainThreadRequest) msg.obj;
918 uiccCard = getUiccCardFromRequest(request);
919 if (uiccCard == null) {
920 loge("getForbiddenPlmns() UiccCard is null");
921 request.result = new IllegalArgumentException(
922 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700923 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800924 break;
925 }
926 Integer appType = (Integer) request.argument;
927 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
928 if (uiccApp == null) {
929 loge("getForbiddenPlmns() no app with specified type -- "
930 + appType);
931 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700932 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800933 break;
934 } else {
935 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
936 + " specified type -- " + appType);
937 }
938 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
939 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
940 onCompleted);
941 break;
942
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000943 case CMD_SWITCH_SLOTS:
944 request = (MainThreadRequest) msg.obj;
945 int[] physicalSlots = (int[]) request.argument;
946 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
947 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
948 break;
949
950 case EVENT_SWITCH_SLOTS_DONE:
951 ar = (AsyncResult) msg.obj;
952 request = (MainThreadRequest) ar.userObj;
953 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700954 notifyRequester(request);
955 break;
956 case CMD_GET_NETWORK_SELECTION_MODE:
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
959 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
960 break;
961
962 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception != null) {
966 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
967 } else {
968 int mode = ((int[]) ar.result)[0];
969 if (mode == 0) {
970 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
971 } else {
972 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
973 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000974 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700975 notifyRequester(request);
976 break;
977 case CMD_GET_CDMA_ROAMING_MODE:
978 request = (MainThreadRequest) msg.obj;
979 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
980 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
981 break;
982 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 if (ar.exception != null) {
986 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
987 } else {
988 request.result = ((int[]) ar.result)[0];
989 }
990 notifyRequester(request);
991 break;
992 case CMD_SET_CDMA_ROAMING_MODE:
993 request = (MainThreadRequest) msg.obj;
994 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
995 int mode = (int) request.argument;
996 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
997 break;
998 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 request.result = ar.exception == null;
1002 notifyRequester(request);
1003 break;
1004 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1005 request = (MainThreadRequest) msg.obj;
1006 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1007 int subscriptionMode = (int) request.argument;
1008 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1009 break;
1010 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 request.result = ar.exception == null;
1014 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001015 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001016 case CMD_GET_ALL_CELL_INFO:
1017 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001019 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001020 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001021 case EVENT_GET_ALL_CELL_INFO_DONE:
1022 ar = (AsyncResult) msg.obj;
1023 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001024 // If a timeout occurs, the response will be null
1025 request.result = (ar.exception == null && ar.result != null)
1026 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001027 synchronized (request) {
1028 request.notifyAll();
1029 }
1030 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001031 case CMD_REQUEST_CELL_INFO_UPDATE:
1032 request = (MainThreadRequest) msg.obj;
1033 request.phone.requestCellInfoUpdate(request.workSource,
1034 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1035 break;
1036 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
1039 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1040 try {
1041 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001042 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001043 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1044 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001045 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001046 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001047 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001048 } else {
1049 // use the result as returned
1050 cb.onCellInfo((List<CellInfo>) ar.result);
1051 }
1052 } catch (RemoteException re) {
1053 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1054 }
1055 break;
1056 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 request = (MainThreadRequest) msg.obj;
1058 WorkSource ws = (WorkSource) request.argument;
1059 Phone phone = getPhoneFromRequest(request);
1060 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1061 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
1065 if (ar.exception == null) {
1066 request.result = ar.result;
1067 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1070 ? new CdmaCellLocation() : new GsmCellLocation();
1071 }
1072
1073 synchronized (request) {
1074 request.notifyAll();
1075 }
1076 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001077 case CMD_MODEM_REBOOT:
1078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001080 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001081 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001082 case EVENT_CMD_MODEM_REBOOT_DONE:
1083 handleNullReturnEvent(msg, "rebootModem");
1084 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 default:
1086 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1087 break;
1088 }
1089 }
Jake Hambye994d462014-02-03 13:10:13 -08001090
Pengquan Meng0c05b502018-09-06 09:59:22 -07001091 private void notifyRequester(MainThreadRequest request) {
1092 synchronized (request) {
1093 request.notifyAll();
1094 }
1095 }
1096
Jake Hambye994d462014-02-03 13:10:13 -08001097 private void handleNullReturnEvent(Message msg, String command) {
1098 AsyncResult ar = (AsyncResult) msg.obj;
1099 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1100 if (ar.exception == null) {
1101 request.result = true;
1102 } else {
1103 request.result = false;
1104 if (ar.exception instanceof CommandException) {
1105 loge(command + ": CommandException: " + ar.exception);
1106 } else {
1107 loge(command + ": Unknown exception");
1108 }
1109 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001110 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001112 }
1113
1114 /**
1115 * Posts the specified command to be executed on the main thread,
1116 * waits for the request to complete, and returns the result.
1117 * @see #sendRequestAsync
1118 */
1119 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001120 return sendRequest(
1121 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001122 }
1123
1124 /**
1125 * Posts the specified command to be executed on the main thread,
1126 * waits for the request to complete, and returns the result.
1127 * @see #sendRequestAsync
1128 */
1129 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1130 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001131 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001132 }
1133
1134 /**
1135 * Posts the specified command to be executed on the main thread,
1136 * waits for the request to complete, and returns the result.
1137 * @see #sendRequestAsync
1138 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001139 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001140 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001141 }
1142
1143 /**
1144 * Posts the specified command to be executed on the main thread,
1145 * waits for the request to complete, and returns the result.
1146 * @see #sendRequestAsync
1147 */
Nathan Harold92bed182018-10-12 18:16:49 -07001148 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1149 return sendRequest(command, argument, subId, null, workSource);
1150 }
1151
1152 /**
1153 * Posts the specified command to be executed on the main thread,
1154 * waits for the request to complete, and returns the result.
1155 * @see #sendRequestAsync
1156 */
1157 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1158 return sendRequest(
1159 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1160 }
1161
1162 /**
1163 * Posts the specified command to be executed on the main thread,
1164 * waits for the request to complete, and returns the result.
1165 * @see #sendRequestAsync
1166 */
1167 private Object sendRequest(
1168 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1170 throw new RuntimeException("This method will deadlock if called from the main thread.");
1171 }
1172
Nathan Harold92bed182018-10-12 18:16:49 -07001173 MainThreadRequest request = null;
1174 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1175 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1176 } else if (phone != null) {
1177 request = new MainThreadRequest(argument, phone, workSource);
1178 } else {
1179 request = new MainThreadRequest(argument, subId, workSource);
1180 }
1181
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001182 Message msg = mMainThreadHandler.obtainMessage(command, request);
1183 msg.sendToTarget();
1184
1185 // Wait for the request to complete
1186 synchronized (request) {
1187 while (request.result == null) {
1188 try {
1189 request.wait();
1190 } catch (InterruptedException e) {
1191 // Do nothing, go back and wait until the request is complete
1192 }
1193 }
1194 }
1195 return request.result;
1196 }
1197
1198 /**
1199 * Asynchronous ("fire and forget") version of sendRequest():
1200 * Posts the specified command to be executed on the main thread, and
1201 * returns immediately.
1202 * @see #sendRequest
1203 */
1204 private void sendRequestAsync(int command) {
1205 mMainThreadHandler.sendEmptyMessage(command);
1206 }
1207
1208 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001209 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001210 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001211 */
1212 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001213 sendRequestAsync(command, argument, null, null);
1214 }
1215
1216 /**
1217 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1218 * @see {@link #sendRequest(int,Object)}
1219 */
1220 private void sendRequestAsync(
1221 int command, Object argument, Phone phone, WorkSource workSource) {
1222 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001223 Message msg = mMainThreadHandler.obtainMessage(command, request);
1224 msg.sendToTarget();
1225 }
1226
1227 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 * Initialize the singleton PhoneInterfaceManager instance.
1229 * This is only done once, at startup, from PhoneApp.onCreate().
1230 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001231 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 synchronized (PhoneInterfaceManager.class) {
1233 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001234 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 } else {
1236 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1237 }
1238 return sInstance;
1239 }
1240 }
1241
1242 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001243 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001246 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1248 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001249 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001250 mTelephonySharedPreferences =
1251 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001252 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001253 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 publish();
1256 }
1257
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001258 private Phone getDefaultPhone() {
1259 Phone thePhone = getPhone(getDefaultSubscription());
1260 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1261 }
1262
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 private void publish() {
1264 if (DBG) log("publish: " + this);
1265
1266 ServiceManager.addService("phone", this);
1267 }
1268
Stuart Scott584921c2015-01-15 17:10:34 -08001269 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001270 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001271 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001272 }
1273
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001274 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1275 Phone phone = getPhoneFromRequest(request);
1276 return phone == null ? null :
1277 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1278 }
1279
Wink Saville36469e72014-06-11 15:17:00 -07001280 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001281 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001282 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284
1285 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001286 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001287 }
1288
Wink Savilleb564aae2014-10-23 10:18:09 -07001289 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 if (DBG) log("dial: " + number);
1291 // No permission check needed here: This is just a wrapper around the
1292 // ACTION_DIAL intent, which is available to any app since it puts up
1293 // the UI before it does anything.
1294
Malcolm Chend965c8b2018-02-28 15:00:40 -08001295 final long identity = Binder.clearCallingIdentity();
1296 try {
1297 String url = createTelUrl(number);
1298 if (url == null) {
1299 return;
1300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301
Malcolm Chend965c8b2018-02-28 15:00:40 -08001302 // PENDING: should we just silently fail if phone is offhook or ringing?
1303 PhoneConstants.State state = mCM.getState(subId);
1304 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1305 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1306 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1307 mApp.startActivity(intent);
1308 }
1309 } finally {
1310 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 }
1312 }
1313
1314 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001315 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001316 }
1317
Wink Savilleb564aae2014-10-23 10:18:09 -07001318 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 if (DBG) log("call: " + number);
1320
1321 // This is just a wrapper around the ACTION_CALL intent, but we still
1322 // need to do a permission check since we're calling startActivity()
1323 // from the context of the phone app.
1324 enforceCallPermission();
1325
1326 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1327 != AppOpsManager.MODE_ALLOWED) {
1328 return;
1329 }
1330
Malcolm Chend965c8b2018-02-28 15:00:40 -08001331 final long identity = Binder.clearCallingIdentity();
1332 try {
1333 String url = createTelUrl(number);
1334 if (url == null) {
1335 return;
1336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337
Malcolm Chend965c8b2018-02-28 15:00:40 -08001338 boolean isValid = false;
1339 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1340 if (slist != null) {
1341 for (SubscriptionInfo subInfoRecord : slist) {
1342 if (subInfoRecord.getSubscriptionId() == subId) {
1343 isValid = true;
1344 break;
1345 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001346 }
Wink Saville08874612014-08-31 19:19:58 -07001347 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001348 if (!isValid) {
1349 return;
1350 }
Wink Saville08874612014-08-31 19:19:58 -07001351
Malcolm Chend965c8b2018-02-28 15:00:40 -08001352 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1353 intent.putExtra(SUBSCRIPTION_KEY, subId);
1354 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1355 mApp.startActivity(intent);
1356 } finally {
1357 Binder.restoreCallingIdentity(identity);
1358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 }
1360
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001362 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001363 }
1364
Wink Savilleb564aae2014-10-23 10:18:09 -07001365 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001366 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001367 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1368 }
1369
1370 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001371 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
1373
Wink Savilleb564aae2014-10-23 10:18:09 -07001374 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001376 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1377 }
1378
1379 /** {@hide} */
1380 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001381 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001382 }
1383
Wink Savilleb564aae2014-10-23 10:18:09 -07001384 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001386
1387 final long identity = Binder.clearCallingIdentity();
1388 try {
1389 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1390 checkSimPin.start();
1391 return checkSimPin.unlockSim(null, pin);
1392 } finally {
1393 Binder.restoreCallingIdentity(identity);
1394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 }
1396
Wink Saville9de0f752013-10-22 19:04:03 -07001397 /** {@hide} */
1398 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001400 }
1401
Wink Savilleb564aae2014-10-23 10:18:09 -07001402 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001404
1405 final long identity = Binder.clearCallingIdentity();
1406 try {
1407 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1408 checkSimPuk.start();
1409 return checkSimPuk.unlockSim(puk, pin);
1410 } finally {
1411 Binder.restoreCallingIdentity(identity);
1412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 }
1414
1415 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001416 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001417 * a synchronous one.
1418 */
1419 private static class UnlockSim extends Thread {
1420
1421 private final IccCard mSimCard;
1422
1423 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001424 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1425 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426
1427 // For replies from SimCard interface
1428 private Handler mHandler;
1429
1430 // For async handler to identify request type
1431 private static final int SUPPLY_PIN_COMPLETE = 100;
1432
1433 public UnlockSim(IccCard simCard) {
1434 mSimCard = simCard;
1435 }
1436
1437 @Override
1438 public void run() {
1439 Looper.prepare();
1440 synchronized (UnlockSim.this) {
1441 mHandler = new Handler() {
1442 @Override
1443 public void handleMessage(Message msg) {
1444 AsyncResult ar = (AsyncResult) msg.obj;
1445 switch (msg.what) {
1446 case SUPPLY_PIN_COMPLETE:
1447 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1448 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001449 mRetryCount = msg.arg1;
1450 if (ar.exception != null) {
1451 if (ar.exception instanceof CommandException &&
1452 ((CommandException)(ar.exception)).getCommandError()
1453 == CommandException.Error.PASSWORD_INCORRECT) {
1454 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1455 } else {
1456 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1457 }
1458 } else {
1459 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 mDone = true;
1462 UnlockSim.this.notifyAll();
1463 }
1464 break;
1465 }
1466 }
1467 };
1468 UnlockSim.this.notifyAll();
1469 }
1470 Looper.loop();
1471 }
1472
1473 /*
1474 * Use PIN or PUK to unlock SIM card
1475 *
1476 * If PUK is null, unlock SIM card with PIN
1477 *
1478 * If PUK is not null, unlock SIM card with PUK and set PIN code
1479 */
Wink Saville9de0f752013-10-22 19:04:03 -07001480 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481
1482 while (mHandler == null) {
1483 try {
1484 wait();
1485 } catch (InterruptedException e) {
1486 Thread.currentThread().interrupt();
1487 }
1488 }
1489 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1490
1491 if (puk == null) {
1492 mSimCard.supplyPin(pin, callback);
1493 } else {
1494 mSimCard.supplyPuk(puk, pin, callback);
1495 }
1496
1497 while (!mDone) {
1498 try {
1499 Log.d(LOG_TAG, "wait for done");
1500 wait();
1501 } catch (InterruptedException e) {
1502 // Restore the interrupted status
1503 Thread.currentThread().interrupt();
1504 }
1505 }
1506 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001507 int[] resultArray = new int[2];
1508 resultArray[0] = mResult;
1509 resultArray[1] = mRetryCount;
1510 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 }
1512 }
1513
1514 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001515 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001516
1517 }
1518
Wink Savilleb564aae2014-10-23 10:18:09 -07001519 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 // No permission check needed here: this call is harmless, and it's
1521 // needed for the ServiceState.requestStateUpdate() call (which is
1522 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001523 final long identity = Binder.clearCallingIdentity();
1524 try {
1525 final Phone phone = getPhone(subId);
1526 if (phone != null) {
1527 phone.updateServiceLocation();
1528 }
1529 } finally {
1530 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 }
1533
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001534 @Override
1535 public boolean isRadioOn(String callingPackage) {
1536 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001539 @Override
1540 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001542 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001543 return false;
1544 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001545
1546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 return isRadioOnForSubscriber(subId);
1549 } finally {
1550 Binder.restoreCallingIdentity(identity);
1551 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001552 }
1553
1554 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001555 final long identity = Binder.clearCallingIdentity();
1556 try {
1557 final Phone phone = getPhone(subId);
1558 if (phone != null) {
1559 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1560 } else {
1561 return false;
1562 }
1563 } finally {
1564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
1568 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001569 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
Wink Saville36469e72014-06-11 15:17:00 -07001571
Wink Savilleb564aae2014-10-23 10:18:09 -07001572 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001574
1575 final long identity = Binder.clearCallingIdentity();
1576 try {
1577 final Phone phone = getPhone(subId);
1578 if (phone != null) {
1579 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1580 }
1581 } finally {
1582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001583 }
Wink Saville36469e72014-06-11 15:17:00 -07001584 }
1585
1586 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001587 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001588 }
1589
Wink Savilleb564aae2014-10-23 10:18:09 -07001590 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001591 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001592
1593 final long identity = Binder.clearCallingIdentity();
1594 try {
1595 final Phone phone = getPhone(subId);
1596 if (phone == null) {
1597 return false;
1598 }
1599 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1600 toggleRadioOnOffForSubscriber(subId);
1601 }
1602 return true;
1603 } finally {
1604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 }
Wink Saville36469e72014-06-11 15:17:00 -07001607
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001608 public boolean needMobileRadioShutdown() {
1609 /*
1610 * If any of the Radios are available, it will need to be
1611 * shutdown. So return true if any Radio is available.
1612 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001613 final long identity = Binder.clearCallingIdentity();
1614 try {
1615 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1616 Phone phone = PhoneFactory.getPhone(i);
1617 if (phone != null && phone.isRadioAvailable()) return true;
1618 }
1619 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1620 return false;
1621 } finally {
1622 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001623 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001624 }
1625
Malcolm Chend965c8b2018-02-28 15:00:40 -08001626 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001627 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001628 enforceModifyPermission();
1629
1630 final long identity = Binder.clearCallingIdentity();
1631 try {
1632 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1633 logv("Shutting down Phone " + i);
1634 shutdownRadioUsingPhoneId(i);
1635 }
1636 } finally {
1637 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001638 }
1639 }
1640
1641 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001642 Phone phone = PhoneFactory.getPhone(phoneId);
1643 if (phone != null && phone.isRadioAvailable()) {
1644 phone.shutdownRadio();
1645 }
1646 }
1647
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001649 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001650
1651 final long identity = Binder.clearCallingIdentity();
1652 try {
1653 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1654 if (defaultPhone != null) {
1655 defaultPhone.setRadioPower(turnOn);
1656 return true;
1657 } else {
1658 loge("There's no default phone.");
1659 return false;
1660 }
1661 } finally {
1662 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001663 }
Wink Saville36469e72014-06-11 15:17:00 -07001664 }
1665
Wink Savilleb564aae2014-10-23 10:18:09 -07001666 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001668
1669 final long identity = Binder.clearCallingIdentity();
1670 try {
1671 final Phone phone = getPhone(subId);
1672 if (phone != null) {
1673 phone.setRadioPower(turnOn);
1674 return true;
1675 } else {
1676 return false;
1677 }
1678 } finally {
1679 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682
Wink Saville36469e72014-06-11 15:17:00 -07001683 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 public boolean enableDataConnectivity() {
1686 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001687
1688 final long identity = Binder.clearCallingIdentity();
1689 try {
1690 int subId = mSubscriptionController.getDefaultDataSubId();
1691 final Phone phone = getPhone(subId);
1692 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001693 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001694 return true;
1695 } else {
1696 return false;
1697 }
1698 } finally {
1699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 }
1702
Wink Saville36469e72014-06-11 15:17:00 -07001703 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 public boolean disableDataConnectivity() {
1706 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001707
1708 final long identity = Binder.clearCallingIdentity();
1709 try {
1710 int subId = mSubscriptionController.getDefaultDataSubId();
1711 final Phone phone = getPhone(subId);
1712 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001713 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001714 return true;
1715 } else {
1716 return false;
1717 }
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 }
1722
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001724 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001725 final long identity = Binder.clearCallingIdentity();
1726 try {
1727 final Phone phone = getPhone(subId);
1728 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001729 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001730 } else {
1731 return false;
1732 }
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 }
1737
1738 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001739 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001740 }
1741
pkanwarae03a6b2016-11-06 20:37:09 -08001742 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001743 enforceCallPermission();
1744
1745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1748 return;
1749 }
1750 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1751 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1752 } finally {
1753 Binder.restoreCallingIdentity(identity);
1754 }
pkanwar32d516d2016-10-14 19:37:38 -07001755 };
1756
Wink Savilleb564aae2014-10-23 10:18:09 -07001757 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001759
1760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1763 return false;
1764 }
1765 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001772 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001773 }
1774
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001775 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 Phone phone = PhoneFactory.getPhone(slotIndex);
1779 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1780 PhoneConstantConversions.convertCallState(phone.getState());
1781 } finally {
1782 Binder.restoreCallingIdentity(identity);
1783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 }
1785
Sanket Padawe356d7632015-06-22 14:03:32 -07001786 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1791 if (phone != null) {
1792 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1793 } else {
1794 return PhoneConstantConversions.convertDataState(
1795 PhoneConstants.DataState.DISCONNECTED);
1796 }
1797 } finally {
1798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001799 }
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 getDataActivity() {
Malcolm Chend965c8b2018-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 DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1809 } else {
1810 return TelephonyManager.DATA_ACTIVITY_NONE;
1811 }
1812 } finally {
1813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
1816
1817 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001818 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001819 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001820 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001821 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1822 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001823 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001826 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001827 final long identity = Binder.clearCallingIdentity();
1828 try {
1829 if (DBG_LOC) log("getCellLocation: is active user");
1830 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001831 int subId = mSubscriptionController.getDefaultDataSubId();
1832 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1833 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001834 return data;
1835 } finally {
1836 Binder.restoreCallingIdentity(identity);
1837 }
Svetoslav64fad262015-04-14 14:35:21 -07001838 }
1839
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001841 public String getNetworkCountryIsoForPhone(int phoneId) {
1842 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1843 // registered cell info, so return a NULL country instead.
1844 final long identity = Binder.clearCallingIdentity();
1845 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001846 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1847 // Get default phone in this case.
1848 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1849 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001850 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001851 // Todo: fix this when we can get the actual cellular network info when the device
1852 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001853 if (TelephonyManager.NETWORK_TYPE_IWLAN
1854 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1855 return "";
1856 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001857 Phone phone = PhoneFactory.getPhone(phoneId);
1858 if (phone != null) {
1859 ServiceStateTracker sst = phone.getServiceStateTracker();
1860 if (sst != null) {
1861 LocaleTracker lt = sst.getLocaleTracker();
1862 if (lt != null) {
1863 return lt.getCurrentCountry();
1864 }
1865 }
1866 }
1867 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001868 } finally {
1869 Binder.restoreCallingIdentity(identity);
1870 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001871 }
1872
1873 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001875 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001876 }
1877
Sanket Padawe356d7632015-06-22 14:03:32 -07001878 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001879 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 mApp.enforceCallingOrSelfPermission(
1881 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001882
1883 final long identity = Binder.clearCallingIdentity();
1884 try {
1885 final Phone phone = getPhone(subId);
1886 if (phone != null) {
1887 phone.enableLocationUpdates();
1888 }
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 }
1893
1894 @Override
1895 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001896 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001897 }
1898
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001900 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 mApp.enforceCallingOrSelfPermission(
1902 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001903
1904 final long identity = Binder.clearCallingIdentity();
1905 try {
1906 final Phone phone = getPhone(subId);
1907 if (phone != null) {
1908 phone.disableLocationUpdates();
1909 }
1910 } finally {
1911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
Nathan Harold31d7ff32018-10-15 20:20:30 -07001915 /**
1916 * Returns the target SDK version number for a given package name.
1917 *
1918 * @return target SDK if the package is found or INT_MAX.
1919 */
1920 private int getTargetSdk(String packageName) {
1921 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001922 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1923 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001924 if (ai != null) return ai.targetSdkVersion;
1925 } catch (PackageManager.NameNotFoundException unexpected) {
1926 }
1927 return Integer.MAX_VALUE;
1928 }
1929
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 @Override
1931 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001932 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1933 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001934 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1935 throw new SecurityException(
1936 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1937 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001938
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1940 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1941 return null;
1942 }
Svetoslav64fad262015-04-14 14:35:21 -07001943
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001944 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945
Nathan Haroldf180aac2018-06-01 18:43:55 -07001946 List<CellInfo> info = getAllCellInfo(callingPackage);
1947 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948
Nathan Haroldf180aac2018-06-01 18:43:55 -07001949 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1950 for (CellInfo ci : info) {
1951 if (ci instanceof CellInfoGsm) {
1952 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1953 } else if (ci instanceof CellInfoWcdma) {
1954 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001957 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 }
1959
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001960 private List<CellInfo> getCachedCellInfo() {
1961 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1962 for (Phone phone : PhoneFactory.getPhones()) {
1963 List<CellInfo> info = phone.getAllCellInfo();
1964 if (info != null) cellInfos.addAll(info);
1965 }
1966 return cellInfos;
1967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968
1969 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001970 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001971 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001972 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001973 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001974 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001975 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 }
1977
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001978 final int targetSdk = getTargetSdk(callingPackage);
1979 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1980 return getCachedCellInfo();
1981 }
1982
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001983 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001984 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1988 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001989 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001990 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001991 if (info != null) cellInfos.addAll(info);
1992 }
1993 return cellInfos;
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997 }
1998
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001999 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002000 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2001 requestCellInfoUpdateInternal(
2002 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2003 }
2004
2005 @Override
2006 public void requestCellInfoUpdateWithWorkSource(
2007 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2008 enforceModifyPermission();
2009 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2010 }
2011
2012 private void requestCellInfoUpdateInternal(
2013 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002014 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002015 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002016 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2017 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002018 return;
2019 }
2020
2021 final Phone phone = getPhone(subId);
2022 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2023
2024 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2025 }
2026
2027 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002029 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002030 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002031
2032 final long identity = Binder.clearCallingIdentity();
2033 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002034 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002035 } finally {
2036 Binder.restoreCallingIdentity(identity);
2037 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 }
2039
Shishir Agrawala9f32182016-04-12 12:00:16 -07002040 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002041 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002042 Phone phone = PhoneFactory.getPhone(slotIndex);
2043 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002044 return null;
2045 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002046 int subId = phone.getSubId();
2047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2048 mApp, subId, callingPackage, "getImeiForSlot")) {
2049 return null;
2050 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002051
2052 final long identity = Binder.clearCallingIdentity();
2053 try {
2054 return phone.getImei();
2055 } finally {
2056 Binder.restoreCallingIdentity(identity);
2057 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002058 }
2059
2060 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002061 public String getTypeAllocationCodeForSlot(int slotIndex) {
2062 Phone phone = PhoneFactory.getPhone(slotIndex);
2063 String tac = null;
2064 if (phone != null) {
2065 String imei = phone.getImei();
2066 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2067 }
2068 return tac;
2069 }
2070
2071 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002072 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002073 Phone phone = PhoneFactory.getPhone(slotIndex);
2074 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002075 return null;
2076 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002077
Jeff Davidson913390f2018-02-23 17:11:49 -08002078 int subId = phone.getSubId();
2079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2080 mApp, subId, callingPackage, "getMeidForSlot")) {
2081 return null;
2082 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002083
2084 final long identity = Binder.clearCallingIdentity();
2085 try {
2086 return phone.getMeid();
2087 } finally {
2088 Binder.restoreCallingIdentity(identity);
2089 }
Jack Yu2af8d712017-03-15 17:14:14 -07002090 }
2091
2092 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002093 public String getManufacturerCodeForSlot(int slotIndex) {
2094 Phone phone = PhoneFactory.getPhone(slotIndex);
2095 String manufacturerCode = null;
2096 if (phone != null) {
2097 String meid = phone.getMeid();
2098 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2099 }
2100 return manufacturerCode;
2101 }
2102
2103 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002104 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002105 Phone phone = PhoneFactory.getPhone(slotIndex);
2106 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002107 return null;
2108 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002109 int subId = phone.getSubId();
2110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2111 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2112 return null;
2113 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002114
2115 final long identity = Binder.clearCallingIdentity();
2116 try {
2117 return phone.getDeviceSvn();
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
2120 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002121 }
2122
fionaxu43304da2017-11-27 22:51:16 -08002123 @Override
2124 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002125 final long identity = Binder.clearCallingIdentity();
2126 try {
2127 final Phone phone = getPhone(subId);
2128 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
2131 }
fionaxu43304da2017-11-27 22:51:16 -08002132 }
2133
2134 @Override
2135 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002136 final long identity = Binder.clearCallingIdentity();
2137 try {
2138 final Phone phone = getPhone(subId);
2139 return phone == null ? null : phone.getCarrierName();
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
2142 }
fionaxu43304da2017-11-27 22:51:16 -08002143 }
2144
calvinpaneed9ae82018-11-01 19:43:06 +08002145 @Override
chen xuc93cc282018-11-04 17:17:00 -08002146 public int getSubscriptionPreciseCarrierId(int subId) {
2147 final long identity = Binder.clearCallingIdentity();
2148 try {
2149 final Phone phone = getPhone(subId);
2150 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2151 : phone.getPreciseCarrierId();
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
2155 }
2156
2157 @Override
2158 public String getSubscriptionPreciseCarrierName(int subId) {
2159 final long identity = Binder.clearCallingIdentity();
2160 try {
2161 final Phone phone = getPhone(subId);
2162 return phone == null ? null : phone.getPreciseCarrierName();
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
2165 }
2166 }
2167
chen xu02581692018-11-11 19:03:44 -08002168 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002169 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2170 if (!isSubscriptionMccMnc) {
2171 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2172 }
chen xu02581692018-11-11 19:03:44 -08002173 final Phone phone = PhoneFactory.getPhone(slotIndex);
2174 if (phone == null) {
2175 return TelephonyManager.UNKNOWN_CARRIER_ID;
2176 }
2177 final long identity = Binder.clearCallingIdentity();
2178 try {
2179 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
2182 }
2183 }
2184
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 //
2186 // Internal helper methods.
2187 //
2188
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002189 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2191 *
2192 * @throws SecurityException if the caller does not have the required permission
2193 */
2194 private void enforceModifyPermission() {
2195 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2196 }
2197
2198 /**
2199 * Make sure the caller has the CALL_PHONE permission.
2200 *
2201 * @throws SecurityException if the caller does not have the required permission
2202 */
2203 private void enforceCallPermission() {
2204 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2205 }
2206
Stuart Scott8eef64f2015-04-08 15:13:54 -07002207 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002208 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002209 "ConnectivityService");
2210 }
2211
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 private String createTelUrl(String number) {
2213 if (TextUtils.isEmpty(number)) {
2214 return null;
2215 }
2216
Jake Hambye994d462014-02-03 13:10:13 -08002217 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219
Ihab Awadf9e92732013-12-05 18:02:52 -08002220 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2222 }
2223
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002224 private static void logv(String msg) {
2225 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2226 }
2227
Ihab Awadf9e92732013-12-05 18:02:52 -08002228 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2230 }
2231
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002232 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002234 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002235 }
2236
Sanket Padawe356d7632015-06-22 14:03:32 -07002237 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002238 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 final Phone phone = PhoneFactory.getPhone(slotIndex);
2242 if (phone == null) {
2243 return PhoneConstants.PHONE_TYPE_NONE;
2244 } else {
2245 return phone.getPhoneType();
2246 }
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
2252 /**
2253 * Returns the CDMA ERI icon index to display
2254 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002255 @Override
2256 public int getCdmaEriIconIndex(String callingPackage) {
2257 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002258 }
2259
Sanket Padawe356d7632015-06-22 14:03:32 -07002260 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002261 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002263 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002264 return -1;
2265 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002266
2267 final long identity = Binder.clearCallingIdentity();
2268 try {
2269 final Phone phone = getPhone(subId);
2270 if (phone != null) {
2271 return phone.getCdmaEriIconIndex();
2272 } else {
2273 return -1;
2274 }
2275 } finally {
2276 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 }
2279
2280 /**
2281 * Returns the CDMA ERI icon mode,
2282 * 0 - ON
2283 * 1 - FLASHING
2284 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002285 @Override
2286 public int getCdmaEriIconMode(String callingPackage) {
2287 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002288 }
2289
Sanket Padawe356d7632015-06-22 14:03:32 -07002290 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002291 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002293 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002294 return -1;
2295 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002296
2297 final long identity = Binder.clearCallingIdentity();
2298 try {
2299 final Phone phone = getPhone(subId);
2300 if (phone != null) {
2301 return phone.getCdmaEriIconMode();
2302 } else {
2303 return -1;
2304 }
2305 } finally {
2306 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 }
2309
2310 /**
2311 * Returns the CDMA ERI text,
2312 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002313 @Override
2314 public String getCdmaEriText(String callingPackage) {
2315 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002319 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002321 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 return null;
2323 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 final Phone phone = getPhone(subId);
2328 if (phone != null) {
2329 return phone.getCdmaEriText();
2330 } else {
2331 return null;
2332 }
2333 } finally {
2334 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 }
2337
2338 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002339 * Returns the CDMA MDN.
2340 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002342 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2344 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002345
2346 final long identity = Binder.clearCallingIdentity();
2347 try {
2348 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002349 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002350 return phone.getLine1Number();
2351 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002352 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002353 return null;
2354 }
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002357 }
2358 }
2359
2360 /**
2361 * Returns the CDMA MIN.
2362 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002363 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002364 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2366 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002367
2368 final long identity = Binder.clearCallingIdentity();
2369 try {
2370 final Phone phone = getPhone(subId);
2371 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2372 return phone.getCdmaMin();
2373 } else {
2374 return null;
2375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002378 }
2379 }
2380
Hall Liud892bec2018-11-30 14:51:45 -08002381 @Override
2382 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2383 INumberVerificationCallback callback, String callingPackage) {
2384 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2385 != PERMISSION_GRANTED) {
2386 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2387 }
2388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2389
2390 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2391 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2392 throw new SecurityException("Calling package must be configured in the device config");
2393 }
2394
2395 if (range == null) {
2396 throw new NullPointerException("Range must be non-null");
2397 }
2398
2399 timeoutMillis = Math.min(timeoutMillis,
2400 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2401
2402 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2403 }
2404
Junda Liuca05d5d2014-08-14 22:36:34 -07002405 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 * Returns true if CDMA provisioning needs to run.
2407 */
2408 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002411 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002412 } finally {
2413 Binder.restoreCallingIdentity(identity);
2414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 }
2416
2417 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002418 * Sets the voice mail number of a given subId.
2419 */
2420 @Override
2421 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002422 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002423
2424 final long identity = Binder.clearCallingIdentity();
2425 try {
2426 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2427 new Pair<String, String>(alphaTag, number), new Integer(subId));
2428 return success;
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
2431 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002432 }
2433
Ta-wei Yen87c49842016-05-13 21:19:52 -07002434 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002435 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2436 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002437 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002438 if (!TextUtils.equals(callingPackage, systemDialer)) {
2439 throw new SecurityException("caller must be system dialer");
2440 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002441
2442 final long identity = Binder.clearCallingIdentity();
2443 try {
2444 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2445 if (phoneAccountHandle == null) {
2446 return null;
2447 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002448 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002449 } finally {
2450 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002451 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002452 }
2453
2454 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002455 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002458 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002459 return null;
2460 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002461
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002462 final long identity = Binder.clearCallingIdentity();
2463 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002464 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002465 } finally {
2466 Binder.restoreCallingIdentity(identity);
2467 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002468 }
2469
2470 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002471 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2472 VisualVoicemailSmsFilterSettings settings) {
2473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002474
2475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002478 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002479 } finally {
2480 Binder.restoreCallingIdentity(identity);
2481 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002482 }
2483
2484 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002485 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2486 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002487
2488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002491 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002492 } finally {
2493 Binder.restoreCallingIdentity(identity);
2494 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002495 }
2496
2497 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002498 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2499 String callingPackage, int subId) {
2500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002501
2502 final long identity = Binder.clearCallingIdentity();
2503 try {
2504 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002505 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002506 } finally {
2507 Binder.restoreCallingIdentity(identity);
2508 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002509 }
2510
2511 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002512 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002513 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002514
2515 final long identity = Binder.clearCallingIdentity();
2516 try {
2517 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002518 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002519 } finally {
2520 Binder.restoreCallingIdentity(identity);
2521 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002522 }
2523
2524 @Override
2525 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2526 String number, int port, String text, PendingIntent sentIntent) {
2527 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002528 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002529 enforceSendSmsPermission();
2530 // Make the calls as the phone process.
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2534 if (port == 0) {
2535 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2536 sentIntent, null, false);
2537 } else {
2538 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2539 smsManager.sendDataMessageWithSelfPermissions(number, null,
2540 (short) port, data, sentIntent, null);
2541 }
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002545 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002546 /**
fionaxu0152e512016-11-14 13:36:14 -08002547 * Sets the voice activation state of a given subId.
2548 */
2549 @Override
2550 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2552 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002553
2554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 final Phone phone = getPhone(subId);
2557 if (phone != null) {
2558 phone.setVoiceActivationState(activationState);
2559 } else {
2560 loge("setVoiceActivationState fails with invalid subId: " + subId);
2561 }
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002564 }
2565 }
2566
2567 /**
2568 * Sets the data activation state of a given subId.
2569 */
2570 @Override
2571 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2573 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 if (phone != null) {
2579 phone.setDataActivationState(activationState);
2580 } else {
2581 loge("setVoiceActivationState fails with invalid subId: " + subId);
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002585 }
2586 }
2587
2588 /**
2589 * Returns the voice activation state of a given subId.
2590 */
2591 @Override
2592 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002593 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002594
fionaxu0152e512016-11-14 13:36:14 -08002595 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 if (phone != null) {
2599 return phone.getVoiceActivationState();
2600 } else {
2601 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2602 }
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002605 }
2606 }
2607
2608 /**
2609 * Returns the data activation state of a given subId.
2610 */
2611 @Override
2612 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002613 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002614
fionaxu0152e512016-11-14 13:36:14 -08002615 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 if (phone != null) {
2619 return phone.getDataActivationState();
2620 } else {
2621 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2622 }
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002625 }
2626 }
2627
2628 /**
Wink Saville36469e72014-06-11 15:17:00 -07002629 * Returns the unread count of voicemails for a subId
2630 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002631 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002632 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2634 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2635 return 0;
2636 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 if (phone != null) {
2641 return phone.getVoiceMessageCount();
2642 } else {
2643 return 0;
2644 }
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 }
2649
2650 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002651 * returns true, if the device is in a state where both voice and data
2652 * are supported simultaneously. This can change based on location or network condition.
2653 */
2654 @Override
2655 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 final Phone phone = getPhone(subId);
2659 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002663 }
2664
2665 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002666 * Send the dialer code if called from the current default dialer or the caller has
2667 * carrier privilege.
2668 * @param inputCode The dialer code to send
2669 */
2670 @Override
2671 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002672 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002674 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2675 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002676 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002677 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2678 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002679 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002680
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002683 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002684 } finally {
2685 Binder.restoreCallingIdentity(identity);
2686 }
fionaxu235cc5e2017-03-06 22:25:57 -08002687 }
2688
2689 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002690 * Returns the data network type.
2691 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 *
2693 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2694 */
2695 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002696 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 final Phone phone = getPhone(getDefaultSubscription());
2700 if (phone != null) {
2701 return phone.getServiceState().getDataNetworkType();
2702 } else {
2703 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002707 }
Wink Saville36469e72014-06-11 15:17:00 -07002708 }
2709
Pengquan Meng0c05b502018-09-06 09:59:22 -07002710 @Override
2711 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002712 if (!isActiveSubscription(subId)) {
2713 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2714 }
2715
Pengquan Meng0c05b502018-09-06 09:59:22 -07002716 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2717 }
2718
Brad Ebinger4c460712018-10-01 10:40:55 -07002719 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002720 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2721 throws RemoteException {
2722 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002723 final long token = Binder.clearCallingIdentity();
2724 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002725 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002726 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002727 .addRegistrationCallbackForSubscription(c, subId);
2728 } finally {
2729 Binder.restoreCallingIdentity(token);
2730 }
2731 }
2732
2733 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002734 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2735 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2737 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2738 }
2739 Binder.withCleanCallingIdentity(() -> {
2740 try {
2741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002742 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002743 .removeRegistrationCallbackForSubscription(c, subId);
2744 } catch (IllegalArgumentException e) {
2745 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2746 + "is inactive, ignoring unregister.");
2747 // If the subscription is no longer active, just return, since the callback
2748 // will already have been removed internally.
2749 }
2750 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002751 }
2752
2753 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002754 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2755 throws RemoteException {
2756 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2758 final long token = Binder.clearCallingIdentity();
2759 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002760 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002761 .addCapabilitiesCallbackForSubscription(c, subId);
2762 } finally {
2763 Binder.restoreCallingIdentity(token);
2764 }
2765 }
2766
2767 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002768 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2769 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002770
2771 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2772 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2773 }
2774 Binder.withCleanCallingIdentity(() -> {
2775 try {
2776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002777 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002778 .removeCapabilitiesCallbackForSubscription(c, subId);
2779 } catch (IllegalArgumentException e) {
2780 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2781 + "is inactive, ignoring unregister.");
2782 // If the subscription is no longer active, just return, since the callback
2783 // will already have been removed internally.
2784 }
2785 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002786 }
2787
2788 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002789 public boolean isCapable(int subId, int capability, int regTech) {
2790 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002791 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2792 final long token = Binder.clearCallingIdentity();
2793 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002794 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002795 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2796 } catch (ImsException e) {
2797 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2798 return false;
2799 } finally {
2800 Binder.restoreCallingIdentity(token);
2801 }
2802 }
2803
2804 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002805 public boolean isAvailable(int subId, int capability, int regTech) {
2806 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002807 final long token = Binder.clearCallingIdentity();
2808 try {
2809 Phone phone = getPhone(subId);
2810 if (phone == null) return false;
2811 return phone.isImsCapabilityAvailable(capability, regTech);
2812 } finally {
2813 Binder.restoreCallingIdentity(token);
2814 }
2815 }
2816
2817 @Override
2818 public boolean isAdvancedCallingSettingEnabled(int subId) {
2819 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2820 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2821 final long token = Binder.clearCallingIdentity();
2822 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002823 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002824 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2825 } finally {
2826 Binder.restoreCallingIdentity(token);
2827 }
2828 }
2829
2830 @Override
2831 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2833 "setAdvancedCallingSetting");
2834 final long identity = Binder.clearCallingIdentity();
2835 try {
2836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002837 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002838 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
2841 }
2842 }
2843
2844 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002845 public boolean isVtSettingEnabled(int subId) {
2846 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002850 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002851 getSlotIndexOrException(subId)).isVtEnabledByUser();
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
2854 }
2855 }
2856
2857 @Override
2858 public void setVtSetting(int subId, boolean isEnabled) {
2859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2860 "setVtSetting");
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002864 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
2868 }
2869
2870 @Override
2871 public boolean isVoWiFiSettingEnabled(int subId) {
2872 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2873 final long identity = Binder.clearCallingIdentity();
2874 try {
2875 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002876 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002877 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
2880 }
2881 }
2882
2883 @Override
2884 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2886 "setVoWiFiSetting");
2887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002890 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002891 } finally {
2892 Binder.restoreCallingIdentity(identity);
2893 }
2894 }
2895
2896 @Override
2897 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2898 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002902 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002903 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
2907 }
2908
2909 @Override
2910 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2912 "setVoWiFiRoamingSetting");
2913 final long identity = Binder.clearCallingIdentity();
2914 try {
2915 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002916 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002917 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
2920 }
2921 }
2922
2923 @Override
2924 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2926 "setVoWiFiNonPersistent");
2927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002930 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002931 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
2934 }
2935 }
2936
2937 @Override
2938 public int getVoWiFiModeSetting(int subId) {
2939 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002943 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002944 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
2947 }
2948 }
2949
2950 @Override
2951 public void setVoWiFiModeSetting(int subId, int mode) {
2952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2953 "setVoWiFiModeSetting");
2954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002957 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002958 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2959 } finally {
2960 Binder.restoreCallingIdentity(identity);
2961 }
2962 }
2963
2964 @Override
2965 public int getVoWiFiRoamingModeSetting(int subId) {
2966 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002970 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002971 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
2975 }
2976
2977 @Override
2978 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2980 "setVoWiFiRoamingModeSetting");
2981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002984 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002985 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
2989 }
2990
2991 @Override
2992 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2994 "setRttCapabilityEnabled");
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002998 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002999 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
3003 }
3004
3005 @Override
3006 public boolean isTtyOverVolteEnabled(int subId) {
3007 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003011 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003012 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
3015 }
3016 }
3017
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003018 @Override
3019 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3020 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003024 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003025 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003026 } finally {
3027 Binder.restoreCallingIdentity(identity);
3028 }
3029 }
3030
3031 @Override
3032 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3033 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3034 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003035 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3036 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3037 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003038 try {
3039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003040 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003041 .removeProvisioningCallbackForSubscription(callback, subId);
3042 } catch (IllegalArgumentException e) {
3043 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3044 + "is inactive, ignoring unregister.");
3045 // If the subscription is no longer active, just return, since the callback will already
3046 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
3050 }
3051
3052 @Override
3053 public int getImsProvisioningInt(int subId, int key) {
3054 enforceReadPrivilegedPermission("getImsProvisioningInt");
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003058 return ImsManager.getInstance(mApp,
3059 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003060 } catch (ImsException e) {
3061 throw new IllegalArgumentException(e.getMessage());
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
3065 }
3066
3067 @Override
3068 public String getImsProvisioningString(int subId, int key) {
3069 enforceReadPrivilegedPermission("getImsProvisioningString");
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003073 return ImsManager.getInstance(mApp,
3074 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003075 } catch (ImsException e) {
3076 throw new IllegalArgumentException(e.getMessage());
3077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
3080 }
3081
3082 @Override
3083 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3085 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003089 return ImsManager.getInstance(mApp,
3090 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003091 } catch (ImsException e) {
3092 throw new IllegalArgumentException(e.getMessage());
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
3096 }
3097
3098 @Override
3099 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3101 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003105 return ImsManager.getInstance(mApp,
3106 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003107 } catch (ImsException e) {
3108 throw new IllegalArgumentException(e.getMessage());
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
3112 }
3113
Brad Ebinger4c460712018-10-01 10:40:55 -07003114 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3115 int slotId = SubscriptionManager.getSlotIndex(subId);
3116 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3117 throw new IllegalArgumentException("Invalid Subscription Id.");
3118 }
3119 return slotId;
3120 }
3121
Wink Saville36469e72014-06-11 15:17:00 -07003122 /**
3123 * Returns the network type for a subId
3124 */
3125 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003126 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003128 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003129 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3130 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003131
Malcolm Chend965c8b2018-02-28 15:00:40 -08003132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 final Phone phone = getPhone(subId);
3135 if (phone != null) {
3136 return phone.getServiceState().getDataNetworkType();
3137 } else {
3138 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3139 }
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 }
3144
3145 /**
3146 * Returns the data network type
3147 */
3148 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003149 public int getDataNetworkType(String callingPackage) {
3150 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003151 }
3152
3153 /**
3154 * Returns the data network type for a subId
3155 */
3156 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003157 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003159 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003160 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3161 }
3162
Malcolm Chend965c8b2018-02-28 15:00:40 -08003163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 final Phone phone = getPhone(subId);
3166 if (phone != null) {
3167 return phone.getServiceState().getDataNetworkType();
3168 } else {
3169 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3170 }
3171 } finally {
3172 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003174 }
3175
3176 /**
Wink Saville36469e72014-06-11 15:17:00 -07003177 * Returns the Voice network type for a subId
3178 */
3179 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003180 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003182 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003183 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3184 }
3185
Malcolm Chend965c8b2018-02-28 15:00:40 -08003186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 final Phone phone = getPhone(subId);
3189 if (phone != null) {
3190 return phone.getServiceState().getVoiceNetworkType();
3191 } else {
3192 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
3199 /**
3200 * @return true if a ICC card is present
3201 */
3202 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003203 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003204 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3205 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003206 }
3207
3208 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003209 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003210 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003211 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003212 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003213 final long identity = Binder.clearCallingIdentity();
3214 try {
3215 final Phone phone = PhoneFactory.getPhone(slotIndex);
3216 if (phone != null) {
3217 return phone.getIccCard().hasIccCard();
3218 } else {
3219 return false;
3220 }
3221 } finally {
3222 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 }
3225
3226 /**
3227 * Return if the current radio is LTE on CDMA. This
3228 * is a tri-state return value as for a period of time
3229 * the mode may be unknown.
3230 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003231 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003233 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003234 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003235 @Override
3236 public int getLteOnCdmaMode(String callingPackage) {
3237 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003238 }
3239
Sanket Padawe356d7632015-06-22 14:03:32 -07003240 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003241 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003243 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003244 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3245 }
3246
Malcolm Chend965c8b2018-02-28 15:00:40 -08003247 final long identity = Binder.clearCallingIdentity();
3248 try {
3249 final Phone phone = getPhone(subId);
3250 if (phone == null) {
3251 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3252 } else {
3253 return phone.getLteOnCdmaMode();
3254 }
3255 } finally {
3256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003257 }
Wink Saville36469e72014-06-11 15:17:00 -07003258 }
3259
Wink Saville36469e72014-06-11 15:17:00 -07003260 /**
3261 * {@hide}
3262 * Returns Default subId, 0 in the case of single standby.
3263 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003264 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003265 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003266 }
3267
Shishir Agrawala9f32182016-04-12 12:00:16 -07003268 private int getSlotForDefaultSubscription() {
3269 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3270 }
3271
Wink Savilleb564aae2014-10-23 10:18:09 -07003272 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003273 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003275
Pengquan Meng466e2482018-09-21 15:54:48 -07003276 private boolean isActiveSubscription(int subId) {
3277 return mSubscriptionController.isActiveSubId(subId);
3278 }
3279
Ihab Awadf2177b72013-11-25 13:33:23 -08003280 /**
3281 * @see android.telephony.TelephonyManager.WifiCallingChoices
3282 */
3283 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003284 final long identity = Binder.clearCallingIdentity();
3285 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003286 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003287 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3288 getWhenToMakeWifiCallsDefaultPreference());
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
3291 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003292 }
3293
3294 /**
3295 * @see android.telephony.TelephonyManager.WifiCallingChoices
3296 */
3297 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003301 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003302 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003306 }
3307
Sailesh Nepald1e68152013-12-12 19:08:02 -08003308 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003309 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003310 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003311 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003312
Shishir Agrawal566b7612013-10-28 14:41:00 -07003313 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003314 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3315 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3317 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003318 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003319
Malcolm Chend965c8b2018-02-28 15:00:40 -08003320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 if (TextUtils.equals(ISDR_AID, aid)) {
3323 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003324 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3325 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003326 if (bestComponent == null
3327 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3328 loge("The calling package is not allowed to access ISD-R.");
3329 throw new SecurityException(
3330 "The calling package is not allowed to access ISD-R.");
3331 }
Derek Tan740e1672017-06-27 14:56:27 -07003332 }
Derek Tan740e1672017-06-27 14:56:27 -07003333
Malcolm Chend965c8b2018-02-28 15:00:40 -08003334 if (DBG) {
3335 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3336 }
3337 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3338 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3339 if (DBG) log("iccOpenLogicalChannel: " + response);
3340 return response;
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003344 }
3345
3346 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003347 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3349 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003350
Malcolm Chend965c8b2018-02-28 15:00:40 -08003351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3354 if (channel < 0) {
3355 return false;
3356 }
3357 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3358 if (DBG) log("iccCloseLogicalChannel: " + success);
3359 return success;
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003362 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003363 }
3364
3365 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003366 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003367 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3369 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003370
Malcolm Chend965c8b2018-02-28 15:00:40 -08003371 final long identity = Binder.clearCallingIdentity();
3372 try {
3373 if (DBG) {
3374 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3375 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3376 + p3 + " data=" + data);
3377 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003378
Malcolm Chend965c8b2018-02-28 15:00:40 -08003379 if (channel < 0) {
3380 return "";
3381 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003382
Malcolm Chend965c8b2018-02-28 15:00:40 -08003383 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3384 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3385 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003386
Malcolm Chend965c8b2018-02-28 15:00:40 -08003387 // Append the returned status code to the end of the response payload.
3388 String s = Integer.toHexString(
3389 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3390 if (response.payload != null) {
3391 s = IccUtils.bytesToHexString(response.payload) + s;
3392 }
3393 return s;
3394 } finally {
3395 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003396 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003397 }
Jake Hambye994d462014-02-03 13:10:13 -08003398
Evan Charltonc66da362014-05-16 14:06:40 -07003399 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003400 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3401 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3403 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003404 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003405
Malcolm Chend965c8b2018-02-28 15:00:40 -08003406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3409 && TextUtils.equals(ISDR_AID, data)) {
3410 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003411 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3412 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003413 if (bestComponent == null
3414 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3415 loge("The calling package is not allowed to select ISD-R.");
3416 throw new SecurityException(
3417 "The calling package is not allowed to select ISD-R.");
3418 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003419 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003420
Malcolm Chend965c8b2018-02-28 15:00:40 -08003421 if (DBG) {
3422 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3423 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3424 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003425
Malcolm Chend965c8b2018-02-28 15:00:40 -08003426 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3427 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3428 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003429
Malcolm Chend965c8b2018-02-28 15:00:40 -08003430 // Append the returned status code to the end of the response payload.
3431 String s = Integer.toHexString(
3432 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3433 if (response.payload != null) {
3434 s = IccUtils.bytesToHexString(response.payload) + s;
3435 }
3436 return s;
3437 } finally {
3438 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003439 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003440 }
3441
3442 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003443 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003444 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3446 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003447
Malcolm Chend965c8b2018-02-28 15:00:40 -08003448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 if (DBG) {
3451 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3452 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3453 }
3454
3455 IccIoResult response =
3456 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3457 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3458 subId);
3459
3460 if (DBG) {
3461 log("Exchange SIM_IO [R]" + response);
3462 }
3463
3464 byte[] result = null;
3465 int length = 2;
3466 if (response.payload != null) {
3467 length = 2 + response.payload.length;
3468 result = new byte[length];
3469 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3470 } else {
3471 result = new byte[length];
3472 }
3473
3474 result[length - 1] = (byte) response.sw2;
3475 result[length - 2] = (byte) response.sw1;
3476 return result;
3477 } finally {
3478 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003479 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003480 }
3481
Nathan Haroldb3014052017-01-25 15:57:32 -08003482 /**
3483 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3484 * on a particular subscription
3485 */
sqianb6e41952018-03-12 14:54:01 -07003486 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3488 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3489 return null;
3490 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003491
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 if (appType != TelephonyManager.APPTYPE_USIM
3495 && appType != TelephonyManager.APPTYPE_SIM) {
3496 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3497 return null;
3498 }
3499 Object response = sendRequest(
3500 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3501 if (response instanceof String[]) {
3502 return (String[]) response;
3503 }
3504 // Response is an Exception of some kind,
3505 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003506 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003507 } finally {
3508 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003509 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003510 }
3511
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003512 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003513 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3515 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003516
Malcolm Chend965c8b2018-02-28 15:00:40 -08003517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3520 if (response.payload == null) {
3521 return "";
3522 }
Evan Charltonc66da362014-05-16 14:06:40 -07003523
Malcolm Chend965c8b2018-02-28 15:00:40 -08003524 // Append the returned status code to the end of the response payload.
3525 String s = Integer.toHexString(
3526 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3527 s = IccUtils.bytesToHexString(response.payload) + s;
3528 return s;
3529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
Evan Charltonc66da362014-05-16 14:06:40 -07003532 }
3533
Jake Hambye994d462014-02-03 13:10:13 -08003534 /**
3535 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3536 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3537 *
3538 * @param itemID the ID of the item to read
3539 * @return the NV item as a String, or null on error.
3540 */
3541 @Override
3542 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003543 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3545 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003546
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003550 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003551 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3552 return value;
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
Jake Hambye994d462014-02-03 13:10:13 -08003556 }
3557
3558 /**
3559 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3560 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3561 *
3562 * @param itemID the ID of the item to read
3563 * @param itemValue the value to write, as a String
3564 * @return true on success; false on any failure
3565 */
3566 @Override
3567 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003568 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3570 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003571
3572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3575 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003576 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003577 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3578 return success;
3579 } finally {
3580 Binder.restoreCallingIdentity(identity);
3581 }
Jake Hambye994d462014-02-03 13:10:13 -08003582 }
3583
3584 /**
3585 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3586 * Used for device configuration by some CDMA operators.
3587 *
3588 * @param preferredRoamingList byte array containing the new PRL
3589 * @return true on success; false on any failure
3590 */
3591 @Override
3592 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3594 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3599 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3600 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3601 return success;
3602 } finally {
3603 Binder.restoreCallingIdentity(identity);
3604 }
Jake Hambye994d462014-02-03 13:10:13 -08003605 }
3606
3607 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003608 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003609 * Used for device configuration by some CDMA operators.
3610 *
chen xu1cc0abe2018-10-26 17:39:23 -07003611 * @param slotIndex - device slot.
3612 *
Jake Hambye994d462014-02-03 13:10:13 -08003613 * @return true on success; false on any failure
3614 */
3615 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003616 public boolean resetModemConfig(int slotIndex) {
3617 Phone phone = PhoneFactory.getPhone(slotIndex);
3618 if (phone != null) {
3619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3620 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003621
chen xu1cc0abe2018-10-26 17:39:23 -07003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3625 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3626 return success;
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003630 }
chen xu1cc0abe2018-10-26 17:39:23 -07003631 return false;
3632 }
3633
3634 /**
3635 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3636 *
3637 * @param slotIndex - device slot.
3638 *
3639 * @return true on success; false on any failure
3640 */
3641 @Override
3642 public boolean rebootModem(int slotIndex) {
3643 Phone phone = PhoneFactory.getPhone(slotIndex);
3644 if (phone != null) {
3645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3646 mApp, phone.getSubId(), "rebootModem");
3647
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3651 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3652 return success;
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
3656 }
3657 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003658 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003659
Svet Ganovb320e182015-04-16 12:30:10 -07003660 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003661 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003663 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003664 return new String[0];
3665 }
3666
Malcolm Chend965c8b2018-02-28 15:00:40 -08003667 final long identity = Binder.clearCallingIdentity();
3668 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003669 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003670 } finally {
3671 Binder.restoreCallingIdentity(identity);
3672 }
Wink Saville36469e72014-06-11 15:17:00 -07003673 }
3674
Brad Ebinger51f743a2017-01-23 13:50:20 -08003675 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003676 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3677 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003678 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003679 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003680 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003681
3682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 PhoneFactory.getImsResolver().enableIms(slotId);
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003688 }
3689
3690 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003691 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3692 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003693 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003694 public void disableIms(int slotId) {
3695 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003696
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 PhoneFactory.getImsResolver().disableIms(slotId);
3700 } finally {
3701 Binder.restoreCallingIdentity(identity);
3702 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003703 }
3704
3705 /**
3706 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3707 * feature or {@link null} if the service is not available. If the feature is available, the
3708 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3709 */
3710 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003711 IImsServiceFeatureCallback callback) {
3712 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003713
3714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3717 } finally {
3718 Binder.restoreCallingIdentity(identity);
3719 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003720 }
3721
3722 /**
3723 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3724 * feature during emergency calling or {@link null} if the service is not available. If the
3725 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3726 * listener for feature updates.
3727 */
3728 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3729 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003730
3731 final long identity = Binder.clearCallingIdentity();
3732 try {
3733 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003737 }
3738
Brad Ebinger5f64b052017-12-14 14:26:15 -08003739 /**
3740 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3741 * specified.
3742 */
3743 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3744 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003745
3746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3749 } finally {
3750 Binder.restoreCallingIdentity(identity);
3751 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003752 }
3753
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003754 /**
3755 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3756 * specified.
3757 */
3758 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3759 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003760
3761 final long identity = Binder.clearCallingIdentity();
3762 try {
3763 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003767 }
3768
Brad Ebinger884c07b2018-02-15 16:17:40 -08003769 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003770 * Sets the ImsService Package Name that Telephony will bind to.
3771 *
3772 * @param slotId the slot ID that the ImsService should bind for.
3773 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3774 * ImsService is the device default ImsService.
3775 * @param packageName The package name of the application that contains the ImsService to bind
3776 * to.
3777 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3778 * @hide
3779 */
3780 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003781 int[] subIds = SubscriptionManager.getSubId(slotId);
3782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3783 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3784 "setImsService");
3785
Malcolm Chend965c8b2018-02-28 15:00:40 -08003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3789 isCarrierImsService, packageName);
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
3792 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003793 }
3794
3795 /**
3796 * Return the ImsService configuration.
3797 *
3798 * @param slotId The slot that the ImsService is associated with.
3799 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3800 * the device default.
3801 * @return the package name of the ImsService configuration.
3802 */
3803 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003804 int[] subIds = SubscriptionManager.getSubId(slotId);
3805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3806 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3807 "getImsService");
3808
Malcolm Chend965c8b2018-02-28 15:00:40 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3812 isCarrierImsService);
3813 } finally {
3814 Binder.restoreCallingIdentity(identity);
3815 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003816 }
3817
Wink Saville36469e72014-06-11 15:17:00 -07003818 public void setImsRegistrationState(boolean registered) {
3819 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003820
3821 final long identity = Binder.clearCallingIdentity();
3822 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003823 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003824 } finally {
3825 Binder.restoreCallingIdentity(identity);
3826 }
Wink Saville36469e72014-06-11 15:17:00 -07003827 }
3828
3829 /**
Stuart Scott54788802015-03-30 13:18:01 -07003830 * Set the network selection mode to automatic.
3831 *
3832 */
3833 @Override
3834 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3836 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003837
Pengquan Meng466e2482018-09-21 15:54:48 -07003838 if (!isActiveSubscription(subId)) {
3839 return;
3840 }
3841
Malcolm Chend965c8b2018-02-28 15:00:40 -08003842 final long identity = Binder.clearCallingIdentity();
3843 try {
3844 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3845 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3846 } finally {
3847 Binder.restoreCallingIdentity(identity);
3848 }
Stuart Scott54788802015-03-30 13:18:01 -07003849 }
3850
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003851 /**
3852 * Ask the radio to connect to the input network and change selection mode to manual.
3853 *
3854 * @param subId the id of the subscription.
3855 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3856 * the operator to attach to.
3857 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3858 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3859 * normal network selection next time.
3860 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003861 */
3862 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003863 public boolean setNetworkSelectionModeManual(
3864 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3866 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003867
3868 if (!isActiveSubscription(subId)) {
3869 return false;
3870 }
3871
Malcolm Chend965c8b2018-02-28 15:00:40 -08003872 final long identity = Binder.clearCallingIdentity();
3873 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003874 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003875 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003876 if (DBG) {
3877 log("setNetworkSelectionModeManual: subId: " + subId
3878 + " operator: " + operatorInfo);
3879 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003880 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3881 } finally {
3882 Binder.restoreCallingIdentity(identity);
3883 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003884 }
3885
3886 /**
3887 * Scans for available networks.
3888 */
3889 @Override
3890 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3892 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003893
Pengquan Meng0c05b502018-09-06 09:59:22 -07003894 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003895 try {
3896 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003897 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003898 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003899 } finally {
3900 Binder.restoreCallingIdentity(identity);
3901 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003902 }
3903
3904 /**
yinxub1bed742017-04-17 11:45:04 -07003905 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003906 *
yinxub1bed742017-04-17 11:45:04 -07003907 * @param subId id of the subscription
3908 * @param request contains the radio access networks with bands/channels to scan
3909 * @param messenger callback messenger for scan results or errors
3910 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003911 * @return the id of the requested scan which can be used to stop the scan.
3912 */
3913 @Override
3914 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3915 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3917 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003918
3919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 return mNetworkScanRequestTracker.startNetworkScan(
3922 request, messenger, binder, getPhone(subId));
3923 } finally {
3924 Binder.restoreCallingIdentity(identity);
3925 }
yinxu504e1392017-04-12 16:03:22 -07003926 }
3927
3928 /**
3929 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003930 *
3931 * @param subId id of the subscription
3932 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003933 */
3934 @Override
3935 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3937 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003938
3939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3942 } finally {
3943 Binder.restoreCallingIdentity(identity);
3944 }
yinxu504e1392017-04-12 16:03:22 -07003945 }
3946
3947 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003948 * Get the calculated preferred network type.
3949 * Used for debugging incorrect network type.
3950 *
3951 * @return the preferred network type, defined in RILConstants.java.
3952 */
3953 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003954 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003955 final Phone defaultPhone = getDefaultPhone();
3956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3957 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003958 return RILConstants.PREFERRED_NETWORK_MODE;
3959 }
3960
Malcolm Chend965c8b2018-02-28 15:00:40 -08003961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003964 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003965 } finally {
3966 Binder.restoreCallingIdentity(identity);
3967 }
Junda Liu84d15a22014-07-02 11:21:04 -07003968 }
3969
3970 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003971 * Get the preferred network type.
3972 * Used for device configuration by some CDMA operators.
3973 *
3974 * @return the preferred network type, defined in RILConstants.java.
3975 */
3976 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003977 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3979 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003980
3981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 if (DBG) log("getPreferredNetworkType");
3984 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3985 int networkType = (result != null ? result[0] : -1);
3986 if (DBG) log("getPreferredNetworkType: " + networkType);
3987 return networkType;
3988 } finally {
3989 Binder.restoreCallingIdentity(identity);
3990 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003991 }
3992
3993 /**
3994 * Set the preferred network type.
3995 * Used for device configuration by some CDMA operators.
3996 *
3997 * @param networkType the preferred network type, defined in RILConstants.java.
3998 * @return true on success; false on any failure.
3999 */
4000 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004001 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4003 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004004
4005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4008 Boolean success = (Boolean) sendRequest(
4009 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4010 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4011 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004012 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004013 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4014 }
4015 return success;
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004018 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004019 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004020
4021 /**
Junda Liu475951f2014-11-07 16:45:03 -08004022 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004023 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004024 * tethering.
4025 *
4026 * @return 0: Not required. 1: required. 2: Not set.
4027 * @hide
4028 */
4029 @Override
4030 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004031 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004032
4033 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004034 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004035 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004036 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004037 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004038 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004039 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004040 dunRequired = 1;
4041 }
4042 return dunRequired;
4043 } finally {
4044 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004045 }
Junda Liu475951f2014-11-07 16:45:03 -08004046 }
4047
4048 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004049 * Set mobile data enabled
4050 * Used by the user through settings etc to turn on/off mobile data
4051 *
4052 * @param enable {@code true} turn turn data on, else {@code false}
4053 */
4054 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004055 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4057 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004058
4059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 int phoneId = mSubscriptionController.getPhoneId(subId);
4062 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4063 Phone phone = PhoneFactory.getPhone(phoneId);
4064 if (phone != null) {
4065 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004066 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004067 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004068 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004069 }
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004072 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004073 }
4074
4075 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004076 * Get the user enabled state of Mobile Data.
4077 *
4078 * TODO: remove and use isUserDataEnabled.
4079 * This can't be removed now because some vendor codes
4080 * calls through ITelephony directly while they should
4081 * use TelephonyManager.
4082 *
4083 * @return true on enabled
4084 */
4085 @Override
4086 public boolean getDataEnabled(int subId) {
4087 return isUserDataEnabled(subId);
4088 }
4089
4090 /**
4091 * Get whether mobile data is enabled per user setting.
4092 *
4093 * There are other factors deciding whether mobile data is actually enabled, but they are
4094 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004095 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004096 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004097 *
4098 * @return {@code true} if data is enabled else {@code false}
4099 */
4100 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004101 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004102 try {
4103 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4104 null);
4105 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4107 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004108 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004109
4110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 int phoneId = mSubscriptionController.getPhoneId(subId);
4113 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4114 Phone phone = PhoneFactory.getPhone(phoneId);
4115 if (phone != null) {
4116 boolean retVal = phone.isUserDataEnabled();
4117 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4118 return retVal;
4119 } else {
4120 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4121 return false;
4122 }
4123 } finally {
4124 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004125 }
4126 }
4127
4128 /**
4129 * Get whether mobile data is enabled.
4130 *
4131 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4132 * whether mobile data is actually enabled.
4133 *
4134 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4135 *
4136 * @return {@code true} if data is enabled else {@code false}
4137 */
4138 @Override
4139 public boolean isDataEnabled(int subId) {
4140 try {
4141 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4142 null);
4143 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4145 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004146 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004147
4148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 int phoneId = mSubscriptionController.getPhoneId(subId);
4151 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4152 Phone phone = PhoneFactory.getPhone(phoneId);
4153 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004154 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004155 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4156 return retVal;
4157 } else {
4158 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4159 return false;
4160 }
4161 } finally {
4162 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004163 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004164 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004165
4166 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004167 public int getCarrierPrivilegeStatus(int subId) {
4168 final Phone phone = getPhone(subId);
4169 if (phone == null) {
4170 loge("getCarrierPrivilegeStatus: Invalid subId");
4171 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4172 }
4173 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004174 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004175 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004176 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4177 }
4178 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004179 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004180 }
Junda Liu29340342014-07-10 15:23:27 -07004181
4182 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004183 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4184 final Phone phone = getPhone(subId);
4185 if (phone == null) {
4186 loge("getCarrierPrivilegeStatus: Invalid subId");
4187 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4188 }
4189 UiccProfile profile =
4190 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4191 if (profile == null) {
4192 loge("getCarrierPrivilegeStatus: No UICC");
4193 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4194 }
4195 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4196 }
4197
4198 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004199 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004200 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004201 if (TextUtils.isEmpty(pkgName))
4202 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004203 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004204 if (card == null) {
4205 loge("checkCarrierPrivilegesForPackage: No UICC");
4206 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4207 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004208 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4209 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004210 }
4211
4212 @Override
4213 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004214 if (TextUtils.isEmpty(pkgName))
4215 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004216 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4217 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4218 UiccCard card = UiccController.getInstance().getUiccCard(i);
4219 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004220 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004221 continue;
4222 }
4223
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004224 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004225 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4226 break;
4227 }
4228 }
4229
4230 return result;
Junda Liu29340342014-07-10 15:23:27 -07004231 }
Derek Tan89e89d42014-07-08 17:00:10 -07004232
4233 @Override
Junda Liue64de782015-04-16 17:19:16 -07004234 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4235 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4236 loge("phoneId " + phoneId + " is not valid.");
4237 return null;
4238 }
4239 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004240 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004241 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004242 return null ;
4243 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004244 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004245 }
4246
Amith Yamasani6e118872016-02-19 12:53:51 -08004247 @Override
4248 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004249 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004250 List<String> privilegedPackages = new ArrayList<>();
4251 List<PackageInfo> packages = null;
4252 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4253 UiccCard card = UiccController.getInstance().getUiccCard(i);
4254 if (card == null) {
4255 // No UICC in that slot.
4256 continue;
4257 }
4258 if (card.hasCarrierPrivilegeRules()) {
4259 if (packages == null) {
4260 // Only check packages in user 0 for now
4261 packages = pm.getInstalledPackagesAsUser(
4262 PackageManager.MATCH_DISABLED_COMPONENTS
4263 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4264 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4265 }
4266 for (int p = packages.size() - 1; p >= 0; p--) {
4267 PackageInfo pkgInfo = packages.get(p);
4268 if (pkgInfo != null && pkgInfo.packageName != null
4269 && card.getCarrierPrivilegeStatus(pkgInfo)
4270 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4271 privilegedPackages.add(pkgInfo.packageName);
4272 }
4273 }
4274 }
4275 }
4276 return privilegedPackages;
4277 }
4278
Wink Savilleb564aae2014-10-23 10:18:09 -07004279 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004280 final Phone phone = getPhone(subId);
4281 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004282 if (card == null) {
4283 loge("getIccId: No UICC");
4284 return null;
4285 }
4286 String iccId = card.getIccId();
4287 if (TextUtils.isEmpty(iccId)) {
4288 loge("getIccId: ICC ID is null or empty.");
4289 return null;
4290 }
4291 return iccId;
4292 }
4293
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004294 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004295 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4296 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004297 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4298 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004299
Malcolm Chend965c8b2018-02-28 15:00:40 -08004300 final long identity = Binder.clearCallingIdentity();
4301 try {
4302 final String iccId = getIccId(subId);
4303 final Phone phone = getPhone(subId);
4304 if (phone == null) {
4305 return false;
4306 }
4307 final String subscriberId = phone.getSubscriberId();
4308
4309 if (DBG_MERGE) {
4310 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4311 + subscriberId + " to " + number);
4312 }
4313
4314 if (TextUtils.isEmpty(iccId)) {
4315 return false;
4316 }
4317
4318 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4319
4320 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4321 if (alphaTag == null) {
4322 editor.remove(alphaTagPrefKey);
4323 } else {
4324 editor.putString(alphaTagPrefKey, alphaTag);
4325 }
4326
4327 // Record both the line number and IMSI for this ICCID, since we need to
4328 // track all merged IMSIs based on line number
4329 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4330 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4331 if (number == null) {
4332 editor.remove(numberPrefKey);
4333 editor.remove(subscriberPrefKey);
4334 } else {
4335 editor.putString(numberPrefKey, number);
4336 editor.putString(subscriberPrefKey, subscriberId);
4337 }
4338
4339 editor.commit();
4340 return true;
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004343 }
Derek Tan7226c842014-07-02 17:42:23 -07004344 }
4345
4346 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004347 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004348 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004349 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004350 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004351 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004352 return null;
4353 }
Derek Tan97ebb422014-09-05 16:55:38 -07004354
Malcolm Chend965c8b2018-02-28 15:00:40 -08004355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 String iccId = getIccId(subId);
4358 if (iccId != null) {
4359 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4360 if (DBG_MERGE) {
4361 log("getLine1NumberForDisplay returning "
4362 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4363 }
4364 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004365 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004366 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4367 return null;
4368 } finally {
4369 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004370 }
Derek Tan7226c842014-07-02 17:42:23 -07004371 }
4372
4373 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004374 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004376 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004377 return null;
4378 }
Derek Tan97ebb422014-09-05 16:55:38 -07004379
Malcolm Chend965c8b2018-02-28 15:00:40 -08004380 final long identity = Binder.clearCallingIdentity();
4381 try {
4382 String iccId = getIccId(subId);
4383 if (iccId != null) {
4384 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4385 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4386 }
4387 return null;
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004390 }
Derek Tan7226c842014-07-02 17:42:23 -07004391 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004392
4393 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004394 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004395 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4396 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004398 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4399 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004400 return null;
4401 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004402
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004403 final long identity = Binder.clearCallingIdentity();
4404 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004405 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004406 final TelephonyManager tele = TelephonyManager.from(context);
4407 final SubscriptionManager sub = SubscriptionManager.from(context);
4408
4409 // Figure out what subscribers are currently active
4410 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4411 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4412 // the process, where TelephonyManager was instantiated.
4413 // Otherwise AppOps check will fail.
4414
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004415 final int[] subIds = sub.getActiveSubscriptionIdList();
4416 for (int subId : subIds) {
4417 activeSubscriberIds.add(tele.getSubscriberId(subId));
4418 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004419
4420 // First pass, find a number override for an active subscriber
4421 String mergeNumber = null;
4422 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4423 for (String key : prefs.keySet()) {
4424 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4425 final String subscriberId = (String) prefs.get(key);
4426 if (activeSubscriberIds.contains(subscriberId)) {
4427 final String iccId = key.substring(
4428 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4429 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4430 mergeNumber = (String) prefs.get(numberKey);
4431 if (DBG_MERGE) {
4432 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4433 + " for active subscriber " + subscriberId);
4434 }
4435 if (!TextUtils.isEmpty(mergeNumber)) {
4436 break;
4437 }
4438 }
4439 }
4440 }
4441
4442 // Shortcut when no active merged subscribers
4443 if (TextUtils.isEmpty(mergeNumber)) {
4444 return null;
4445 }
4446
4447 // Second pass, find all subscribers under that line override
4448 final ArraySet<String> result = new ArraySet<>();
4449 for (String key : prefs.keySet()) {
4450 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4451 final String number = (String) prefs.get(key);
4452 if (mergeNumber.equals(number)) {
4453 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4454 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4455 final String subscriberId = (String) prefs.get(subscriberKey);
4456 if (!TextUtils.isEmpty(subscriberId)) {
4457 result.add(subscriberId);
4458 }
4459 }
4460 }
4461 }
4462
4463 final String[] resultArray = result.toArray(new String[result.size()]);
4464 Arrays.sort(resultArray);
4465 if (DBG_MERGE) {
4466 Slog.d(LOG_TAG,
4467 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4468 }
4469 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004470 } finally {
4471 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004472 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004473 }
4474
4475 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004476 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004477 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4478 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004479
4480 final long identity = Binder.clearCallingIdentity();
4481 try {
4482 final Phone phone = getPhone(subId);
4483 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004487 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004488
4489 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004490 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004491 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4492 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004493 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004494
4495 final long identity = Binder.clearCallingIdentity();
4496 try {
4497 final Phone phone = getPhone(subId);
4498 if (phone == null) {
4499 return false;
4500 }
4501 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4502 cdmaNonRoamingList);
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004505 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004506 }
4507
4508 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004509 @Deprecated
4510 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4511 enforceModifyPermission();
4512
4513 int returnValue = 0;
4514 try {
vagdevie435a3e2018-08-15 16:01:53 -07004515 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004516 if(result.exception == null) {
4517 if (result.result != null) {
4518 byte[] responseData = (byte[])(result.result);
4519 if(responseData.length > oemResp.length) {
4520 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4521 responseData.length + "bytes. Buffer Size is " +
4522 oemResp.length + "bytes.");
4523 }
4524 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4525 returnValue = responseData.length;
4526 }
4527 } else {
4528 CommandException ex = (CommandException) result.exception;
4529 returnValue = ex.getCommandError().ordinal();
4530 if(returnValue > 0) returnValue *= -1;
4531 }
4532 } catch (RuntimeException e) {
4533 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4534 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4535 if(returnValue > 0) returnValue *= -1;
4536 }
4537
4538 return returnValue;
4539 }
4540
4541 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004542 public void setRadioCapability(RadioAccessFamily[] rafs) {
4543 try {
4544 ProxyController.getInstance().setRadioCapability(rafs);
4545 } catch (RuntimeException e) {
4546 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4547 }
4548 }
4549
4550 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004551 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004552 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004553 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004554 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004555 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004556 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004557 final long identity = Binder.clearCallingIdentity();
4558 try {
chen xufeeed752018-10-26 14:17:57 -07004559 TelephonyPermissions
4560 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4561 mApp, phone.getSubId(), "getRadioAccessFamily");
4562 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004563 } finally {
4564 Binder.restoreCallingIdentity(identity);
4565 }
chen xufeeed752018-10-26 14:17:57 -07004566 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004567 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004568
4569 @Override
4570 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004571 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004572 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004573
4574 final long identity = Binder.clearCallingIdentity();
4575 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004576 ImsManager.getInstance(defaultPhone.getContext(),
4577 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004581 }
4582
4583 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004584 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004585 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004587 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004588 return false;
4589 }
Svet Ganovb320e182015-04-16 12:30:10 -07004590
Malcolm Chend965c8b2018-02-28 15:00:40 -08004591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 // Check the user preference and the system-level IMS setting. Even if the user has
4594 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4595 // In the long run, we may instead need to check if there exists a connection service
4596 // which can support video calling.
4597 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004598 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004599 return imsManager.isVtEnabledByPlatform()
4600 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4601 && imsManager.isVtEnabledByUser();
4602 } finally {
4603 Binder.restoreCallingIdentity(identity);
4604 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004605 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004606
Andrew Leea1239f22015-03-02 17:44:07 -08004607 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004608 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4610 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4611 return false;
4612 }
4613
4614 final long identity = Binder.clearCallingIdentity();
4615 try {
4616 CarrierConfigManager configManager =
4617 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004618 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004619 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
Andrew Leea1239f22015-03-02 17:44:07 -08004623 }
4624
4625 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004626 public boolean isWorldPhone(int subId, String callingPackage) {
4627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4628 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4629 return false;
4630 }
4631
4632 final long identity = Binder.clearCallingIdentity();
4633 try {
4634 CarrierConfigManager configManager =
4635 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004636 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004637 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
Andrew Leea1239f22015-03-02 17:44:07 -08004641 }
4642
Andrew Lee9431b832015-03-09 18:46:45 -07004643 @Override
4644 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004645 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004646 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004647 }
4648
4649 @Override
4650 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004651 final long identity = Binder.clearCallingIdentity();
4652 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004653 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004654 } finally {
4655 Binder.restoreCallingIdentity(identity);
4656 }
Andrew Lee9431b832015-03-09 18:46:45 -07004657 }
4658
Hall Liuf6668912018-10-31 17:05:23 -07004659 /**
4660 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4661 * support for the feature and device firmware support.
4662 *
4663 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4664 */
4665 @Override
4666 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004667 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004668 final Phone phone = getPhone(subscriptionId);
4669 if (phone == null) {
4670 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4671 return false;
4672 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004673 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004674 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004675 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4676 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004677 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004678 return isCarrierSupported && isDeviceSupported;
4679 } finally {
4680 Binder.restoreCallingIdentity(identity);
4681 }
Hall Liu98187582018-01-22 19:15:32 -08004682 }
4683
Hall Liuf6668912018-10-31 17:05:23 -07004684 /**
4685 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4686 * both also support RTT.
4687 */
4688 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004689 final long identity = Binder.clearCallingIdentity();
4690 try {
Hall Liuf6668912018-10-31 17:05:23 -07004691 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004692 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004696 }
4697
Sanket Padawe7310cc72015-01-14 09:53:20 -08004698 /**
4699 * Returns the unique device ID of phone, for example, the IMEI for
4700 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4701 *
4702 * <p>Requires Permission:
4703 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4704 */
4705 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004706 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004707 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004708 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004709 return null;
4710 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004711 int subId = phone.getSubId();
4712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4713 mApp, subId, callingPackage, "getDeviceId")) {
4714 return null;
4715 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004716
4717 final long identity = Binder.clearCallingIdentity();
4718 try {
4719 return phone.getDeviceId();
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004723 }
4724
Ping Sunc67b7c22016-03-02 19:16:45 +08004725 /**
4726 * {@hide}
4727 * Returns the IMS Registration Status on a particular subid
4728 *
4729 * @param subId
4730 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004731 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004732 Phone phone = getPhone(subId);
4733 if (phone != null) {
4734 return phone.isImsRegistered();
4735 } else {
4736 return false;
4737 }
4738 }
4739
Santos Cordon7a1885b2015-02-03 11:15:19 -08004740 @Override
4741 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004742 final long identity = Binder.clearCallingIdentity();
4743 try {
4744 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004748 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004749
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004750 /**
4751 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004752 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004753 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004754 final long identity = Binder.clearCallingIdentity();
4755 try {
4756 Phone phone = getPhone(subId);
4757 if (phone != null) {
4758 return phone.isWifiCallingEnabled();
4759 } else {
4760 return false;
4761 }
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004764 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004765 }
4766
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004767 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004768 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004769 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004770 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004771 final long identity = Binder.clearCallingIdentity();
4772 try {
4773 Phone phone = getPhone(subId);
4774 if (phone != null) {
4775 return phone.isVideoEnabled();
4776 } else {
4777 return false;
4778 }
4779 } finally {
4780 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004781 }
4782 }
4783
4784 /**
4785 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4786 * defined in {@link ImsRegistrationImplBase}.
4787 */
4788 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 Phone phone = getPhone(subId);
4792 if (phone != null) {
4793 return phone.getImsRegistrationTech();
4794 } else {
4795 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4796 }
4797 } finally {
4798 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004799 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004800 }
4801
Stuart Scott8eef64f2015-04-08 15:13:54 -07004802 @Override
4803 public void factoryReset(int subId) {
4804 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004805 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4806 return;
4807 }
4808
Svet Ganovcc087f82015-05-12 20:35:54 -07004809 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004810
Svet Ganovcc087f82015-05-12 20:35:54 -07004811 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004812 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4813 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004814 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004815 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004816 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004817 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4818 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004819 }
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004822 }
4823 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004824
4825 @Override
4826 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004827 final long identity = Binder.clearCallingIdentity();
4828 try {
4829 // We query all subscriptions instead of just the active ones, because
4830 // this might be called early on in the provisioning flow when the
4831 // subscriptions potentially aren't active yet.
4832 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4833 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004834 return null;
4835 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004836
Malcolm Chend965c8b2018-02-28 15:00:40 -08004837 // This function may be called very early, say, from the setup wizard, at
4838 // which point we won't have a default subscription set. If that's the case
4839 // we just choose the first, which will be valid in "most cases".
4840 final int defaultSubId = getDefaultSubscription();
4841 SubscriptionInfo info = null;
4842 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4843 info = slist.get(0);
4844 } else {
4845 for (SubscriptionInfo item : slist) {
4846 if (item.getSubscriptionId() == defaultSubId) {
4847 info = item;
4848 break;
4849 }
4850 }
4851
4852 if (info == null) {
4853 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004854 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004855 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004856
Malcolm Chend965c8b2018-02-28 15:00:40 -08004857 // Try and fetch the locale from the carrier properties or from the SIM language
4858 // preferences (EF-PL and EF-LI)...
4859 final int mcc = info.getMcc();
4860 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4861 String simLanguage = null;
4862 if (defaultPhone != null) {
4863 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4864 if (localeFromDefaultSim != null) {
4865 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4866 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4867 return localeFromDefaultSim.toLanguageTag();
4868 } else {
4869 simLanguage = localeFromDefaultSim.getLanguage();
4870 }
4871 }
4872 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004873
Malcolm Chend965c8b2018-02-28 15:00:40 -08004874 // The SIM language preferences only store a language (e.g. fr = French), not an
4875 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4876 // the SIM and carrier preferences does not include a country we add the country
4877 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004878 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004879 if (mccLocale != null) {
4880 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4881 return mccLocale.toLanguageTag();
4882 }
4883
4884 if (DBG) log("No locale found - returning null");
4885 return null;
4886 } finally {
4887 Binder.restoreCallingIdentity(identity);
4888 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004889 }
4890
4891 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004892 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004893 }
4894
Malcolm Chend965c8b2018-02-28 15:00:40 -08004895 /**
4896 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4897 */
4898 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004899 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004900 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004901
Chenjie Yu1ba97252018-01-11 18:16:20 -08004902 private final ModemActivityInfo mLastModemActivityInfo =
4903 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4904
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004905 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004906 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4907 * representing the state of the modem.
4908 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004909 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4910 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004911 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004912 */
4913 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004914 public void requestModemActivityInfo(ResultReceiver result) {
4915 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004916 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004917
4918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 ModemActivityInfo ret = null;
4921 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004922 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4923 CMD_GET_MODEM_ACTIVITY_INFO,
4924 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004925 if (isModemActivityInfoValid(info)) {
4926 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4927 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4928 mergedTxTimeMs[i] =
4929 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4930 }
4931 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4932 mLastModemActivityInfo.setSleepTimeMillis(
4933 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4934 mLastModemActivityInfo.setIdleTimeMillis(
4935 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4936 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4937 mLastModemActivityInfo.setRxTimeMillis(
4938 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4939 mLastModemActivityInfo.setEnergyUsed(
4940 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004941 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004942 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4943 mLastModemActivityInfo.getSleepTimeMillis(),
4944 mLastModemActivityInfo.getIdleTimeMillis(),
4945 mLastModemActivityInfo.getTxTimeMillis(),
4946 mLastModemActivityInfo.getRxTimeMillis(),
4947 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004948 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004949 Bundle bundle = new Bundle();
4950 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4951 result.send(0, bundle);
4952 } finally {
4953 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004954 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004955 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004956
Siddharth Rayf5d29552018-06-17 15:02:38 -07004957 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4958 // less than total activity duration.
4959 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4960 if (info == null) {
4961 return false;
4962 }
4963 int activityDurationMs =
4964 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4965 int totalTxTimeMs = 0;
4966 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4967 totalTxTimeMs += info.getTxTimeMillis()[i];
4968 }
4969 return (info.isValid()
4970 && (info.getSleepTimeMillis() <= activityDurationMs)
4971 && (info.getIdleTimeMillis() <= activityDurationMs)
4972 && (info.getRxTimeMillis() <= activityDurationMs)
4973 && (totalTxTimeMs <= activityDurationMs));
4974 }
4975
Jack Yu85bd38a2015-11-09 11:34:32 -08004976 /**
4977 * {@hide}
4978 * Returns the service state information on specified subscription.
4979 */
4980 @Override
4981 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004983 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004984 return null;
4985 }
4986
Malcolm Chend965c8b2018-02-28 15:00:40 -08004987 final long identity = Binder.clearCallingIdentity();
4988 try {
4989 final Phone phone = getPhone(subId);
4990 if (phone == null) {
4991 return null;
4992 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004993
Malcolm Chend965c8b2018-02-28 15:00:40 -08004994 return phone.getServiceState();
4995 } finally {
4996 Binder.restoreCallingIdentity(identity);
4997 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004998 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004999
5000 /**
5001 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5002 *
5003 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5004 * voicemail ringtone.
5005 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5006 * PhoneAccount.
5007 */
5008 @Override
5009 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005010 final long identity = Binder.clearCallingIdentity();
5011 try {
5012 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5013 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005014 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005015 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005016
Malcolm Chend965c8b2018-02-28 15:00:40 -08005017 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5018 } finally {
5019 Binder.restoreCallingIdentity(identity);
5020 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005021 }
5022
5023 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005024 * Sets the per-account voicemail ringtone.
5025 *
5026 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5027 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5028 *
5029 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5030 * voicemail ringtone.
5031 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5032 * PhoneAccount.
5033 */
5034 @Override
5035 public void setVoicemailRingtoneUri(String callingPackage,
5036 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005037 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005038 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5039 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005040 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5042 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5043 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005044 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005045
5046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5049 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005050 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005051 }
5052 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5053 } finally {
5054 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005055 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005056 }
5057
5058 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005059 * Returns whether vibration is set for voicemail notification in Phone settings.
5060 *
5061 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5062 * voicemail vibration setting.
5063 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5064 */
5065 @Override
5066 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005067 final long identity = Binder.clearCallingIdentity();
5068 try {
5069 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5070 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005071 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005072 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005073
Malcolm Chend965c8b2018-02-28 15:00:40 -08005074 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5075 } finally {
5076 Binder.restoreCallingIdentity(identity);
5077 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005078 }
5079
Youhan Wange64578a2016-05-02 15:32:42 -07005080 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005081 * Sets the per-account voicemail vibration.
5082 *
5083 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5084 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5085 *
5086 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5087 * voicemail vibration setting.
5088 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5089 * specific PhoneAccount.
5090 */
5091 @Override
5092 public void setVoicemailVibrationEnabled(String callingPackage,
5093 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005094 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005095 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5096 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005097 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5099 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5100 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005101 }
5102
Malcolm Chend965c8b2018-02-28 15:00:40 -08005103 final long identity = Binder.clearCallingIdentity();
5104 try {
5105 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5106 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005107 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005108 }
5109 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5110 } finally {
5111 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005112 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005113 }
5114
5115 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005116 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5117 *
5118 * @throws SecurityException if the caller does not have the required permission
5119 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005120 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005121 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005122 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005123 }
5124
5125 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005126 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5127 * permission.
5128 *
5129 * @throws SecurityException if the caller does not have the required permission
5130 */
5131 private void enforceSendSmsPermission() {
5132 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5133 }
5134
5135 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005136 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005137 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005138 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005139 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005140 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005141 final long identity = Binder.clearCallingIdentity();
5142 try {
5143 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005144 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005145 if (componentName == null) {
5146 throw new SecurityException(
5147 "Caller not current active visual voicemail package[null]");
5148 }
5149 String vvmPackage = componentName.getPackageName();
5150 if (!callingPackage.equals(vvmPackage)) {
5151 throw new SecurityException("Caller not current active visual voicemail package["
5152 + vvmPackage + "]");
5153 }
5154 } finally {
5155 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005156 }
5157 }
5158
5159 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005160 * Return the application ID for the app type.
5161 *
5162 * @param subId the subscription ID that this request applies to.
5163 * @param appType the uicc app type.
5164 * @return Application ID for specificied app type, or null if no uicc.
5165 */
5166 @Override
5167 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005168 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005169 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005170
5171 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005172 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005173 if (phone == null) {
5174 return null;
5175 }
5176 String aid = null;
5177 try {
5178 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5179 .getApplicationByType(appType).getAid();
5180 } catch (Exception e) {
5181 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5182 }
5183 return aid;
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005186 }
Youhan Wange64578a2016-05-02 15:32:42 -07005187 }
5188
Youhan Wang4001d252016-05-11 10:29:41 -07005189 /**
5190 * Return the Electronic Serial Number.
5191 *
5192 * @param subId the subscription ID that this request applies to.
5193 * @return ESN or null if error.
5194 */
5195 @Override
5196 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005197 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005198 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005199
5200 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005201 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005202 if (phone == null) {
5203 return null;
5204 }
5205 String esn = null;
5206 try {
5207 esn = phone.getEsn();
5208 } catch (Exception e) {
5209 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5210 }
5211 return esn;
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005214 }
Youhan Wang4001d252016-05-11 10:29:41 -07005215 }
5216
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005217 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005218 * Return the Preferred Roaming List Version.
5219 *
5220 * @param subId the subscription ID that this request applies to.
5221 * @return PRLVersion or null if error.
5222 */
5223 @Override
5224 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005225 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005226 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005227
5228 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005229 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005230 if (phone == null) {
5231 return null;
5232 }
5233 String cdmaPrlVersion = null;
5234 try {
5235 cdmaPrlVersion = phone.getCdmaPrlVersion();
5236 } catch (Exception e) {
5237 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5238 }
5239 return cdmaPrlVersion;
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005242 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005243 }
5244
5245 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005246 * Get snapshot of Telephony histograms
5247 * @return List of Telephony histograms
5248 * @hide
5249 */
5250 @Override
5251 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5253 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005254
5255 final long identity = Binder.clearCallingIdentity();
5256 try {
5257 return RIL.getTelephonyRILTimingHistograms();
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005261 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005262
5263 /**
5264 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005265 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005266 * Require system privileges. In the future we may add this to carrier APIs.
5267 *
5268 * @return The number of carriers set successfully, should match length of carriers
5269 */
5270 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005271 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005272 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005274
Meng Wang9b7c4e92017-02-17 11:41:27 -08005275 if (carriers == null) {
5276 throw new NullPointerException("carriers cannot be null");
5277 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005278
Malcolm Chend965c8b2018-02-28 15:00:40 -08005279 final long identity = Binder.clearCallingIdentity();
5280 try {
Michele85121de2018-12-19 15:25:20 -08005281 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5282 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdevie435a3e2018-08-15 16:01:53 -07005283 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5284 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005285 return retVal[0];
5286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005289 }
5290
5291 /**
5292 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005293 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005294 * Require system privileges. In the future we may add this to carrier APIs.
5295 *
5296 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5297 * means all carriers are allowed.
5298 */
5299 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005300 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005301 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005302 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005303
5304 final long identity = Binder.clearCallingIdentity();
5305 try {
Michele85121de2018-12-19 15:25:20 -08005306 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5307 int subId = (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID);
vagdevie435a3e2018-08-15 16:01:53 -07005308 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5309 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005310 } finally {
5311 Binder.restoreCallingIdentity(identity);
5312 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005313 }
5314
fionaxu59545b42016-05-25 15:53:37 -07005315 /**
5316 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5317 * @param subId the subscription ID that this action applies to.
5318 * @param enabled control enable or disable metered apns.
5319 * {@hide}
5320 */
5321 @Override
5322 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5323 enforceModifyPermission();
5324 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005325
5326 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005327 if (phone == null) {
5328 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5329 return;
5330 }
5331 try {
5332 phone.carrierActionSetMeteredApnsEnabled(enabled);
5333 } catch (Exception e) {
5334 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005335 } finally {
5336 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005337 }
5338 }
5339
5340 /**
5341 * Action set from carrier signalling broadcast receivers to enable/disable radio
5342 * @param subId the subscription ID that this action applies to.
5343 * @param enabled control enable or disable radio.
5344 * {@hide}
5345 */
5346 @Override
5347 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5348 enforceModifyPermission();
5349 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005350
5351 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005352 if (phone == null) {
5353 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5354 return;
5355 }
5356 try {
5357 phone.carrierActionSetRadioEnabled(enabled);
5358 } catch (Exception e) {
5359 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005360 } finally {
5361 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005362 }
5363 }
5364
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005365 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005366 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5367 * network status based on which carrier apps could apply actions accordingly,
5368 * enable/disable default url handler for example.
5369 *
5370 * @param subId the subscription ID that this action applies to.
5371 * @param report control start/stop reporting the default network status.
5372 * {@hide}
5373 */
5374 @Override
5375 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5376 enforceModifyPermission();
5377 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005378
5379 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005380 if (phone == null) {
5381 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5382 return;
5383 }
5384 try {
5385 phone.carrierActionReportDefaultNetworkStatus(report);
5386 } catch (Exception e) {
5387 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005388 } finally {
5389 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005390 }
5391 }
5392
5393 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005394 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5395 * bug report is being generated.
5396 */
5397 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005398 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005399 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5400 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005401 writer.println("Permission Denial: can't dump Phone from pid="
5402 + Binder.getCallingPid()
5403 + ", uid=" + Binder.getCallingUid()
5404 + "without permission "
5405 + android.Manifest.permission.DUMP);
5406 return;
5407 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005408 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005409 }
Jack Yueb89b242016-06-22 13:27:47 -07005410
Brad Ebingerdac2f002018-04-03 15:17:52 -07005411 @Override
5412 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5413 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5414 throws RemoteException {
5415 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5416 }
5417
Jack Yueb89b242016-06-22 13:27:47 -07005418 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005419 * Get aggregated video call data usage since boot.
5420 *
5421 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5422 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005423 * {@hide}
5424 */
5425 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005426 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005427 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5428 null);
5429
Malcolm Chend965c8b2018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 // NetworkStatsService keeps tracking the active network interface and identity. It
5433 // records the delta with the corresponding network identity.
5434 // We just return the total video call data usage snapshot since boot.
5435 Phone phone = getPhone(subId);
5436 if (phone != null) {
5437 return phone.getVtDataUsage(perUidStats);
5438 }
5439 return null;
5440 } finally {
5441 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005442 }
Jack Yueb89b242016-06-22 13:27:47 -07005443 }
Jack Yu75ab2952016-07-08 14:29:33 -07005444
5445 /**
5446 * Policy control of data connection. Usually used when data limit is passed.
5447 * @param enabled True if enabling the data, otherwise disabling.
5448 * @param subId Subscription index
5449 * {@hide}
5450 */
5451 @Override
5452 public void setPolicyDataEnabled(boolean enabled, int subId) {
5453 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005454
5455 final long identity = Binder.clearCallingIdentity();
5456 try {
5457 Phone phone = getPhone(subId);
5458 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005459 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005460 }
5461 } finally {
5462 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005463 }
5464 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005465
5466 /**
5467 * Get Client request stats
5468 * @return List of Client Request Stats
5469 * @hide
5470 */
5471 @Override
5472 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005474 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005475 return null;
5476 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005477 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005478
Malcolm Chend965c8b2018-02-28 15:00:40 -08005479 final long identity = Binder.clearCallingIdentity();
5480 try {
5481 if (phone != null) {
5482 return phone.getClientRequestStats();
5483 }
5484
5485 return null;
5486 } finally {
5487 Binder.restoreCallingIdentity(identity);
5488 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005489 }
5490
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005491 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005492 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005493 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005494 }
Jack Yueb4124c2017-02-16 15:32:43 -08005495
5496 /**
Grace Chen70990072017-03-24 17:21:30 -07005497 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005498 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005499 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005500 * @param state State of SIM (power down, power up, pass through)
5501 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5502 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5503 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005504 *
5505 **/
5506 @Override
Grace Chen70990072017-03-24 17:21:30 -07005507 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005508 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005509 Phone phone = PhoneFactory.getPhone(slotIndex);
5510
vagdevie435a3e2018-08-15 16:01:53 -07005511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5512
Malcolm Chend965c8b2018-02-28 15:00:40 -08005513 final long identity = Binder.clearCallingIdentity();
5514 try {
5515 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005516 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005517 }
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005520 }
5521 }
Shuo Qiandd210312017-04-12 22:11:33 +00005522
Tyler Gunn65d45c22017-06-05 11:22:26 -07005523 private boolean isUssdApiAllowed(int subId) {
5524 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005525 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005526 if (configManager == null) {
5527 return false;
5528 }
5529 PersistableBundle pb = configManager.getConfigForSubId(subId);
5530 if (pb == null) {
5531 return false;
5532 }
5533 return pb.getBoolean(
5534 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5535 }
5536
Shuo Qiandd210312017-04-12 22:11:33 +00005537 /**
5538 * Check if phone is in emergency callback mode
5539 * @return true if phone is in emergency callback mode
5540 * @param subId sub id
5541 */
goneil9c5f4872017-12-05 14:07:56 -08005542 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005543 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005544 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005545 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005546
5547 final long identity = Binder.clearCallingIdentity();
5548 try {
5549 if (phone != null) {
5550 return phone.isInEcm();
5551 } else {
5552 return false;
5553 }
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005556 }
5557 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005558
5559 /**
5560 * Get the current signal strength information for the given subscription.
5561 * Because this information is not updated when the device is in a low power state
5562 * it should not be relied-upon to be current.
5563 * @param subId Subscription index
5564 * @return the most recent cached signal strength info from the modem
5565 */
5566 @Override
5567 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005568 final long identity = Binder.clearCallingIdentity();
5569 try {
5570 Phone p = getPhone(subId);
5571 if (p == null) {
5572 return null;
5573 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005574
Malcolm Chend965c8b2018-02-28 15:00:40 -08005575 return p.getSignalStrength();
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005579 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005580
Pengquan Meng9140aec2018-08-22 14:49:57 -07005581 /**
chen xu907e5a22018-10-11 13:21:04 -07005582 * Get the current modem radio state for the given slot.
5583 * @param slotIndex slot index.
5584 * @param callingPackage the name of the package making the call.
5585 * @return the current radio power state from the modem
5586 */
5587 @Override
5588 public int getRadioPowerState(int slotIndex, String callingPackage) {
5589 Phone phone = PhoneFactory.getPhone(slotIndex);
5590 if (phone != null) {
5591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5592 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5593 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5594 }
5595
5596 final long identity = Binder.clearCallingIdentity();
5597 try {
5598 return phone.getRadioPowerState();
5599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
5602 }
5603 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5604 }
5605
5606 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005607 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5608 *
5609 * <p>Requires one of the following permissions:
5610 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5611 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5612 * privileges.
5613 *
5614 * @param subId subscription id
5615 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5616 * {@code false}.
5617 */
5618 @Override
5619 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005620 boolean isEnabled = false;
5621 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005622 try {
5623 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005624 null /* message */);
5625 Phone phone = getPhone(subId);
5626 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005627 } catch (Exception e) {
5628 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5629 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005630 } finally {
5631 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005632 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005633 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005634 }
5635
5636
5637 /**
5638 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5639 *
5640 * <p> Requires permission:
5641 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5642 * privileges.
5643 *
5644 * @param subId subscription id
5645 * @param isEnabled {@code true} means enable, {@code false} means disable.
5646 */
5647 @Override
5648 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005649 final long identity = Binder.clearCallingIdentity();
5650 try {
5651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5652 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005653
Pengquan Meng0c05b502018-09-06 09:59:22 -07005654 Phone phone = getPhone(subId);
5655 if (phone != null) {
5656 phone.setDataRoamingEnabled(isEnabled);
5657 }
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005660 }
5661 }
5662
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005663 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005664 public boolean isManualNetworkSelectionAllowed(int subId) {
5665 boolean isAllowed = true;
5666 final long identity = Binder.clearCallingIdentity();
5667 try {
5668 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5669 mApp, subId, "isManualNetworkSelectionAllowed");
5670 Phone phone = getPhone(subId);
5671 if (phone != null) {
5672 isAllowed = phone.isCspPlmnEnabled();
5673 }
5674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
5677 return isAllowed;
5678 }
5679
5680 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005681 public UiccCardInfo[] getUiccCardsInfo() {
5682 enforceReadPrivilegedPermission("getUiccCardsInfo");
5683
5684 final long identity = Binder.clearCallingIdentity();
5685 try {
5686 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5687 return cards.toArray(new UiccCardInfo[cards.size()]);
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
5690 }
5691 }
5692
5693 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005694 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005695 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005696
Malcolm Chend965c8b2018-02-28 15:00:40 -08005697 final long identity = Binder.clearCallingIdentity();
5698 try {
5699 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5700 if (slots == null) {
5701 Rlog.i(LOG_TAG, "slots is null.");
5702 return null;
5703 }
5704
5705 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5706 for (int i = 0; i < slots.length; i++) {
5707 UiccSlot slot = slots[i];
5708 if (slot == null) {
5709 continue;
5710 }
5711
5712 String cardId;
5713 UiccCard card = slot.getUiccCard();
5714 if (card != null) {
5715 cardId = card.getCardId();
5716 } else {
5717 cardId = slot.getIccId();
5718 }
5719
5720 int cardState = 0;
5721 switch (slot.getCardState()) {
5722 case CARDSTATE_ABSENT:
5723 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5724 break;
5725 case CARDSTATE_PRESENT:
5726 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5727 break;
5728 case CARDSTATE_ERROR:
5729 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5730 break;
5731 case CARDSTATE_RESTRICTED:
5732 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5733 break;
5734 default:
5735 break;
5736
5737 }
5738
5739 infos[i] = new UiccSlotInfo(
5740 slot.isActive(),
5741 slot.isEuicc(),
5742 cardId,
5743 cardState,
5744 slot.getPhoneId(),
5745 slot.isExtendedApduSupported());
5746 }
5747 return infos;
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005750 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005751 }
5752
5753 @Override
5754 public boolean switchSlots(int[] physicalSlots) {
5755 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005756
5757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5760 } finally {
5761 Binder.restoreCallingIdentity(identity);
5762 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005763 }
Jack Yu4c988042018-02-27 15:30:01 -08005764
5765 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005766 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5768 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5769 return TelephonyManager.INVALID_CARD_ID;
5770 }
5771
5772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 return UiccController.getInstance().getCardIdForDefaultEuicc();
5775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
5778 }
5779
5780 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005781 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5782 enforceModifyPermission();
5783 final Phone phone = getPhone(subId);
5784 if (phone == null) {
5785 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5786 return;
5787 }
5788
Malcolm Chend965c8b2018-02-28 15:00:40 -08005789 final long identity = Binder.clearCallingIdentity();
5790 try {
5791 phone.setRadioIndicationUpdateMode(filters, mode);
5792 } finally {
5793 Binder.restoreCallingIdentity(identity);
5794 }
Jack Yu4c988042018-02-27 15:30:01 -08005795 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005796
5797 /**
goneil47ffb6e2018-04-06 15:40:58 -07005798 * A test API to reload the UICC profile.
5799 *
5800 * <p>Requires that the calling app has permission
5801 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5802 * @hide
5803 */
5804 @Override
5805 public void refreshUiccProfile(int subId) {
5806 enforceModifyPermission();
5807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 Phone phone = getPhone(subId);
5811 if (phone == null) {
5812 return;
5813 }
5814 UiccCard uiccCard = phone.getUiccCard();
5815 if (uiccCard == null) {
5816 return;
5817 }
5818 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5819 if (uiccProfile == null) {
5820 return;
5821 }
5822 uiccProfile.refresh();
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
5826 }
5827
5828 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005829 * Returns false if the mobile data is disabled by default, otherwise return true.
5830 */
5831 private boolean getDefaultDataEnabled() {
5832 return "true".equalsIgnoreCase(
5833 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5834 }
5835
5836 /**
5837 * Returns true if the data roaming is enabled by default, i.e the system property
5838 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5839 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5840 */
5841 private boolean getDefaultDataRoamingEnabled(int subId) {
5842 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005843 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005844 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5845 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5846 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5847 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5848 return isDataRoamingEnabled;
5849 }
5850
5851 /**
5852 * Returns the default network type for the given {@code subId}, if the default network type is
5853 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5854 */
5855 private int getDefaultNetworkType(int subId) {
5856 return Integer.parseInt(
5857 TelephonyManager.getTelephonyProperty(
5858 mSubscriptionController.getPhoneId(subId),
5859 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5860 String.valueOf(Phone.PREFERRED_NT_MODE)));
5861 }
fionaxua13278b2018-03-21 00:08:13 -07005862
5863 @Override
5864 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5865 gid1, String gid2, String plmn, String spn) {
5866 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005867
5868 final long identity = Binder.clearCallingIdentity();
5869 try {
5870 final Phone phone = getPhone(subId);
5871 if (phone == null) {
5872 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5873 return;
5874 }
5875 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5876 } finally {
5877 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005878 }
fionaxua13278b2018-03-21 00:08:13 -07005879 }
5880
5881 @Override
5882 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005883 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005884
5885 final long identity = Binder.clearCallingIdentity();
5886 try {
5887 final Phone phone = getPhone(subId);
5888 if (phone == null) {
5889 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5890 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5891 }
5892 return phone.getCarrierIdListVersion();
5893 } finally {
5894 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005895 }
fionaxua13278b2018-03-21 00:08:13 -07005896 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005897
5898 @Override
5899 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5901 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5902 return -1;
5903 }
5904
5905 final long identity = Binder.clearCallingIdentity();
5906 try {
5907 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5908 } finally {
5909 Binder.restoreCallingIdentity(identity);
5910 }
5911 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005912
5913 @Override
5914 public int getCdmaRoamingMode(int subId) {
5915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5916 mApp, subId, "getCdmaRoamingMode");
5917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
5924 }
5925
5926 @Override
5927 public boolean setCdmaRoamingMode(int subId, int mode) {
5928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5929 mApp, subId, "setCdmaRoamingMode");
5930
5931 final long identity = Binder.clearCallingIdentity();
5932 try {
5933 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5934 } finally {
5935 Binder.restoreCallingIdentity(identity);
5936 }
5937 }
5938
5939 @Override
5940 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5942 mApp, subId, "setCdmaSubscriptionMode");
5943
5944 final long identity = Binder.clearCallingIdentity();
5945 try {
5946 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
5950 }
chen xu7ee67862018-10-30 22:27:10 -07005951
sqian2fff4a32018-11-05 14:18:37 -08005952 private void ensureUserRunning(int userId) {
5953 if (!mUserManager.isUserRunning(userId)) {
5954 throw new IllegalStateException("User " + userId + " does not exist or not running");
5955 }
5956 }
5957
5958 /**
5959 * Returns a list of SMS apps on a given user.
5960 *
5961 * Only the shell user (UID 2000 or 0) can call it.
5962 * Target user must be running.
5963 */
5964 @Override
5965 public String[] getSmsApps(int userId) {
5966 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5967 ensureUserRunning(userId);
5968
5969 final Collection<SmsApplicationData> apps =
5970 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5971
5972 String[] ret = new String[apps.size()];
5973 int i = 0;
5974 for (SmsApplicationData app : apps) {
5975 ret[i++] = app.mPackageName;
5976 }
5977 return ret;
5978 }
5979
5980 /**
5981 * Returns the default SMS app package name on a given user.
5982 *
5983 * Only the shell user (UID 2000 or 0) can call it.
5984 * Target user must be running.
5985 */
5986 @Override
5987 public String getDefaultSmsApp(int userId) {
5988 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5989 ensureUserRunning(userId);
5990
5991 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5992 /* updateIfNeeded= */ true, userId);
5993 return cn == null ? null : cn.getPackageName();
5994 }
5995
5996 /**
5997 * Set a package as the default SMS app on a given user.
5998 *
5999 * Only the shell user (UID 2000 or 0) can call it.
6000 * Target user must be running.
6001 */
6002 @Override
6003 public void setDefaultSmsApp(int userId, String packageName) {
6004 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6005 ensureUserRunning(userId);
6006
6007 boolean found = false;
6008 for (String pkg : getSmsApps(userId)) {
6009 if (TextUtils.equals(packageName, pkg)) {
6010 found = true;
6011 break;
6012 }
6013 }
6014 if (!found) {
6015 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6016 }
6017
6018 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6019 }
6020
chen xu7ee67862018-10-30 22:27:10 -07006021 @Override
sqian04b86072018-11-07 14:02:21 -08006022 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6023 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6025 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6026 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6027 }
6028 final long identity = Binder.clearCallingIdentity();
6029 try {
sqian991b35e2018-12-12 16:48:18 -08006030 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6031 for (Phone phone: PhoneFactory.getPhones()) {
6032 if (phone.getEmergencyNumberTracker() != null
6033 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6034 emergencyNumberListInternal.put(
6035 phone.getSubId(),
6036 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6037 }
sqian03bca152018-12-05 18:48:28 -08006038 }
sqian991b35e2018-12-12 16:48:18 -08006039 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006040 } finally {
6041 Binder.restoreCallingIdentity(identity);
6042 }
sqian04b86072018-11-07 14:02:21 -08006043 }
6044
6045 @Override
sqian03bca152018-12-05 18:48:28 -08006046 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6047 final Phone defaultPhone = getDefaultPhone();
6048 if (!exactMatch) {
6049 TelephonyPermissions
6050 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6051 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6052 }
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
sqian991b35e2018-12-12 16:48:18 -08006055 for (Phone phone: PhoneFactory.getPhones()) {
6056 if (phone.getEmergencyNumberTracker() != null
6057 && phone.getEmergencyNumberTracker() != null) {
6058 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6059 number, exactMatch)) {
6060 return true;
sqian03bca152018-12-05 18:48:28 -08006061 }
6062 }
sqian03bca152018-12-05 18:48:28 -08006063 }
6064 return false;
6065 } finally {
6066 Binder.restoreCallingIdentity(identity);
6067 }
6068 }
6069
sqian04b86072018-11-07 14:02:21 -08006070 @Override
chen xu7ee67862018-10-30 22:27:10 -07006071 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6072 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6073 Phone phone = getPhone(subId);
6074 if (phone == null) {
6075 return null;
6076 }
6077 final long identity = Binder.clearCallingIdentity();
6078 try {
6079 UiccProfile profile = UiccController.getInstance()
6080 .getUiccProfileForPhone(phone.getPhoneId());
6081 if (profile != null) {
6082 return profile.getCertsFromCarrierPrivilegeAccessRules();
6083 }
6084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
6087 return null;
6088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006089}