blob: 9f2f08ece69bcddc08e31e2d46153c90a6578a1c [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;
Santos Cordon7a1885b2015-02-03 11:15:19 -080055import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080056import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070057import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070058import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080059import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080081import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000082import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070085import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080086import android.telephony.data.ApnSetting;
87import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070088import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070089import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080090import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070091import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080092import android.telephony.ims.aidl.IImsMmTelFeature;
93import android.telephony.ims.aidl.IImsRcsFeature;
94import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070095import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080096import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800100import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800101import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800102
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700104import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800105import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700107import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700108import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800109import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700110import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800113import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800115import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700116import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100117import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700118import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700121import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800122import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700123import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700124import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700125import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700126import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700127import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700128import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700129import com.android.internal.telephony.SmsApplication;
130import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800131import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800132import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700133import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700134import com.android.internal.telephony.uicc.IccIoResult;
135import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800136import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700137import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800138import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800140import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000141import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700142import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800143import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700144import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800145import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700146import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700147import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800148
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700149import java.io.FileDescriptor;
150import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800151import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800153import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700154import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800155import java.util.HashMap;
Jake Hambye994d462014-02-03 13:10:13 -0800156import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100157import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159
160/**
161 * Implementation of the ITelephony interface.
162 */
Santos Cordon117fee72014-05-16 17:56:12 -0700163public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700164 private static final String LOG_TAG = "PhoneInterfaceManager";
165 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
166 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168
169 // Message codes used with mMainThreadHandler
170 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700171 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
172 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173 private static final int CMD_OPEN_CHANNEL = 9;
174 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
175 private static final int CMD_CLOSE_CHANNEL = 11;
176 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800177 private static final int CMD_NV_READ_ITEM = 13;
178 private static final int EVENT_NV_READ_ITEM_DONE = 14;
179 private static final int CMD_NV_WRITE_ITEM = 15;
180 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
181 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
182 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700183 private static final int CMD_RESET_MODEM_CONFIG = 19;
184 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800185 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
186 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
187 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
188 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800189 private static final int CMD_SEND_ENVELOPE = 25;
190 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000191 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
192 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700193 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
194 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
195 private static final int CMD_EXCHANGE_SIM_IO = 31;
196 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800197 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
198 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700199 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
200 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700201 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
202 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700203 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
204 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
205 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
206 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700207 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
208 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
209 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
210 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700211 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800212 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
213 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000214 private static final int CMD_SWITCH_SLOTS = 50;
215 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700216 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
217 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
218 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
219 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
220 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
221 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
222 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
223 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700224 private static final int CMD_GET_ALL_CELL_INFO = 60;
225 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
226 private static final int CMD_GET_CELL_LOCATION = 62;
227 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700228 private static final int CMD_MODEM_REBOOT = 64;
229 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700230 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
231 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800233 // Parameters of select command.
234 private static final int SELECT_COMMAND = 0xA4;
235 private static final int SELECT_P1 = 0x04;
236 private static final int SELECT_P2 = 0;
237 private static final int SELECT_P3 = 0x10;
238
Pengquan Meng85728fb2018-03-12 16:31:21 -0700239 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
240 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
241 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
242
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243 /** The singleton instance. */
244 private static PhoneInterfaceManager sInstance;
245
Wink Saville3ab207e2014-11-20 13:07:20 -0800246 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800247 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700248 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800249 private AppOpsManager mAppOps;
250 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800251 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800252 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700253 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254
Derek Tan97ebb422014-09-05 16:55:38 -0700255 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
256 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700258
Derek Tan740e1672017-06-27 14:56:27 -0700259 // The AID of ISD-R.
260 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
261
yinxub1bed742017-04-17 11:45:04 -0700262 private NetworkScanRequestTracker mNetworkScanRequestTracker;
263
David Kelly5e06a7f2018-03-12 14:10:59 +0000264 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
265 private static final int MANUFACTURER_CODE_LENGTH = 8;
266
Derek Tan89e89d42014-07-08 17:00:10 -0700267 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700268 * A request object to use for transmitting data to an ICC.
269 */
270 private static final class IccAPDUArgument {
271 public int channel, cla, command, p1, p2, p3;
272 public String data;
273
274 public IccAPDUArgument(int channel, int cla, int command,
275 int p1, int p2, int p3, String data) {
276 this.channel = channel;
277 this.cla = cla;
278 this.command = command;
279 this.p1 = p1;
280 this.p2 = p2;
281 this.p3 = p3;
282 this.data = data;
283 }
284 }
285
286 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700287 * A request object to use for transmitting data to an ICC.
288 */
289 private static final class ManualNetworkSelectionArgument {
290 public OperatorInfo operatorInfo;
291 public boolean persistSelection;
292
293 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
294 this.operatorInfo = operatorInfo;
295 this.persistSelection = persistSelection;
296 }
297 }
298
299 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
301 * request after sending. The main thread will notify the request when it is complete.
302 */
303 private static final class MainThreadRequest {
304 /** The argument to use for the request */
305 public Object argument;
306 /** The result of the request that is run on the main thread */
307 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800308 // The subscriber id that this request applies to. Defaults to
309 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
310 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Nathan Harold92bed182018-10-12 18:16:49 -0700312 // In cases where subId is unavailable, the caller needs to specify the phone.
313 public Phone phone;
314
vagdeviaf9a5b92018-08-15 16:01:53 -0700315 public WorkSource workSource;
316
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317 public MainThreadRequest(Object argument) {
318 this.argument = argument;
319 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800320
Nathan Harold92bed182018-10-12 18:16:49 -0700321 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
322 this.argument = argument;
323 if (phone != null) {
324 this.phone = phone;
325 }
326 this.workSource = workSource;
327 }
328
vagdeviaf9a5b92018-08-15 16:01:53 -0700329 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800330 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800331 if (subId != null) {
332 this.subId = subId;
333 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700334 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 }
337
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800338 private static final class IncomingThirdPartyCallArgs {
339 public final ComponentName component;
340 public final String callId;
341 public final String callerDisplayName;
342
343 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
344 String callerDisplayName) {
345 this.component = component;
346 this.callId = callId;
347 this.callerDisplayName = callerDisplayName;
348 }
349 }
350
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 /**
352 * A handler that processes messages on the main thread in the phone process. Since many
353 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
354 * inbound binder threads to the main thread in the phone process. The Binder thread
355 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
356 * on, which will be notified when the operation completes and will contain the result of the
357 * request.
358 *
359 * <p>If a MainThreadRequest object is provided in the msg.obj field,
360 * note that request.result must be set to something non-null for the calling thread to
361 * unblock.
362 */
363 private final class MainThreadHandler extends Handler {
364 @Override
365 public void handleMessage(Message msg) {
366 MainThreadRequest request;
367 Message onCompleted;
368 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800369 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700370 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800371 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
373 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700374 case CMD_HANDLE_USSD_REQUEST: {
375 request = (MainThreadRequest) msg.obj;
376 final Phone phone = getPhoneFromRequest(request);
377 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
378 String ussdRequest = ussdObject.first;
379 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700380
Pengquan Menga1bb6272018-09-06 09:59:22 -0700381 if (!isUssdApiAllowed(request.subId)) {
382 // Carrier does not support use of this API, return failure.
383 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
384 UssdResponse response = new UssdResponse(ussdRequest, null);
385 Bundle returnData = new Bundle();
386 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
387 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700388
Pengquan Menga1bb6272018-09-06 09:59:22 -0700389 request.result = true;
390 notifyRequester(request);
391 return;
392 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700393
Pengquan Menga1bb6272018-09-06 09:59:22 -0700394 try {
395 request.result = phone != null
396 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
397 } catch (CallStateException cse) {
398 request.result = false;
399 }
400 // Wake up the requesting thread
401 notifyRequester(request);
402 break;
pkanwar32d516d2016-10-14 19:37:38 -0700403 }
404
Yorke Lee716f67e2015-06-17 15:39:16 -0700405 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700407 final Phone phone = getPhoneFromRequest(request);
408 request.result = phone != null ?
409 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
410 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700412 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800419 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700420 if (uiccCard == null) {
421 loge("iccTransmitApduLogicalChannel: No UICC");
422 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700424 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
426 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 iccArgument.channel, iccArgument.cla, iccArgument.command,
429 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 break;
433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 ar = (AsyncResult) msg.obj;
436 request = (MainThreadRequest) ar.userObj;
437 if (ar.exception == null && ar.result != null) {
438 request.result = ar.result;
439 } else {
440 request.result = new IccIoResult(0x6F, 0, (byte[])null);
441 if (ar.result == null) {
442 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800443 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800445 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 } else {
447 loge("iccTransmitApduLogicalChannel: Unknown exception");
448 }
449 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700450 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 break;
452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
454 request = (MainThreadRequest) msg.obj;
455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduBasicChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 } else {
462 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
463 request);
464 uiccCard.iccTransmitApduBasicChannel(
465 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
466 iccArgument.p3, iccArgument.data, onCompleted);
467 }
468 break;
469
470 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
471 ar = (AsyncResult) msg.obj;
472 request = (MainThreadRequest) ar.userObj;
473 if (ar.exception == null && ar.result != null) {
474 request.result = ar.result;
475 } else {
476 request.result = new IccIoResult(0x6F, 0, (byte[])null);
477 if (ar.result == null) {
478 loge("iccTransmitApduBasicChannel: Empty response");
479 } else if (ar.exception instanceof CommandException) {
480 loge("iccTransmitApduBasicChannel: CommandException: " +
481 ar.exception);
482 } else {
483 loge("iccTransmitApduBasicChannel: Unknown exception");
484 }
485 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 break;
488
489 case CMD_EXCHANGE_SIM_IO:
490 request = (MainThreadRequest) msg.obj;
491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 if (uiccCard == null) {
494 loge("iccExchangeSimIO: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 } else {
498 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
499 request);
500 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
501 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
502 iccArgument.data, onCompleted);
503 }
504 break;
505
506 case EVENT_EXCHANGE_SIM_IO_DONE:
507 ar = (AsyncResult) msg.obj;
508 request = (MainThreadRequest) ar.userObj;
509 if (ar.exception == null && ar.result != null) {
510 request.result = ar.result;
511 } else {
512 request.result = new IccIoResult(0x6f, 0, (byte[])null);
513 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 break;
516
Derek Tan4d5e5c12014-02-04 11:54:58 -0800517 case CMD_SEND_ENVELOPE:
518 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800519 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700520 if (uiccCard == null) {
521 loge("sendEnvelopeWithStatus: No UICC");
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700524 } else {
525 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
526 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
527 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800528 break;
529
530 case EVENT_SEND_ENVELOPE_DONE:
531 ar = (AsyncResult) msg.obj;
532 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700533 if (ar.exception == null && ar.result != null) {
534 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
537 if (ar.result == null) {
538 loge("sendEnvelopeWithStatus: Empty response");
539 } else if (ar.exception instanceof CommandException) {
540 loge("sendEnvelopeWithStatus: CommandException: " +
541 ar.exception);
542 } else {
543 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
544 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 break;
548
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 case CMD_OPEN_CHANNEL:
550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800552 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800555 request.result = new IccOpenLogicalChannelResponse(-1,
556 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 } else {
559 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800560 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
561 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 break;
564
565 case EVENT_OPEN_CHANNEL_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 int[] result = (int[]) ar.result;
571 int channelId = result[0];
572 byte[] selectResponse = null;
573 if (result.length > 1) {
574 selectResponse = new byte[result.length - 1];
575 for (int i = 1; i < result.length; ++i) {
576 selectResponse[i - 1] = (byte) result[i];
577 }
578 }
579 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700580 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 if (ar.result == null) {
583 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 if (ar.exception != null) {
586 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
587 }
588
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700589 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700590 if (ar.exception instanceof CommandException) {
591 CommandException.Error error =
592 ((CommandException) (ar.exception)).getCommandError();
593 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700595 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 }
598 }
599 openChannelResp = new IccOpenLogicalChannelResponse(
600 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700602 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 break;
605
606 case CMD_CLOSE_CHANNEL:
607 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800608 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700609 if (uiccCard == null) {
610 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900611 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700613 } else {
614 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
615 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
616 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 break;
618
619 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800620 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
621 break;
622
623 case CMD_NV_READ_ITEM:
624 request = (MainThreadRequest) msg.obj;
625 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800626 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
627 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800628 break;
629
630 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800636 request.result = "";
637 if (ar.result == null) {
638 loge("nvReadItem: Empty response");
639 } else if (ar.exception instanceof CommandException) {
640 loge("nvReadItem: CommandException: " +
641 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800643 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
Jake Hambye994d462014-02-03 13:10:13 -0800649 case CMD_NV_WRITE_ITEM:
650 request = (MainThreadRequest) msg.obj;
651 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
652 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800653 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700654 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800655 break;
656
657 case EVENT_NV_WRITE_ITEM_DONE:
658 handleNullReturnEvent(msg, "nvWriteItem");
659 break;
660
661 case CMD_NV_WRITE_CDMA_PRL:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800664 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800665 break;
666
667 case EVENT_NV_WRITE_CDMA_PRL_DONE:
668 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
669 break;
670
chen xu6dac5ab2018-10-26 17:39:23 -0700671 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800672 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700673 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800674 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800675 break;
676
chen xu6dac5ab2018-10-26 17:39:23 -0700677 case EVENT_RESET_MODEM_CONFIG_DONE:
678 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800679 break;
680
Jake Hamby7c27be32014-03-03 13:25:59 -0800681 case CMD_GET_PREFERRED_NETWORK_TYPE:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700684 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800685 break;
686
687 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
688 ar = (AsyncResult) msg.obj;
689 request = (MainThreadRequest) ar.userObj;
690 if (ar.exception == null && ar.result != null) {
691 request.result = ar.result; // Integer
692 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800693 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800694 if (ar.result == null) {
695 loge("getPreferredNetworkType: Empty response");
696 } else if (ar.exception instanceof CommandException) {
697 loge("getPreferredNetworkType: CommandException: " +
698 ar.exception);
699 } else {
700 loge("getPreferredNetworkType: Unknown exception");
701 }
702 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case CMD_SET_PREFERRED_NETWORK_TYPE:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
709 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700710 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 break;
712
713 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
714 handleNullReturnEvent(msg, "setPreferredNetworkType");
715 break;
716
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000717 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
718 request = (MainThreadRequest)msg.obj;
719 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800720 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000721 break;
722
723 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
724 ar = (AsyncResult)msg.obj;
725 request = (MainThreadRequest)ar.userObj;
726 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000728 break;
729
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800730 case CMD_SET_VOICEMAIL_NUMBER:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
733 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800734 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
735 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800736 break;
737
738 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
739 handleNullReturnEvent(msg, "setVoicemailNumber");
740 break;
741
Stuart Scott54788802015-03-30 13:18:01 -0700742 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
745 request);
746 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
747 break;
748
749 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
750 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
751 break;
752
Shishir Agrawal302c8692015-06-19 13:49:39 -0700753 case CMD_PERFORM_NETWORK_SCAN:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
756 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
757 break;
758
759 case EVENT_PERFORM_NETWORK_SCAN_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
762 CellNetworkScanResult cellScanResult;
763 if (ar.exception == null && ar.result != null) {
764 cellScanResult = new CellNetworkScanResult(
765 CellNetworkScanResult.STATUS_SUCCESS,
766 (List<OperatorInfo>) ar.result);
767 } else {
768 if (ar.result == null) {
769 loge("getCellNetworkScanResults: Empty response");
770 }
771 if (ar.exception != null) {
772 loge("getCellNetworkScanResults: Exception: " + ar.exception);
773 }
774 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
775 if (ar.exception instanceof CommandException) {
776 CommandException.Error error =
777 ((CommandException) (ar.exception)).getCommandError();
778 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
779 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
780 } else if (error == CommandException.Error.GENERIC_FAILURE) {
781 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
782 }
783 }
784 cellScanResult = new CellNetworkScanResult(errorCode, null);
785 }
786 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700787 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700788 break;
789
790 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
791 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700792 ManualNetworkSelectionArgument selArg =
793 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
795 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700796 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
797 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 break;
799
800 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700801 ar = (AsyncResult) msg.obj;
802 request = (MainThreadRequest) ar.userObj;
803 if (ar.exception == null) {
804 request.result = true;
805 } else {
806 request.result = false;
807 loge("setNetworkSelectionModeManual " + ar.exception);
808 }
809 notifyRequester(request);
810 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700811 break;
812
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700813 case CMD_GET_MODEM_ACTIVITY_INFO:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800816 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700817 break;
818
819 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null && ar.result != null) {
823 request.result = ar.result;
824 } else {
825 if (ar.result == null) {
826 loge("queryModemActivityInfo: Empty response");
827 } else if (ar.exception instanceof CommandException) {
828 loge("queryModemActivityInfo: CommandException: " +
829 ar.exception);
830 } else {
831 loge("queryModemActivityInfo: Unknown exception");
832 }
833 }
Amit Mahajand4766222016-01-28 15:28:28 -0800834 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
835 if (request.result == null) {
836 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
837 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700838 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 break;
840
Meng Wang1a7c35a2016-05-05 20:56:15 -0700841 case CMD_SET_ALLOWED_CARRIERS:
842 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800843 CarrierRestrictionRules argument =
844 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700845 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800846 defaultPhone.setAllowedCarriers(argument, 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 {
Michele Berionne482f8202018-11-27 18:57:59 -0800855 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
856 if (ar.exception instanceof CommandException) {
857 loge("setAllowedCarriers: CommandException: " + ar.exception);
858 CommandException.Error error =
859 ((CommandException) (ar.exception)).getCommandError();
860 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
861 request.result =
862 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
863 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700864 } else {
865 loge("setAllowedCarriers: Unknown exception");
866 }
867 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700868 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 break;
870
871 case CMD_GET_ALLOWED_CARRIERS:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800874 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 break;
876
877 case EVENT_GET_ALLOWED_CARRIERS_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result;
882 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800883 request.result = new IllegalStateException(
884 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 if (ar.result == null) {
886 loge("getAllowedCarriers: Empty response");
887 } else if (ar.exception instanceof CommandException) {
888 loge("getAllowedCarriers: CommandException: " +
889 ar.exception);
890 } else {
891 loge("getAllowedCarriers: Unknown exception");
892 }
893 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700894 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 break;
896
Nathan Haroldb3014052017-01-25 15:57:32 -0800897 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
903 request.result = new IllegalArgumentException(
904 "Failed to retrieve Forbidden Plmns");
905 if (ar.result == null) {
906 loge("getForbiddenPlmns: Empty response");
907 } else {
908 loge("getForbiddenPlmns: Unknown exception");
909 }
910 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700911 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800912 break;
913
914 case CMD_GET_FORBIDDEN_PLMNS:
915 request = (MainThreadRequest) msg.obj;
916 uiccCard = getUiccCardFromRequest(request);
917 if (uiccCard == null) {
918 loge("getForbiddenPlmns() UiccCard is null");
919 request.result = new IllegalArgumentException(
920 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700921 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800922 break;
923 }
924 Integer appType = (Integer) request.argument;
925 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
926 if (uiccApp == null) {
927 loge("getForbiddenPlmns() no app with specified type -- "
928 + appType);
929 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700930 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800931 break;
932 } else {
933 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
934 + " specified type -- " + appType);
935 }
936 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
937 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
938 onCompleted);
939 break;
940
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000941 case CMD_SWITCH_SLOTS:
942 request = (MainThreadRequest) msg.obj;
943 int[] physicalSlots = (int[]) request.argument;
944 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
945 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
946 break;
947
948 case EVENT_SWITCH_SLOTS_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700952 notifyRequester(request);
953 break;
954 case CMD_GET_NETWORK_SELECTION_MODE:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
957 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
958 break;
959
960 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 if (ar.exception != null) {
964 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
965 } else {
966 int mode = ((int[]) ar.result)[0];
967 if (mode == 0) {
968 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
969 } else {
970 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
971 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000972 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700973 notifyRequester(request);
974 break;
975 case CMD_GET_CDMA_ROAMING_MODE:
976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
978 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
979 break;
980 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 if (ar.exception != null) {
984 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
985 } else {
986 request.result = ((int[]) ar.result)[0];
987 }
988 notifyRequester(request);
989 break;
990 case CMD_SET_CDMA_ROAMING_MODE:
991 request = (MainThreadRequest) msg.obj;
992 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
993 int mode = (int) request.argument;
994 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
995 break;
996 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = ar.exception == null;
1000 notifyRequester(request);
1001 break;
1002 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1005 int subscriptionMode = (int) request.argument;
1006 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1007 break;
1008 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 request.result = ar.exception == null;
1012 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001013 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001014 case CMD_GET_ALL_CELL_INFO:
1015 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001016 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001017 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001019 case EVENT_GET_ALL_CELL_INFO_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001022 // If a timeout occurs, the response will be null
1023 request.result = (ar.exception == null && ar.result != null)
1024 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001025 synchronized (request) {
1026 request.notifyAll();
1027 }
1028 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001029 case CMD_REQUEST_CELL_INFO_UPDATE:
1030 request = (MainThreadRequest) msg.obj;
1031 request.phone.requestCellInfoUpdate(request.workSource,
1032 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1033 break;
1034 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
1037 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1038 try {
1039 if (ar.exception != null) {
1040 // something went wrong... the response is null
1041 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1042 cb.onCellInfo(null);
1043 } else if (ar.result == null) {
1044 // timeout occurred, so force the result to non-null "empty"
1045 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1046 cb.onCellInfo(new ArrayList<CellInfo>());
1047 } else {
1048 // use the result as returned
1049 cb.onCellInfo((List<CellInfo>) ar.result);
1050 }
1051 } catch (RemoteException re) {
1052 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1053 }
1054 break;
1055 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 request = (MainThreadRequest) msg.obj;
1057 WorkSource ws = (WorkSource) request.argument;
1058 Phone phone = getPhoneFromRequest(request);
1059 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1060 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 ar = (AsyncResult) msg.obj;
1063 request = (MainThreadRequest) ar.userObj;
1064 if (ar.exception == null) {
1065 request.result = ar.result;
1066 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001067 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001068 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1069 ? new CdmaCellLocation() : new GsmCellLocation();
1070 }
1071
1072 synchronized (request) {
1073 request.notifyAll();
1074 }
1075 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001076 case CMD_MODEM_REBOOT:
1077 request = (MainThreadRequest) msg.obj;
1078 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001079 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001080 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001081 case EVENT_CMD_MODEM_REBOOT_DONE:
1082 handleNullReturnEvent(msg, "rebootModem");
1083 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001084 default:
1085 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1086 break;
1087 }
1088 }
Jake Hambye994d462014-02-03 13:10:13 -08001089
Pengquan Menga1bb6272018-09-06 09:59:22 -07001090 private void notifyRequester(MainThreadRequest request) {
1091 synchronized (request) {
1092 request.notifyAll();
1093 }
1094 }
1095
Jake Hambye994d462014-02-03 13:10:13 -08001096 private void handleNullReturnEvent(Message msg, String command) {
1097 AsyncResult ar = (AsyncResult) msg.obj;
1098 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null) {
1100 request.result = true;
1101 } else {
1102 request.result = false;
1103 if (ar.exception instanceof CommandException) {
1104 loge(command + ": CommandException: " + ar.exception);
1105 } else {
1106 loge(command + ": Unknown exception");
1107 }
1108 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001109 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001111 }
1112
1113 /**
1114 * Posts the specified command to be executed on the main thread,
1115 * waits for the request to complete, and returns the result.
1116 * @see #sendRequestAsync
1117 */
1118 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001119 return sendRequest(
1120 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001121 }
1122
1123 /**
1124 * Posts the specified command to be executed on the main thread,
1125 * waits for the request to complete, and returns the result.
1126 * @see #sendRequestAsync
1127 */
1128 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1129 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001130 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001131 }
1132
1133 /**
1134 * Posts the specified command to be executed on the main thread,
1135 * waits for the request to complete, and returns the result.
1136 * @see #sendRequestAsync
1137 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001138 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001139 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001140 }
1141
1142 /**
1143 * Posts the specified command to be executed on the main thread,
1144 * waits for the request to complete, and returns the result.
1145 * @see #sendRequestAsync
1146 */
Nathan Harold92bed182018-10-12 18:16:49 -07001147 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1148 return sendRequest(command, argument, subId, null, workSource);
1149 }
1150
1151 /**
1152 * Posts the specified command to be executed on the main thread,
1153 * waits for the request to complete, and returns the result.
1154 * @see #sendRequestAsync
1155 */
1156 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1157 return sendRequest(
1158 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1159 }
1160
1161 /**
1162 * Posts the specified command to be executed on the main thread,
1163 * waits for the request to complete, and returns the result.
1164 * @see #sendRequestAsync
1165 */
1166 private Object sendRequest(
1167 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1169 throw new RuntimeException("This method will deadlock if called from the main thread.");
1170 }
1171
Nathan Harold92bed182018-10-12 18:16:49 -07001172 MainThreadRequest request = null;
1173 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1174 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1175 } else if (phone != null) {
1176 request = new MainThreadRequest(argument, phone, workSource);
1177 } else {
1178 request = new MainThreadRequest(argument, subId, workSource);
1179 }
1180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001181 Message msg = mMainThreadHandler.obtainMessage(command, request);
1182 msg.sendToTarget();
1183
1184 // Wait for the request to complete
1185 synchronized (request) {
1186 while (request.result == null) {
1187 try {
1188 request.wait();
1189 } catch (InterruptedException e) {
1190 // Do nothing, go back and wait until the request is complete
1191 }
1192 }
1193 }
1194 return request.result;
1195 }
1196
1197 /**
1198 * Asynchronous ("fire and forget") version of sendRequest():
1199 * Posts the specified command to be executed on the main thread, and
1200 * returns immediately.
1201 * @see #sendRequest
1202 */
1203 private void sendRequestAsync(int command) {
1204 mMainThreadHandler.sendEmptyMessage(command);
1205 }
1206
1207 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001208 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001209 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001210 */
1211 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001212 sendRequestAsync(command, argument, null, null);
1213 }
1214
1215 /**
1216 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1217 * @see {@link #sendRequest(int,Object)}
1218 */
1219 private void sendRequestAsync(
1220 int command, Object argument, Phone phone, WorkSource workSource) {
1221 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001222 Message msg = mMainThreadHandler.obtainMessage(command, request);
1223 msg.sendToTarget();
1224 }
1225
1226 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001227 * Initialize the singleton PhoneInterfaceManager instance.
1228 * This is only done once, at startup, from PhoneApp.onCreate().
1229 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001230 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 synchronized (PhoneInterfaceManager.class) {
1232 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001233 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 } else {
1235 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1236 }
1237 return sInstance;
1238 }
1239 }
1240
1241 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001242 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001245 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1247 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001248 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001249 mTelephonySharedPreferences =
1250 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001251 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001252 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001253
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 publish();
1255 }
1256
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001257 private Phone getDefaultPhone() {
1258 Phone thePhone = getPhone(getDefaultSubscription());
1259 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1260 }
1261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 private void publish() {
1263 if (DBG) log("publish: " + this);
1264
1265 ServiceManager.addService("phone", this);
1266 }
1267
Stuart Scott584921c2015-01-15 17:10:34 -08001268 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001269 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001270 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001271 }
1272
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001273 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1274 Phone phone = getPhoneFromRequest(request);
1275 return phone == null ? null :
1276 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1277 }
1278
Wink Saville36469e72014-06-11 15:17:00 -07001279 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001280 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001281 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283
1284 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001285 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
1287
Wink Savilleb564aae2014-10-23 10:18:09 -07001288 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001289 if (DBG) log("dial: " + number);
1290 // No permission check needed here: This is just a wrapper around the
1291 // ACTION_DIAL intent, which is available to any app since it puts up
1292 // the UI before it does anything.
1293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001294 final long identity = Binder.clearCallingIdentity();
1295 try {
1296 String url = createTelUrl(number);
1297 if (url == null) {
1298 return;
1299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001301 // PENDING: should we just silently fail if phone is offhook or ringing?
1302 PhoneConstants.State state = mCM.getState(subId);
1303 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1304 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1305 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1306 mApp.startActivity(intent);
1307 }
1308 } finally {
1309 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 }
1311 }
1312
1313 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001314 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001315 }
1316
Wink Savilleb564aae2014-10-23 10:18:09 -07001317 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (DBG) log("call: " + number);
1319
1320 // This is just a wrapper around the ACTION_CALL intent, but we still
1321 // need to do a permission check since we're calling startActivity()
1322 // from the context of the phone app.
1323 enforceCallPermission();
1324
1325 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1326 != AppOpsManager.MODE_ALLOWED) {
1327 return;
1328 }
1329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001330 final long identity = Binder.clearCallingIdentity();
1331 try {
1332 String url = createTelUrl(number);
1333 if (url == null) {
1334 return;
1335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001337 boolean isValid = false;
1338 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1339 if (slist != null) {
1340 for (SubscriptionInfo subInfoRecord : slist) {
1341 if (subInfoRecord.getSubscriptionId() == subId) {
1342 isValid = true;
1343 break;
1344 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001345 }
Wink Saville08874612014-08-31 19:19:58 -07001346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001347 if (!isValid) {
1348 return;
1349 }
Wink Saville08874612014-08-31 19:19:58 -07001350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001351 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1352 intent.putExtra(SUBSCRIPTION_KEY, subId);
1353 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1354 mApp.startActivity(intent);
1355 } finally {
1356 Binder.restoreCallingIdentity(identity);
1357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 }
1359
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001361 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001362 }
1363
Wink Savilleb564aae2014-10-23 10:18:09 -07001364 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001365 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001366 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1367 }
1368
1369 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001370 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
1372
Wink Savilleb564aae2014-10-23 10:18:09 -07001373 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001375 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1376 }
1377
1378 /** {@hide} */
1379 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001380 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001381 }
1382
Wink Savilleb564aae2014-10-23 10:18:09 -07001383 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001385
1386 final long identity = Binder.clearCallingIdentity();
1387 try {
1388 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1389 checkSimPin.start();
1390 return checkSimPin.unlockSim(null, pin);
1391 } finally {
1392 Binder.restoreCallingIdentity(identity);
1393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 }
1395
Wink Saville9de0f752013-10-22 19:04:03 -07001396 /** {@hide} */
1397 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001399 }
1400
Wink Savilleb564aae2014-10-23 10:18:09 -07001401 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001403
1404 final long identity = Binder.clearCallingIdentity();
1405 try {
1406 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1407 checkSimPuk.start();
1408 return checkSimPuk.unlockSim(puk, pin);
1409 } finally {
1410 Binder.restoreCallingIdentity(identity);
1411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 }
1413
1414 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001415 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 * a synchronous one.
1417 */
1418 private static class UnlockSim extends Thread {
1419
1420 private final IccCard mSimCard;
1421
1422 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001423 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1424 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
1426 // For replies from SimCard interface
1427 private Handler mHandler;
1428
1429 // For async handler to identify request type
1430 private static final int SUPPLY_PIN_COMPLETE = 100;
1431
1432 public UnlockSim(IccCard simCard) {
1433 mSimCard = simCard;
1434 }
1435
1436 @Override
1437 public void run() {
1438 Looper.prepare();
1439 synchronized (UnlockSim.this) {
1440 mHandler = new Handler() {
1441 @Override
1442 public void handleMessage(Message msg) {
1443 AsyncResult ar = (AsyncResult) msg.obj;
1444 switch (msg.what) {
1445 case SUPPLY_PIN_COMPLETE:
1446 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1447 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001448 mRetryCount = msg.arg1;
1449 if (ar.exception != null) {
1450 if (ar.exception instanceof CommandException &&
1451 ((CommandException)(ar.exception)).getCommandError()
1452 == CommandException.Error.PASSWORD_INCORRECT) {
1453 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1454 } else {
1455 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1456 }
1457 } else {
1458 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 mDone = true;
1461 UnlockSim.this.notifyAll();
1462 }
1463 break;
1464 }
1465 }
1466 };
1467 UnlockSim.this.notifyAll();
1468 }
1469 Looper.loop();
1470 }
1471
1472 /*
1473 * Use PIN or PUK to unlock SIM card
1474 *
1475 * If PUK is null, unlock SIM card with PIN
1476 *
1477 * If PUK is not null, unlock SIM card with PUK and set PIN code
1478 */
Wink Saville9de0f752013-10-22 19:04:03 -07001479 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480
1481 while (mHandler == null) {
1482 try {
1483 wait();
1484 } catch (InterruptedException e) {
1485 Thread.currentThread().interrupt();
1486 }
1487 }
1488 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1489
1490 if (puk == null) {
1491 mSimCard.supplyPin(pin, callback);
1492 } else {
1493 mSimCard.supplyPuk(puk, pin, callback);
1494 }
1495
1496 while (!mDone) {
1497 try {
1498 Log.d(LOG_TAG, "wait for done");
1499 wait();
1500 } catch (InterruptedException e) {
1501 // Restore the interrupted status
1502 Thread.currentThread().interrupt();
1503 }
1504 }
1505 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001506 int[] resultArray = new int[2];
1507 resultArray[0] = mResult;
1508 resultArray[1] = mRetryCount;
1509 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 }
1511 }
1512
1513 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001514 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001515
1516 }
1517
Wink Savilleb564aae2014-10-23 10:18:09 -07001518 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001519 // No permission check needed here: this call is harmless, and it's
1520 // needed for the ServiceState.requestStateUpdate() call (which is
1521 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001522 final long identity = Binder.clearCallingIdentity();
1523 try {
1524 final Phone phone = getPhone(subId);
1525 if (phone != null) {
1526 phone.updateServiceLocation();
1527 }
1528 } finally {
1529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 }
1532
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001533 @Override
1534 public boolean isRadioOn(String callingPackage) {
1535 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001536 }
1537
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001538 @Override
1539 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001541 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001542 return false;
1543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001544
1545 final long identity = Binder.clearCallingIdentity();
1546 try {
1547 return isRadioOnForSubscriber(subId);
1548 } finally {
1549 Binder.restoreCallingIdentity(identity);
1550 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001551 }
1552
1553 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001554 final long identity = Binder.clearCallingIdentity();
1555 try {
1556 final Phone phone = getPhone(subId);
1557 if (phone != null) {
1558 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1559 } else {
1560 return false;
1561 }
1562 } finally {
1563 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
1566
1567 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001568 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
Wink Saville36469e72014-06-11 15:17:00 -07001570
Wink Savilleb564aae2014-10-23 10:18:09 -07001571 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001573
1574 final long identity = Binder.clearCallingIdentity();
1575 try {
1576 final Phone phone = getPhone(subId);
1577 if (phone != null) {
1578 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1579 }
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001582 }
Wink Saville36469e72014-06-11 15:17:00 -07001583 }
1584
1585 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001586 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001587 }
1588
Wink Savilleb564aae2014-10-23 10:18:09 -07001589 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001591
1592 final long identity = Binder.clearCallingIdentity();
1593 try {
1594 final Phone phone = getPhone(subId);
1595 if (phone == null) {
1596 return false;
1597 }
1598 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1599 toggleRadioOnOffForSubscriber(subId);
1600 }
1601 return true;
1602 } finally {
1603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 }
Wink Saville36469e72014-06-11 15:17:00 -07001606
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001607 public boolean needMobileRadioShutdown() {
1608 /*
1609 * If any of the Radios are available, it will need to be
1610 * shutdown. So return true if any Radio is available.
1611 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001612 final long identity = Binder.clearCallingIdentity();
1613 try {
1614 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1615 Phone phone = PhoneFactory.getPhone(i);
1616 if (phone != null && phone.isRadioAvailable()) return true;
1617 }
1618 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1619 return false;
1620 } finally {
1621 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001622 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001623 }
1624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001625 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001626 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001627 enforceModifyPermission();
1628
1629 final long identity = Binder.clearCallingIdentity();
1630 try {
1631 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1632 logv("Shutting down Phone " + i);
1633 shutdownRadioUsingPhoneId(i);
1634 }
1635 } finally {
1636 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001637 }
1638 }
1639
1640 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001641 Phone phone = PhoneFactory.getPhone(phoneId);
1642 if (phone != null && phone.isRadioAvailable()) {
1643 phone.shutdownRadio();
1644 }
1645 }
1646
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001649
1650 final long identity = Binder.clearCallingIdentity();
1651 try {
1652 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1653 if (defaultPhone != null) {
1654 defaultPhone.setRadioPower(turnOn);
1655 return true;
1656 } else {
1657 loge("There's no default phone.");
1658 return false;
1659 }
1660 } finally {
1661 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001662 }
Wink Saville36469e72014-06-11 15:17:00 -07001663 }
1664
Wink Savilleb564aae2014-10-23 10:18:09 -07001665 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001667
1668 final long identity = Binder.clearCallingIdentity();
1669 try {
1670 final Phone phone = getPhone(subId);
1671 if (phone != null) {
1672 phone.setRadioPower(turnOn);
1673 return true;
1674 } else {
1675 return false;
1676 }
1677 } finally {
1678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681
Wink Saville36469e72014-06-11 15:17:00 -07001682 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001683 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 public boolean enableDataConnectivity() {
1685 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001686
1687 final long identity = Binder.clearCallingIdentity();
1688 try {
1689 int subId = mSubscriptionController.getDefaultDataSubId();
1690 final Phone phone = getPhone(subId);
1691 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001692 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001693 return true;
1694 } else {
1695 return false;
1696 }
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 }
1701
Wink Saville36469e72014-06-11 15:17:00 -07001702 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 public boolean disableDataConnectivity() {
1705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001706
1707 final long identity = Binder.clearCallingIdentity();
1708 try {
1709 int subId = mSubscriptionController.getDefaultDataSubId();
1710 final Phone phone = getPhone(subId);
1711 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001712 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713 return true;
1714 } else {
1715 return false;
1716 }
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 }
1721
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001723 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001724 final long identity = Binder.clearCallingIdentity();
1725 try {
1726 final Phone phone = getPhone(subId);
1727 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001728 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729 } else {
1730 return false;
1731 }
1732 } finally {
1733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 }
1736
1737 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001738 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001739 }
1740
pkanwarae03a6b2016-11-06 20:37:09 -08001741 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742 enforceCallPermission();
1743
1744 final long identity = Binder.clearCallingIdentity();
1745 try {
1746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1747 return;
1748 }
1749 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1750 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1751 } finally {
1752 Binder.restoreCallingIdentity(identity);
1753 }
pkanwar32d516d2016-10-14 19:37:38 -07001754 };
1755
Wink Savilleb564aae2014-10-23 10:18:09 -07001756 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001758
1759 final long identity = Binder.clearCallingIdentity();
1760 try {
1761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1762 return false;
1763 }
1764 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001771 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001772 }
1773
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001774 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 Phone phone = PhoneFactory.getPhone(slotIndex);
1778 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1779 PhoneConstantConversions.convertCallState(phone.getState());
1780 } finally {
1781 Binder.restoreCallingIdentity(identity);
1782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 }
1784
Sanket Padawe356d7632015-06-22 14:03:32 -07001785 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787 final long identity = Binder.clearCallingIdentity();
1788 try {
1789 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1790 if (phone != null) {
1791 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1792 } else {
1793 return PhoneConstantConversions.convertDataState(
1794 PhoneConstants.DataState.DISCONNECTED);
1795 }
1796 } finally {
1797 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 }
1800
Sanket Padawe356d7632015-06-22 14:03:32 -07001801 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1806 if (phone != null) {
1807 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1808 } else {
1809 return TelephonyManager.DATA_ACTIVITY_NONE;
1810 }
1811 } finally {
1812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 }
1815
1816 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001817 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001818 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001819 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001820 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1821 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001822 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001825 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001826 final long identity = Binder.clearCallingIdentity();
1827 try {
1828 if (DBG_LOC) log("getCellLocation: is active user");
1829 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001830 int subId = mSubscriptionController.getDefaultDataSubId();
1831 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1832 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833 return data;
1834 } finally {
1835 Binder.restoreCallingIdentity(identity);
1836 }
Svetoslav64fad262015-04-14 14:35:21 -07001837 }
1838
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001840 public String getNetworkCountryIsoForPhone(int phoneId) {
1841 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1842 // registered cell info, so return a NULL country instead.
1843 final long identity = Binder.clearCallingIdentity();
1844 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001845 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1846 // Get default phone in this case.
1847 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1848 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001849 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001850 // Todo: fix this when we can get the actual cellular network info when the device
1851 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001852 if (TelephonyManager.NETWORK_TYPE_IWLAN
1853 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1854 return "";
1855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001856 Phone phone = PhoneFactory.getPhone(phoneId);
1857 if (phone != null) {
1858 ServiceStateTracker sst = phone.getServiceStateTracker();
1859 if (sst != null) {
1860 LocaleTracker lt = sst.getLocaleTracker();
1861 if (lt != null) {
1862 return lt.getCurrentCountry();
1863 }
1864 }
1865 }
1866 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001867 } finally {
1868 Binder.restoreCallingIdentity(identity);
1869 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001870 }
1871
1872 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001874 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001875 }
1876
Sanket Padawe356d7632015-06-22 14:03:32 -07001877 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001878 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 mApp.enforceCallingOrSelfPermission(
1880 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001881
1882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 final Phone phone = getPhone(subId);
1885 if (phone != null) {
1886 phone.enableLocationUpdates();
1887 }
1888 } finally {
1889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 }
1892
1893 @Override
1894 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001895 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001896 }
1897
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001899 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 mApp.enforceCallingOrSelfPermission(
1901 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001902
1903 final long identity = Binder.clearCallingIdentity();
1904 try {
1905 final Phone phone = getPhone(subId);
1906 if (phone != null) {
1907 phone.disableLocationUpdates();
1908 }
1909 } finally {
1910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 }
1913
Nathan Harold31d7ff32018-10-15 20:20:30 -07001914 /**
1915 * Returns the target SDK version number for a given package name.
1916 *
1917 * @return target SDK if the package is found or INT_MAX.
1918 */
1919 private int getTargetSdk(String packageName) {
1920 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001921 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1922 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001923 if (ai != null) return ai.targetSdkVersion;
1924 } catch (PackageManager.NameNotFoundException unexpected) {
1925 }
1926 return Integer.MAX_VALUE;
1927 }
1928
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 @Override
1930 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001931 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1932 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001933 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1934 throw new SecurityException(
1935 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1936 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001937
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1939 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1940 return null;
1941 }
Svetoslav64fad262015-04-14 14:35:21 -07001942
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001943 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944
Nathan Haroldf180aac2018-06-01 18:43:55 -07001945 List<CellInfo> info = getAllCellInfo(callingPackage);
1946 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947
Nathan Haroldf180aac2018-06-01 18:43:55 -07001948 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1949 for (CellInfo ci : info) {
1950 if (ci instanceof CellInfoGsm) {
1951 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1952 } else if (ci instanceof CellInfoWcdma) {
1953 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001956 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 }
1958
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001959 private List<CellInfo> getCachedCellInfo() {
1960 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1961 for (Phone phone : PhoneFactory.getPhones()) {
1962 List<CellInfo> info = phone.getAllCellInfo();
1963 if (info != null) cellInfos.addAll(info);
1964 }
1965 return cellInfos;
1966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967
1968 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001969 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001970 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001971 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001972 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001973 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001974 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 }
1976
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001977 final int targetSdk = getTargetSdk(callingPackage);
1978 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1979 return getCachedCellInfo();
1980 }
1981
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001982 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001983 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001984 final long identity = Binder.clearCallingIdentity();
1985 try {
1986 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1987 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001988 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001989 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990 if (info != null) cellInfos.addAll(info);
1991 }
1992 return cellInfos;
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
1996 }
1997
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001998 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001999 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2000 requestCellInfoUpdateInternal(
2001 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2002 }
2003
2004 @Override
2005 public void requestCellInfoUpdateWithWorkSource(
2006 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2007 enforceModifyPermission();
2008 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2009 }
2010
2011 private void requestCellInfoUpdateInternal(
2012 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002013 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002014 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002015 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2016 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002017 return;
2018 }
2019
2020 final Phone phone = getPhone(subId);
2021 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2022
2023 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2024 }
2025
2026 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002028 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002029 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002030
2031 final long identity = Binder.clearCallingIdentity();
2032 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002033 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002034 } finally {
2035 Binder.restoreCallingIdentity(identity);
2036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 }
2038
Shishir Agrawala9f32182016-04-12 12:00:16 -07002039 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002040 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002041 Phone phone = PhoneFactory.getPhone(slotIndex);
2042 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002043 return null;
2044 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002045 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002046 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2047 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002048 return null;
2049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002050
2051 final long identity = Binder.clearCallingIdentity();
2052 try {
2053 return phone.getImei();
2054 } finally {
2055 Binder.restoreCallingIdentity(identity);
2056 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002057 }
2058
2059 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002060 public String getTypeAllocationCodeForSlot(int slotIndex) {
2061 Phone phone = PhoneFactory.getPhone(slotIndex);
2062 String tac = null;
2063 if (phone != null) {
2064 String imei = phone.getImei();
2065 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2066 }
2067 return tac;
2068 }
2069
2070 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002071 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002072 Phone phone = PhoneFactory.getPhone(slotIndex);
2073 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002074 return null;
2075 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002076
Jeff Davidson913390f2018-02-23 17:11:49 -08002077 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002078 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2079 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002080 return null;
2081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002082
2083 final long identity = Binder.clearCallingIdentity();
2084 try {
2085 return phone.getMeid();
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
2088 }
Jack Yu2af8d712017-03-15 17:14:14 -07002089 }
2090
2091 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002092 public String getManufacturerCodeForSlot(int slotIndex) {
2093 Phone phone = PhoneFactory.getPhone(slotIndex);
2094 String manufacturerCode = null;
2095 if (phone != null) {
2096 String meid = phone.getMeid();
2097 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2098 }
2099 return manufacturerCode;
2100 }
2101
2102 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002103 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002104 Phone phone = PhoneFactory.getPhone(slotIndex);
2105 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002106 return null;
2107 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002108 int subId = phone.getSubId();
2109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2110 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2111 return null;
2112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 return phone.getDeviceSvn();
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002120 }
2121
fionaxu43304da2017-11-27 22:51:16 -08002122 @Override
2123 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002124 final long identity = Binder.clearCallingIdentity();
2125 try {
2126 final Phone phone = getPhone(subId);
2127 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2128 } finally {
2129 Binder.restoreCallingIdentity(identity);
2130 }
fionaxu43304da2017-11-27 22:51:16 -08002131 }
2132
2133 @Override
2134 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final Phone phone = getPhone(subId);
2138 return phone == null ? null : phone.getCarrierName();
2139 } finally {
2140 Binder.restoreCallingIdentity(identity);
2141 }
fionaxu43304da2017-11-27 22:51:16 -08002142 }
2143
calvinpanffe225e2018-11-01 19:43:06 +08002144 @Override
chen xu25637222018-11-04 17:17:00 -08002145 public int getSubscriptionPreciseCarrierId(int subId) {
2146 final long identity = Binder.clearCallingIdentity();
2147 try {
2148 final Phone phone = getPhone(subId);
2149 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2150 : phone.getPreciseCarrierId();
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
2153 }
2154 }
2155
2156 @Override
2157 public String getSubscriptionPreciseCarrierName(int subId) {
2158 final long identity = Binder.clearCallingIdentity();
2159 try {
2160 final Phone phone = getPhone(subId);
2161 return phone == null ? null : phone.getPreciseCarrierName();
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
2164 }
2165 }
2166
chen xu651eec72018-11-11 19:03:44 -08002167 @Override
chen xu864e11c2018-12-06 22:10:03 -08002168 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2169 if (!isSubscriptionMccMnc) {
2170 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2171 }
chen xu651eec72018-11-11 19:03:44 -08002172 final Phone phone = PhoneFactory.getPhone(slotIndex);
2173 if (phone == null) {
2174 return TelephonyManager.UNKNOWN_CARRIER_ID;
2175 }
2176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
2181 }
2182 }
2183
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 //
2185 // Internal helper methods.
2186 //
2187
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002188 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2190 *
2191 * @throws SecurityException if the caller does not have the required permission
2192 */
2193 private void enforceModifyPermission() {
2194 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2195 }
2196
2197 /**
2198 * Make sure the caller has the CALL_PHONE permission.
2199 *
2200 * @throws SecurityException if the caller does not have the required permission
2201 */
2202 private void enforceCallPermission() {
2203 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2204 }
2205
Stuart Scott8eef64f2015-04-08 15:13:54 -07002206 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002207 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002208 "ConnectivityService");
2209 }
2210
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 private String createTelUrl(String number) {
2212 if (TextUtils.isEmpty(number)) {
2213 return null;
2214 }
2215
Jake Hambye994d462014-02-03 13:10:13 -08002216 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Ihab Awadf9e92732013-12-05 18:02:52 -08002219 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2221 }
2222
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002223 private static void logv(String msg) {
2224 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2225 }
2226
Ihab Awadf9e92732013-12-05 18:02:52 -08002227 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2229 }
2230
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002231 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002233 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002234 }
2235
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002237 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238 final long identity = Binder.clearCallingIdentity();
2239 try {
2240 final Phone phone = PhoneFactory.getPhone(slotIndex);
2241 if (phone == null) {
2242 return PhoneConstants.PHONE_TYPE_NONE;
2243 } else {
2244 return phone.getPhoneType();
2245 }
2246 } finally {
2247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 }
2250
2251 /**
2252 * Returns the CDMA ERI icon index to display
2253 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002254 @Override
2255 public int getCdmaEriIconIndex(String callingPackage) {
2256 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002257 }
2258
Sanket Padawe356d7632015-06-22 14:03:32 -07002259 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002260 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002262 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002263 return -1;
2264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002265
2266 final long identity = Binder.clearCallingIdentity();
2267 try {
2268 final Phone phone = getPhone(subId);
2269 if (phone != null) {
2270 return phone.getCdmaEriIconIndex();
2271 } else {
2272 return -1;
2273 }
2274 } finally {
2275 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 }
2278
2279 /**
2280 * Returns the CDMA ERI icon mode,
2281 * 0 - ON
2282 * 1 - FLASHING
2283 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002284 @Override
2285 public int getCdmaEriIconMode(String callingPackage) {
2286 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002287 }
2288
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002290 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002292 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002293 return -1;
2294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 final Phone phone = getPhone(subId);
2299 if (phone != null) {
2300 return phone.getCdmaEriIconMode();
2301 } else {
2302 return -1;
2303 }
2304 } finally {
2305 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 }
2308
2309 /**
2310 * Returns the CDMA ERI text,
2311 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002312 @Override
2313 public String getCdmaEriText(String callingPackage) {
2314 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002315 }
2316
Sanket Padawe356d7632015-06-22 14:03:32 -07002317 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002318 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002320 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002321 return null;
2322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002323
2324 final long identity = Binder.clearCallingIdentity();
2325 try {
2326 final Phone phone = getPhone(subId);
2327 if (phone != null) {
2328 return phone.getCdmaEriText();
2329 } else {
2330 return null;
2331 }
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 }
2336
2337 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002338 * Returns the CDMA MDN.
2339 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002341 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2343 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002348 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349 return phone.getLine1Number();
2350 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002351 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352 return null;
2353 }
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002356 }
2357 }
2358
2359 /**
2360 * Returns the CDMA MIN.
2361 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002362 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002363 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2365 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002366
2367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 final Phone phone = getPhone(subId);
2370 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2371 return phone.getCdmaMin();
2372 } else {
2373 return null;
2374 }
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002377 }
2378 }
2379
Hall Liud892bec2018-11-30 14:51:45 -08002380 @Override
2381 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2382 INumberVerificationCallback callback, String callingPackage) {
2383 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2384 != PERMISSION_GRANTED) {
2385 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2386 }
2387 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2388
2389 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2390 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2391 throw new SecurityException("Calling package must be configured in the device config");
2392 }
2393
2394 if (range == null) {
2395 throw new NullPointerException("Range must be non-null");
2396 }
2397
2398 timeoutMillis = Math.min(timeoutMillis,
2399 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2400
2401 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2402 }
2403
Junda Liuca05d5d2014-08-14 22:36:34 -07002404 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 * Returns true if CDMA provisioning needs to run.
2406 */
2407 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002408 final long identity = Binder.clearCallingIdentity();
2409 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002410 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002411 } finally {
2412 Binder.restoreCallingIdentity(identity);
2413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 }
2415
2416 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002417 * Sets the voice mail number of a given subId.
2418 */
2419 @Override
2420 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002421 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422
2423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2426 new Pair<String, String>(alphaTag, number), new Integer(subId));
2427 return success;
2428 } finally {
2429 Binder.restoreCallingIdentity(identity);
2430 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002431 }
2432
Ta-wei Yen87c49842016-05-13 21:19:52 -07002433 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002434 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2435 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002436 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002437 if (!TextUtils.equals(callingPackage, systemDialer)) {
2438 throw new SecurityException("caller must be system dialer");
2439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
2443 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2444 if (phoneAccountHandle == null) {
2445 return null;
2446 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002447 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 } finally {
2449 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002450 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002451 }
2452
2453 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002454 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002457 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002458 return null;
2459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002461 final long identity = Binder.clearCallingIdentity();
2462 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002463 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002464 } finally {
2465 Binder.restoreCallingIdentity(identity);
2466 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002467 }
2468
2469 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002470 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2471 VisualVoicemailSmsFilterSettings settings) {
2472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473
2474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002477 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 } finally {
2479 Binder.restoreCallingIdentity(identity);
2480 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002481 }
2482
2483 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002484 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486
2487 final long identity = Binder.clearCallingIdentity();
2488 try {
2489 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002490 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 } finally {
2492 Binder.restoreCallingIdentity(identity);
2493 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002494 }
2495
2496 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002497 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2498 String callingPackage, int subId) {
2499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002504 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 } finally {
2506 Binder.restoreCallingIdentity(identity);
2507 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002508 }
2509
2510 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002511 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002512 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513
2514 final long identity = Binder.clearCallingIdentity();
2515 try {
2516 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002517 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518 } finally {
2519 Binder.restoreCallingIdentity(identity);
2520 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002521 }
2522
2523 @Override
2524 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2525 String number, int port, String text, PendingIntent sentIntent) {
2526 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002527 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002528 enforceSendSmsPermission();
2529 // Make the calls as the phone process.
2530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2533 if (port == 0) {
2534 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2535 sentIntent, null, false);
2536 } else {
2537 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2538 smsManager.sendDataMessageWithSelfPermissions(number, null,
2539 (short) port, data, sentIntent, null);
2540 }
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
2543 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002544 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002545 /**
fionaxu0152e512016-11-14 13:36:14 -08002546 * Sets the voice activation state of a given subId.
2547 */
2548 @Override
2549 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2551 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 phone.setVoiceActivationState(activationState);
2558 } else {
2559 loge("setVoiceActivationState fails with invalid subId: " + subId);
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002563 }
2564 }
2565
2566 /**
2567 * Sets the data activation state of a given subId.
2568 */
2569 @Override
2570 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2572 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone phone = getPhone(subId);
2577 if (phone != null) {
2578 phone.setDataActivationState(activationState);
2579 } else {
2580 loge("setVoiceActivationState fails with invalid subId: " + subId);
2581 }
2582 } finally {
2583 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002584 }
2585 }
2586
2587 /**
2588 * Returns the voice activation state of a given subId.
2589 */
2590 @Override
2591 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002592 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593
fionaxu0152e512016-11-14 13:36:14 -08002594 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 if (phone != null) {
2598 return phone.getVoiceActivationState();
2599 } else {
2600 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002604 }
2605 }
2606
2607 /**
2608 * Returns the data activation state of a given subId.
2609 */
2610 @Override
2611 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002612 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613
fionaxu0152e512016-11-14 13:36:14 -08002614 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 if (phone != null) {
2618 return phone.getDataActivationState();
2619 } else {
2620 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002624 }
2625 }
2626
2627 /**
Wink Saville36469e72014-06-11 15:17:00 -07002628 * Returns the unread count of voicemails for a subId
2629 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002630 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002631 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2633 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2634 return 0;
2635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 final Phone phone = getPhone(subId);
2639 if (phone != null) {
2640 return phone.getVoiceMessageCount();
2641 } else {
2642 return 0;
2643 }
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648
2649 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002650 * returns true, if the device is in a state where both voice and data
2651 * are supported simultaneously. This can change based on location or network condition.
2652 */
2653 @Override
2654 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 final Phone phone = getPhone(subId);
2658 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002662 }
2663
2664 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002665 * Send the dialer code if called from the current default dialer or the caller has
2666 * carrier privilege.
2667 * @param inputCode The dialer code to send
2668 */
2669 @Override
2670 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002671 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002672 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002673 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2674 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002675 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002676 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2677 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679
2680 final long identity = Binder.clearCallingIdentity();
2681 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002682 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
fionaxu235cc5e2017-03-06 22:25:57 -08002686 }
2687
2688 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002689 * Returns the data network type.
2690 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 *
2692 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2693 */
2694 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002695 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 final Phone phone = getPhone(getDefaultSubscription());
2699 if (phone != null) {
2700 return phone.getServiceState().getDataNetworkType();
2701 } else {
2702 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002706 }
Wink Saville36469e72014-06-11 15:17:00 -07002707 }
2708
Pengquan Menga1bb6272018-09-06 09:59:22 -07002709 @Override
2710 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002711 if (!isActiveSubscription(subId)) {
2712 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2713 }
2714
Pengquan Menga1bb6272018-09-06 09:59:22 -07002715 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2716 }
2717
Brad Ebinger35c841c2018-10-01 10:40:55 -07002718 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002719 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2720 throws RemoteException {
2721 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2723 final long token = Binder.clearCallingIdentity();
2724 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002725 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002726 .addRegistrationCallbackForSubscription(c, subId);
2727 } finally {
2728 Binder.restoreCallingIdentity(token);
2729 }
2730 }
2731
2732 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002733 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2734 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2736 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002737 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002738 .removeRegistrationCallbackForSubscription(c, subId));
2739 }
2740
2741 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002742 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2743 throws RemoteException {
2744 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2746 final long token = Binder.clearCallingIdentity();
2747 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002748 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002749 .addCapabilitiesCallbackForSubscription(c, subId);
2750 } finally {
2751 Binder.restoreCallingIdentity(token);
2752 }
2753 }
2754
2755 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002756 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2757 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2759 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002760 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002761 .removeCapabilitiesCallbackForSubscription(c, subId));
2762 }
2763
2764 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002765 public boolean isCapable(int subId, int capability, int regTech) {
2766 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002767 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2768 final long token = Binder.clearCallingIdentity();
2769 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002770 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002771 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2772 } catch (ImsException e) {
2773 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2774 return false;
2775 } finally {
2776 Binder.restoreCallingIdentity(token);
2777 }
2778 }
2779
2780 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002781 public boolean isAvailable(int subId, int capability, int regTech) {
2782 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002783 final long token = Binder.clearCallingIdentity();
2784 try {
2785 Phone phone = getPhone(subId);
2786 if (phone == null) return false;
2787 return phone.isImsCapabilityAvailable(capability, regTech);
2788 } finally {
2789 Binder.restoreCallingIdentity(token);
2790 }
2791 }
2792
2793 @Override
2794 public boolean isAdvancedCallingSettingEnabled(int subId) {
2795 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2797 final long token = Binder.clearCallingIdentity();
2798 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002799 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002800 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2801 } finally {
2802 Binder.restoreCallingIdentity(token);
2803 }
2804 }
2805
2806 @Override
2807 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2809 "setAdvancedCallingSetting");
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002813 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002814 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
2818 }
2819
2820 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002821 public boolean isVtSettingEnabled(int subId) {
2822 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002826 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002827 getSlotIndexOrException(subId)).isVtEnabledByUser();
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
2830 }
2831 }
2832
2833 @Override
2834 public void setVtSetting(int subId, boolean isEnabled) {
2835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2836 "setVtSetting");
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002840 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002841 } finally {
2842 Binder.restoreCallingIdentity(identity);
2843 }
2844 }
2845
2846 @Override
2847 public boolean isVoWiFiSettingEnabled(int subId) {
2848 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002852 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002853 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
2856 }
2857 }
2858
2859 @Override
2860 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2862 "setVoWiFiSetting");
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
2870 }
2871
2872 @Override
2873 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2874 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002878 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002879 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
2882 }
2883 }
2884
2885 @Override
2886 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2888 "setVoWiFiRoamingSetting");
2889 final long identity = Binder.clearCallingIdentity();
2890 try {
2891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002892 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002893 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
2896 }
2897 }
2898
2899 @Override
2900 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2902 "setVoWiFiNonPersistent");
2903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002906 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002907 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
2910 }
2911 }
2912
2913 @Override
2914 public int getVoWiFiModeSetting(int subId) {
2915 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2916 final long identity = Binder.clearCallingIdentity();
2917 try {
2918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002919 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002920 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
2923 }
2924 }
2925
2926 @Override
2927 public void setVoWiFiModeSetting(int subId, int mode) {
2928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2929 "setVoWiFiModeSetting");
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002933 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002934 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
2938 }
2939
2940 @Override
2941 public int getVoWiFiRoamingModeSetting(int subId) {
2942 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2943 final long identity = Binder.clearCallingIdentity();
2944 try {
2945 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002946 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002947 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
2951 }
2952
2953 @Override
2954 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2956 "setVoWiFiRoamingModeSetting");
2957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002960 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 }
2966
2967 @Override
2968 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2970 "setRttCapabilityEnabled");
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002974 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002975 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
2979 }
2980
2981 @Override
2982 public boolean isTtyOverVolteEnabled(int subId) {
2983 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
2992 }
2993
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002994 @Override
2995 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2996 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003000 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003001 .getConfigInterface().addConfigCallback(callback);
3002 } catch (ImsException e) {
3003 throw new IllegalArgumentException(e.getMessage());
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
3007 }
3008
3009 @Override
3010 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3011 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003015 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003016 .getConfigInterface().removeConfigCallback(callback);
3017 } catch (ImsException e) {
3018 throw new IllegalArgumentException(e.getMessage());
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public int getImsProvisioningInt(int subId, int key) {
3026 enforceReadPrivilegedPermission("getImsProvisioningInt");
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003030 return ImsManager.getInstance(mApp,
3031 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003032 } catch (ImsException e) {
3033 throw new IllegalArgumentException(e.getMessage());
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 @Override
3040 public String getImsProvisioningString(int subId, int key) {
3041 enforceReadPrivilegedPermission("getImsProvisioningString");
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003045 return ImsManager.getInstance(mApp,
3046 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003047 } catch (ImsException e) {
3048 throw new IllegalArgumentException(e.getMessage());
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
3052 }
3053
3054 @Override
3055 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3057 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003061 return ImsManager.getInstance(mApp,
3062 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003063 } catch (ImsException e) {
3064 throw new IllegalArgumentException(e.getMessage());
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
3071 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3073 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003077 return ImsManager.getInstance(mApp,
3078 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003079 } catch (ImsException e) {
3080 throw new IllegalArgumentException(e.getMessage());
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
3084 }
3085
Brad Ebinger35c841c2018-10-01 10:40:55 -07003086 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3087 int slotId = SubscriptionManager.getSlotIndex(subId);
3088 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3089 throw new IllegalArgumentException("Invalid Subscription Id.");
3090 }
3091 return slotId;
3092 }
3093
Wink Saville36469e72014-06-11 15:17:00 -07003094 /**
3095 * Returns the network type for a subId
3096 */
3097 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003098 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003100 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003101 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3102 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 final Phone phone = getPhone(subId);
3107 if (phone != null) {
3108 return phone.getServiceState().getDataNetworkType();
3109 } else {
3110 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3111 }
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003115 }
3116
3117 /**
3118 * Returns the data network type
3119 */
3120 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003121 public int getDataNetworkType(String callingPackage) {
3122 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003123 }
3124
3125 /**
3126 * Returns the data network type for a subId
3127 */
3128 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003129 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003131 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003132 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3133 }
3134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 final Phone phone = getPhone(subId);
3138 if (phone != null) {
3139 return phone.getServiceState().getDataNetworkType();
3140 } else {
3141 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3142 }
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146 }
3147
3148 /**
Wink Saville36469e72014-06-11 15:17:00 -07003149 * Returns the Voice network type for a subId
3150 */
3151 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003152 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003154 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3156 }
3157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 final Phone phone = getPhone(subId);
3161 if (phone != null) {
3162 return phone.getServiceState().getVoiceNetworkType();
3163 } else {
3164 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3165 }
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 }
3170
3171 /**
3172 * @return true if a ICC card is present
3173 */
3174 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003175 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003176 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3177 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003178 }
3179
3180 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003181 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003182 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003183 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003184 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = PhoneFactory.getPhone(slotIndex);
3188 if (phone != null) {
3189 return phone.getIccCard().hasIccCard();
3190 } else {
3191 return false;
3192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
3198 /**
3199 * Return if the current radio is LTE on CDMA. This
3200 * is a tri-state return value as for a period of time
3201 * the mode may be unknown.
3202 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003203 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003205 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003207 @Override
3208 public int getLteOnCdmaMode(String callingPackage) {
3209 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003210 }
3211
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003213 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003215 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003216 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3217 }
3218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 final Phone phone = getPhone(subId);
3222 if (phone == null) {
3223 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3224 } else {
3225 return phone.getLteOnCdmaMode();
3226 }
3227 } finally {
3228 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003229 }
Wink Saville36469e72014-06-11 15:17:00 -07003230 }
3231
Wink Saville36469e72014-06-11 15:17:00 -07003232 /**
3233 * {@hide}
3234 * Returns Default subId, 0 in the case of single standby.
3235 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003236 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003237 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003238 }
3239
Shishir Agrawala9f32182016-04-12 12:00:16 -07003240 private int getSlotForDefaultSubscription() {
3241 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3242 }
3243
Wink Savilleb564aae2014-10-23 10:18:09 -07003244 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003245 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003246 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003247
Pengquan Menge92a50d2018-09-21 15:54:48 -07003248 private boolean isActiveSubscription(int subId) {
3249 return mSubscriptionController.isActiveSubId(subId);
3250 }
3251
Ihab Awadf2177b72013-11-25 13:33:23 -08003252 /**
3253 * @see android.telephony.TelephonyManager.WifiCallingChoices
3254 */
3255 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003256 final long identity = Binder.clearCallingIdentity();
3257 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003258 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003259 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3260 getWhenToMakeWifiCallsDefaultPreference());
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
3263 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003264 }
3265
3266 /**
3267 * @see android.telephony.TelephonyManager.WifiCallingChoices
3268 */
3269 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270 final long identity = Binder.clearCallingIdentity();
3271 try {
3272 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003273 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003278 }
3279
Sailesh Nepald1e68152013-12-12 19:08:02 -08003280 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003281 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003282 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003283 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003284
Shishir Agrawal566b7612013-10-28 14:41:00 -07003285 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003286 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3287 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3289 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 if (TextUtils.equals(ISDR_AID, aid)) {
3295 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003296 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3297 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003298 if (bestComponent == null
3299 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3300 loge("The calling package is not allowed to access ISD-R.");
3301 throw new SecurityException(
3302 "The calling package is not allowed to access ISD-R.");
3303 }
Derek Tan740e1672017-06-27 14:56:27 -07003304 }
Derek Tan740e1672017-06-27 14:56:27 -07003305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003306 if (DBG) {
3307 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3308 }
3309 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3310 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3311 if (DBG) log("iccOpenLogicalChannel: " + response);
3312 return response;
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003316 }
3317
3318 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003319 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3321 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3326 if (channel < 0) {
3327 return false;
3328 }
3329 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3330 if (DBG) log("iccCloseLogicalChannel: " + success);
3331 return success;
3332 } finally {
3333 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003334 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003335 }
3336
3337 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003338 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003339 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3341 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 if (DBG) {
3346 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3347 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3348 + p3 + " data=" + data);
3349 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351 if (channel < 0) {
3352 return "";
3353 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3356 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3357 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359 // Append the returned status code to the end of the response payload.
3360 String s = Integer.toHexString(
3361 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3362 if (response.payload != null) {
3363 s = IccUtils.bytesToHexString(response.payload) + s;
3364 }
3365 return s;
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003368 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003369 }
Jake Hambye994d462014-02-03 13:10:13 -08003370
Evan Charltonc66da362014-05-16 14:06:40 -07003371 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003372 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3373 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3375 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3381 && TextUtils.equals(ISDR_AID, data)) {
3382 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003383 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3384 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003385 if (bestComponent == null
3386 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3387 loge("The calling package is not allowed to select ISD-R.");
3388 throw new SecurityException(
3389 "The calling package is not allowed to select ISD-R.");
3390 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003391 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 if (DBG) {
3394 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3395 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3396 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3399 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3400 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402 // Append the returned status code to the end of the response payload.
3403 String s = Integer.toHexString(
3404 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3405 if (response.payload != null) {
3406 s = IccUtils.bytesToHexString(response.payload) + s;
3407 }
3408 return s;
3409 } finally {
3410 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003411 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003412 }
3413
3414 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003415 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003416 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3418 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 if (DBG) {
3423 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3424 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3425 }
3426
3427 IccIoResult response =
3428 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3429 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3430 subId);
3431
3432 if (DBG) {
3433 log("Exchange SIM_IO [R]" + response);
3434 }
3435
3436 byte[] result = null;
3437 int length = 2;
3438 if (response.payload != null) {
3439 length = 2 + response.payload.length;
3440 result = new byte[length];
3441 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3442 } else {
3443 result = new byte[length];
3444 }
3445
3446 result[length - 1] = (byte) response.sw2;
3447 result[length - 2] = (byte) response.sw1;
3448 return result;
3449 } finally {
3450 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003451 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003452 }
3453
Nathan Haroldb3014052017-01-25 15:57:32 -08003454 /**
3455 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3456 * on a particular subscription
3457 */
sqianb6e41952018-03-12 14:54:01 -07003458 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3460 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3461 return null;
3462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463
3464 final long identity = Binder.clearCallingIdentity();
3465 try {
3466 if (appType != TelephonyManager.APPTYPE_USIM
3467 && appType != TelephonyManager.APPTYPE_SIM) {
3468 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3469 return null;
3470 }
3471 Object response = sendRequest(
3472 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3473 if (response instanceof String[]) {
3474 return (String[]) response;
3475 }
3476 // Response is an Exception of some kind,
3477 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003478 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003481 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003482 }
3483
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003484 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003485 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3487 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3492 if (response.payload == null) {
3493 return "";
3494 }
Evan Charltonc66da362014-05-16 14:06:40 -07003495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496 // Append the returned status code to the end of the response payload.
3497 String s = Integer.toHexString(
3498 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3499 s = IccUtils.bytesToHexString(response.payload) + s;
3500 return s;
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
3503 }
Evan Charltonc66da362014-05-16 14:06:40 -07003504 }
3505
Jake Hambye994d462014-02-03 13:10:13 -08003506 /**
3507 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3508 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3509 *
3510 * @param itemID the ID of the item to read
3511 * @return the NV item as a String, or null on error.
3512 */
3513 @Override
3514 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003515 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3517 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003518
3519 final long identity = Binder.clearCallingIdentity();
3520 try {
3521 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003522 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3524 return value;
3525 } finally {
3526 Binder.restoreCallingIdentity(identity);
3527 }
Jake Hambye994d462014-02-03 13:10:13 -08003528 }
3529
3530 /**
3531 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3532 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3533 *
3534 * @param itemID the ID of the item to read
3535 * @param itemValue the value to write, as a String
3536 * @return true on success; false on any failure
3537 */
3538 @Override
3539 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003540 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3542 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3547 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003548 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3550 return success;
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
Jake Hambye994d462014-02-03 13:10:13 -08003554 }
3555
3556 /**
3557 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3558 * Used for device configuration by some CDMA operators.
3559 *
3560 * @param preferredRoamingList byte array containing the new PRL
3561 * @return true on success; false on any failure
3562 */
3563 @Override
3564 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3566 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567
3568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3571 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3572 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3573 return success;
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
3576 }
Jake Hambye994d462014-02-03 13:10:13 -08003577 }
3578
3579 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003580 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003581 * Used for device configuration by some CDMA operators.
3582 *
chen xu6dac5ab2018-10-26 17:39:23 -07003583 * @param slotIndex - device slot.
3584 *
Jake Hambye994d462014-02-03 13:10:13 -08003585 * @return true on success; false on any failure
3586 */
3587 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003588 public boolean resetModemConfig(int slotIndex) {
3589 Phone phone = PhoneFactory.getPhone(slotIndex);
3590 if (phone != null) {
3591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3592 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593
chen xu6dac5ab2018-10-26 17:39:23 -07003594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3597 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3598 return success;
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
3601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602 }
chen xu6dac5ab2018-10-26 17:39:23 -07003603 return false;
3604 }
3605
3606 /**
3607 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3608 *
3609 * @param slotIndex - device slot.
3610 *
3611 * @return true on success; false on any failure
3612 */
3613 @Override
3614 public boolean rebootModem(int slotIndex) {
3615 Phone phone = PhoneFactory.getPhone(slotIndex);
3616 if (phone != null) {
3617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3618 mApp, phone.getSubId(), "rebootModem");
3619
3620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3623 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3624 return success;
3625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
3628 }
3629 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003630 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003631
Svet Ganovb320e182015-04-16 12:30:10 -07003632 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003633 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003635 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003636 return new String[0];
3637 }
3638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003641 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
Wink Saville36469e72014-06-11 15:17:00 -07003645 }
3646
Brad Ebinger51f743a2017-01-23 13:50:20 -08003647 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003648 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3649 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003650 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003651 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003652 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653
3654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 PhoneFactory.getImsResolver().enableIms(slotId);
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003660 }
3661
3662 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003663 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3664 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003665 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003666 public void disableIms(int slotId) {
3667 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668
3669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 PhoneFactory.getImsResolver().disableIms(slotId);
3672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003675 }
3676
3677 /**
3678 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3679 * feature or {@link null} if the service is not available. If the feature is available, the
3680 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3681 */
3682 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003683 IImsServiceFeatureCallback callback) {
3684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003692 }
3693
3694 /**
3695 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3696 * feature during emergency calling or {@link null} if the service is not available. If the
3697 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3698 * listener for feature updates.
3699 */
3700 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003709 }
3710
Brad Ebinger5f64b052017-12-14 14:26:15 -08003711 /**
3712 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3713 * specified.
3714 */
3715 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3716 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003717
3718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003724 }
3725
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003726 /**
3727 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3728 * specified.
3729 */
3730 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732
3733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003739 }
3740
Brad Ebinger884c07b2018-02-15 16:17:40 -08003741 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003742 * Sets the ImsService Package Name that Telephony will bind to.
3743 *
3744 * @param slotId the slot ID that the ImsService should bind for.
3745 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3746 * ImsService is the device default ImsService.
3747 * @param packageName The package name of the application that contains the ImsService to bind
3748 * to.
3749 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3750 * @hide
3751 */
3752 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003753 int[] subIds = SubscriptionManager.getSubId(slotId);
3754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3755 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3756 "setImsService");
3757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003758 final long identity = Binder.clearCallingIdentity();
3759 try {
3760 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3761 isCarrierImsService, packageName);
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003765 }
3766
3767 /**
3768 * Return the ImsService configuration.
3769 *
3770 * @param slotId The slot that the ImsService is associated with.
3771 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3772 * the device default.
3773 * @return the package name of the ImsService configuration.
3774 */
3775 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003776 int[] subIds = SubscriptionManager.getSubId(slotId);
3777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3778 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3779 "getImsService");
3780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3784 isCarrierImsService);
3785 } finally {
3786 Binder.restoreCallingIdentity(identity);
3787 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003788 }
3789
Wink Saville36469e72014-06-11 15:17:00 -07003790 public void setImsRegistrationState(boolean registered) {
3791 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792
3793 final long identity = Binder.clearCallingIdentity();
3794 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
Wink Saville36469e72014-06-11 15:17:00 -07003799 }
3800
3801 /**
Stuart Scott54788802015-03-30 13:18:01 -07003802 * Set the network selection mode to automatic.
3803 *
3804 */
3805 @Override
3806 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3808 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809
Pengquan Menge92a50d2018-09-21 15:54:48 -07003810 if (!isActiveSubscription(subId)) {
3811 return;
3812 }
3813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3817 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
Stuart Scott54788802015-03-30 13:18:01 -07003821 }
3822
Pengquan Mengea84e042018-09-20 14:57:26 -07003823 /**
3824 * Ask the radio to connect to the input network and change selection mode to manual.
3825 *
3826 * @param subId the id of the subscription.
3827 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3828 * the operator to attach to.
3829 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3830 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3831 * normal network selection next time.
3832 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003833 */
3834 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003835 public boolean setNetworkSelectionModeManual(
3836 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3838 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003839
3840 if (!isActiveSubscription(subId)) {
3841 return false;
3842 }
3843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003846 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003848 if (DBG) {
3849 log("setNetworkSelectionModeManual: subId: " + subId
3850 + " operator: " + operatorInfo);
3851 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003852 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
3855 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003856 }
3857
3858 /**
3859 * Scans for available networks.
3860 */
3861 @Override
3862 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3864 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865
Pengquan Menga1bb6272018-09-06 09:59:22 -07003866 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867 try {
3868 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003869 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003874 }
3875
3876 /**
yinxub1bed742017-04-17 11:45:04 -07003877 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003878 *
yinxub1bed742017-04-17 11:45:04 -07003879 * @param subId id of the subscription
3880 * @param request contains the radio access networks with bands/channels to scan
3881 * @param messenger callback messenger for scan results or errors
3882 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003883 * @return the id of the requested scan which can be used to stop the scan.
3884 */
3885 @Override
3886 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3887 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3889 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890
3891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 return mNetworkScanRequestTracker.startNetworkScan(
3894 request, messenger, binder, getPhone(subId));
3895 } finally {
3896 Binder.restoreCallingIdentity(identity);
3897 }
yinxu504e1392017-04-12 16:03:22 -07003898 }
3899
3900 /**
3901 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003902 *
3903 * @param subId id of the subscription
3904 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003905 */
3906 @Override
3907 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3909 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910
3911 final long identity = Binder.clearCallingIdentity();
3912 try {
3913 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3914 } finally {
3915 Binder.restoreCallingIdentity(identity);
3916 }
yinxu504e1392017-04-12 16:03:22 -07003917 }
3918
3919 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003920 * Get the calculated preferred network type.
3921 * Used for debugging incorrect network type.
3922 *
3923 * @return the preferred network type, defined in RILConstants.java.
3924 */
3925 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003926 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003927 final Phone defaultPhone = getDefaultPhone();
3928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3929 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003930 return RILConstants.PREFERRED_NETWORK_MODE;
3931 }
3932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003936 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
Junda Liu84d15a22014-07-02 11:21:04 -07003940 }
3941
3942 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003943 * Get the preferred network type.
3944 * Used for device configuration by some CDMA operators.
3945 *
3946 * @return the preferred network type, defined in RILConstants.java.
3947 */
3948 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003949 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08003950 TelephonyPermissions
3951 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
3952 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953
3954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 if (DBG) log("getPreferredNetworkType");
3957 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3958 int networkType = (result != null ? result[0] : -1);
3959 if (DBG) log("getPreferredNetworkType: " + networkType);
3960 return networkType;
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003964 }
3965
3966 /**
3967 * Set the preferred network type.
3968 * Used for device configuration by some CDMA operators.
3969 *
3970 * @param networkType the preferred network type, defined in RILConstants.java.
3971 * @return true on success; false on any failure.
3972 */
3973 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003974 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3976 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003977
3978 final long identity = Binder.clearCallingIdentity();
3979 try {
3980 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3981 Boolean success = (Boolean) sendRequest(
3982 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3983 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3984 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003985 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3987 }
3988 return success;
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003991 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003992 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003993
3994 /**
Junda Liu475951f2014-11-07 16:45:03 -08003995 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07003996 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003997 * tethering.
3998 *
3999 * @return 0: Not required. 1: required. 2: Not set.
4000 * @hide
4001 */
4002 @Override
4003 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005
4006 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004007 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004009 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07004011 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004012 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 dunRequired = 1;
4014 }
4015 return dunRequired;
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004018 }
Junda Liu475951f2014-11-07 16:45:03 -08004019 }
4020
4021 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004022 * Set mobile data enabled
4023 * Used by the user through settings etc to turn on/off mobile data
4024 *
4025 * @param enable {@code true} turn turn data on, else {@code false}
4026 */
4027 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004028 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4030 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 int phoneId = mSubscriptionController.getPhoneId(subId);
4035 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4036 Phone phone = PhoneFactory.getPhone(phoneId);
4037 if (phone != null) {
4038 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004039 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004040 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004041 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 }
4043 } finally {
4044 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004045 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004046 }
4047
4048 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004049 * Get the user enabled state of Mobile Data.
4050 *
4051 * TODO: remove and use isUserDataEnabled.
4052 * This can't be removed now because some vendor codes
4053 * calls through ITelephony directly while they should
4054 * use TelephonyManager.
4055 *
4056 * @return true on enabled
4057 */
4058 @Override
4059 public boolean getDataEnabled(int subId) {
4060 return isUserDataEnabled(subId);
4061 }
4062
4063 /**
4064 * Get whether mobile data is enabled per user setting.
4065 *
4066 * There are other factors deciding whether mobile data is actually enabled, but they are
4067 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004068 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004069 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004070 *
4071 * @return {@code true} if data is enabled else {@code false}
4072 */
4073 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004074 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004075 try {
4076 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4077 null);
4078 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082
4083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 int phoneId = mSubscriptionController.getPhoneId(subId);
4086 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4087 Phone phone = PhoneFactory.getPhone(phoneId);
4088 if (phone != null) {
4089 boolean retVal = phone.isUserDataEnabled();
4090 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4091 return retVal;
4092 } else {
4093 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4094 return false;
4095 }
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004098 }
4099 }
4100
4101 /**
4102 * Get whether mobile data is enabled.
4103 *
4104 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4105 * whether mobile data is actually enabled.
4106 *
4107 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4108 *
4109 * @return {@code true} if data is enabled else {@code false}
4110 */
4111 @Override
4112 public boolean isDataEnabled(int subId) {
4113 try {
4114 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4115 null);
4116 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4118 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004119 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120
4121 final long identity = Binder.clearCallingIdentity();
4122 try {
4123 int phoneId = mSubscriptionController.getPhoneId(subId);
4124 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4125 Phone phone = PhoneFactory.getPhone(phoneId);
4126 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004127 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4129 return retVal;
4130 } else {
4131 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4132 return false;
4133 }
4134 } finally {
4135 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004136 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004137 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004138
4139 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004140 public int getCarrierPrivilegeStatus(int subId) {
4141 final Phone phone = getPhone(subId);
4142 if (phone == null) {
4143 loge("getCarrierPrivilegeStatus: Invalid subId");
4144 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4145 }
4146 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004147 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004148 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004149 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4150 }
4151 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004152 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004153 }
Junda Liu29340342014-07-10 15:23:27 -07004154
4155 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4157 final Phone phone = getPhone(subId);
4158 if (phone == null) {
4159 loge("getCarrierPrivilegeStatus: Invalid subId");
4160 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4161 }
4162 UiccProfile profile =
4163 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4164 if (profile == null) {
4165 loge("getCarrierPrivilegeStatus: No UICC");
4166 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4167 }
4168 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4169 }
4170
4171 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004172 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004173 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004174 if (TextUtils.isEmpty(pkgName))
4175 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004176 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004177 if (card == null) {
4178 loge("checkCarrierPrivilegesForPackage: No UICC");
4179 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4180 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004181 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4182 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004183 }
4184
4185 @Override
4186 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004187 if (TextUtils.isEmpty(pkgName))
4188 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004189 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4190 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4191 UiccCard card = UiccController.getInstance().getUiccCard(i);
4192 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004193 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004194 continue;
4195 }
4196
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004197 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004198 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4199 break;
4200 }
4201 }
4202
4203 return result;
Junda Liu29340342014-07-10 15:23:27 -07004204 }
Derek Tan89e89d42014-07-08 17:00:10 -07004205
4206 @Override
Junda Liue64de782015-04-16 17:19:16 -07004207 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4208 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4209 loge("phoneId " + phoneId + " is not valid.");
4210 return null;
4211 }
4212 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004213 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004214 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004215 return null ;
4216 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004217 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004218 }
4219
Amith Yamasani6e118872016-02-19 12:53:51 -08004220 @Override
4221 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004222 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004223 List<String> privilegedPackages = new ArrayList<>();
4224 List<PackageInfo> packages = null;
4225 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4226 UiccCard card = UiccController.getInstance().getUiccCard(i);
4227 if (card == null) {
4228 // No UICC in that slot.
4229 continue;
4230 }
4231 if (card.hasCarrierPrivilegeRules()) {
4232 if (packages == null) {
4233 // Only check packages in user 0 for now
4234 packages = pm.getInstalledPackagesAsUser(
4235 PackageManager.MATCH_DISABLED_COMPONENTS
4236 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4237 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4238 }
4239 for (int p = packages.size() - 1; p >= 0; p--) {
4240 PackageInfo pkgInfo = packages.get(p);
4241 if (pkgInfo != null && pkgInfo.packageName != null
4242 && card.getCarrierPrivilegeStatus(pkgInfo)
4243 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4244 privilegedPackages.add(pkgInfo.packageName);
4245 }
4246 }
4247 }
4248 }
4249 return privilegedPackages;
4250 }
4251
Wink Savilleb564aae2014-10-23 10:18:09 -07004252 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004253 final Phone phone = getPhone(subId);
4254 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004255 if (card == null) {
4256 loge("getIccId: No UICC");
4257 return null;
4258 }
4259 String iccId = card.getIccId();
4260 if (TextUtils.isEmpty(iccId)) {
4261 loge("getIccId: ICC ID is null or empty.");
4262 return null;
4263 }
4264 return iccId;
4265 }
4266
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004267 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004268 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4269 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004270 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4271 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 final String iccId = getIccId(subId);
4276 final Phone phone = getPhone(subId);
4277 if (phone == null) {
4278 return false;
4279 }
4280 final String subscriberId = phone.getSubscriberId();
4281
4282 if (DBG_MERGE) {
4283 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4284 + subscriberId + " to " + number);
4285 }
4286
4287 if (TextUtils.isEmpty(iccId)) {
4288 return false;
4289 }
4290
4291 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4292
4293 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4294 if (alphaTag == null) {
4295 editor.remove(alphaTagPrefKey);
4296 } else {
4297 editor.putString(alphaTagPrefKey, alphaTag);
4298 }
4299
4300 // Record both the line number and IMSI for this ICCID, since we need to
4301 // track all merged IMSIs based on line number
4302 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4303 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4304 if (number == null) {
4305 editor.remove(numberPrefKey);
4306 editor.remove(subscriberPrefKey);
4307 } else {
4308 editor.putString(numberPrefKey, number);
4309 editor.putString(subscriberPrefKey, subscriberId);
4310 }
4311
4312 editor.commit();
4313 return true;
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004316 }
Derek Tan7226c842014-07-02 17:42:23 -07004317 }
4318
4319 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004320 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004321 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004323 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004324 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004325 return null;
4326 }
Derek Tan97ebb422014-09-05 16:55:38 -07004327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 String iccId = getIccId(subId);
4331 if (iccId != null) {
4332 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4333 if (DBG_MERGE) {
4334 log("getLine1NumberForDisplay returning "
4335 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4336 }
4337 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4340 return null;
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004343 }
Derek Tan7226c842014-07-02 17:42:23 -07004344 }
4345
4346 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004347 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004349 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004350 return null;
4351 }
Derek Tan97ebb422014-09-05 16:55:38 -07004352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 String iccId = getIccId(subId);
4356 if (iccId != null) {
4357 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4358 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4359 }
4360 return null;
4361 } finally {
4362 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004363 }
Derek Tan7226c842014-07-02 17:42:23 -07004364 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004365
4366 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004367 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004368 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4369 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004371 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4372 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004373 return null;
4374 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004375
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004376 final long identity = Binder.clearCallingIdentity();
4377 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004378 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004379 final TelephonyManager tele = TelephonyManager.from(context);
4380 final SubscriptionManager sub = SubscriptionManager.from(context);
4381
4382 // Figure out what subscribers are currently active
4383 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4384 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4385 // the process, where TelephonyManager was instantiated.
4386 // Otherwise AppOps check will fail.
4387
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004388 final int[] subIds = sub.getActiveSubscriptionIdList();
4389 for (int subId : subIds) {
4390 activeSubscriberIds.add(tele.getSubscriberId(subId));
4391 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004392
4393 // First pass, find a number override for an active subscriber
4394 String mergeNumber = null;
4395 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4396 for (String key : prefs.keySet()) {
4397 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4398 final String subscriberId = (String) prefs.get(key);
4399 if (activeSubscriberIds.contains(subscriberId)) {
4400 final String iccId = key.substring(
4401 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4402 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4403 mergeNumber = (String) prefs.get(numberKey);
4404 if (DBG_MERGE) {
4405 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4406 + " for active subscriber " + subscriberId);
4407 }
4408 if (!TextUtils.isEmpty(mergeNumber)) {
4409 break;
4410 }
4411 }
4412 }
4413 }
4414
4415 // Shortcut when no active merged subscribers
4416 if (TextUtils.isEmpty(mergeNumber)) {
4417 return null;
4418 }
4419
4420 // Second pass, find all subscribers under that line override
4421 final ArraySet<String> result = new ArraySet<>();
4422 for (String key : prefs.keySet()) {
4423 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4424 final String number = (String) prefs.get(key);
4425 if (mergeNumber.equals(number)) {
4426 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4427 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4428 final String subscriberId = (String) prefs.get(subscriberKey);
4429 if (!TextUtils.isEmpty(subscriberId)) {
4430 result.add(subscriberId);
4431 }
4432 }
4433 }
4434 }
4435
4436 final String[] resultArray = result.toArray(new String[result.size()]);
4437 Arrays.sort(resultArray);
4438 if (DBG_MERGE) {
4439 Slog.d(LOG_TAG,
4440 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4441 }
4442 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004443 } finally {
4444 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004445 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004446 }
4447
4448 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004449 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004450 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4451 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452
4453 final long identity = Binder.clearCallingIdentity();
4454 try {
4455 final Phone phone = getPhone(subId);
4456 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4457 } finally {
4458 Binder.restoreCallingIdentity(identity);
4459 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004460 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004461
4462 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004463 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004464 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4465 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004466 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467
4468 final long identity = Binder.clearCallingIdentity();
4469 try {
4470 final Phone phone = getPhone(subId);
4471 if (phone == null) {
4472 return false;
4473 }
4474 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4475 cdmaNonRoamingList);
4476 } finally {
4477 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004478 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004479 }
4480
4481 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004482 @Deprecated
4483 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4484 enforceModifyPermission();
4485
4486 int returnValue = 0;
4487 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004488 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004489 if(result.exception == null) {
4490 if (result.result != null) {
4491 byte[] responseData = (byte[])(result.result);
4492 if(responseData.length > oemResp.length) {
4493 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4494 responseData.length + "bytes. Buffer Size is " +
4495 oemResp.length + "bytes.");
4496 }
4497 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4498 returnValue = responseData.length;
4499 }
4500 } else {
4501 CommandException ex = (CommandException) result.exception;
4502 returnValue = ex.getCommandError().ordinal();
4503 if(returnValue > 0) returnValue *= -1;
4504 }
4505 } catch (RuntimeException e) {
4506 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4507 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4508 if(returnValue > 0) returnValue *= -1;
4509 }
4510
4511 return returnValue;
4512 }
4513
4514 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004515 public void setRadioCapability(RadioAccessFamily[] rafs) {
4516 try {
4517 ProxyController.getInstance().setRadioCapability(rafs);
4518 } catch (RuntimeException e) {
4519 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4520 }
4521 }
4522
4523 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004524 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004525 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004526 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004527 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004528 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530 final long identity = Binder.clearCallingIdentity();
4531 try {
chen xub97461a2018-10-26 14:17:57 -07004532 TelephonyPermissions
4533 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4534 mApp, phone.getSubId(), "getRadioAccessFamily");
4535 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
chen xub97461a2018-10-26 14:17:57 -07004539 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004540 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004541
4542 @Override
4543 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004544 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004545 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546
4547 final long identity = Binder.clearCallingIdentity();
4548 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004549 ImsManager.getInstance(defaultPhone.getContext(),
4550 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551 } finally {
4552 Binder.restoreCallingIdentity(identity);
4553 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004554 }
4555
4556 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004557 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004558 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004560 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004561 return false;
4562 }
Svet Ganovb320e182015-04-16 12:30:10 -07004563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 final long identity = Binder.clearCallingIdentity();
4565 try {
4566 // Check the user preference and the system-level IMS setting. Even if the user has
4567 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4568 // In the long run, we may instead need to check if there exists a connection service
4569 // which can support video calling.
4570 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004571 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 return imsManager.isVtEnabledByPlatform()
4573 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4574 && imsManager.isVtEnabledByUser();
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004578 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004579
Andrew Leea1239f22015-03-02 17:44:07 -08004580 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4583 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4584 return false;
4585 }
4586
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
4589 CarrierConfigManager configManager =
4590 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004591 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4593 } finally {
4594 Binder.restoreCallingIdentity(identity);
4595 }
Andrew Leea1239f22015-03-02 17:44:07 -08004596 }
4597
4598 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599 public boolean isWorldPhone(int subId, String callingPackage) {
4600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4601 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4602 return false;
4603 }
4604
4605 final long identity = Binder.clearCallingIdentity();
4606 try {
4607 CarrierConfigManager configManager =
4608 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004609 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4611 } finally {
4612 Binder.restoreCallingIdentity(identity);
4613 }
Andrew Leea1239f22015-03-02 17:44:07 -08004614 }
4615
Andrew Lee9431b832015-03-09 18:46:45 -07004616 @Override
4617 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004618 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004619 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004620 }
4621
4622 @Override
4623 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 final long identity = Binder.clearCallingIdentity();
4625 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004626 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
Andrew Lee9431b832015-03-09 18:46:45 -07004630 }
4631
Hall Liuf6668912018-10-31 17:05:23 -07004632 /**
4633 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4634 * support for the feature and device firmware support.
4635 *
4636 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4637 */
4638 @Override
4639 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004641 final Phone phone = getPhone(subscriptionId);
4642 if (phone == null) {
4643 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4644 return false;
4645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004647 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4649 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004650 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 return isCarrierSupported && isDeviceSupported;
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Hall Liu98187582018-01-22 19:15:32 -08004655 }
4656
Hall Liuf6668912018-10-31 17:05:23 -07004657 /**
4658 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4659 * both also support RTT.
4660 */
4661 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 final long identity = Binder.clearCallingIdentity();
4663 try {
Hall Liuf6668912018-10-31 17:05:23 -07004664 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004665 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004669 }
4670
Sanket Padawe7310cc72015-01-14 09:53:20 -08004671 /**
4672 * Returns the unique device ID of phone, for example, the IMEI for
4673 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4674 *
4675 * <p>Requires Permission:
4676 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4677 */
4678 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004679 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004680 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004681 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004682 return null;
4683 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004684 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004685 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4686 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004687 return null;
4688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 return phone.getDeviceId();
4693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004696 }
4697
Ping Sunc67b7c22016-03-02 19:16:45 +08004698 /**
4699 * {@hide}
4700 * Returns the IMS Registration Status on a particular subid
4701 *
4702 * @param subId
4703 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004704 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004705 Phone phone = getPhone(subId);
4706 if (phone != null) {
4707 return phone.isImsRegistered();
4708 } else {
4709 return false;
4710 }
4711 }
4712
Santos Cordon7a1885b2015-02-03 11:15:19 -08004713 @Override
4714 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004715 final long identity = Binder.clearCallingIdentity();
4716 try {
4717 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004721 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004722
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004723 /**
4724 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004725 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004726 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 Phone phone = getPhone(subId);
4730 if (phone != null) {
4731 return phone.isWifiCallingEnabled();
4732 } else {
4733 return false;
4734 }
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004737 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004738 }
4739
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004740 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004741 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004742 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004743 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004744 final long identity = Binder.clearCallingIdentity();
4745 try {
4746 Phone phone = getPhone(subId);
4747 if (phone != null) {
4748 return phone.isVideoEnabled();
4749 } else {
4750 return false;
4751 }
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004754 }
4755 }
4756
4757 /**
4758 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4759 * defined in {@link ImsRegistrationImplBase}.
4760 */
4761 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 final long identity = Binder.clearCallingIdentity();
4763 try {
4764 Phone phone = getPhone(subId);
4765 if (phone != null) {
4766 return phone.getImsRegistrationTech();
4767 } else {
4768 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4769 }
4770 } finally {
4771 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004772 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004773 }
4774
Stuart Scott8eef64f2015-04-08 15:13:54 -07004775 @Override
4776 public void factoryReset(int subId) {
4777 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004778 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4779 return;
4780 }
4781
Svet Ganovcc087f82015-05-12 20:35:54 -07004782 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004783
Svet Ganovcc087f82015-05-12 20:35:54 -07004784 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004785 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4786 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004787 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004788 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004789 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004790 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4791 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004792 }
4793 } finally {
4794 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004795 }
4796 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004797
4798 @Override
4799 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800 final long identity = Binder.clearCallingIdentity();
4801 try {
4802 // We query all subscriptions instead of just the active ones, because
4803 // this might be called early on in the provisioning flow when the
4804 // subscriptions potentially aren't active yet.
4805 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4806 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004807 return null;
4808 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 // This function may be called very early, say, from the setup wizard, at
4811 // which point we won't have a default subscription set. If that's the case
4812 // we just choose the first, which will be valid in "most cases".
4813 final int defaultSubId = getDefaultSubscription();
4814 SubscriptionInfo info = null;
4815 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4816 info = slist.get(0);
4817 } else {
4818 for (SubscriptionInfo item : slist) {
4819 if (item.getSubscriptionId() == defaultSubId) {
4820 info = item;
4821 break;
4822 }
4823 }
4824
4825 if (info == null) {
4826 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004827 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004828 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830 // Try and fetch the locale from the carrier properties or from the SIM language
4831 // preferences (EF-PL and EF-LI)...
4832 final int mcc = info.getMcc();
4833 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4834 String simLanguage = null;
4835 if (defaultPhone != null) {
4836 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4837 if (localeFromDefaultSim != null) {
4838 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4839 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4840 return localeFromDefaultSim.toLanguageTag();
4841 } else {
4842 simLanguage = localeFromDefaultSim.getLanguage();
4843 }
4844 }
4845 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 // The SIM language preferences only store a language (e.g. fr = French), not an
4848 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4849 // the SIM and carrier preferences does not include a country we add the country
4850 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004851 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 if (mccLocale != null) {
4853 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4854 return mccLocale.toLanguageTag();
4855 }
4856
4857 if (DBG) log("No locale found - returning null");
4858 return null;
4859 } finally {
4860 Binder.restoreCallingIdentity(identity);
4861 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004862 }
4863
4864 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004865 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004866 }
4867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004868 /**
4869 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4870 */
4871 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004872 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004873 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004874
Chenjie Yu1ba97252018-01-11 18:16:20 -08004875 private final ModemActivityInfo mLastModemActivityInfo =
4876 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4877
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004878 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004879 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4880 * representing the state of the modem.
4881 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004882 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4883 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004884 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004885 */
4886 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004887 public void requestModemActivityInfo(ResultReceiver result) {
4888 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 ModemActivityInfo ret = null;
4894 synchronized (mLastModemActivityInfo) {
4895 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4896 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004897 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004898 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4900 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004901 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
4902 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 }
4904 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004905 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
4906 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 mLastModemActivityInfo.setIdleTimeMillis(
4908 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4909 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4910 mLastModemActivityInfo.setRxTimeMillis(
4911 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4912 mLastModemActivityInfo.setEnergyUsed(
4913 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4916 mLastModemActivityInfo.getSleepTimeMillis(),
4917 mLastModemActivityInfo.getIdleTimeMillis(),
4918 mLastModemActivityInfo.getTxTimeMillis(),
4919 mLastModemActivityInfo.getRxTimeMillis(),
4920 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004921 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004922 Bundle bundle = new Bundle();
4923 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4924 result.send(0, bundle);
4925 } finally {
4926 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004927 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004928 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004929
Siddharth Rayb8114062018-06-17 15:02:38 -07004930 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4931 // less than total activity duration.
4932 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4933 if (info == null) {
4934 return false;
4935 }
4936 int activityDurationMs =
4937 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4938 int totalTxTimeMs = 0;
4939 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4940 totalTxTimeMs += info.getTxTimeMillis()[i];
4941 }
4942 return (info.isValid()
4943 && (info.getSleepTimeMillis() <= activityDurationMs)
4944 && (info.getIdleTimeMillis() <= activityDurationMs)
4945 && (info.getRxTimeMillis() <= activityDurationMs)
4946 && (totalTxTimeMs <= activityDurationMs));
4947 }
4948
Jack Yu85bd38a2015-11-09 11:34:32 -08004949 /**
4950 * {@hide}
4951 * Returns the service state information on specified subscription.
4952 */
4953 @Override
4954 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004956 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004957 return null;
4958 }
4959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 final long identity = Binder.clearCallingIdentity();
4961 try {
4962 final Phone phone = getPhone(subId);
4963 if (phone == null) {
4964 return null;
4965 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 return phone.getServiceState();
4968 } finally {
4969 Binder.restoreCallingIdentity(identity);
4970 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004971 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004972
4973 /**
4974 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4975 *
4976 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4977 * voicemail ringtone.
4978 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4979 * PhoneAccount.
4980 */
4981 @Override
4982 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4986 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004987 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4991 } finally {
4992 Binder.restoreCallingIdentity(identity);
4993 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004994 }
4995
4996 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004997 * Sets the per-account voicemail ringtone.
4998 *
4999 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5000 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5001 *
5002 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5003 * voicemail ringtone.
5004 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5005 * PhoneAccount.
5006 */
5007 @Override
5008 public void setVoicemailRingtoneUri(String callingPackage,
5009 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005010 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005011 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5012 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005013 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5015 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5016 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018
5019 final long identity = Binder.clearCallingIdentity();
5020 try {
5021 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5022 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005023 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 }
5025 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005028 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005029 }
5030
5031 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005032 * Returns whether vibration is set for voicemail notification in Phone settings.
5033 *
5034 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5035 * voicemail vibration setting.
5036 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5037 */
5038 @Override
5039 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
5042 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5043 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005044 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5048 } finally {
5049 Binder.restoreCallingIdentity(identity);
5050 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005051 }
5052
Youhan Wange64578a2016-05-02 15:32:42 -07005053 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005054 * Sets the per-account voicemail vibration.
5055 *
5056 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5057 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5058 *
5059 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5060 * voicemail vibration setting.
5061 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5062 * specific PhoneAccount.
5063 */
5064 @Override
5065 public void setVoicemailVibrationEnabled(String callingPackage,
5066 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005067 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5069 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005070 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5072 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5073 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005074 }
5075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5079 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005080 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 }
5082 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005085 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005086 }
5087
5088 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005089 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5090 *
5091 * @throws SecurityException if the caller does not have the required permission
5092 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005093 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005094 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005095 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005096 }
5097
5098 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005099 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5100 * permission.
5101 *
5102 * @throws SecurityException if the caller does not have the required permission
5103 */
5104 private void enforceSendSmsPermission() {
5105 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5106 }
5107
5108 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005109 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005110 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005111 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005112 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005113 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114 final long identity = Binder.clearCallingIdentity();
5115 try {
5116 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005117 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118 if (componentName == null) {
5119 throw new SecurityException(
5120 "Caller not current active visual voicemail package[null]");
5121 }
5122 String vvmPackage = componentName.getPackageName();
5123 if (!callingPackage.equals(vvmPackage)) {
5124 throw new SecurityException("Caller not current active visual voicemail package["
5125 + vvmPackage + "]");
5126 }
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005129 }
5130 }
5131
5132 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005133 * Return the application ID for the app type.
5134 *
5135 * @param subId the subscription ID that this request applies to.
5136 * @param appType the uicc app type.
5137 * @return Application ID for specificied app type, or null if no uicc.
5138 */
5139 @Override
5140 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005141 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005142 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143
5144 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005145 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 if (phone == null) {
5147 return null;
5148 }
5149 String aid = null;
5150 try {
5151 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5152 .getApplicationByType(appType).getAid();
5153 } catch (Exception e) {
5154 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5155 }
5156 return aid;
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005159 }
Youhan Wange64578a2016-05-02 15:32:42 -07005160 }
5161
Youhan Wang4001d252016-05-11 10:29:41 -07005162 /**
5163 * Return the Electronic Serial Number.
5164 *
5165 * @param subId the subscription ID that this request applies to.
5166 * @return ESN or null if error.
5167 */
5168 @Override
5169 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005170 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005171 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172
5173 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005174 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 if (phone == null) {
5176 return null;
5177 }
5178 String esn = null;
5179 try {
5180 esn = phone.getEsn();
5181 } catch (Exception e) {
5182 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5183 }
5184 return esn;
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005187 }
Youhan Wang4001d252016-05-11 10:29:41 -07005188 }
5189
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005190 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005191 * Return the Preferred Roaming List Version.
5192 *
5193 * @param subId the subscription ID that this request applies to.
5194 * @return PRLVersion or null if error.
5195 */
5196 @Override
5197 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005198 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005199 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200
5201 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005202 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 if (phone == null) {
5204 return null;
5205 }
5206 String cdmaPrlVersion = null;
5207 try {
5208 cdmaPrlVersion = phone.getCdmaPrlVersion();
5209 } catch (Exception e) {
5210 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5211 }
5212 return cdmaPrlVersion;
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005215 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005216 }
5217
5218 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005219 * Get snapshot of Telephony histograms
5220 * @return List of Telephony histograms
5221 * @hide
5222 */
5223 @Override
5224 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5226 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227
5228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 return RIL.getTelephonyRILTimingHistograms();
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
5233 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005234 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005235
5236 /**
5237 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005238 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5239 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005240 * Require system privileges. In the future we may add this to carrier APIs.
5241 *
Michele Berionne482f8202018-11-27 18:57:59 -08005242 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005243 */
5244 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005245 @TelephonyManager.SetCarrierRestrictionResult
5246 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005247 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005248 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005249
Michele Berionne482f8202018-11-27 18:57:59 -08005250 if (carrierRestrictionRules == null) {
5251 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005252 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 final long identity = Binder.clearCallingIdentity();
5255 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005256 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005257 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005261 }
5262
5263 /**
5264 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005265 * Get the allowed carrier list and the excluded carrier list, including the priority between
5266 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005267 * Require system privileges. In the future we may add this to carrier APIs.
5268 *
Michele Berionne482f8202018-11-27 18:57:59 -08005269 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005270 */
5271 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005272 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005273 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005274 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275
5276 final long identity = Binder.clearCallingIdentity();
5277 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005278 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5279 if (response instanceof CarrierRestrictionRules) {
5280 return (CarrierRestrictionRules) response;
5281 }
5282 // Response is an Exception of some kind,
5283 // which is signalled to the user as a NULL retval
5284 return null;
5285 } catch (Exception e) {
5286 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5287 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 } finally {
5289 Binder.restoreCallingIdentity(identity);
5290 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005291 }
5292
fionaxu59545b42016-05-25 15:53:37 -07005293 /**
5294 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5295 * @param subId the subscription ID that this action applies to.
5296 * @param enabled control enable or disable metered apns.
5297 * {@hide}
5298 */
5299 @Override
5300 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5301 enforceModifyPermission();
5302 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303
5304 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005305 if (phone == null) {
5306 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5307 return;
5308 }
5309 try {
5310 phone.carrierActionSetMeteredApnsEnabled(enabled);
5311 } catch (Exception e) {
5312 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 } finally {
5314 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005315 }
5316 }
5317
5318 /**
5319 * Action set from carrier signalling broadcast receivers to enable/disable radio
5320 * @param subId the subscription ID that this action applies to.
5321 * @param enabled control enable or disable radio.
5322 * {@hide}
5323 */
5324 @Override
5325 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5326 enforceModifyPermission();
5327 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328
5329 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005330 if (phone == null) {
5331 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5332 return;
5333 }
5334 try {
5335 phone.carrierActionSetRadioEnabled(enabled);
5336 } catch (Exception e) {
5337 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 } finally {
5339 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005340 }
5341 }
5342
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005343 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005344 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5345 * network status based on which carrier apps could apply actions accordingly,
5346 * enable/disable default url handler for example.
5347 *
5348 * @param subId the subscription ID that this action applies to.
5349 * @param report control start/stop reporting the default network status.
5350 * {@hide}
5351 */
5352 @Override
5353 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5354 enforceModifyPermission();
5355 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356
5357 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005358 if (phone == null) {
5359 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5360 return;
5361 }
5362 try {
5363 phone.carrierActionReportDefaultNetworkStatus(report);
5364 } catch (Exception e) {
5365 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 } finally {
5367 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005368 }
5369 }
5370
5371 /**
fionaxud9622282017-07-17 17:51:30 -07005372 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5373 * @param subId the subscription ID that this action applies to.
5374 * {@hide}
5375 */
5376 @Override
5377 public void carrierActionResetAll(int subId) {
5378 enforceModifyPermission();
5379 final Phone phone = getPhone(subId);
5380 if (phone == null) {
5381 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5382 return;
5383 }
5384 try {
5385 phone.carrierActionResetAll();
5386 } catch (Exception e) {
5387 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5388 }
5389 }
5390
5391 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005392 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5393 * bug report is being generated.
5394 */
5395 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005396 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005397 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5398 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005399 writer.println("Permission Denial: can't dump Phone from pid="
5400 + Binder.getCallingPid()
5401 + ", uid=" + Binder.getCallingUid()
5402 + "without permission "
5403 + android.Manifest.permission.DUMP);
5404 return;
5405 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005406 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005407 }
Jack Yueb89b242016-06-22 13:27:47 -07005408
Brad Ebingerdac2f002018-04-03 15:17:52 -07005409 @Override
5410 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5411 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5412 throws RemoteException {
5413 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5414 }
5415
Jack Yueb89b242016-06-22 13:27:47 -07005416 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005417 * Get aggregated video call data usage since boot.
5418 *
5419 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5420 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005421 * {@hide}
5422 */
5423 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005424 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005425 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5426 null);
5427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 final long identity = Binder.clearCallingIdentity();
5429 try {
5430 // NetworkStatsService keeps tracking the active network interface and identity. It
5431 // records the delta with the corresponding network identity.
5432 // We just return the total video call data usage snapshot since boot.
5433 Phone phone = getPhone(subId);
5434 if (phone != null) {
5435 return phone.getVtDataUsage(perUidStats);
5436 }
5437 return null;
5438 } finally {
5439 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005440 }
Jack Yueb89b242016-06-22 13:27:47 -07005441 }
Jack Yu75ab2952016-07-08 14:29:33 -07005442
5443 /**
5444 * Policy control of data connection. Usually used when data limit is passed.
5445 * @param enabled True if enabling the data, otherwise disabling.
5446 * @param subId Subscription index
5447 * {@hide}
5448 */
5449 @Override
5450 public void setPolicyDataEnabled(boolean enabled, int subId) {
5451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452
5453 final long identity = Binder.clearCallingIdentity();
5454 try {
5455 Phone phone = getPhone(subId);
5456 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005457 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 }
5459 } finally {
5460 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005461 }
5462 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005463
5464 /**
5465 * Get Client request stats
5466 * @return List of Client Request Stats
5467 * @hide
5468 */
5469 @Override
5470 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005472 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005473 return null;
5474 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005475 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 final long identity = Binder.clearCallingIdentity();
5478 try {
5479 if (phone != null) {
5480 return phone.getClientRequestStats();
5481 }
5482
5483 return null;
5484 } finally {
5485 Binder.restoreCallingIdentity(identity);
5486 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005487 }
5488
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005489 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005490 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005491 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005492 }
Jack Yueb4124c2017-02-16 15:32:43 -08005493
5494 /**
Grace Chen70990072017-03-24 17:21:30 -07005495 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005496 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005497 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005498 * @param state State of SIM (power down, power up, pass through)
5499 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5500 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5501 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005502 *
5503 **/
5504 @Override
Grace Chen70990072017-03-24 17:21:30 -07005505 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005506 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005507 Phone phone = PhoneFactory.getPhone(slotIndex);
5508
vagdeviaf9a5b92018-08-15 16:01:53 -07005509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 final long identity = Binder.clearCallingIdentity();
5512 try {
5513 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005514 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 }
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005518 }
5519 }
Shuo Qiandd210312017-04-12 22:11:33 +00005520
Tyler Gunn65d45c22017-06-05 11:22:26 -07005521 private boolean isUssdApiAllowed(int subId) {
5522 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005523 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005524 if (configManager == null) {
5525 return false;
5526 }
5527 PersistableBundle pb = configManager.getConfigForSubId(subId);
5528 if (pb == null) {
5529 return false;
5530 }
5531 return pb.getBoolean(
5532 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5533 }
5534
Shuo Qiandd210312017-04-12 22:11:33 +00005535 /**
5536 * Check if phone is in emergency callback mode
5537 * @return true if phone is in emergency callback mode
5538 * @param subId sub id
5539 */
goneil9c5f4872017-12-05 14:07:56 -08005540 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005541 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005542 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005543 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544
5545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 if (phone != null) {
5548 return phone.isInEcm();
5549 } else {
5550 return false;
5551 }
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005554 }
5555 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005556
5557 /**
5558 * Get the current signal strength information for the given subscription.
5559 * Because this information is not updated when the device is in a low power state
5560 * it should not be relied-upon to be current.
5561 * @param subId Subscription index
5562 * @return the most recent cached signal strength info from the modem
5563 */
5564 @Override
5565 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 Phone p = getPhone(subId);
5569 if (p == null) {
5570 return null;
5571 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573 return p.getSignalStrength();
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005577 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005578
Pengquan Meng77b7f132018-08-22 14:49:57 -07005579 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005580 * Get the current modem radio state for the given slot.
5581 * @param slotIndex slot index.
5582 * @param callingPackage the name of the package making the call.
5583 * @return the current radio power state from the modem
5584 */
5585 @Override
5586 public int getRadioPowerState(int slotIndex, String callingPackage) {
5587 Phone phone = PhoneFactory.getPhone(slotIndex);
5588 if (phone != null) {
5589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5590 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5591 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5592 }
5593
5594 final long identity = Binder.clearCallingIdentity();
5595 try {
5596 return phone.getRadioPowerState();
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
5600 }
5601 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5602 }
5603
5604 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005605 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5606 *
5607 * <p>Requires one of the following permissions:
5608 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5609 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5610 * privileges.
5611 *
5612 * @param subId subscription id
5613 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5614 * {@code false}.
5615 */
5616 @Override
5617 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005618 boolean isEnabled = false;
5619 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005620 try {
5621 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005622 null /* message */);
5623 Phone phone = getPhone(subId);
5624 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005625 } catch (Exception e) {
5626 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5627 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005628 } finally {
5629 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005630 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005631 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005632 }
5633
5634
5635 /**
5636 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5637 *
5638 * <p> Requires permission:
5639 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5640 * privileges.
5641 *
5642 * @param subId subscription id
5643 * @param isEnabled {@code true} means enable, {@code false} means disable.
5644 */
5645 @Override
5646 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005647 final long identity = Binder.clearCallingIdentity();
5648 try {
5649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5650 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005651
Pengquan Menga1bb6272018-09-06 09:59:22 -07005652 Phone phone = getPhone(subId);
5653 if (phone != null) {
5654 phone.setDataRoamingEnabled(isEnabled);
5655 }
5656 } finally {
5657 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005658 }
5659 }
5660
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005661 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005662 public boolean isManualNetworkSelectionAllowed(int subId) {
5663 boolean isAllowed = true;
5664 final long identity = Binder.clearCallingIdentity();
5665 try {
5666 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5667 mApp, subId, "isManualNetworkSelectionAllowed");
5668 Phone phone = getPhone(subId);
5669 if (phone != null) {
5670 isAllowed = phone.isCspPlmnEnabled();
5671 }
5672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
5675 return isAllowed;
5676 }
5677
5678 @Override
Jordan Liu5aa07002018-12-18 15:44:48 -08005679 public UiccCardInfo[] getUiccCardsInfo() {
5680 enforceReadPrivilegedPermission("getUiccCardsInfo");
5681
5682 final long identity = Binder.clearCallingIdentity();
5683 try {
5684 ArrayList<UiccCardInfo> cards = UiccController.getInstance().getAllUiccCardInfos();
5685 return cards.toArray(new UiccCardInfo[cards.size()]);
5686 } finally {
5687 Binder.restoreCallingIdentity(identity);
5688 }
5689 }
5690
5691 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005692 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005693 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5698 if (slots == null) {
5699 Rlog.i(LOG_TAG, "slots is null.");
5700 return null;
5701 }
5702
5703 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5704 for (int i = 0; i < slots.length; i++) {
5705 UiccSlot slot = slots[i];
5706 if (slot == null) {
5707 continue;
5708 }
5709
5710 String cardId;
5711 UiccCard card = slot.getUiccCard();
5712 if (card != null) {
5713 cardId = card.getCardId();
5714 } else {
5715 cardId = slot.getIccId();
5716 }
5717
5718 int cardState = 0;
5719 switch (slot.getCardState()) {
5720 case CARDSTATE_ABSENT:
5721 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5722 break;
5723 case CARDSTATE_PRESENT:
5724 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5725 break;
5726 case CARDSTATE_ERROR:
5727 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5728 break;
5729 case CARDSTATE_RESTRICTED:
5730 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5731 break;
5732 default:
5733 break;
5734
5735 }
5736
5737 infos[i] = new UiccSlotInfo(
5738 slot.isActive(),
5739 slot.isEuicc(),
5740 cardId,
5741 cardState,
5742 slot.getPhoneId(),
5743 slot.isExtendedApduSupported());
5744 }
5745 return infos;
5746 } finally {
5747 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005748 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005749 }
5750
5751 @Override
5752 public boolean switchSlots(int[] physicalSlots) {
5753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5758 } finally {
5759 Binder.restoreCallingIdentity(identity);
5760 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005761 }
Jack Yu4c988042018-02-27 15:30:01 -08005762
5763 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005764 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5766 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5767 return TelephonyManager.INVALID_CARD_ID;
5768 }
5769
5770 final long identity = Binder.clearCallingIdentity();
5771 try {
5772 return UiccController.getInstance().getCardIdForDefaultEuicc();
5773 } finally {
5774 Binder.restoreCallingIdentity(identity);
5775 }
5776 }
5777
5778 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005779 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5780 enforceModifyPermission();
5781 final Phone phone = getPhone(subId);
5782 if (phone == null) {
5783 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5784 return;
5785 }
5786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 final long identity = Binder.clearCallingIdentity();
5788 try {
5789 phone.setRadioIndicationUpdateMode(filters, mode);
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
5792 }
Jack Yu4c988042018-02-27 15:30:01 -08005793 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005794
5795 /**
goneil47ffb6e2018-04-06 15:40:58 -07005796 * A test API to reload the UICC profile.
5797 *
5798 * <p>Requires that the calling app has permission
5799 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5800 * @hide
5801 */
5802 @Override
5803 public void refreshUiccProfile(int subId) {
5804 enforceModifyPermission();
5805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 Phone phone = getPhone(subId);
5809 if (phone == null) {
5810 return;
5811 }
5812 UiccCard uiccCard = phone.getUiccCard();
5813 if (uiccCard == null) {
5814 return;
5815 }
5816 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5817 if (uiccProfile == null) {
5818 return;
5819 }
5820 uiccProfile.refresh();
5821 } finally {
5822 Binder.restoreCallingIdentity(identity);
5823 }
5824 }
5825
5826 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005827 * Returns false if the mobile data is disabled by default, otherwise return true.
5828 */
5829 private boolean getDefaultDataEnabled() {
5830 return "true".equalsIgnoreCase(
5831 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5832 }
5833
5834 /**
5835 * Returns true if the data roaming is enabled by default, i.e the system property
5836 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5837 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5838 */
5839 private boolean getDefaultDataRoamingEnabled(int subId) {
5840 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005841 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005842 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5843 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5844 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5845 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5846 return isDataRoamingEnabled;
5847 }
5848
5849 /**
5850 * Returns the default network type for the given {@code subId}, if the default network type is
5851 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5852 */
5853 private int getDefaultNetworkType(int subId) {
5854 return Integer.parseInt(
5855 TelephonyManager.getTelephonyProperty(
5856 mSubscriptionController.getPhoneId(subId),
5857 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5858 String.valueOf(Phone.PREFERRED_NT_MODE)));
5859 }
fionaxua13278b2018-03-21 00:08:13 -07005860
5861 @Override
5862 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5863 gid1, String gid2, String plmn, String spn) {
5864 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865
5866 final long identity = Binder.clearCallingIdentity();
5867 try {
5868 final Phone phone = getPhone(subId);
5869 if (phone == null) {
5870 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5871 return;
5872 }
5873 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005876 }
fionaxua13278b2018-03-21 00:08:13 -07005877 }
5878
5879 @Override
5880 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005881 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
5885 final Phone phone = getPhone(subId);
5886 if (phone == null) {
5887 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5888 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5889 }
5890 return phone.getCarrierIdListVersion();
5891 } finally {
5892 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005893 }
fionaxua13278b2018-03-21 00:08:13 -07005894 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005895
5896 @Override
5897 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5899 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5900 return -1;
5901 }
5902
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
5905 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
5909 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005910
5911 @Override
5912 public int getCdmaRoamingMode(int subId) {
5913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5914 mApp, subId, "getCdmaRoamingMode");
5915
5916 final long identity = Binder.clearCallingIdentity();
5917 try {
5918 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5919 } finally {
5920 Binder.restoreCallingIdentity(identity);
5921 }
5922 }
5923
5924 @Override
5925 public boolean setCdmaRoamingMode(int subId, int mode) {
5926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5927 mApp, subId, "setCdmaRoamingMode");
5928
5929 final long identity = Binder.clearCallingIdentity();
5930 try {
5931 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
5935 }
5936
5937 @Override
5938 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5940 mApp, subId, "setCdmaSubscriptionMode");
5941
5942 final long identity = Binder.clearCallingIdentity();
5943 try {
5944 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5945 } finally {
5946 Binder.restoreCallingIdentity(identity);
5947 }
5948 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005949
5950 private void ensureUserRunning(int userId) {
5951 if (!mUserManager.isUserRunning(userId)) {
5952 throw new IllegalStateException("User " + userId + " does not exist or not running");
5953 }
5954 }
5955
5956 /**
5957 * Returns a list of SMS apps on a given user.
5958 *
5959 * Only the shell user (UID 2000 or 0) can call it.
5960 * Target user must be running.
5961 */
5962 @Override
5963 public String[] getSmsApps(int userId) {
5964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5965 ensureUserRunning(userId);
5966
5967 final Collection<SmsApplicationData> apps =
5968 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5969
5970 String[] ret = new String[apps.size()];
5971 int i = 0;
5972 for (SmsApplicationData app : apps) {
5973 ret[i++] = app.mPackageName;
5974 }
5975 return ret;
5976 }
5977
5978 /**
5979 * Returns the default SMS app package name on a given user.
5980 *
5981 * Only the shell user (UID 2000 or 0) can call it.
5982 * Target user must be running.
5983 */
5984 @Override
5985 public String getDefaultSmsApp(int userId) {
5986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5987 ensureUserRunning(userId);
5988
5989 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5990 /* updateIfNeeded= */ true, userId);
5991 return cn == null ? null : cn.getPackageName();
5992 }
5993
5994 /**
5995 * Set a package as the default SMS app on a given user.
5996 *
5997 * Only the shell user (UID 2000 or 0) can call it.
5998 * Target user must be running.
5999 */
6000 @Override
6001 public void setDefaultSmsApp(int userId, String packageName) {
6002 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6003 ensureUserRunning(userId);
6004
6005 boolean found = false;
6006 for (String pkg : getSmsApps(userId)) {
6007 if (TextUtils.equals(packageName, pkg)) {
6008 found = true;
6009 break;
6010 }
6011 }
6012 if (!found) {
6013 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6014 }
6015
6016 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6017 }
sqianc5eccab2018-10-19 18:46:41 -07006018
6019 @Override
6020 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6021 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6023 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6024 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6025 }
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
sqian854d44b2018-12-12 16:48:18 -08006028 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6029 for (Phone phone: PhoneFactory.getPhones()) {
6030 if (phone.getEmergencyNumberTracker() != null
6031 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6032 emergencyNumberListInternal.put(
6033 phone.getSubId(),
6034 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6035 }
sqian11b7a0e2018-12-05 18:48:28 -08006036 }
sqian854d44b2018-12-12 16:48:18 -08006037 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006038 } finally {
6039 Binder.restoreCallingIdentity(identity);
6040 }
sqianc5eccab2018-10-19 18:46:41 -07006041 }
6042
6043 @Override
sqian11b7a0e2018-12-05 18:48:28 -08006044 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006045 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006046 if (!exactMatch) {
6047 TelephonyPermissions
6048 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006049 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006050 }
6051 final long identity = Binder.clearCallingIdentity();
6052 try {
sqian854d44b2018-12-12 16:48:18 -08006053 for (Phone phone: PhoneFactory.getPhones()) {
6054 if (phone.getEmergencyNumberTracker() != null
6055 && phone.getEmergencyNumberTracker() != null) {
6056 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6057 number, exactMatch)) {
6058 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006059 }
6060 }
sqian11b7a0e2018-12-05 18:48:28 -08006061 }
6062 return false;
6063 } finally {
6064 Binder.restoreCallingIdentity(identity);
6065 }
6066 }
6067
chen xud6b45bd2018-10-30 22:27:10 -07006068 @Override
6069 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6070 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6071 Phone phone = getPhone(subId);
6072 if (phone == null) {
6073 return null;
6074 }
6075 final long identity = Binder.clearCallingIdentity();
6076 try {
6077 UiccProfile profile = UiccController.getInstance()
6078 .getUiccProfileForPhone(phone.getPhoneId());
6079 if (profile != null) {
6080 return profile.getCertsFromCarrierPrivilegeAccessRules();
6081 }
6082 } finally {
6083 Binder.restoreCallingIdentity(identity);
6084 }
6085 return null;
6086 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006087}