blob: 4e2cb15727742c7670484aca117b2367f2e57598 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070055import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
sqian11b7a0e2018-12-05 18:48:28 -080072import android.telephony.PhoneNumberUtils;
Wink Saville5d475dd2014-10-17 15:00:58 -070073import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070074import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080076import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070077import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080078import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080079import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070080import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070081import android.telephony.TelephonyManager;
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;
156import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800157import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100158import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800159import java.util.Map;
sqian11b7a0e2018-12-05 18:48:28 -0800160import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161
162/**
163 * Implementation of the ITelephony interface.
164 */
Santos Cordon117fee72014-05-16 17:56:12 -0700165public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166 private static final String LOG_TAG = "PhoneInterfaceManager";
167 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
168 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800169 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170
171 // Message codes used with mMainThreadHandler
172 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700173 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
174 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700175 private static final int CMD_OPEN_CHANNEL = 9;
176 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
177 private static final int CMD_CLOSE_CHANNEL = 11;
178 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800179 private static final int CMD_NV_READ_ITEM = 13;
180 private static final int EVENT_NV_READ_ITEM_DONE = 14;
181 private static final int CMD_NV_WRITE_ITEM = 15;
182 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
183 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
184 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700185 private static final int CMD_RESET_MODEM_CONFIG = 19;
186 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800187 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
188 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
189 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
190 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800191 private static final int CMD_SEND_ENVELOPE = 25;
192 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000193 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
194 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700195 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
196 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
197 private static final int CMD_EXCHANGE_SIM_IO = 31;
198 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800199 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
200 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700201 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
202 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700203 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
204 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700205 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
206 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
207 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
208 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700209 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
210 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
211 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
212 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700213 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800214 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
215 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000216 private static final int CMD_SWITCH_SLOTS = 50;
217 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700218 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
219 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
220 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
221 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
222 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
223 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
224 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
225 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700226 private static final int CMD_GET_ALL_CELL_INFO = 60;
227 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
228 private static final int CMD_GET_CELL_LOCATION = 62;
229 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700230 private static final int CMD_MODEM_REBOOT = 64;
231 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700232 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
233 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800235 // Parameters of select command.
236 private static final int SELECT_COMMAND = 0xA4;
237 private static final int SELECT_P1 = 0x04;
238 private static final int SELECT_P2 = 0;
239 private static final int SELECT_P3 = 0x10;
240
Pengquan Meng85728fb2018-03-12 16:31:21 -0700241 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
242 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
243 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
244
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245 /** The singleton instance. */
246 private static PhoneInterfaceManager sInstance;
247
Wink Saville3ab207e2014-11-20 13:07:20 -0800248 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800249 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700250 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800251 private AppOpsManager mAppOps;
252 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800253 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800254 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700255 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256
Derek Tan97ebb422014-09-05 16:55:38 -0700257 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
258 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800259 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700260
Derek Tan740e1672017-06-27 14:56:27 -0700261 // The AID of ISD-R.
262 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
263
yinxub1bed742017-04-17 11:45:04 -0700264 private NetworkScanRequestTracker mNetworkScanRequestTracker;
265
David Kelly5e06a7f2018-03-12 14:10:59 +0000266 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
267 private static final int MANUFACTURER_CODE_LENGTH = 8;
268
Derek Tan89e89d42014-07-08 17:00:10 -0700269 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700270 * A request object to use for transmitting data to an ICC.
271 */
272 private static final class IccAPDUArgument {
273 public int channel, cla, command, p1, p2, p3;
274 public String data;
275
276 public IccAPDUArgument(int channel, int cla, int command,
277 int p1, int p2, int p3, String data) {
278 this.channel = channel;
279 this.cla = cla;
280 this.command = command;
281 this.p1 = p1;
282 this.p2 = p2;
283 this.p3 = p3;
284 this.data = data;
285 }
286 }
287
288 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700289 * A request object to use for transmitting data to an ICC.
290 */
291 private static final class ManualNetworkSelectionArgument {
292 public OperatorInfo operatorInfo;
293 public boolean persistSelection;
294
295 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
296 this.operatorInfo = operatorInfo;
297 this.persistSelection = persistSelection;
298 }
299 }
300
301 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
303 * request after sending. The main thread will notify the request when it is complete.
304 */
305 private static final class MainThreadRequest {
306 /** The argument to use for the request */
307 public Object argument;
308 /** The result of the request that is run on the main thread */
309 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800310 // The subscriber id that this request applies to. Defaults to
311 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
312 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700313
Nathan Harold92bed182018-10-12 18:16:49 -0700314 // In cases where subId is unavailable, the caller needs to specify the phone.
315 public Phone phone;
316
vagdeviaf9a5b92018-08-15 16:01:53 -0700317 public WorkSource workSource;
318
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 public MainThreadRequest(Object argument) {
320 this.argument = argument;
321 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800322
Nathan Harold92bed182018-10-12 18:16:49 -0700323 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
324 this.argument = argument;
325 if (phone != null) {
326 this.phone = phone;
327 }
328 this.workSource = workSource;
329 }
330
vagdeviaf9a5b92018-08-15 16:01:53 -0700331 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800332 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800333 if (subId != null) {
334 this.subId = subId;
335 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700336 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 }
339
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800340 private static final class IncomingThirdPartyCallArgs {
341 public final ComponentName component;
342 public final String callId;
343 public final String callerDisplayName;
344
345 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
346 String callerDisplayName) {
347 this.component = component;
348 this.callId = callId;
349 this.callerDisplayName = callerDisplayName;
350 }
351 }
352
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 /**
354 * A handler that processes messages on the main thread in the phone process. Since many
355 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
356 * inbound binder threads to the main thread in the phone process. The Binder thread
357 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
358 * on, which will be notified when the operation completes and will contain the result of the
359 * request.
360 *
361 * <p>If a MainThreadRequest object is provided in the msg.obj field,
362 * note that request.result must be set to something non-null for the calling thread to
363 * unblock.
364 */
365 private final class MainThreadHandler extends Handler {
366 @Override
367 public void handleMessage(Message msg) {
368 MainThreadRequest request;
369 Message onCompleted;
370 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800371 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700372 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800373 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
375 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700376 case CMD_HANDLE_USSD_REQUEST: {
377 request = (MainThreadRequest) msg.obj;
378 final Phone phone = getPhoneFromRequest(request);
379 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
380 String ussdRequest = ussdObject.first;
381 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700382
Pengquan Menga1bb6272018-09-06 09:59:22 -0700383 if (!isUssdApiAllowed(request.subId)) {
384 // Carrier does not support use of this API, return failure.
385 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
386 UssdResponse response = new UssdResponse(ussdRequest, null);
387 Bundle returnData = new Bundle();
388 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
389 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700390
Pengquan Menga1bb6272018-09-06 09:59:22 -0700391 request.result = true;
392 notifyRequester(request);
393 return;
394 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700395
Pengquan Menga1bb6272018-09-06 09:59:22 -0700396 try {
397 request.result = phone != null
398 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
399 } catch (CallStateException cse) {
400 request.result = false;
401 }
402 // Wake up the requesting thread
403 notifyRequester(request);
404 break;
pkanwar32d516d2016-10-14 19:37:38 -0700405 }
406
Yorke Lee716f67e2015-06-17 15:39:16 -0700407 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700409 final Phone phone = getPhoneFromRequest(request);
410 request.result = phone != null ?
411 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
412 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700414 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800421 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 if (uiccCard == null) {
423 loge("iccTransmitApduLogicalChannel: No UICC");
424 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700425 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
428 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700430 iccArgument.channel, iccArgument.cla, iccArgument.command,
431 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700433 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 break;
435
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 ar = (AsyncResult) msg.obj;
438 request = (MainThreadRequest) ar.userObj;
439 if (ar.exception == null && ar.result != null) {
440 request.result = ar.result;
441 } else {
442 request.result = new IccIoResult(0x6F, 0, (byte[])null);
443 if (ar.result == null) {
444 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800445 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800447 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 } else {
449 loge("iccTransmitApduLogicalChannel: Unknown exception");
450 }
451 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 break;
454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
456 request = (MainThreadRequest) msg.obj;
457 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800458 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 if (uiccCard == null) {
460 loge("iccTransmitApduBasicChannel: No UICC");
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 } else {
464 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
465 request);
466 uiccCard.iccTransmitApduBasicChannel(
467 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
468 iccArgument.p3, iccArgument.data, onCompleted);
469 }
470 break;
471
472 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
473 ar = (AsyncResult) msg.obj;
474 request = (MainThreadRequest) ar.userObj;
475 if (ar.exception == null && ar.result != null) {
476 request.result = ar.result;
477 } else {
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
479 if (ar.result == null) {
480 loge("iccTransmitApduBasicChannel: Empty response");
481 } else if (ar.exception instanceof CommandException) {
482 loge("iccTransmitApduBasicChannel: CommandException: " +
483 ar.exception);
484 } else {
485 loge("iccTransmitApduBasicChannel: Unknown exception");
486 }
487 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 break;
490
491 case CMD_EXCHANGE_SIM_IO:
492 request = (MainThreadRequest) msg.obj;
493 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800494 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 if (uiccCard == null) {
496 loge("iccExchangeSimIO: No UICC");
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700498 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 } else {
500 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
501 request);
502 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
503 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
504 iccArgument.data, onCompleted);
505 }
506 break;
507
508 case EVENT_EXCHANGE_SIM_IO_DONE:
509 ar = (AsyncResult) msg.obj;
510 request = (MainThreadRequest) ar.userObj;
511 if (ar.exception == null && ar.result != null) {
512 request.result = ar.result;
513 } else {
514 request.result = new IccIoResult(0x6f, 0, (byte[])null);
515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 break;
518
Derek Tan4d5e5c12014-02-04 11:54:58 -0800519 case CMD_SEND_ENVELOPE:
520 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 if (uiccCard == null) {
523 loge("sendEnvelopeWithStatus: No UICC");
524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 } else {
527 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
528 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
529 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 break;
531
532 case EVENT_SEND_ENVELOPE_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("sendEnvelopeWithStatus: Empty response");
541 } else if (ar.exception instanceof CommandException) {
542 loge("sendEnvelopeWithStatus: CommandException: " +
543 ar.exception);
544 } else {
545 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
546 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 break;
550
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 case CMD_OPEN_CHANNEL:
552 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800553 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800554 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 if (uiccCard == null) {
556 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800557 request.result = new IccOpenLogicalChannelResponse(-1,
558 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 } else {
561 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800562 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
563 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
567 case EVENT_OPEN_CHANNEL_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 int[] result = (int[]) ar.result;
573 int channelId = result[0];
574 byte[] selectResponse = null;
575 if (result.length > 1) {
576 selectResponse = new byte[result.length - 1];
577 for (int i = 1; i < result.length; ++i) {
578 selectResponse[i - 1] = (byte) result[i];
579 }
580 }
581 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 if (ar.result == null) {
585 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 if (ar.exception != null) {
588 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
589 }
590
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700591 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700592 if (ar.exception instanceof CommandException) {
593 CommandException.Error error =
594 ((CommandException) (ar.exception)).getCommandError();
595 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700597 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700598 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 }
600 }
601 openChannelResp = new IccOpenLogicalChannelResponse(
602 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700604 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
608 case CMD_CLOSE_CHANNEL:
609 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800610 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 if (uiccCard == null) {
612 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900613 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 } else {
616 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
617 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
618 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 break;
620
621 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800622 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
623 break;
624
625 case CMD_NV_READ_ITEM:
626 request = (MainThreadRequest) msg.obj;
627 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800628 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
629 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800630 break;
631
632 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 ar = (AsyncResult) msg.obj;
634 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800635 if (ar.exception == null && ar.result != null) {
636 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800638 request.result = "";
639 if (ar.result == null) {
640 loge("nvReadItem: Empty response");
641 } else if (ar.exception instanceof CommandException) {
642 loge("nvReadItem: CommandException: " +
643 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800645 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 }
647 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
Jake Hambye994d462014-02-03 13:10:13 -0800651 case CMD_NV_WRITE_ITEM:
652 request = (MainThreadRequest) msg.obj;
653 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
654 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800655 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700656 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800657 break;
658
659 case EVENT_NV_WRITE_ITEM_DONE:
660 handleNullReturnEvent(msg, "nvWriteItem");
661 break;
662
663 case CMD_NV_WRITE_CDMA_PRL:
664 request = (MainThreadRequest) msg.obj;
665 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800666 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800667 break;
668
669 case EVENT_NV_WRITE_CDMA_PRL_DONE:
670 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
671 break;
672
chen xu6dac5ab2018-10-26 17:39:23 -0700673 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800674 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700675 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800676 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800677 break;
678
chen xu6dac5ab2018-10-26 17:39:23 -0700679 case EVENT_RESET_MODEM_CONFIG_DONE:
680 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800681 break;
682
Jake Hamby7c27be32014-03-03 13:25:59 -0800683 case CMD_GET_PREFERRED_NETWORK_TYPE:
684 request = (MainThreadRequest) msg.obj;
685 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700686 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 break;
688
689 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
690 ar = (AsyncResult) msg.obj;
691 request = (MainThreadRequest) ar.userObj;
692 if (ar.exception == null && ar.result != null) {
693 request.result = ar.result; // Integer
694 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800695 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800696 if (ar.result == null) {
697 loge("getPreferredNetworkType: Empty response");
698 } else if (ar.exception instanceof CommandException) {
699 loge("getPreferredNetworkType: CommandException: " +
700 ar.exception);
701 } else {
702 loge("getPreferredNetworkType: Unknown exception");
703 }
704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 break;
707
708 case CMD_SET_PREFERRED_NETWORK_TYPE:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
711 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700712 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 break;
714
715 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
716 handleNullReturnEvent(msg, "setPreferredNetworkType");
717 break;
718
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000719 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
720 request = (MainThreadRequest)msg.obj;
721 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800722 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000723 break;
724
725 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
726 ar = (AsyncResult)msg.obj;
727 request = (MainThreadRequest)ar.userObj;
728 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000730 break;
731
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800732 case CMD_SET_VOICEMAIL_NUMBER:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
735 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800736 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
737 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800738 break;
739
740 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
741 handleNullReturnEvent(msg, "setVoicemailNumber");
742 break;
743
Stuart Scott54788802015-03-30 13:18:01 -0700744 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
745 request = (MainThreadRequest) msg.obj;
746 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
747 request);
748 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
749 break;
750
751 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
752 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
753 break;
754
Shishir Agrawal302c8692015-06-19 13:49:39 -0700755 case CMD_PERFORM_NETWORK_SCAN:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
758 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
759 break;
760
761 case EVENT_PERFORM_NETWORK_SCAN_DONE:
762 ar = (AsyncResult) msg.obj;
763 request = (MainThreadRequest) ar.userObj;
764 CellNetworkScanResult cellScanResult;
765 if (ar.exception == null && ar.result != null) {
766 cellScanResult = new CellNetworkScanResult(
767 CellNetworkScanResult.STATUS_SUCCESS,
768 (List<OperatorInfo>) ar.result);
769 } else {
770 if (ar.result == null) {
771 loge("getCellNetworkScanResults: Empty response");
772 }
773 if (ar.exception != null) {
774 loge("getCellNetworkScanResults: Exception: " + ar.exception);
775 }
776 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
777 if (ar.exception instanceof CommandException) {
778 CommandException.Error error =
779 ((CommandException) (ar.exception)).getCommandError();
780 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
781 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
782 } else if (error == CommandException.Error.GENERIC_FAILURE) {
783 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
784 }
785 }
786 cellScanResult = new CellNetworkScanResult(errorCode, null);
787 }
788 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700789 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 break;
791
792 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
793 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700794 ManualNetworkSelectionArgument selArg =
795 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
797 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700798 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
799 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700800 break;
801
802 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 if (ar.exception == null) {
806 request.result = true;
807 } else {
808 request.result = false;
809 loge("setNetworkSelectionModeManual " + ar.exception);
810 }
811 notifyRequester(request);
812 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700813 break;
814
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700815 case CMD_GET_MODEM_ACTIVITY_INFO:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800818 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700819 break;
820
821 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null && ar.result != null) {
825 request.result = ar.result;
826 } else {
827 if (ar.result == null) {
828 loge("queryModemActivityInfo: Empty response");
829 } else if (ar.exception instanceof CommandException) {
830 loge("queryModemActivityInfo: CommandException: " +
831 ar.exception);
832 } else {
833 loge("queryModemActivityInfo: Unknown exception");
834 }
835 }
Amit Mahajand4766222016-01-28 15:28:28 -0800836 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
837 if (request.result == null) {
838 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
839 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700840 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700841 break;
842
Meng Wang1a7c35a2016-05-05 20:56:15 -0700843 case CMD_SET_ALLOWED_CARRIERS:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800846 defaultPhone.setAllowedCarriers(
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700848 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700849 break;
850
851 case EVENT_SET_ALLOWED_CARRIERS_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 if (ar.result == null) {
858 loge("setAllowedCarriers: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("setAllowedCarriers: CommandException: " +
861 ar.exception);
862 } else {
863 loge("setAllowedCarriers: Unknown exception");
864 }
865 }
866 // Result cannot be null. Return -1 on error.
867 if (request.result == null) {
868 request.result = new int[]{-1};
869 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700870 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700871 break;
872
873 case CMD_GET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800876 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 break;
878
879 case EVENT_GET_ALLOWED_CARRIERS_DONE:
880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
882 if (ar.exception == null && ar.result != null) {
883 request.result = ar.result;
884 } else {
885 if (ar.result == null) {
886 loge("getAllowedCarriers: Empty response");
887 } else if (ar.exception instanceof CommandException) {
888 loge("getAllowedCarriers: CommandException: " +
889 ar.exception);
890 } else {
891 loge("getAllowedCarriers: Unknown exception");
892 }
893 }
894 // Result cannot be null. Return empty list of CarrierIdentifier.
895 if (request.result == null) {
896 request.result = new ArrayList<CarrierIdentifier>(0);
897 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700898 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700899 break;
900
Nathan Haroldb3014052017-01-25 15:57:32 -0800901 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
902 ar = (AsyncResult) msg.obj;
903 request = (MainThreadRequest) ar.userObj;
904 if (ar.exception == null && ar.result != null) {
905 request.result = ar.result;
906 } else {
907 request.result = new IllegalArgumentException(
908 "Failed to retrieve Forbidden Plmns");
909 if (ar.result == null) {
910 loge("getForbiddenPlmns: Empty response");
911 } else {
912 loge("getForbiddenPlmns: Unknown exception");
913 }
914 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700915 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800916 break;
917
918 case CMD_GET_FORBIDDEN_PLMNS:
919 request = (MainThreadRequest) msg.obj;
920 uiccCard = getUiccCardFromRequest(request);
921 if (uiccCard == null) {
922 loge("getForbiddenPlmns() UiccCard is null");
923 request.result = new IllegalArgumentException(
924 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700925 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800926 break;
927 }
928 Integer appType = (Integer) request.argument;
929 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
930 if (uiccApp == null) {
931 loge("getForbiddenPlmns() no app with specified type -- "
932 + appType);
933 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700934 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800935 break;
936 } else {
937 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
938 + " specified type -- " + appType);
939 }
940 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
941 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
942 onCompleted);
943 break;
944
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000945 case CMD_SWITCH_SLOTS:
946 request = (MainThreadRequest) msg.obj;
947 int[] physicalSlots = (int[]) request.argument;
948 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
949 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
950 break;
951
952 case EVENT_SWITCH_SLOTS_DONE:
953 ar = (AsyncResult) msg.obj;
954 request = (MainThreadRequest) ar.userObj;
955 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
957 break;
958 case CMD_GET_NETWORK_SELECTION_MODE:
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
961 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
962 break;
963
964 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 if (ar.exception != null) {
968 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
969 } else {
970 int mode = ((int[]) ar.result)[0];
971 if (mode == 0) {
972 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
973 } else {
974 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
975 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000976 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700977 notifyRequester(request);
978 break;
979 case CMD_GET_CDMA_ROAMING_MODE:
980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
982 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
983 break;
984 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception != null) {
988 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
989 } else {
990 request.result = ((int[]) ar.result)[0];
991 }
992 notifyRequester(request);
993 break;
994 case CMD_SET_CDMA_ROAMING_MODE:
995 request = (MainThreadRequest) msg.obj;
996 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
997 int mode = (int) request.argument;
998 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
999 break;
1000 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1001 ar = (AsyncResult) msg.obj;
1002 request = (MainThreadRequest) ar.userObj;
1003 request.result = ar.exception == null;
1004 notifyRequester(request);
1005 break;
1006 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1009 int subscriptionMode = (int) request.argument;
1010 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1011 break;
1012 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 request.result = ar.exception == null;
1016 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001017 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 case CMD_GET_ALL_CELL_INFO:
1019 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001020 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001021 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001022 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001023 case EVENT_GET_ALL_CELL_INFO_DONE:
1024 ar = (AsyncResult) msg.obj;
1025 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001026 // If a timeout occurs, the response will be null
1027 request.result = (ar.exception == null && ar.result != null)
1028 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001029 synchronized (request) {
1030 request.notifyAll();
1031 }
1032 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001033 case CMD_REQUEST_CELL_INFO_UPDATE:
1034 request = (MainThreadRequest) msg.obj;
1035 request.phone.requestCellInfoUpdate(request.workSource,
1036 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1037 break;
1038 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
1041 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1042 try {
1043 if (ar.exception != null) {
1044 // something went wrong... the response is null
1045 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1046 cb.onCellInfo(null);
1047 } else if (ar.result == null) {
1048 // timeout occurred, so force the result to non-null "empty"
1049 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1050 cb.onCellInfo(new ArrayList<CellInfo>());
1051 } else {
1052 // use the result as returned
1053 cb.onCellInfo((List<CellInfo>) ar.result);
1054 }
1055 } catch (RemoteException re) {
1056 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1057 }
1058 break;
1059 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 request = (MainThreadRequest) msg.obj;
1061 WorkSource ws = (WorkSource) request.argument;
1062 Phone phone = getPhoneFromRequest(request);
1063 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1064 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
1068 if (ar.exception == null) {
1069 request.result = ar.result;
1070 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001071 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001072 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1073 ? new CdmaCellLocation() : new GsmCellLocation();
1074 }
1075
1076 synchronized (request) {
1077 request.notifyAll();
1078 }
1079 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001080 case CMD_MODEM_REBOOT:
1081 request = (MainThreadRequest) msg.obj;
1082 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001083 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001084 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001085 case EVENT_CMD_MODEM_REBOOT_DONE:
1086 handleNullReturnEvent(msg, "rebootModem");
1087 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001088 default:
1089 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1090 break;
1091 }
1092 }
Jake Hambye994d462014-02-03 13:10:13 -08001093
Pengquan Menga1bb6272018-09-06 09:59:22 -07001094 private void notifyRequester(MainThreadRequest request) {
1095 synchronized (request) {
1096 request.notifyAll();
1097 }
1098 }
1099
Jake Hambye994d462014-02-03 13:10:13 -08001100 private void handleNullReturnEvent(Message msg, String command) {
1101 AsyncResult ar = (AsyncResult) msg.obj;
1102 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1103 if (ar.exception == null) {
1104 request.result = true;
1105 } else {
1106 request.result = false;
1107 if (ar.exception instanceof CommandException) {
1108 loge(command + ": CommandException: " + ar.exception);
1109 } else {
1110 loge(command + ": Unknown exception");
1111 }
1112 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001113 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001115 }
1116
1117 /**
1118 * Posts the specified command to be executed on the main thread,
1119 * waits for the request to complete, and returns the result.
1120 * @see #sendRequestAsync
1121 */
1122 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001123 return sendRequest(
1124 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001125 }
1126
1127 /**
1128 * Posts the specified command to be executed on the main thread,
1129 * waits for the request to complete, and returns the result.
1130 * @see #sendRequestAsync
1131 */
1132 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1133 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001134 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001135 }
1136
1137 /**
1138 * Posts the specified command to be executed on the main thread,
1139 * waits for the request to complete, and returns the result.
1140 * @see #sendRequestAsync
1141 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001142 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001143 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001144 }
1145
1146 /**
1147 * Posts the specified command to be executed on the main thread,
1148 * waits for the request to complete, and returns the result.
1149 * @see #sendRequestAsync
1150 */
Nathan Harold92bed182018-10-12 18:16:49 -07001151 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1152 return sendRequest(command, argument, subId, null, workSource);
1153 }
1154
1155 /**
1156 * Posts the specified command to be executed on the main thread,
1157 * waits for the request to complete, and returns the result.
1158 * @see #sendRequestAsync
1159 */
1160 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1161 return sendRequest(
1162 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1163 }
1164
1165 /**
1166 * Posts the specified command to be executed on the main thread,
1167 * waits for the request to complete, and returns the result.
1168 * @see #sendRequestAsync
1169 */
1170 private Object sendRequest(
1171 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1173 throw new RuntimeException("This method will deadlock if called from the main thread.");
1174 }
1175
Nathan Harold92bed182018-10-12 18:16:49 -07001176 MainThreadRequest request = null;
1177 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1178 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1179 } else if (phone != null) {
1180 request = new MainThreadRequest(argument, phone, workSource);
1181 } else {
1182 request = new MainThreadRequest(argument, subId, workSource);
1183 }
1184
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001185 Message msg = mMainThreadHandler.obtainMessage(command, request);
1186 msg.sendToTarget();
1187
1188 // Wait for the request to complete
1189 synchronized (request) {
1190 while (request.result == null) {
1191 try {
1192 request.wait();
1193 } catch (InterruptedException e) {
1194 // Do nothing, go back and wait until the request is complete
1195 }
1196 }
1197 }
1198 return request.result;
1199 }
1200
1201 /**
1202 * Asynchronous ("fire and forget") version of sendRequest():
1203 * Posts the specified command to be executed on the main thread, and
1204 * returns immediately.
1205 * @see #sendRequest
1206 */
1207 private void sendRequestAsync(int command) {
1208 mMainThreadHandler.sendEmptyMessage(command);
1209 }
1210
1211 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001212 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001213 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001214 */
1215 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001216 sendRequestAsync(command, argument, null, null);
1217 }
1218
1219 /**
1220 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1221 * @see {@link #sendRequest(int,Object)}
1222 */
1223 private void sendRequestAsync(
1224 int command, Object argument, Phone phone, WorkSource workSource) {
1225 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001226 Message msg = mMainThreadHandler.obtainMessage(command, request);
1227 msg.sendToTarget();
1228 }
1229
1230 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 * Initialize the singleton PhoneInterfaceManager instance.
1232 * This is only done once, at startup, from PhoneApp.onCreate().
1233 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001234 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 synchronized (PhoneInterfaceManager.class) {
1236 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001237 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001238 } else {
1239 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1240 }
1241 return sInstance;
1242 }
1243 }
1244
1245 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001246 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001249 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1251 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001252 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001253 mTelephonySharedPreferences =
1254 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001255 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001256 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001257
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 publish();
1259 }
1260
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001261 private Phone getDefaultPhone() {
1262 Phone thePhone = getPhone(getDefaultSubscription());
1263 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1264 }
1265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 private void publish() {
1267 if (DBG) log("publish: " + this);
1268
1269 ServiceManager.addService("phone", this);
1270 }
1271
Stuart Scott584921c2015-01-15 17:10:34 -08001272 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001273 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001274 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001275 }
1276
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001277 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1278 Phone phone = getPhoneFromRequest(request);
1279 return phone == null ? null :
1280 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1281 }
1282
Wink Saville36469e72014-06-11 15:17:00 -07001283 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001284 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001285 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001287
1288 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001289 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001290 }
1291
Wink Savilleb564aae2014-10-23 10:18:09 -07001292 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 if (DBG) log("dial: " + number);
1294 // No permission check needed here: This is just a wrapper around the
1295 // ACTION_DIAL intent, which is available to any app since it puts up
1296 // the UI before it does anything.
1297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001298 final long identity = Binder.clearCallingIdentity();
1299 try {
1300 String url = createTelUrl(number);
1301 if (url == null) {
1302 return;
1303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001305 // PENDING: should we just silently fail if phone is offhook or ringing?
1306 PhoneConstants.State state = mCM.getState(subId);
1307 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1308 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1309 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1310 mApp.startActivity(intent);
1311 }
1312 } finally {
1313 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 }
1315 }
1316
1317 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001318 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001319 }
1320
Wink Savilleb564aae2014-10-23 10:18:09 -07001321 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 if (DBG) log("call: " + number);
1323
1324 // This is just a wrapper around the ACTION_CALL intent, but we still
1325 // need to do a permission check since we're calling startActivity()
1326 // from the context of the phone app.
1327 enforceCallPermission();
1328
1329 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1330 != AppOpsManager.MODE_ALLOWED) {
1331 return;
1332 }
1333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001334 final long identity = Binder.clearCallingIdentity();
1335 try {
1336 String url = createTelUrl(number);
1337 if (url == null) {
1338 return;
1339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001341 boolean isValid = false;
1342 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1343 if (slist != null) {
1344 for (SubscriptionInfo subInfoRecord : slist) {
1345 if (subInfoRecord.getSubscriptionId() == subId) {
1346 isValid = true;
1347 break;
1348 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001349 }
Wink Saville08874612014-08-31 19:19:58 -07001350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001351 if (!isValid) {
1352 return;
1353 }
Wink Saville08874612014-08-31 19:19:58 -07001354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001355 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1356 intent.putExtra(SUBSCRIPTION_KEY, subId);
1357 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1358 mApp.startActivity(intent);
1359 } finally {
1360 Binder.restoreCallingIdentity(identity);
1361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 }
1363
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001365 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001366 }
1367
Wink Savilleb564aae2014-10-23 10:18:09 -07001368 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001369 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001370 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1371 }
1372
1373 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
1376
Wink Savilleb564aae2014-10-23 10:18:09 -07001377 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001378 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001379 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1380 }
1381
1382 /** {@hide} */
1383 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001384 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001385 }
1386
Wink Savilleb564aae2014-10-23 10:18:09 -07001387 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001389
1390 final long identity = Binder.clearCallingIdentity();
1391 try {
1392 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1393 checkSimPin.start();
1394 return checkSimPin.unlockSim(null, pin);
1395 } finally {
1396 Binder.restoreCallingIdentity(identity);
1397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001398 }
1399
Wink Saville9de0f752013-10-22 19:04:03 -07001400 /** {@hide} */
1401 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001402 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001403 }
1404
Wink Savilleb564aae2014-10-23 10:18:09 -07001405 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001407
1408 final long identity = Binder.clearCallingIdentity();
1409 try {
1410 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1411 checkSimPuk.start();
1412 return checkSimPuk.unlockSim(puk, pin);
1413 } finally {
1414 Binder.restoreCallingIdentity(identity);
1415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 }
1417
1418 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001419 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 * a synchronous one.
1421 */
1422 private static class UnlockSim extends Thread {
1423
1424 private final IccCard mSimCard;
1425
1426 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001427 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1428 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429
1430 // For replies from SimCard interface
1431 private Handler mHandler;
1432
1433 // For async handler to identify request type
1434 private static final int SUPPLY_PIN_COMPLETE = 100;
1435
1436 public UnlockSim(IccCard simCard) {
1437 mSimCard = simCard;
1438 }
1439
1440 @Override
1441 public void run() {
1442 Looper.prepare();
1443 synchronized (UnlockSim.this) {
1444 mHandler = new Handler() {
1445 @Override
1446 public void handleMessage(Message msg) {
1447 AsyncResult ar = (AsyncResult) msg.obj;
1448 switch (msg.what) {
1449 case SUPPLY_PIN_COMPLETE:
1450 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1451 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001452 mRetryCount = msg.arg1;
1453 if (ar.exception != null) {
1454 if (ar.exception instanceof CommandException &&
1455 ((CommandException)(ar.exception)).getCommandError()
1456 == CommandException.Error.PASSWORD_INCORRECT) {
1457 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1458 } else {
1459 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1460 }
1461 } else {
1462 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 mDone = true;
1465 UnlockSim.this.notifyAll();
1466 }
1467 break;
1468 }
1469 }
1470 };
1471 UnlockSim.this.notifyAll();
1472 }
1473 Looper.loop();
1474 }
1475
1476 /*
1477 * Use PIN or PUK to unlock SIM card
1478 *
1479 * If PUK is null, unlock SIM card with PIN
1480 *
1481 * If PUK is not null, unlock SIM card with PUK and set PIN code
1482 */
Wink Saville9de0f752013-10-22 19:04:03 -07001483 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484
1485 while (mHandler == null) {
1486 try {
1487 wait();
1488 } catch (InterruptedException e) {
1489 Thread.currentThread().interrupt();
1490 }
1491 }
1492 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1493
1494 if (puk == null) {
1495 mSimCard.supplyPin(pin, callback);
1496 } else {
1497 mSimCard.supplyPuk(puk, pin, callback);
1498 }
1499
1500 while (!mDone) {
1501 try {
1502 Log.d(LOG_TAG, "wait for done");
1503 wait();
1504 } catch (InterruptedException e) {
1505 // Restore the interrupted status
1506 Thread.currentThread().interrupt();
1507 }
1508 }
1509 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001510 int[] resultArray = new int[2];
1511 resultArray[0] = mResult;
1512 resultArray[1] = mRetryCount;
1513 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514 }
1515 }
1516
1517 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001518 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001519
1520 }
1521
Wink Savilleb564aae2014-10-23 10:18:09 -07001522 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523 // No permission check needed here: this call is harmless, and it's
1524 // needed for the ServiceState.requestStateUpdate() call (which is
1525 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001526 final long identity = Binder.clearCallingIdentity();
1527 try {
1528 final Phone phone = getPhone(subId);
1529 if (phone != null) {
1530 phone.updateServiceLocation();
1531 }
1532 } finally {
1533 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 }
1536
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001537 @Override
1538 public boolean isRadioOn(String callingPackage) {
1539 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001540 }
1541
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001542 @Override
1543 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001545 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001546 return false;
1547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001548
1549 final long identity = Binder.clearCallingIdentity();
1550 try {
1551 return isRadioOnForSubscriber(subId);
1552 } finally {
1553 Binder.restoreCallingIdentity(identity);
1554 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001555 }
1556
1557 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 final Phone phone = getPhone(subId);
1561 if (phone != null) {
1562 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1563 } else {
1564 return false;
1565 }
1566 } finally {
1567 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
1570
1571 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001572 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 }
Wink Saville36469e72014-06-11 15:17:00 -07001574
Wink Savilleb564aae2014-10-23 10:18:09 -07001575 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001577
1578 final long identity = Binder.clearCallingIdentity();
1579 try {
1580 final Phone phone = getPhone(subId);
1581 if (phone != null) {
1582 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1583 }
1584 } finally {
1585 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 }
Wink Saville36469e72014-06-11 15:17:00 -07001587 }
1588
1589 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001590 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001591 }
1592
Wink Savilleb564aae2014-10-23 10:18:09 -07001593 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001594 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001595
1596 final long identity = Binder.clearCallingIdentity();
1597 try {
1598 final Phone phone = getPhone(subId);
1599 if (phone == null) {
1600 return false;
1601 }
1602 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1603 toggleRadioOnOffForSubscriber(subId);
1604 }
1605 return true;
1606 } finally {
1607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 }
Wink Saville36469e72014-06-11 15:17:00 -07001610
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001611 public boolean needMobileRadioShutdown() {
1612 /*
1613 * If any of the Radios are available, it will need to be
1614 * shutdown. So return true if any Radio is available.
1615 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001616 final long identity = Binder.clearCallingIdentity();
1617 try {
1618 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1619 Phone phone = PhoneFactory.getPhone(i);
1620 if (phone != null && phone.isRadioAvailable()) return true;
1621 }
1622 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1623 return false;
1624 } finally {
1625 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001626 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001627 }
1628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001629 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001630 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001631 enforceModifyPermission();
1632
1633 final long identity = Binder.clearCallingIdentity();
1634 try {
1635 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1636 logv("Shutting down Phone " + i);
1637 shutdownRadioUsingPhoneId(i);
1638 }
1639 } finally {
1640 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001641 }
1642 }
1643
1644 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001645 Phone phone = PhoneFactory.getPhone(phoneId);
1646 if (phone != null && phone.isRadioAvailable()) {
1647 phone.shutdownRadio();
1648 }
1649 }
1650
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001652 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001653
1654 final long identity = Binder.clearCallingIdentity();
1655 try {
1656 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1657 if (defaultPhone != null) {
1658 defaultPhone.setRadioPower(turnOn);
1659 return true;
1660 } else {
1661 loge("There's no default phone.");
1662 return false;
1663 }
1664 } finally {
1665 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001666 }
Wink Saville36469e72014-06-11 15:17:00 -07001667 }
1668
Wink Savilleb564aae2014-10-23 10:18:09 -07001669 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001671
1672 final long identity = Binder.clearCallingIdentity();
1673 try {
1674 final Phone phone = getPhone(subId);
1675 if (phone != null) {
1676 phone.setRadioPower(turnOn);
1677 return true;
1678 } else {
1679 return false;
1680 }
1681 } finally {
1682 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 }
1685
Wink Saville36469e72014-06-11 15:17:00 -07001686 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001687 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 public boolean enableDataConnectivity() {
1689 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001690
1691 final long identity = Binder.clearCallingIdentity();
1692 try {
1693 int subId = mSubscriptionController.getDefaultDataSubId();
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001696 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001697 return true;
1698 } else {
1699 return false;
1700 }
1701 } finally {
1702 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
Wink Saville36469e72014-06-11 15:17:00 -07001706 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 public boolean disableDataConnectivity() {
1709 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001710
1711 final long identity = Binder.clearCallingIdentity();
1712 try {
1713 int subId = mSubscriptionController.getDefaultDataSubId();
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001716 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717 return true;
1718 } else {
1719 return false;
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Sanket Padawe356d7632015-06-22 14:03:32 -07001726 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001727 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728 final long identity = Binder.clearCallingIdentity();
1729 try {
1730 final Phone phone = getPhone(subId);
1731 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001732 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733 } else {
1734 return false;
1735 }
1736 } finally {
1737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 }
1740
1741 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001742 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001743 }
1744
pkanwarae03a6b2016-11-06 20:37:09 -08001745 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001746 enforceCallPermission();
1747
1748 final long identity = Binder.clearCallingIdentity();
1749 try {
1750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1751 return;
1752 }
1753 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1754 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1755 } finally {
1756 Binder.restoreCallingIdentity(identity);
1757 }
pkanwar32d516d2016-10-14 19:37:38 -07001758 };
1759
Wink Savilleb564aae2014-10-23 10:18:09 -07001760 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762
1763 final long identity = Binder.clearCallingIdentity();
1764 try {
1765 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1766 return false;
1767 }
1768 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1769 } finally {
1770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001775 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001776 }
1777
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001778 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779 final long identity = Binder.clearCallingIdentity();
1780 try {
1781 Phone phone = PhoneFactory.getPhone(slotIndex);
1782 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1783 PhoneConstantConversions.convertCallState(phone.getState());
1784 } finally {
1785 Binder.restoreCallingIdentity(identity);
1786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 }
1788
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001791 final long identity = Binder.clearCallingIdentity();
1792 try {
1793 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1794 if (phone != null) {
1795 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1796 } else {
1797 return PhoneConstantConversions.convertDataState(
1798 PhoneConstants.DataState.DISCONNECTED);
1799 }
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001802 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 }
1804
Sanket Padawe356d7632015-06-22 14:03:32 -07001805 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001807 final long identity = Binder.clearCallingIdentity();
1808 try {
1809 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1810 if (phone != null) {
1811 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1812 } else {
1813 return TelephonyManager.DATA_ACTIVITY_NONE;
1814 }
1815 } finally {
1816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 }
1819
1820 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001821 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001822 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001823 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001824 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1825 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001826 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 }
1828
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001829 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001830 final long identity = Binder.clearCallingIdentity();
1831 try {
1832 if (DBG_LOC) log("getCellLocation: is active user");
1833 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001834 int subId = mSubscriptionController.getDefaultDataSubId();
1835 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1836 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837 return data;
1838 } finally {
1839 Binder.restoreCallingIdentity(identity);
1840 }
Svetoslav64fad262015-04-14 14:35:21 -07001841 }
1842
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001844 public String getNetworkCountryIsoForPhone(int phoneId) {
1845 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1846 // registered cell info, so return a NULL country instead.
1847 final long identity = Binder.clearCallingIdentity();
1848 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001849 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1850 // Get default phone in this case.
1851 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1852 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001853 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001854 // Todo: fix this when we can get the actual cellular network info when the device
1855 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001856 if (TelephonyManager.NETWORK_TYPE_IWLAN
1857 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1858 return "";
1859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001860 Phone phone = PhoneFactory.getPhone(phoneId);
1861 if (phone != null) {
1862 ServiceStateTracker sst = phone.getServiceStateTracker();
1863 if (sst != null) {
1864 LocaleTracker lt = sst.getLocaleTracker();
1865 if (lt != null) {
1866 return lt.getCurrentCountry();
1867 }
1868 }
1869 }
1870 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001871 } finally {
1872 Binder.restoreCallingIdentity(identity);
1873 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001874 }
1875
1876 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001878 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001879 }
1880
Sanket Padawe356d7632015-06-22 14:03:32 -07001881 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001882 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 mApp.enforceCallingOrSelfPermission(
1884 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885
1886 final long identity = Binder.clearCallingIdentity();
1887 try {
1888 final Phone phone = getPhone(subId);
1889 if (phone != null) {
1890 phone.enableLocationUpdates();
1891 }
1892 } finally {
1893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 }
1896
1897 @Override
1898 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001899 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001900 }
1901
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001903 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 mApp.enforceCallingOrSelfPermission(
1905 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001906
1907 final long identity = Binder.clearCallingIdentity();
1908 try {
1909 final Phone phone = getPhone(subId);
1910 if (phone != null) {
1911 phone.disableLocationUpdates();
1912 }
1913 } finally {
1914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 }
1917
Nathan Harold31d7ff32018-10-15 20:20:30 -07001918 /**
1919 * Returns the target SDK version number for a given package name.
1920 *
1921 * @return target SDK if the package is found or INT_MAX.
1922 */
1923 private int getTargetSdk(String packageName) {
1924 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001925 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1926 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001927 if (ai != null) return ai.targetSdkVersion;
1928 } catch (PackageManager.NameNotFoundException unexpected) {
1929 }
1930 return Integer.MAX_VALUE;
1931 }
1932
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 @Override
1934 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001935 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1936 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001937 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1938 throw new SecurityException(
1939 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1940 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001941
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1943 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1944 return null;
1945 }
Svetoslav64fad262015-04-14 14:35:21 -07001946
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001947 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948
Nathan Haroldf180aac2018-06-01 18:43:55 -07001949 List<CellInfo> info = getAllCellInfo(callingPackage);
1950 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951
Nathan Haroldf180aac2018-06-01 18:43:55 -07001952 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1953 for (CellInfo ci : info) {
1954 if (ci instanceof CellInfoGsm) {
1955 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1956 } else if (ci instanceof CellInfoWcdma) {
1957 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1958 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001960 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 }
1962
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001963 private List<CellInfo> getCachedCellInfo() {
1964 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1965 for (Phone phone : PhoneFactory.getPhones()) {
1966 List<CellInfo> info = phone.getAllCellInfo();
1967 if (info != null) cellInfos.addAll(info);
1968 }
1969 return cellInfos;
1970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971
1972 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001973 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001974 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001975 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001976 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001977 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001978 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 }
1980
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001981 final int targetSdk = getTargetSdk(callingPackage);
1982 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1983 return getCachedCellInfo();
1984 }
1985
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001986 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001988 final long identity = Binder.clearCallingIdentity();
1989 try {
1990 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1991 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001992 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001993 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001994 if (info != null) cellInfos.addAll(info);
1995 }
1996 return cellInfos;
1997 } finally {
1998 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000 }
2001
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002002 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002003 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2004 requestCellInfoUpdateInternal(
2005 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2006 }
2007
2008 @Override
2009 public void requestCellInfoUpdateWithWorkSource(
2010 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2011 enforceModifyPermission();
2012 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2013 }
2014
2015 private void requestCellInfoUpdateInternal(
2016 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002017 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002018 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002019 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2020 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002021 return;
2022 }
2023
2024 final Phone phone = getPhone(subId);
2025 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2026
2027 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2028 }
2029
2030 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002032 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002034
2035 final long identity = Binder.clearCallingIdentity();
2036 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002037 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 } finally {
2039 Binder.restoreCallingIdentity(identity);
2040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 }
2042
Shishir Agrawala9f32182016-04-12 12:00:16 -07002043 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002044 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002045 Phone phone = PhoneFactory.getPhone(slotIndex);
2046 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002047 return null;
2048 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002049 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002050 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2051 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002052 return null;
2053 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054
2055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 return phone.getImei();
2058 } finally {
2059 Binder.restoreCallingIdentity(identity);
2060 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002061 }
2062
2063 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002064 public String getTypeAllocationCodeForSlot(int slotIndex) {
2065 Phone phone = PhoneFactory.getPhone(slotIndex);
2066 String tac = null;
2067 if (phone != null) {
2068 String imei = phone.getImei();
2069 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2070 }
2071 return tac;
2072 }
2073
2074 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002075 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002076 Phone phone = PhoneFactory.getPhone(slotIndex);
2077 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002078 return null;
2079 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002080
Jeff Davidson913390f2018-02-23 17:11:49 -08002081 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002082 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2083 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002084 return null;
2085 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086
2087 final long identity = Binder.clearCallingIdentity();
2088 try {
2089 return phone.getMeid();
2090 } finally {
2091 Binder.restoreCallingIdentity(identity);
2092 }
Jack Yu2af8d712017-03-15 17:14:14 -07002093 }
2094
2095 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002096 public String getManufacturerCodeForSlot(int slotIndex) {
2097 Phone phone = PhoneFactory.getPhone(slotIndex);
2098 String manufacturerCode = null;
2099 if (phone != null) {
2100 String meid = phone.getMeid();
2101 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2102 }
2103 return manufacturerCode;
2104 }
2105
2106 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002107 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002108 Phone phone = PhoneFactory.getPhone(slotIndex);
2109 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002110 return null;
2111 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002112 int subId = phone.getSubId();
2113 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2114 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2115 return null;
2116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002117
2118 final long identity = Binder.clearCallingIdentity();
2119 try {
2120 return phone.getDeviceSvn();
2121 } finally {
2122 Binder.restoreCallingIdentity(identity);
2123 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002124 }
2125
fionaxu43304da2017-11-27 22:51:16 -08002126 @Override
2127 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002128 final long identity = Binder.clearCallingIdentity();
2129 try {
2130 final Phone phone = getPhone(subId);
2131 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2132 } finally {
2133 Binder.restoreCallingIdentity(identity);
2134 }
fionaxu43304da2017-11-27 22:51:16 -08002135 }
2136
2137 @Override
2138 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139 final long identity = Binder.clearCallingIdentity();
2140 try {
2141 final Phone phone = getPhone(subId);
2142 return phone == null ? null : phone.getCarrierName();
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
2145 }
fionaxu43304da2017-11-27 22:51:16 -08002146 }
2147
calvinpanffe225e2018-11-01 19:43:06 +08002148 @Override
chen xu25637222018-11-04 17:17:00 -08002149 public int getSubscriptionPreciseCarrierId(int subId) {
2150 final long identity = Binder.clearCallingIdentity();
2151 try {
2152 final Phone phone = getPhone(subId);
2153 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2154 : phone.getPreciseCarrierId();
2155 } finally {
2156 Binder.restoreCallingIdentity(identity);
2157 }
2158 }
2159
2160 @Override
2161 public String getSubscriptionPreciseCarrierName(int subId) {
2162 final long identity = Binder.clearCallingIdentity();
2163 try {
2164 final Phone phone = getPhone(subId);
2165 return phone == null ? null : phone.getPreciseCarrierName();
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
2168 }
2169 }
2170
chen xu651eec72018-11-11 19:03:44 -08002171 @Override
chen xu864e11c2018-12-06 22:10:03 -08002172 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2173 if (!isSubscriptionMccMnc) {
2174 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2175 }
chen xu651eec72018-11-11 19:03:44 -08002176 final Phone phone = PhoneFactory.getPhone(slotIndex);
2177 if (phone == null) {
2178 return TelephonyManager.UNKNOWN_CARRIER_ID;
2179 }
2180 final long identity = Binder.clearCallingIdentity();
2181 try {
2182 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
2185 }
2186 }
2187
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 //
2189 // Internal helper methods.
2190 //
2191
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002192 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2194 *
2195 * @throws SecurityException if the caller does not have the required permission
2196 */
2197 private void enforceModifyPermission() {
2198 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2199 }
2200
2201 /**
2202 * Make sure the caller has the CALL_PHONE permission.
2203 *
2204 * @throws SecurityException if the caller does not have the required permission
2205 */
2206 private void enforceCallPermission() {
2207 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2208 }
2209
Stuart Scott8eef64f2015-04-08 15:13:54 -07002210 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002211 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002212 "ConnectivityService");
2213 }
2214
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 private String createTelUrl(String number) {
2216 if (TextUtils.isEmpty(number)) {
2217 return null;
2218 }
2219
Jake Hambye994d462014-02-03 13:10:13 -08002220 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 }
2222
Ihab Awadf9e92732013-12-05 18:02:52 -08002223 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2225 }
2226
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002227 private static void logv(String msg) {
2228 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2229 }
2230
Ihab Awadf9e92732013-12-05 18:02:52 -08002231 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2233 }
2234
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002235 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002237 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002238 }
2239
Sanket Padawe356d7632015-06-22 14:03:32 -07002240 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002241 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 final Phone phone = PhoneFactory.getPhone(slotIndex);
2245 if (phone == null) {
2246 return PhoneConstants.PHONE_TYPE_NONE;
2247 } else {
2248 return phone.getPhoneType();
2249 }
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
2255 /**
2256 * Returns the CDMA ERI icon index to display
2257 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002258 @Override
2259 public int getCdmaEriIconIndex(String callingPackage) {
2260 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002261 }
2262
Sanket Padawe356d7632015-06-22 14:03:32 -07002263 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002264 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002266 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002267 return -1;
2268 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269
2270 final long identity = Binder.clearCallingIdentity();
2271 try {
2272 final Phone phone = getPhone(subId);
2273 if (phone != null) {
2274 return phone.getCdmaEriIconIndex();
2275 } else {
2276 return -1;
2277 }
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
2283 /**
2284 * Returns the CDMA ERI icon mode,
2285 * 0 - ON
2286 * 1 - FLASHING
2287 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002288 @Override
2289 public int getCdmaEriIconMode(String callingPackage) {
2290 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002291 }
2292
Sanket Padawe356d7632015-06-22 14:03:32 -07002293 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002294 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002296 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002297 return -1;
2298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299
2300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 final Phone phone = getPhone(subId);
2303 if (phone != null) {
2304 return phone.getCdmaEriIconMode();
2305 } else {
2306 return -1;
2307 }
2308 } finally {
2309 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 }
2312
2313 /**
2314 * Returns the CDMA ERI text,
2315 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002316 @Override
2317 public String getCdmaEriText(String callingPackage) {
2318 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002319 }
2320
Sanket Padawe356d7632015-06-22 14:03:32 -07002321 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002324 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002325 return null;
2326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 final Phone phone = getPhone(subId);
2331 if (phone != null) {
2332 return phone.getCdmaEriText();
2333 } else {
2334 return null;
2335 }
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
2341 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002342 * Returns the CDMA MDN.
2343 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002344 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002345 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2347 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348
2349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002352 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002353 return phone.getLine1Number();
2354 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002355 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356 return null;
2357 }
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002360 }
2361 }
2362
2363 /**
2364 * Returns the CDMA MIN.
2365 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002366 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002367 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2369 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002370
2371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
2374 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2375 return phone.getCdmaMin();
2376 } else {
2377 return null;
2378 }
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002381 }
2382 }
2383
Hall Liud892bec2018-11-30 14:51:45 -08002384 @Override
2385 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2386 INumberVerificationCallback callback, String callingPackage) {
2387 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2388 != PERMISSION_GRANTED) {
2389 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2390 }
2391 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2392
2393 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2394 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2395 throw new SecurityException("Calling package must be configured in the device config");
2396 }
2397
2398 if (range == null) {
2399 throw new NullPointerException("Range must be non-null");
2400 }
2401
2402 timeoutMillis = Math.min(timeoutMillis,
2403 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2404
2405 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2406 }
2407
Junda Liuca05d5d2014-08-14 22:36:34 -07002408 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 * Returns true if CDMA provisioning needs to run.
2410 */
2411 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412 final long identity = Binder.clearCallingIdentity();
2413 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002414 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415 } finally {
2416 Binder.restoreCallingIdentity(identity);
2417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419
2420 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002421 * Sets the voice mail number of a given subId.
2422 */
2423 @Override
2424 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002425 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426
2427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2430 new Pair<String, String>(alphaTag, number), new Integer(subId));
2431 return success;
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
2434 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002435 }
2436
Ta-wei Yen87c49842016-05-13 21:19:52 -07002437 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002438 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2439 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002440 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002441 if (!TextUtils.equals(callingPackage, systemDialer)) {
2442 throw new SecurityException("caller must be system dialer");
2443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444
2445 final long identity = Binder.clearCallingIdentity();
2446 try {
2447 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2448 if (phoneAccountHandle == null) {
2449 return null;
2450 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002451 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452 } finally {
2453 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002454 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002455 }
2456
2457 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002458 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002461 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002462 return null;
2463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002465 final long identity = Binder.clearCallingIdentity();
2466 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002467 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002468 } finally {
2469 Binder.restoreCallingIdentity(identity);
2470 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002471 }
2472
2473 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002474 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2475 VisualVoicemailSmsFilterSettings settings) {
2476 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477
2478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002481 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 } finally {
2483 Binder.restoreCallingIdentity(identity);
2484 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002485 }
2486
2487 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002488 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002494 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495 } finally {
2496 Binder.restoreCallingIdentity(identity);
2497 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002498 }
2499
2500 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002501 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2502 String callingPackage, int subId) {
2503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002508 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509 } finally {
2510 Binder.restoreCallingIdentity(identity);
2511 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002512 }
2513
2514 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002515 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002516 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517
2518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002521 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522 } finally {
2523 Binder.restoreCallingIdentity(identity);
2524 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002525 }
2526
2527 @Override
2528 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2529 String number, int port, String text, PendingIntent sentIntent) {
2530 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002531 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002532 enforceSendSmsPermission();
2533 // Make the calls as the phone process.
2534 final long identity = Binder.clearCallingIdentity();
2535 try {
2536 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2537 if (port == 0) {
2538 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2539 sentIntent, null, false);
2540 } else {
2541 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2542 smsManager.sendDataMessageWithSelfPermissions(number, null,
2543 (short) port, data, sentIntent, null);
2544 }
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002548 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002549 /**
fionaxu0152e512016-11-14 13:36:14 -08002550 * Sets the voice activation state of a given subId.
2551 */
2552 @Override
2553 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2555 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 final Phone phone = getPhone(subId);
2560 if (phone != null) {
2561 phone.setVoiceActivationState(activationState);
2562 } else {
2563 loge("setVoiceActivationState fails with invalid subId: " + subId);
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002567 }
2568 }
2569
2570 /**
2571 * Sets the data activation state of a given subId.
2572 */
2573 @Override
2574 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2576 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577
2578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 final Phone phone = getPhone(subId);
2581 if (phone != null) {
2582 phone.setDataActivationState(activationState);
2583 } else {
2584 loge("setVoiceActivationState fails with invalid subId: " + subId);
2585 }
2586 } finally {
2587 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002588 }
2589 }
2590
2591 /**
2592 * Returns the voice activation state of a given subId.
2593 */
2594 @Override
2595 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002596 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597
fionaxu0152e512016-11-14 13:36:14 -08002598 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 final long identity = Binder.clearCallingIdentity();
2600 try {
2601 if (phone != null) {
2602 return phone.getVoiceActivationState();
2603 } else {
2604 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002608 }
2609 }
2610
2611 /**
2612 * Returns the data activation state of a given subId.
2613 */
2614 @Override
2615 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002616 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617
fionaxu0152e512016-11-14 13:36:14 -08002618 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 if (phone != null) {
2622 return phone.getDataActivationState();
2623 } else {
2624 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2625 }
2626 } finally {
2627 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002628 }
2629 }
2630
2631 /**
Wink Saville36469e72014-06-11 15:17:00 -07002632 * Returns the unread count of voicemails for a subId
2633 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002634 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002635 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2637 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2638 return 0;
2639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
2643 if (phone != null) {
2644 return phone.getVoiceMessageCount();
2645 } else {
2646 return 0;
2647 }
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 }
2652
2653 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002654 * returns true, if the device is in a state where both voice and data
2655 * are supported simultaneously. This can change based on location or network condition.
2656 */
2657 @Override
2658 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 final Phone phone = getPhone(subId);
2662 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002666 }
2667
2668 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002669 * Send the dialer code if called from the current default dialer or the caller has
2670 * carrier privilege.
2671 * @param inputCode The dialer code to send
2672 */
2673 @Override
2674 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002675 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002677 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2678 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002679 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002680 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2681 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002686 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 } finally {
2688 Binder.restoreCallingIdentity(identity);
2689 }
fionaxu235cc5e2017-03-06 22:25:57 -08002690 }
2691
2692 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002693 * Returns the data network type.
2694 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 *
2696 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2697 */
2698 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002699 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 final Phone phone = getPhone(getDefaultSubscription());
2703 if (phone != null) {
2704 return phone.getServiceState().getDataNetworkType();
2705 } else {
2706 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2707 }
2708 } finally {
2709 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002710 }
Wink Saville36469e72014-06-11 15:17:00 -07002711 }
2712
Pengquan Menga1bb6272018-09-06 09:59:22 -07002713 @Override
2714 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002715 if (!isActiveSubscription(subId)) {
2716 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2717 }
2718
Pengquan Menga1bb6272018-09-06 09:59:22 -07002719 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2720 }
2721
Brad Ebinger35c841c2018-10-01 10:40:55 -07002722 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002723 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2724 throws RemoteException {
2725 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002726 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2727 final long token = Binder.clearCallingIdentity();
2728 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002729 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002730 .addRegistrationCallbackForSubscription(c, subId);
2731 } finally {
2732 Binder.restoreCallingIdentity(token);
2733 }
2734 }
2735
2736 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002737 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2738 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2740 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002741 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002742 .removeRegistrationCallbackForSubscription(c, subId));
2743 }
2744
2745 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002746 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2747 throws RemoteException {
2748 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002749 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2750 final long token = Binder.clearCallingIdentity();
2751 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002752 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002753 .addCapabilitiesCallbackForSubscription(c, subId);
2754 } finally {
2755 Binder.restoreCallingIdentity(token);
2756 }
2757 }
2758
2759 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002760 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2761 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002762 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2763 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002764 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002765 .removeCapabilitiesCallbackForSubscription(c, subId));
2766 }
2767
2768 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002769 public boolean isCapable(int subId, int capability, int regTech) {
2770 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002771 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2772 final long token = Binder.clearCallingIdentity();
2773 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002774 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002775 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2776 } catch (ImsException e) {
2777 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2778 return false;
2779 } finally {
2780 Binder.restoreCallingIdentity(token);
2781 }
2782 }
2783
2784 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002785 public boolean isAvailable(int subId, int capability, int regTech) {
2786 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002787 final long token = Binder.clearCallingIdentity();
2788 try {
2789 Phone phone = getPhone(subId);
2790 if (phone == null) return false;
2791 return phone.isImsCapabilityAvailable(capability, regTech);
2792 } finally {
2793 Binder.restoreCallingIdentity(token);
2794 }
2795 }
2796
2797 @Override
2798 public boolean isAdvancedCallingSettingEnabled(int subId) {
2799 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2800 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2801 final long token = Binder.clearCallingIdentity();
2802 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002803 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002804 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2805 } finally {
2806 Binder.restoreCallingIdentity(token);
2807 }
2808 }
2809
2810 @Override
2811 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2813 "setAdvancedCallingSetting");
2814 final long identity = Binder.clearCallingIdentity();
2815 try {
2816 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002817 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002818 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
2821 }
2822 }
2823
2824 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002825 public boolean isVtSettingEnabled(int subId) {
2826 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002830 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002831 getSlotIndexOrException(subId)).isVtEnabledByUser();
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
2834 }
2835 }
2836
2837 @Override
2838 public void setVtSetting(int subId, boolean isEnabled) {
2839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2840 "setVtSetting");
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002844 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002845 } finally {
2846 Binder.restoreCallingIdentity(identity);
2847 }
2848 }
2849
2850 @Override
2851 public boolean isVoWiFiSettingEnabled(int subId) {
2852 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002856 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002857 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
2860 }
2861 }
2862
2863 @Override
2864 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2866 "setVoWiFiSetting");
2867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002870 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002871 } finally {
2872 Binder.restoreCallingIdentity(identity);
2873 }
2874 }
2875
2876 @Override
2877 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2878 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002882 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002883 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2884 } finally {
2885 Binder.restoreCallingIdentity(identity);
2886 }
2887 }
2888
2889 @Override
2890 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2892 "setVoWiFiRoamingSetting");
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002896 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002897 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
2900 }
2901 }
2902
2903 @Override
2904 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2906 "setVoWiFiNonPersistent");
2907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002910 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002911 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
2914 }
2915 }
2916
2917 @Override
2918 public int getVoWiFiModeSetting(int subId) {
2919 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002923 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002924 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
2927 }
2928 }
2929
2930 @Override
2931 public void setVoWiFiModeSetting(int subId, int mode) {
2932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2933 "setVoWiFiModeSetting");
2934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002937 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002938 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2939 } finally {
2940 Binder.restoreCallingIdentity(identity);
2941 }
2942 }
2943
2944 @Override
2945 public int getVoWiFiRoamingModeSetting(int subId) {
2946 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2947 final long identity = Binder.clearCallingIdentity();
2948 try {
2949 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002950 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002951 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
2954 }
2955 }
2956
2957 @Override
2958 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2960 "setVoWiFiRoamingModeSetting");
2961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002964 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002965 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
2972 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2974 "setRttCapabilityEnabled");
2975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002978 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
2983 }
2984
2985 @Override
2986 public boolean isTtyOverVolteEnabled(int subId) {
2987 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002991 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002998 @Override
2999 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3000 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003005 .getConfigInterface().addConfigCallback(callback);
3006 } catch (ImsException e) {
3007 throw new IllegalArgumentException(e.getMessage());
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
3011 }
3012
3013 @Override
3014 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3015 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003019 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003020 .getConfigInterface().removeConfigCallback(callback);
3021 } catch (ImsException e) {
3022 throw new IllegalArgumentException(e.getMessage());
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
3026 }
3027
3028 @Override
3029 public int getImsProvisioningInt(int subId, int key) {
3030 enforceReadPrivilegedPermission("getImsProvisioningInt");
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 return ImsManager.getInstance(mApp,
3035 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003036 } catch (ImsException e) {
3037 throw new IllegalArgumentException(e.getMessage());
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
3041 }
3042
3043 @Override
3044 public String getImsProvisioningString(int subId, int key) {
3045 enforceReadPrivilegedPermission("getImsProvisioningString");
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003049 return ImsManager.getInstance(mApp,
3050 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003051 } catch (ImsException e) {
3052 throw new IllegalArgumentException(e.getMessage());
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
3056 }
3057
3058 @Override
3059 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3061 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003065 return ImsManager.getInstance(mApp,
3066 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003067 } catch (ImsException e) {
3068 throw new IllegalArgumentException(e.getMessage());
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
3072 }
3073
3074 @Override
3075 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3077 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003081 return ImsManager.getInstance(mApp,
3082 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003083 } catch (ImsException e) {
3084 throw new IllegalArgumentException(e.getMessage());
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
3088 }
3089
Brad Ebinger35c841c2018-10-01 10:40:55 -07003090 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3091 int slotId = SubscriptionManager.getSlotIndex(subId);
3092 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3093 throw new IllegalArgumentException("Invalid Subscription Id.");
3094 }
3095 return slotId;
3096 }
3097
Wink Saville36469e72014-06-11 15:17:00 -07003098 /**
3099 * Returns the network type for a subId
3100 */
3101 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003102 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003104 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003105 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3106 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003108 final long identity = Binder.clearCallingIdentity();
3109 try {
3110 final Phone phone = getPhone(subId);
3111 if (phone != null) {
3112 return phone.getServiceState().getDataNetworkType();
3113 } else {
3114 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3115 }
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119 }
3120
3121 /**
3122 * Returns the data network type
3123 */
3124 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003125 public int getDataNetworkType(String callingPackage) {
3126 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003127 }
3128
3129 /**
3130 * Returns the data network type for a subId
3131 */
3132 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003133 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003135 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003136 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3137 }
3138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 final Phone phone = getPhone(subId);
3142 if (phone != null) {
3143 return phone.getServiceState().getDataNetworkType();
3144 } else {
3145 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3146 }
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 }
3151
3152 /**
Wink Saville36469e72014-06-11 15:17:00 -07003153 * Returns the Voice network type for a subId
3154 */
3155 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003156 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003158 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003159 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3160 }
3161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 final Phone phone = getPhone(subId);
3165 if (phone != null) {
3166 return phone.getServiceState().getVoiceNetworkType();
3167 } else {
3168 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3169 }
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 }
3174
3175 /**
3176 * @return true if a ICC card is present
3177 */
3178 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003179 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003180 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3181 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003182 }
3183
3184 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003185 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003186 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003187 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003188 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 final Phone phone = PhoneFactory.getPhone(slotIndex);
3192 if (phone != null) {
3193 return phone.getIccCard().hasIccCard();
3194 } else {
3195 return false;
3196 }
3197 } finally {
3198 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 }
3201
3202 /**
3203 * Return if the current radio is LTE on CDMA. This
3204 * is a tri-state return value as for a period of time
3205 * the mode may be unknown.
3206 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003207 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003209 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003211 @Override
3212 public int getLteOnCdmaMode(String callingPackage) {
3213 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003214 }
3215
Sanket Padawe356d7632015-06-22 14:03:32 -07003216 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003217 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003219 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003220 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3221 }
3222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 final Phone phone = getPhone(subId);
3226 if (phone == null) {
3227 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3228 } else {
3229 return phone.getLteOnCdmaMode();
3230 }
3231 } finally {
3232 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003233 }
Wink Saville36469e72014-06-11 15:17:00 -07003234 }
3235
Wink Saville36469e72014-06-11 15:17:00 -07003236 /**
3237 * {@hide}
3238 * Returns Default subId, 0 in the case of single standby.
3239 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003240 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003241 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003242 }
3243
Shishir Agrawala9f32182016-04-12 12:00:16 -07003244 private int getSlotForDefaultSubscription() {
3245 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3246 }
3247
Wink Savilleb564aae2014-10-23 10:18:09 -07003248 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003249 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003251
Pengquan Menge92a50d2018-09-21 15:54:48 -07003252 private boolean isActiveSubscription(int subId) {
3253 return mSubscriptionController.isActiveSubId(subId);
3254 }
3255
Ihab Awadf2177b72013-11-25 13:33:23 -08003256 /**
3257 * @see android.telephony.TelephonyManager.WifiCallingChoices
3258 */
3259 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003260 final long identity = Binder.clearCallingIdentity();
3261 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003262 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3264 getWhenToMakeWifiCallsDefaultPreference());
3265 } finally {
3266 Binder.restoreCallingIdentity(identity);
3267 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003268 }
3269
3270 /**
3271 * @see android.telephony.TelephonyManager.WifiCallingChoices
3272 */
3273 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003282 }
3283
Sailesh Nepald1e68152013-12-12 19:08:02 -08003284 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003285 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003286 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003287 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003288
Shishir Agrawal566b7612013-10-28 14:41:00 -07003289 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003290 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3291 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3293 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003294 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 if (TextUtils.equals(ISDR_AID, aid)) {
3299 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003300 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3301 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003302 if (bestComponent == null
3303 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3304 loge("The calling package is not allowed to access ISD-R.");
3305 throw new SecurityException(
3306 "The calling package is not allowed to access ISD-R.");
3307 }
Derek Tan740e1672017-06-27 14:56:27 -07003308 }
Derek Tan740e1672017-06-27 14:56:27 -07003309
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 if (DBG) {
3311 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3312 }
3313 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3314 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3315 if (DBG) log("iccOpenLogicalChannel: " + response);
3316 return response;
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003320 }
3321
3322 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003323 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3325 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3330 if (channel < 0) {
3331 return false;
3332 }
3333 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3334 if (DBG) log("iccCloseLogicalChannel: " + success);
3335 return success;
3336 } finally {
3337 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003338 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003339 }
3340
3341 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003342 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003343 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3345 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 if (DBG) {
3350 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3351 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3352 + p3 + " data=" + data);
3353 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003354
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 if (channel < 0) {
3356 return "";
3357 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3360 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3361 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363 // Append the returned status code to the end of the response payload.
3364 String s = Integer.toHexString(
3365 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3366 if (response.payload != null) {
3367 s = IccUtils.bytesToHexString(response.payload) + s;
3368 }
3369 return s;
3370 } finally {
3371 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003373 }
Jake Hambye994d462014-02-03 13:10:13 -08003374
Evan Charltonc66da362014-05-16 14:06:40 -07003375 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003376 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3377 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3379 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3385 && TextUtils.equals(ISDR_AID, data)) {
3386 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003387 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3388 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 if (bestComponent == null
3390 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3391 loge("The calling package is not allowed to select ISD-R.");
3392 throw new SecurityException(
3393 "The calling package is not allowed to select ISD-R.");
3394 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003395 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 if (DBG) {
3398 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3399 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3400 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3403 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3404 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003405
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003406 // Append the returned status code to the end of the response payload.
3407 String s = Integer.toHexString(
3408 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3409 if (response.payload != null) {
3410 s = IccUtils.bytesToHexString(response.payload) + s;
3411 }
3412 return s;
3413 } finally {
3414 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003415 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003416 }
3417
3418 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003419 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003420 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3422 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 if (DBG) {
3427 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3428 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3429 }
3430
3431 IccIoResult response =
3432 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3433 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3434 subId);
3435
3436 if (DBG) {
3437 log("Exchange SIM_IO [R]" + response);
3438 }
3439
3440 byte[] result = null;
3441 int length = 2;
3442 if (response.payload != null) {
3443 length = 2 + response.payload.length;
3444 result = new byte[length];
3445 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3446 } else {
3447 result = new byte[length];
3448 }
3449
3450 result[length - 1] = (byte) response.sw2;
3451 result[length - 2] = (byte) response.sw1;
3452 return result;
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003455 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003456 }
3457
Nathan Haroldb3014052017-01-25 15:57:32 -08003458 /**
3459 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3460 * on a particular subscription
3461 */
sqianb6e41952018-03-12 14:54:01 -07003462 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3464 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3465 return null;
3466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003467
3468 final long identity = Binder.clearCallingIdentity();
3469 try {
3470 if (appType != TelephonyManager.APPTYPE_USIM
3471 && appType != TelephonyManager.APPTYPE_SIM) {
3472 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3473 return null;
3474 }
3475 Object response = sendRequest(
3476 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3477 if (response instanceof String[]) {
3478 return (String[]) response;
3479 }
3480 // Response is an Exception of some kind,
3481 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003482 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483 } finally {
3484 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003485 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003486 }
3487
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003488 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003489 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3491 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3496 if (response.payload == null) {
3497 return "";
3498 }
Evan Charltonc66da362014-05-16 14:06:40 -07003499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003500 // Append the returned status code to the end of the response payload.
3501 String s = Integer.toHexString(
3502 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3503 s = IccUtils.bytesToHexString(response.payload) + s;
3504 return s;
3505 } finally {
3506 Binder.restoreCallingIdentity(identity);
3507 }
Evan Charltonc66da362014-05-16 14:06:40 -07003508 }
3509
Jake Hambye994d462014-02-03 13:10:13 -08003510 /**
3511 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3512 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3513 *
3514 * @param itemID the ID of the item to read
3515 * @return the NV item as a String, or null on error.
3516 */
3517 @Override
3518 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003519 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3521 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522
3523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003526 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3528 return value;
3529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
Jake Hambye994d462014-02-03 13:10:13 -08003532 }
3533
3534 /**
3535 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3536 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3537 *
3538 * @param itemID the ID of the item to read
3539 * @param itemValue the value to write, as a String
3540 * @return true on success; false on any failure
3541 */
3542 @Override
3543 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3546 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3551 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003552 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003553 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3554 return success;
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
Jake Hambye994d462014-02-03 13:10:13 -08003558 }
3559
3560 /**
3561 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3562 * Used for device configuration by some CDMA operators.
3563 *
3564 * @param preferredRoamingList byte array containing the new PRL
3565 * @return true on success; false on any failure
3566 */
3567 @Override
3568 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3570 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571
3572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3575 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3576 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3577 return success;
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
Jake Hambye994d462014-02-03 13:10:13 -08003581 }
3582
3583 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003584 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003585 * Used for device configuration by some CDMA operators.
3586 *
chen xu6dac5ab2018-10-26 17:39:23 -07003587 * @param slotIndex - device slot.
3588 *
Jake Hambye994d462014-02-03 13:10:13 -08003589 * @return true on success; false on any failure
3590 */
3591 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003592 public boolean resetModemConfig(int slotIndex) {
3593 Phone phone = PhoneFactory.getPhone(slotIndex);
3594 if (phone != null) {
3595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3596 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003597
chen xu6dac5ab2018-10-26 17:39:23 -07003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3601 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3602 return success;
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606 }
chen xu6dac5ab2018-10-26 17:39:23 -07003607 return false;
3608 }
3609
3610 /**
3611 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3612 *
3613 * @param slotIndex - device slot.
3614 *
3615 * @return true on success; false on any failure
3616 */
3617 @Override
3618 public boolean rebootModem(int slotIndex) {
3619 Phone phone = PhoneFactory.getPhone(slotIndex);
3620 if (phone != null) {
3621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3622 mApp, phone.getSubId(), "rebootModem");
3623
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3627 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3628 return success;
3629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
3632 }
3633 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003634 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003635
Svet Ganovb320e182015-04-16 12:30:10 -07003636 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003640 return new String[0];
3641 }
3642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643 final long identity = Binder.clearCallingIdentity();
3644 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003645 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646 } finally {
3647 Binder.restoreCallingIdentity(identity);
3648 }
Wink Saville36469e72014-06-11 15:17:00 -07003649 }
3650
Brad Ebinger51f743a2017-01-23 13:50:20 -08003651 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003652 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3653 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003654 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003655 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003656 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 PhoneFactory.getImsResolver().enableIms(slotId);
3661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003664 }
3665
3666 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003667 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3668 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003669 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003670 public void disableIms(int slotId) {
3671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 PhoneFactory.getImsResolver().disableIms(slotId);
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003679 }
3680
3681 /**
3682 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3683 * feature or {@link null} if the service is not available. If the feature is available, the
3684 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3685 */
3686 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003687 IImsServiceFeatureCallback callback) {
3688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689
3690 final long identity = Binder.clearCallingIdentity();
3691 try {
3692 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003696 }
3697
3698 /**
3699 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3700 * feature during emergency calling or {@link null} if the service is not available. If the
3701 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3702 * listener for feature updates.
3703 */
3704 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706
3707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003713 }
3714
Brad Ebinger5f64b052017-12-14 14:26:15 -08003715 /**
3716 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3717 * specified.
3718 */
3719 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3720 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003728 }
3729
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003730 /**
3731 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3732 * specified.
3733 */
3734 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3735 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736
3737 final long identity = Binder.clearCallingIdentity();
3738 try {
3739 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003743 }
3744
Brad Ebinger884c07b2018-02-15 16:17:40 -08003745 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003746 * Sets the ImsService Package Name that Telephony will bind to.
3747 *
3748 * @param slotId the slot ID that the ImsService should bind for.
3749 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3750 * ImsService is the device default ImsService.
3751 * @param packageName The package name of the application that contains the ImsService to bind
3752 * to.
3753 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3754 * @hide
3755 */
3756 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003757 int[] subIds = SubscriptionManager.getSubId(slotId);
3758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3759 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3760 "setImsService");
3761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3765 isCarrierImsService, packageName);
3766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003769 }
3770
3771 /**
3772 * Return the ImsService configuration.
3773 *
3774 * @param slotId The slot that the ImsService is associated with.
3775 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3776 * the device default.
3777 * @return the package name of the ImsService configuration.
3778 */
3779 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003780 int[] subIds = SubscriptionManager.getSubId(slotId);
3781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3782 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3783 "getImsService");
3784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3788 isCarrierImsService);
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003792 }
3793
Wink Saville36469e72014-06-11 15:17:00 -07003794 public void setImsRegistrationState(boolean registered) {
3795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796
3797 final long identity = Binder.clearCallingIdentity();
3798 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003799 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
Wink Saville36469e72014-06-11 15:17:00 -07003803 }
3804
3805 /**
Stuart Scott54788802015-03-30 13:18:01 -07003806 * Set the network selection mode to automatic.
3807 *
3808 */
3809 @Override
3810 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3812 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813
Pengquan Menge92a50d2018-09-21 15:54:48 -07003814 if (!isActiveSubscription(subId)) {
3815 return;
3816 }
3817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3821 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
3824 }
Stuart Scott54788802015-03-30 13:18:01 -07003825 }
3826
Pengquan Mengea84e042018-09-20 14:57:26 -07003827 /**
3828 * Ask the radio to connect to the input network and change selection mode to manual.
3829 *
3830 * @param subId the id of the subscription.
3831 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3832 * the operator to attach to.
3833 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3834 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3835 * normal network selection next time.
3836 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003837 */
3838 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003839 public boolean setNetworkSelectionModeManual(
3840 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3842 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003843
3844 if (!isActiveSubscription(subId)) {
3845 return false;
3846 }
3847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 final long identity = Binder.clearCallingIdentity();
3849 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003850 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003852 if (DBG) {
3853 log("setNetworkSelectionModeManual: subId: " + subId
3854 + " operator: " + operatorInfo);
3855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
3859 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003860 }
3861
3862 /**
3863 * Scans for available networks.
3864 */
3865 @Override
3866 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3868 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869
Pengquan Menga1bb6272018-09-06 09:59:22 -07003870 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 try {
3872 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003873 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003878 }
3879
3880 /**
yinxub1bed742017-04-17 11:45:04 -07003881 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003882 *
yinxub1bed742017-04-17 11:45:04 -07003883 * @param subId id of the subscription
3884 * @param request contains the radio access networks with bands/channels to scan
3885 * @param messenger callback messenger for scan results or errors
3886 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003887 * @return the id of the requested scan which can be used to stop the scan.
3888 */
3889 @Override
3890 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3891 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3893 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894
3895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 return mNetworkScanRequestTracker.startNetworkScan(
3898 request, messenger, binder, getPhone(subId));
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
3901 }
yinxu504e1392017-04-12 16:03:22 -07003902 }
3903
3904 /**
3905 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003906 *
3907 * @param subId id of the subscription
3908 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003909 */
3910 @Override
3911 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3913 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914
3915 final long identity = Binder.clearCallingIdentity();
3916 try {
3917 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
yinxu504e1392017-04-12 16:03:22 -07003921 }
3922
3923 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003924 * Get the calculated preferred network type.
3925 * Used for debugging incorrect network type.
3926 *
3927 * @return the preferred network type, defined in RILConstants.java.
3928 */
3929 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003930 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003931 final Phone defaultPhone = getDefaultPhone();
3932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3933 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003934 return RILConstants.PREFERRED_NETWORK_MODE;
3935 }
3936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003940 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 } finally {
3942 Binder.restoreCallingIdentity(identity);
3943 }
Junda Liu84d15a22014-07-02 11:21:04 -07003944 }
3945
3946 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003947 * Get the preferred network type.
3948 * Used for device configuration by some CDMA operators.
3949 *
3950 * @return the preferred network type, defined in RILConstants.java.
3951 */
3952 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003953 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3955 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956
3957 final long identity = Binder.clearCallingIdentity();
3958 try {
3959 if (DBG) log("getPreferredNetworkType");
3960 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3961 int networkType = (result != null ? result[0] : -1);
3962 if (DBG) log("getPreferredNetworkType: " + networkType);
3963 return networkType;
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003967 }
3968
3969 /**
3970 * Set the preferred network type.
3971 * Used for device configuration by some CDMA operators.
3972 *
3973 * @param networkType the preferred network type, defined in RILConstants.java.
3974 * @return true on success; false on any failure.
3975 */
3976 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003977 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3979 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980
3981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3984 Boolean success = (Boolean) sendRequest(
3985 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3986 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3987 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003988 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003989 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3990 }
3991 return success;
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003994 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003995 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003996
3997 /**
Junda Liu475951f2014-11-07 16:45:03 -08003998 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07003999 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004000 * tethering.
4001 *
4002 * @return 0: Not required. 1: required. 2: Not set.
4003 * @hide
4004 */
4005 @Override
4006 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004007 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008
4009 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004010 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004012 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07004014 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004015 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 dunRequired = 1;
4017 }
4018 return dunRequired;
4019 } finally {
4020 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004021 }
Junda Liu475951f2014-11-07 16:45:03 -08004022 }
4023
4024 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004025 * Set mobile data enabled
4026 * Used by the user through settings etc to turn on/off mobile data
4027 *
4028 * @param enable {@code true} turn turn data on, else {@code false}
4029 */
4030 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004031 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4033 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004034
4035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 int phoneId = mSubscriptionController.getPhoneId(subId);
4038 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4039 Phone phone = PhoneFactory.getPhone(phoneId);
4040 if (phone != null) {
4041 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004042 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004044 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 }
4046 } finally {
4047 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004048 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004049 }
4050
4051 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004052 * Get the user enabled state of Mobile Data.
4053 *
4054 * TODO: remove and use isUserDataEnabled.
4055 * This can't be removed now because some vendor codes
4056 * calls through ITelephony directly while they should
4057 * use TelephonyManager.
4058 *
4059 * @return true on enabled
4060 */
4061 @Override
4062 public boolean getDataEnabled(int subId) {
4063 return isUserDataEnabled(subId);
4064 }
4065
4066 /**
4067 * Get whether mobile data is enabled per user setting.
4068 *
4069 * There are other factors deciding whether mobile data is actually enabled, but they are
4070 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004071 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004072 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004073 *
4074 * @return {@code true} if data is enabled else {@code false}
4075 */
4076 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004077 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004078 try {
4079 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4080 null);
4081 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4083 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 int phoneId = mSubscriptionController.getPhoneId(subId);
4089 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4090 Phone phone = PhoneFactory.getPhone(phoneId);
4091 if (phone != null) {
4092 boolean retVal = phone.isUserDataEnabled();
4093 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4094 return retVal;
4095 } else {
4096 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4097 return false;
4098 }
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004101 }
4102 }
4103
4104 /**
4105 * Get whether mobile data is enabled.
4106 *
4107 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4108 * whether mobile data is actually enabled.
4109 *
4110 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4111 *
4112 * @return {@code true} if data is enabled else {@code false}
4113 */
4114 @Override
4115 public boolean isDataEnabled(int subId) {
4116 try {
4117 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4118 null);
4119 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4121 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004122 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123
4124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 int phoneId = mSubscriptionController.getPhoneId(subId);
4127 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4128 Phone phone = PhoneFactory.getPhone(phoneId);
4129 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004130 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004131 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4132 return retVal;
4133 } else {
4134 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4135 return false;
4136 }
4137 } finally {
4138 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004139 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004140 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004141
4142 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004143 public int getCarrierPrivilegeStatus(int subId) {
4144 final Phone phone = getPhone(subId);
4145 if (phone == null) {
4146 loge("getCarrierPrivilegeStatus: Invalid subId");
4147 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4148 }
4149 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004150 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004151 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004152 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4153 }
4154 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004155 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004156 }
Junda Liu29340342014-07-10 15:23:27 -07004157
4158 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004159 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4160 final Phone phone = getPhone(subId);
4161 if (phone == null) {
4162 loge("getCarrierPrivilegeStatus: Invalid subId");
4163 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4164 }
4165 UiccProfile profile =
4166 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4167 if (profile == null) {
4168 loge("getCarrierPrivilegeStatus: No UICC");
4169 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4170 }
4171 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4172 }
4173
4174 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004175 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004176 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004177 if (TextUtils.isEmpty(pkgName))
4178 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004179 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004180 if (card == null) {
4181 loge("checkCarrierPrivilegesForPackage: No UICC");
4182 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4183 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004184 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4185 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004186 }
4187
4188 @Override
4189 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004190 if (TextUtils.isEmpty(pkgName))
4191 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004192 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4193 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4194 UiccCard card = UiccController.getInstance().getUiccCard(i);
4195 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004196 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004197 continue;
4198 }
4199
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004200 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004201 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4202 break;
4203 }
4204 }
4205
4206 return result;
Junda Liu29340342014-07-10 15:23:27 -07004207 }
Derek Tan89e89d42014-07-08 17:00:10 -07004208
4209 @Override
Junda Liue64de782015-04-16 17:19:16 -07004210 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4211 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4212 loge("phoneId " + phoneId + " is not valid.");
4213 return null;
4214 }
4215 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004216 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004217 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004218 return null ;
4219 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004220 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004221 }
4222
Amith Yamasani6e118872016-02-19 12:53:51 -08004223 @Override
4224 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004225 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004226 List<String> privilegedPackages = new ArrayList<>();
4227 List<PackageInfo> packages = null;
4228 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4229 UiccCard card = UiccController.getInstance().getUiccCard(i);
4230 if (card == null) {
4231 // No UICC in that slot.
4232 continue;
4233 }
4234 if (card.hasCarrierPrivilegeRules()) {
4235 if (packages == null) {
4236 // Only check packages in user 0 for now
4237 packages = pm.getInstalledPackagesAsUser(
4238 PackageManager.MATCH_DISABLED_COMPONENTS
4239 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4240 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4241 }
4242 for (int p = packages.size() - 1; p >= 0; p--) {
4243 PackageInfo pkgInfo = packages.get(p);
4244 if (pkgInfo != null && pkgInfo.packageName != null
4245 && card.getCarrierPrivilegeStatus(pkgInfo)
4246 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4247 privilegedPackages.add(pkgInfo.packageName);
4248 }
4249 }
4250 }
4251 }
4252 return privilegedPackages;
4253 }
4254
Wink Savilleb564aae2014-10-23 10:18:09 -07004255 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004256 final Phone phone = getPhone(subId);
4257 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004258 if (card == null) {
4259 loge("getIccId: No UICC");
4260 return null;
4261 }
4262 String iccId = card.getIccId();
4263 if (TextUtils.isEmpty(iccId)) {
4264 loge("getIccId: ICC ID is null or empty.");
4265 return null;
4266 }
4267 return iccId;
4268 }
4269
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004270 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004271 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4272 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004273 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4274 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 final String iccId = getIccId(subId);
4279 final Phone phone = getPhone(subId);
4280 if (phone == null) {
4281 return false;
4282 }
4283 final String subscriberId = phone.getSubscriberId();
4284
4285 if (DBG_MERGE) {
4286 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4287 + subscriberId + " to " + number);
4288 }
4289
4290 if (TextUtils.isEmpty(iccId)) {
4291 return false;
4292 }
4293
4294 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4295
4296 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4297 if (alphaTag == null) {
4298 editor.remove(alphaTagPrefKey);
4299 } else {
4300 editor.putString(alphaTagPrefKey, alphaTag);
4301 }
4302
4303 // Record both the line number and IMSI for this ICCID, since we need to
4304 // track all merged IMSIs based on line number
4305 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4306 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4307 if (number == null) {
4308 editor.remove(numberPrefKey);
4309 editor.remove(subscriberPrefKey);
4310 } else {
4311 editor.putString(numberPrefKey, number);
4312 editor.putString(subscriberPrefKey, subscriberId);
4313 }
4314
4315 editor.commit();
4316 return true;
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004319 }
Derek Tan7226c842014-07-02 17:42:23 -07004320 }
4321
4322 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004323 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004324 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004326 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004327 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004328 return null;
4329 }
Derek Tan97ebb422014-09-05 16:55:38 -07004330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 final long identity = Binder.clearCallingIdentity();
4332 try {
4333 String iccId = getIccId(subId);
4334 if (iccId != null) {
4335 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4336 if (DBG_MERGE) {
4337 log("getLine1NumberForDisplay returning "
4338 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4339 }
4340 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004342 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4343 return null;
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004346 }
Derek Tan7226c842014-07-02 17:42:23 -07004347 }
4348
4349 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004350 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004352 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004353 return null;
4354 }
Derek Tan97ebb422014-09-05 16:55:38 -07004355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 final long identity = Binder.clearCallingIdentity();
4357 try {
4358 String iccId = getIccId(subId);
4359 if (iccId != null) {
4360 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4361 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4362 }
4363 return null;
4364 } finally {
4365 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004366 }
Derek Tan7226c842014-07-02 17:42:23 -07004367 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004368
4369 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004370 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004371 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4372 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004374 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4375 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004376 return null;
4377 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004378
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004379 final long identity = Binder.clearCallingIdentity();
4380 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004381 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382 final TelephonyManager tele = TelephonyManager.from(context);
4383 final SubscriptionManager sub = SubscriptionManager.from(context);
4384
4385 // Figure out what subscribers are currently active
4386 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4387 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4388 // the process, where TelephonyManager was instantiated.
4389 // Otherwise AppOps check will fail.
4390
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004391 final int[] subIds = sub.getActiveSubscriptionIdList();
4392 for (int subId : subIds) {
4393 activeSubscriberIds.add(tele.getSubscriberId(subId));
4394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395
4396 // First pass, find a number override for an active subscriber
4397 String mergeNumber = null;
4398 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4399 for (String key : prefs.keySet()) {
4400 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4401 final String subscriberId = (String) prefs.get(key);
4402 if (activeSubscriberIds.contains(subscriberId)) {
4403 final String iccId = key.substring(
4404 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4405 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4406 mergeNumber = (String) prefs.get(numberKey);
4407 if (DBG_MERGE) {
4408 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4409 + " for active subscriber " + subscriberId);
4410 }
4411 if (!TextUtils.isEmpty(mergeNumber)) {
4412 break;
4413 }
4414 }
4415 }
4416 }
4417
4418 // Shortcut when no active merged subscribers
4419 if (TextUtils.isEmpty(mergeNumber)) {
4420 return null;
4421 }
4422
4423 // Second pass, find all subscribers under that line override
4424 final ArraySet<String> result = new ArraySet<>();
4425 for (String key : prefs.keySet()) {
4426 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4427 final String number = (String) prefs.get(key);
4428 if (mergeNumber.equals(number)) {
4429 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4430 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4431 final String subscriberId = (String) prefs.get(subscriberKey);
4432 if (!TextUtils.isEmpty(subscriberId)) {
4433 result.add(subscriberId);
4434 }
4435 }
4436 }
4437 }
4438
4439 final String[] resultArray = result.toArray(new String[result.size()]);
4440 Arrays.sort(resultArray);
4441 if (DBG_MERGE) {
4442 Slog.d(LOG_TAG,
4443 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4444 }
4445 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004446 } finally {
4447 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004448 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004449 }
4450
4451 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004452 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004453 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4454 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455
4456 final long identity = Binder.clearCallingIdentity();
4457 try {
4458 final Phone phone = getPhone(subId);
4459 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4460 } finally {
4461 Binder.restoreCallingIdentity(identity);
4462 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004463 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004464
4465 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004466 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004467 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4468 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004469 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470
4471 final long identity = Binder.clearCallingIdentity();
4472 try {
4473 final Phone phone = getPhone(subId);
4474 if (phone == null) {
4475 return false;
4476 }
4477 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4478 cdmaNonRoamingList);
4479 } finally {
4480 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004481 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004482 }
4483
4484 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004485 @Deprecated
4486 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4487 enforceModifyPermission();
4488
4489 int returnValue = 0;
4490 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004491 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004492 if(result.exception == null) {
4493 if (result.result != null) {
4494 byte[] responseData = (byte[])(result.result);
4495 if(responseData.length > oemResp.length) {
4496 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4497 responseData.length + "bytes. Buffer Size is " +
4498 oemResp.length + "bytes.");
4499 }
4500 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4501 returnValue = responseData.length;
4502 }
4503 } else {
4504 CommandException ex = (CommandException) result.exception;
4505 returnValue = ex.getCommandError().ordinal();
4506 if(returnValue > 0) returnValue *= -1;
4507 }
4508 } catch (RuntimeException e) {
4509 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4510 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4511 if(returnValue > 0) returnValue *= -1;
4512 }
4513
4514 return returnValue;
4515 }
4516
4517 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004518 public void setRadioCapability(RadioAccessFamily[] rafs) {
4519 try {
4520 ProxyController.getInstance().setRadioCapability(rafs);
4521 } catch (RuntimeException e) {
4522 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4523 }
4524 }
4525
4526 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004527 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004528 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004529 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004530 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004531 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 final long identity = Binder.clearCallingIdentity();
4534 try {
chen xub97461a2018-10-26 14:17:57 -07004535 TelephonyPermissions
4536 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4537 mApp, phone.getSubId(), "getRadioAccessFamily");
4538 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539 } finally {
4540 Binder.restoreCallingIdentity(identity);
4541 }
chen xub97461a2018-10-26 14:17:57 -07004542 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004543 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004544
4545 @Override
4546 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004547 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004548 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549
4550 final long identity = Binder.clearCallingIdentity();
4551 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004552 ImsManager.getInstance(defaultPhone.getContext(),
4553 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 } finally {
4555 Binder.restoreCallingIdentity(identity);
4556 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004557 }
4558
4559 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004560 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004561 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004563 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004564 return false;
4565 }
Svet Ganovb320e182015-04-16 12:30:10 -07004566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004567 final long identity = Binder.clearCallingIdentity();
4568 try {
4569 // Check the user preference and the system-level IMS setting. Even if the user has
4570 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4571 // In the long run, we may instead need to check if there exists a connection service
4572 // which can support video calling.
4573 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004574 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 return imsManager.isVtEnabledByPlatform()
4576 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4577 && imsManager.isVtEnabledByUser();
4578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004581 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004582
Andrew Leea1239f22015-03-02 17:44:07 -08004583 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004584 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4586 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4587 return false;
4588 }
4589
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 CarrierConfigManager configManager =
4593 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004594 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
4598 }
Andrew Leea1239f22015-03-02 17:44:07 -08004599 }
4600
4601 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004602 public boolean isWorldPhone(int subId, String callingPackage) {
4603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4604 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4605 return false;
4606 }
4607
4608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 CarrierConfigManager configManager =
4611 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004612 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4614 } finally {
4615 Binder.restoreCallingIdentity(identity);
4616 }
Andrew Leea1239f22015-03-02 17:44:07 -08004617 }
4618
Andrew Lee9431b832015-03-09 18:46:45 -07004619 @Override
4620 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004621 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004622 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004623 }
4624
4625 @Override
4626 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 final long identity = Binder.clearCallingIdentity();
4628 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004629 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630 } finally {
4631 Binder.restoreCallingIdentity(identity);
4632 }
Andrew Lee9431b832015-03-09 18:46:45 -07004633 }
4634
Hall Liuf6668912018-10-31 17:05:23 -07004635 /**
4636 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4637 * support for the feature and device firmware support.
4638 *
4639 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4640 */
4641 @Override
4642 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004644 final Phone phone = getPhone(subscriptionId);
4645 if (phone == null) {
4646 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4647 return false;
4648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004650 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4652 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004653 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 return isCarrierSupported && isDeviceSupported;
4655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
Hall Liu98187582018-01-22 19:15:32 -08004658 }
4659
Hall Liuf6668912018-10-31 17:05:23 -07004660 /**
4661 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4662 * both also support RTT.
4663 */
4664 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 final long identity = Binder.clearCallingIdentity();
4666 try {
Hall Liuf6668912018-10-31 17:05:23 -07004667 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004668 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004672 }
4673
Sanket Padawe7310cc72015-01-14 09:53:20 -08004674 /**
4675 * Returns the unique device ID of phone, for example, the IMEI for
4676 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4677 *
4678 * <p>Requires Permission:
4679 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4680 */
4681 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004682 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004683 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004684 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004685 return null;
4686 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004687 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004688 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4689 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004690 return null;
4691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692
4693 final long identity = Binder.clearCallingIdentity();
4694 try {
4695 return phone.getDeviceId();
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004699 }
4700
Ping Sunc67b7c22016-03-02 19:16:45 +08004701 /**
4702 * {@hide}
4703 * Returns the IMS Registration Status on a particular subid
4704 *
4705 * @param subId
4706 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004707 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004708 Phone phone = getPhone(subId);
4709 if (phone != null) {
4710 return phone.isImsRegistered();
4711 } else {
4712 return false;
4713 }
4714 }
4715
Santos Cordon7a1885b2015-02-03 11:15:19 -08004716 @Override
4717 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 final long identity = Binder.clearCallingIdentity();
4719 try {
4720 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4721 } finally {
4722 Binder.restoreCallingIdentity(identity);
4723 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004724 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004725
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004726 /**
4727 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004728 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004729 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730 final long identity = Binder.clearCallingIdentity();
4731 try {
4732 Phone phone = getPhone(subId);
4733 if (phone != null) {
4734 return phone.isWifiCallingEnabled();
4735 } else {
4736 return false;
4737 }
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004740 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004741 }
4742
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004743 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004744 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004745 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004746 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747 final long identity = Binder.clearCallingIdentity();
4748 try {
4749 Phone phone = getPhone(subId);
4750 if (phone != null) {
4751 return phone.isVideoEnabled();
4752 } else {
4753 return false;
4754 }
4755 } finally {
4756 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004757 }
4758 }
4759
4760 /**
4761 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4762 * defined in {@link ImsRegistrationImplBase}.
4763 */
4764 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 Phone phone = getPhone(subId);
4768 if (phone != null) {
4769 return phone.getImsRegistrationTech();
4770 } else {
4771 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4772 }
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004775 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004776 }
4777
Stuart Scott8eef64f2015-04-08 15:13:54 -07004778 @Override
4779 public void factoryReset(int subId) {
4780 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004781 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4782 return;
4783 }
4784
Svet Ganovcc087f82015-05-12 20:35:54 -07004785 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004786
Svet Ganovcc087f82015-05-12 20:35:54 -07004787 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004788 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4789 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004790 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004791 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004792 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004793 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4794 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004795 }
4796 } finally {
4797 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004798 }
4799 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004800
4801 @Override
4802 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004803 final long identity = Binder.clearCallingIdentity();
4804 try {
4805 // We query all subscriptions instead of just the active ones, because
4806 // this might be called early on in the provisioning flow when the
4807 // subscriptions potentially aren't active yet.
4808 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4809 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004810 return null;
4811 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813 // This function may be called very early, say, from the setup wizard, at
4814 // which point we won't have a default subscription set. If that's the case
4815 // we just choose the first, which will be valid in "most cases".
4816 final int defaultSubId = getDefaultSubscription();
4817 SubscriptionInfo info = null;
4818 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4819 info = slist.get(0);
4820 } else {
4821 for (SubscriptionInfo item : slist) {
4822 if (item.getSubscriptionId() == defaultSubId) {
4823 info = item;
4824 break;
4825 }
4826 }
4827
4828 if (info == null) {
4829 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004830 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004831 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 // Try and fetch the locale from the carrier properties or from the SIM language
4834 // preferences (EF-PL and EF-LI)...
4835 final int mcc = info.getMcc();
4836 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4837 String simLanguage = null;
4838 if (defaultPhone != null) {
4839 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4840 if (localeFromDefaultSim != null) {
4841 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4842 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4843 return localeFromDefaultSim.toLanguageTag();
4844 } else {
4845 simLanguage = localeFromDefaultSim.getLanguage();
4846 }
4847 }
4848 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850 // The SIM language preferences only store a language (e.g. fr = French), not an
4851 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4852 // the SIM and carrier preferences does not include a country we add the country
4853 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004854 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855 if (mccLocale != null) {
4856 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4857 return mccLocale.toLanguageTag();
4858 }
4859
4860 if (DBG) log("No locale found - returning null");
4861 return null;
4862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004865 }
4866
4867 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004868 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004869 }
4870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 /**
4872 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4873 */
4874 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004875 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004876 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004877
Chenjie Yu1ba97252018-01-11 18:16:20 -08004878 private final ModemActivityInfo mLastModemActivityInfo =
4879 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4880
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004881 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004882 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4883 * representing the state of the modem.
4884 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004885 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4886 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004887 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004888 */
4889 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004890 public void requestModemActivityInfo(ResultReceiver result) {
4891 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004892 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893
4894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 ModemActivityInfo ret = null;
4897 synchronized (mLastModemActivityInfo) {
4898 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4899 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004900 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004901 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4903 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004904 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
4905 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 }
4907 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004908 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
4909 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 mLastModemActivityInfo.setIdleTimeMillis(
4911 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4912 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4913 mLastModemActivityInfo.setRxTimeMillis(
4914 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4915 mLastModemActivityInfo.setEnergyUsed(
4916 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004918 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4919 mLastModemActivityInfo.getSleepTimeMillis(),
4920 mLastModemActivityInfo.getIdleTimeMillis(),
4921 mLastModemActivityInfo.getTxTimeMillis(),
4922 mLastModemActivityInfo.getRxTimeMillis(),
4923 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 Bundle bundle = new Bundle();
4926 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4927 result.send(0, bundle);
4928 } finally {
4929 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004930 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004931 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004932
Siddharth Rayb8114062018-06-17 15:02:38 -07004933 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4934 // less than total activity duration.
4935 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4936 if (info == null) {
4937 return false;
4938 }
4939 int activityDurationMs =
4940 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4941 int totalTxTimeMs = 0;
4942 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4943 totalTxTimeMs += info.getTxTimeMillis()[i];
4944 }
4945 return (info.isValid()
4946 && (info.getSleepTimeMillis() <= activityDurationMs)
4947 && (info.getIdleTimeMillis() <= activityDurationMs)
4948 && (info.getRxTimeMillis() <= activityDurationMs)
4949 && (totalTxTimeMs <= activityDurationMs));
4950 }
4951
Jack Yu85bd38a2015-11-09 11:34:32 -08004952 /**
4953 * {@hide}
4954 * Returns the service state information on specified subscription.
4955 */
4956 @Override
4957 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004959 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004960 return null;
4961 }
4962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 final long identity = Binder.clearCallingIdentity();
4964 try {
4965 final Phone phone = getPhone(subId);
4966 if (phone == null) {
4967 return null;
4968 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 return phone.getServiceState();
4971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004974 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004975
4976 /**
4977 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4978 *
4979 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4980 * voicemail ringtone.
4981 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4982 * PhoneAccount.
4983 */
4984 @Override
4985 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986 final long identity = Binder.clearCallingIdentity();
4987 try {
4988 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4989 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004990 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004997 }
4998
4999 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005000 * Sets the per-account voicemail ringtone.
5001 *
5002 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5003 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5004 *
5005 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5006 * voicemail ringtone.
5007 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5008 * PhoneAccount.
5009 */
5010 @Override
5011 public void setVoicemailRingtoneUri(String callingPackage,
5012 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005013 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005014 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5015 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005016 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5018 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5019 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005020 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021
5022 final long identity = Binder.clearCallingIdentity();
5023 try {
5024 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5025 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005026 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027 }
5028 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5029 } finally {
5030 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005031 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005032 }
5033
5034 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005035 * Returns whether vibration is set for voicemail notification in Phone settings.
5036 *
5037 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5038 * voicemail vibration setting.
5039 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5040 */
5041 @Override
5042 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 final long identity = Binder.clearCallingIdentity();
5044 try {
5045 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5046 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005047 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
5053 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005054 }
5055
Youhan Wange64578a2016-05-02 15:32:42 -07005056 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005057 * Sets the per-account voicemail vibration.
5058 *
5059 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5060 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5061 *
5062 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5063 * voicemail vibration setting.
5064 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5065 * specific PhoneAccount.
5066 */
5067 @Override
5068 public void setVoicemailVibrationEnabled(String callingPackage,
5069 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005070 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005071 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5072 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005073 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5075 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5076 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005077 }
5078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 final long identity = Binder.clearCallingIdentity();
5080 try {
5081 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5082 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005083 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005084 }
5085 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5086 } finally {
5087 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005088 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005089 }
5090
5091 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005092 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5093 *
5094 * @throws SecurityException if the caller does not have the required permission
5095 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005096 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005097 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005098 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005099 }
5100
5101 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005102 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5103 * permission.
5104 *
5105 * @throws SecurityException if the caller does not have the required permission
5106 */
5107 private void enforceSendSmsPermission() {
5108 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5109 }
5110
5111 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005112 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005113 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005114 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005115 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005116 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 final long identity = Binder.clearCallingIdentity();
5118 try {
5119 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005120 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 if (componentName == null) {
5122 throw new SecurityException(
5123 "Caller not current active visual voicemail package[null]");
5124 }
5125 String vvmPackage = componentName.getPackageName();
5126 if (!callingPackage.equals(vvmPackage)) {
5127 throw new SecurityException("Caller not current active visual voicemail package["
5128 + vvmPackage + "]");
5129 }
5130 } finally {
5131 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005132 }
5133 }
5134
5135 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005136 * Return the application ID for the app type.
5137 *
5138 * @param subId the subscription ID that this request applies to.
5139 * @param appType the uicc app type.
5140 * @return Application ID for specificied app type, or null if no uicc.
5141 */
5142 @Override
5143 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005144 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005145 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146
5147 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005148 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 if (phone == null) {
5150 return null;
5151 }
5152 String aid = null;
5153 try {
5154 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5155 .getApplicationByType(appType).getAid();
5156 } catch (Exception e) {
5157 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5158 }
5159 return aid;
5160 } finally {
5161 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005162 }
Youhan Wange64578a2016-05-02 15:32:42 -07005163 }
5164
Youhan Wang4001d252016-05-11 10:29:41 -07005165 /**
5166 * Return the Electronic Serial Number.
5167 *
5168 * @param subId the subscription ID that this request applies to.
5169 * @return ESN or null if error.
5170 */
5171 @Override
5172 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005173 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005174 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175
5176 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005177 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 if (phone == null) {
5179 return null;
5180 }
5181 String esn = null;
5182 try {
5183 esn = phone.getEsn();
5184 } catch (Exception e) {
5185 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5186 }
5187 return esn;
5188 } finally {
5189 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005190 }
Youhan Wang4001d252016-05-11 10:29:41 -07005191 }
5192
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005193 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005194 * Return the Preferred Roaming List Version.
5195 *
5196 * @param subId the subscription ID that this request applies to.
5197 * @return PRLVersion or null if error.
5198 */
5199 @Override
5200 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005201 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005202 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203
5204 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005205 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 if (phone == null) {
5207 return null;
5208 }
5209 String cdmaPrlVersion = null;
5210 try {
5211 cdmaPrlVersion = phone.getCdmaPrlVersion();
5212 } catch (Exception e) {
5213 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5214 }
5215 return cdmaPrlVersion;
5216 } finally {
5217 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005218 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005219 }
5220
5221 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005222 * Get snapshot of Telephony histograms
5223 * @return List of Telephony histograms
5224 * @hide
5225 */
5226 @Override
5227 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5229 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230
5231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 return RIL.getTelephonyRILTimingHistograms();
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005237 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005238
5239 /**
5240 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005241 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005242 * Require system privileges. In the future we may add this to carrier APIs.
5243 *
5244 * @return The number of carriers set successfully, should match length of carriers
5245 */
5246 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005247 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005248 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005249 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005250
Meng Wang9b7c4e92017-02-17 11:41:27 -08005251 if (carriers == null) {
5252 throw new NullPointerException("carriers cannot be null");
5253 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 final long identity = Binder.clearCallingIdentity();
5256 try {
5257 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005258 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5259 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 return retVal[0];
5261 } finally {
5262 Binder.restoreCallingIdentity(identity);
5263 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005264 }
5265
5266 /**
5267 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005268 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005269 * Require system privileges. In the future we may add this to carrier APIs.
5270 *
5271 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5272 * means all carriers are allowed.
5273 */
5274 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005275 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005276 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005277 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278
5279 final long identity = Binder.clearCallingIdentity();
5280 try {
5281 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005282 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5283 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005287 }
5288
fionaxu59545b42016-05-25 15:53:37 -07005289 /**
5290 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5291 * @param subId the subscription ID that this action applies to.
5292 * @param enabled control enable or disable metered apns.
5293 * {@hide}
5294 */
5295 @Override
5296 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5297 enforceModifyPermission();
5298 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299
5300 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005301 if (phone == null) {
5302 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5303 return;
5304 }
5305 try {
5306 phone.carrierActionSetMeteredApnsEnabled(enabled);
5307 } catch (Exception e) {
5308 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 } finally {
5310 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005311 }
5312 }
5313
5314 /**
5315 * Action set from carrier signalling broadcast receivers to enable/disable radio
5316 * @param subId the subscription ID that this action applies to.
5317 * @param enabled control enable or disable radio.
5318 * {@hide}
5319 */
5320 @Override
5321 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5322 enforceModifyPermission();
5323 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324
5325 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005326 if (phone == null) {
5327 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5328 return;
5329 }
5330 try {
5331 phone.carrierActionSetRadioEnabled(enabled);
5332 } catch (Exception e) {
5333 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 } finally {
5335 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005336 }
5337 }
5338
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005339 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005340 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5341 * network status based on which carrier apps could apply actions accordingly,
5342 * enable/disable default url handler for example.
5343 *
5344 * @param subId the subscription ID that this action applies to.
5345 * @param report control start/stop reporting the default network status.
5346 * {@hide}
5347 */
5348 @Override
5349 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5350 enforceModifyPermission();
5351 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352
5353 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005354 if (phone == null) {
5355 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5356 return;
5357 }
5358 try {
5359 phone.carrierActionReportDefaultNetworkStatus(report);
5360 } catch (Exception e) {
5361 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005364 }
5365 }
5366
5367 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005368 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5369 * bug report is being generated.
5370 */
5371 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005372 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005373 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5374 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005375 writer.println("Permission Denial: can't dump Phone from pid="
5376 + Binder.getCallingPid()
5377 + ", uid=" + Binder.getCallingUid()
5378 + "without permission "
5379 + android.Manifest.permission.DUMP);
5380 return;
5381 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005382 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005383 }
Jack Yueb89b242016-06-22 13:27:47 -07005384
Brad Ebingerdac2f002018-04-03 15:17:52 -07005385 @Override
5386 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5387 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5388 throws RemoteException {
5389 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5390 }
5391
Jack Yueb89b242016-06-22 13:27:47 -07005392 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005393 * Get aggregated video call data usage since boot.
5394 *
5395 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5396 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005397 * {@hide}
5398 */
5399 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005400 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005401 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5402 null);
5403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 final long identity = Binder.clearCallingIdentity();
5405 try {
5406 // NetworkStatsService keeps tracking the active network interface and identity. It
5407 // records the delta with the corresponding network identity.
5408 // We just return the total video call data usage snapshot since boot.
5409 Phone phone = getPhone(subId);
5410 if (phone != null) {
5411 return phone.getVtDataUsage(perUidStats);
5412 }
5413 return null;
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005416 }
Jack Yueb89b242016-06-22 13:27:47 -07005417 }
Jack Yu75ab2952016-07-08 14:29:33 -07005418
5419 /**
5420 * Policy control of data connection. Usually used when data limit is passed.
5421 * @param enabled True if enabling the data, otherwise disabling.
5422 * @param subId Subscription index
5423 * {@hide}
5424 */
5425 @Override
5426 public void setPolicyDataEnabled(boolean enabled, int subId) {
5427 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428
5429 final long identity = Binder.clearCallingIdentity();
5430 try {
5431 Phone phone = getPhone(subId);
5432 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005433 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 }
5435 } finally {
5436 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005437 }
5438 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005439
5440 /**
5441 * Get Client request stats
5442 * @return List of Client Request Stats
5443 * @hide
5444 */
5445 @Override
5446 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005448 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005449 return null;
5450 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005451 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453 final long identity = Binder.clearCallingIdentity();
5454 try {
5455 if (phone != null) {
5456 return phone.getClientRequestStats();
5457 }
5458
5459 return null;
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005463 }
5464
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005465 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005466 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005467 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005468 }
Jack Yueb4124c2017-02-16 15:32:43 -08005469
5470 /**
Grace Chen70990072017-03-24 17:21:30 -07005471 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005472 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005473 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005474 * @param state State of SIM (power down, power up, pass through)
5475 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5476 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5477 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005478 *
5479 **/
5480 @Override
Grace Chen70990072017-03-24 17:21:30 -07005481 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005482 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005483 Phone phone = PhoneFactory.getPhone(slotIndex);
5484
vagdeviaf9a5b92018-08-15 16:01:53 -07005485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 final long identity = Binder.clearCallingIdentity();
5488 try {
5489 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005490 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 }
5492 } finally {
5493 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005494 }
5495 }
Shuo Qiandd210312017-04-12 22:11:33 +00005496
Tyler Gunn65d45c22017-06-05 11:22:26 -07005497 private boolean isUssdApiAllowed(int subId) {
5498 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005499 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005500 if (configManager == null) {
5501 return false;
5502 }
5503 PersistableBundle pb = configManager.getConfigForSubId(subId);
5504 if (pb == null) {
5505 return false;
5506 }
5507 return pb.getBoolean(
5508 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5509 }
5510
Shuo Qiandd210312017-04-12 22:11:33 +00005511 /**
5512 * Check if phone is in emergency callback mode
5513 * @return true if phone is in emergency callback mode
5514 * @param subId sub id
5515 */
goneil9c5f4872017-12-05 14:07:56 -08005516 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005517 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005518 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005519 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520
5521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 if (phone != null) {
5524 return phone.isInEcm();
5525 } else {
5526 return false;
5527 }
5528 } finally {
5529 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005530 }
5531 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005532
5533 /**
5534 * Get the current signal strength information for the given subscription.
5535 * Because this information is not updated when the device is in a low power state
5536 * it should not be relied-upon to be current.
5537 * @param subId Subscription index
5538 * @return the most recent cached signal strength info from the modem
5539 */
5540 @Override
5541 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 Phone p = getPhone(subId);
5545 if (p == null) {
5546 return null;
5547 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 return p.getSignalStrength();
5550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005553 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005554
Pengquan Meng77b7f132018-08-22 14:49:57 -07005555 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005556 * Get the current modem radio state for the given slot.
5557 * @param slotIndex slot index.
5558 * @param callingPackage the name of the package making the call.
5559 * @return the current radio power state from the modem
5560 */
5561 @Override
5562 public int getRadioPowerState(int slotIndex, String callingPackage) {
5563 Phone phone = PhoneFactory.getPhone(slotIndex);
5564 if (phone != null) {
5565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5566 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5567 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5568 }
5569
5570 final long identity = Binder.clearCallingIdentity();
5571 try {
5572 return phone.getRadioPowerState();
5573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
5576 }
5577 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5578 }
5579
5580 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005581 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5582 *
5583 * <p>Requires one of the following permissions:
5584 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5585 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5586 * privileges.
5587 *
5588 * @param subId subscription id
5589 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5590 * {@code false}.
5591 */
5592 @Override
5593 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005594 boolean isEnabled = false;
5595 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005596 try {
5597 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005598 null /* message */);
5599 Phone phone = getPhone(subId);
5600 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005601 } catch (Exception e) {
5602 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5603 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005606 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005607 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005608 }
5609
5610
5611 /**
5612 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5613 *
5614 * <p> Requires permission:
5615 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5616 * privileges.
5617 *
5618 * @param subId subscription id
5619 * @param isEnabled {@code true} means enable, {@code false} means disable.
5620 */
5621 @Override
5622 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005623 final long identity = Binder.clearCallingIdentity();
5624 try {
5625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005627
Pengquan Menga1bb6272018-09-06 09:59:22 -07005628 Phone phone = getPhone(subId);
5629 if (phone != null) {
5630 phone.setDataRoamingEnabled(isEnabled);
5631 }
5632 } finally {
5633 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005634 }
5635 }
5636
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005637 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005638 public boolean isManualNetworkSelectionAllowed(int subId) {
5639 boolean isAllowed = true;
5640 final long identity = Binder.clearCallingIdentity();
5641 try {
5642 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5643 mApp, subId, "isManualNetworkSelectionAllowed");
5644 Phone phone = getPhone(subId);
5645 if (phone != null) {
5646 isAllowed = phone.isCspPlmnEnabled();
5647 }
5648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
5651 return isAllowed;
5652 }
5653
5654 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005655 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005656 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5661 if (slots == null) {
5662 Rlog.i(LOG_TAG, "slots is null.");
5663 return null;
5664 }
5665
5666 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5667 for (int i = 0; i < slots.length; i++) {
5668 UiccSlot slot = slots[i];
5669 if (slot == null) {
5670 continue;
5671 }
5672
5673 String cardId;
5674 UiccCard card = slot.getUiccCard();
5675 if (card != null) {
5676 cardId = card.getCardId();
5677 } else {
5678 cardId = slot.getIccId();
5679 }
5680
5681 int cardState = 0;
5682 switch (slot.getCardState()) {
5683 case CARDSTATE_ABSENT:
5684 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5685 break;
5686 case CARDSTATE_PRESENT:
5687 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5688 break;
5689 case CARDSTATE_ERROR:
5690 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5691 break;
5692 case CARDSTATE_RESTRICTED:
5693 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5694 break;
5695 default:
5696 break;
5697
5698 }
5699
5700 infos[i] = new UiccSlotInfo(
5701 slot.isActive(),
5702 slot.isEuicc(),
5703 cardId,
5704 cardState,
5705 slot.getPhoneId(),
5706 slot.isExtendedApduSupported());
5707 }
5708 return infos;
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005711 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005712 }
5713
5714 @Override
5715 public boolean switchSlots(int[] physicalSlots) {
5716 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717
5718 final long identity = Binder.clearCallingIdentity();
5719 try {
5720 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5721 } finally {
5722 Binder.restoreCallingIdentity(identity);
5723 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005724 }
Jack Yu4c988042018-02-27 15:30:01 -08005725
5726 @Override
5727 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5728 enforceModifyPermission();
5729 final Phone phone = getPhone(subId);
5730 if (phone == null) {
5731 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5732 return;
5733 }
5734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 phone.setRadioIndicationUpdateMode(filters, mode);
5738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
Jack Yu4c988042018-02-27 15:30:01 -08005741 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005742
5743 /**
goneil47ffb6e2018-04-06 15:40:58 -07005744 * A test API to reload the UICC profile.
5745 *
5746 * <p>Requires that the calling app has permission
5747 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5748 * @hide
5749 */
5750 @Override
5751 public void refreshUiccProfile(int subId) {
5752 enforceModifyPermission();
5753
5754 final long identity = Binder.clearCallingIdentity();
5755 try {
5756 Phone phone = getPhone(subId);
5757 if (phone == null) {
5758 return;
5759 }
5760 UiccCard uiccCard = phone.getUiccCard();
5761 if (uiccCard == null) {
5762 return;
5763 }
5764 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5765 if (uiccProfile == null) {
5766 return;
5767 }
5768 uiccProfile.refresh();
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
5772 }
5773
5774 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005775 * Returns false if the mobile data is disabled by default, otherwise return true.
5776 */
5777 private boolean getDefaultDataEnabled() {
5778 return "true".equalsIgnoreCase(
5779 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5780 }
5781
5782 /**
5783 * Returns true if the data roaming is enabled by default, i.e the system property
5784 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5785 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5786 */
5787 private boolean getDefaultDataRoamingEnabled(int subId) {
5788 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005789 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005790 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5791 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5792 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5793 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5794 return isDataRoamingEnabled;
5795 }
5796
5797 /**
5798 * Returns the default network type for the given {@code subId}, if the default network type is
5799 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5800 */
5801 private int getDefaultNetworkType(int subId) {
5802 return Integer.parseInt(
5803 TelephonyManager.getTelephonyProperty(
5804 mSubscriptionController.getPhoneId(subId),
5805 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5806 String.valueOf(Phone.PREFERRED_NT_MODE)));
5807 }
fionaxua13278b2018-03-21 00:08:13 -07005808
5809 @Override
5810 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5811 gid1, String gid2, String plmn, String spn) {
5812 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813
5814 final long identity = Binder.clearCallingIdentity();
5815 try {
5816 final Phone phone = getPhone(subId);
5817 if (phone == null) {
5818 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5819 return;
5820 }
5821 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5822 } finally {
5823 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005824 }
fionaxua13278b2018-03-21 00:08:13 -07005825 }
5826
5827 @Override
5828 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005829 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830
5831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 final Phone phone = getPhone(subId);
5834 if (phone == null) {
5835 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5836 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5837 }
5838 return phone.getCarrierIdListVersion();
5839 } finally {
5840 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005841 }
fionaxua13278b2018-03-21 00:08:13 -07005842 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005843
5844 @Override
5845 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5846 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5847 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5848 return -1;
5849 }
5850
5851 final long identity = Binder.clearCallingIdentity();
5852 try {
5853 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5854 } finally {
5855 Binder.restoreCallingIdentity(identity);
5856 }
5857 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005858
5859 @Override
5860 public int getCdmaRoamingMode(int subId) {
5861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5862 mApp, subId, "getCdmaRoamingMode");
5863
5864 final long identity = Binder.clearCallingIdentity();
5865 try {
5866 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5867 } finally {
5868 Binder.restoreCallingIdentity(identity);
5869 }
5870 }
5871
5872 @Override
5873 public boolean setCdmaRoamingMode(int subId, int mode) {
5874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5875 mApp, subId, "setCdmaRoamingMode");
5876
5877 final long identity = Binder.clearCallingIdentity();
5878 try {
5879 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
5883 }
5884
5885 @Override
5886 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5888 mApp, subId, "setCdmaSubscriptionMode");
5889
5890 final long identity = Binder.clearCallingIdentity();
5891 try {
5892 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
5896 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005897
5898 private void ensureUserRunning(int userId) {
5899 if (!mUserManager.isUserRunning(userId)) {
5900 throw new IllegalStateException("User " + userId + " does not exist or not running");
5901 }
5902 }
5903
5904 /**
5905 * Returns a list of SMS apps on a given user.
5906 *
5907 * Only the shell user (UID 2000 or 0) can call it.
5908 * Target user must be running.
5909 */
5910 @Override
5911 public String[] getSmsApps(int userId) {
5912 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5913 ensureUserRunning(userId);
5914
5915 final Collection<SmsApplicationData> apps =
5916 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5917
5918 String[] ret = new String[apps.size()];
5919 int i = 0;
5920 for (SmsApplicationData app : apps) {
5921 ret[i++] = app.mPackageName;
5922 }
5923 return ret;
5924 }
5925
5926 /**
5927 * Returns the default SMS app package name on a given user.
5928 *
5929 * Only the shell user (UID 2000 or 0) can call it.
5930 * Target user must be running.
5931 */
5932 @Override
5933 public String getDefaultSmsApp(int userId) {
5934 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5935 ensureUserRunning(userId);
5936
5937 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5938 /* updateIfNeeded= */ true, userId);
5939 return cn == null ? null : cn.getPackageName();
5940 }
5941
5942 /**
5943 * Set a package as the default SMS app on a given user.
5944 *
5945 * Only the shell user (UID 2000 or 0) can call it.
5946 * Target user must be running.
5947 */
5948 @Override
5949 public void setDefaultSmsApp(int userId, String packageName) {
5950 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5951 ensureUserRunning(userId);
5952
5953 boolean found = false;
5954 for (String pkg : getSmsApps(userId)) {
5955 if (TextUtils.equals(packageName, pkg)) {
5956 found = true;
5957 break;
5958 }
5959 }
5960 if (!found) {
5961 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5962 }
5963
5964 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5965 }
sqianc5eccab2018-10-19 18:46:41 -07005966
5967 @Override
5968 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5969 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08005970 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5971 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
5972 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5973 }
5974 final long identity = Binder.clearCallingIdentity();
5975 try {
5976 Map<Integer, List<EmergencyNumber>> results = getEmergencyNumberListInternal();
5977 // Use ecclist to construct Emergency number list for backward compatibality
5978 if (results.isEmpty()) {
5979 results = getEmergencyNumberListFromEccList();
5980 }
5981 return results;
5982 } finally {
5983 Binder.restoreCallingIdentity(identity);
5984 }
sqianc5eccab2018-10-19 18:46:41 -07005985 }
5986
5987 @Override
sqian11b7a0e2018-12-05 18:48:28 -08005988 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005989 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08005990 if (!exactMatch) {
5991 TelephonyPermissions
5992 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005993 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08005994 }
5995 final long identity = Binder.clearCallingIdentity();
5996 try {
5997 Map<Integer, List<EmergencyNumber>> emergencyNumberLists =
5998 getEmergencyNumberListInternal();
5999
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006000 String defaultCountryIso = getNetworkCountryIsoForPhone(defaultPhone.getPhoneId());
sqian11b7a0e2018-12-05 18:48:28 -08006001
6002 if (!emergencyNumberLists.isEmpty()) {
6003 for (List<EmergencyNumber> emergencyNumberList : emergencyNumberLists.values()) {
6004 if (emergencyNumberList != null) {
6005 for (EmergencyNumber num : emergencyNumberList) {
6006 // According to com.android.i18n.phonenumbers.ShortNumberInfo, in
6007 // these countries, if extra digits are added to an emergency number,
6008 // it no longer connects to the emergency service.
6009 Set<String> countriesRequiredForExactMatch = new HashSet<>();
6010 countriesRequiredForExactMatch.add("br");
6011 countriesRequiredForExactMatch.add("cl");
6012 countriesRequiredForExactMatch.add("ni");
6013 if (exactMatch || countriesRequiredForExactMatch.contains(
6014 defaultCountryIso)) {
6015 if (num.getNumber().equals(number)) {
6016 return true;
6017 }
6018 } else {
6019 if (number.startsWith(num.getNumber())) {
6020 return true;
6021 }
6022 }
6023
6024 }
6025 }
6026 }
6027 } else {
6028 // For backward compatibility for devices launched before Q
6029 return PhoneNumberUtils.isEmergencyNumberInternal(number, exactMatch,
6030 defaultCountryIso);
6031 }
6032 return false;
6033 } finally {
6034 Binder.restoreCallingIdentity(identity);
6035 }
6036 }
6037
6038 private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListInternal() {
6039 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6040
6041 for (Phone phone: PhoneFactory.getPhones()) {
6042 if (phone.getEmergencyNumberTracker() != null
6043 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6044 emergencyNumberListInternal.put(
6045 phone.getSubId(),
6046 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6047 }
6048 }
6049 return emergencyNumberListInternal;
6050 }
6051
6052 private List<EmergencyNumber> getEmergencyNumberListFromEccList(int subscriptionId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006053 SubscriptionManager sm = (SubscriptionManager) mApp.getSystemService(
sqian11b7a0e2018-12-05 18:48:28 -08006054 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6055 List<EmergencyNumber> emergencyNumberList = new ArrayList<>();
6056 int slotId = sm.getSlotIndex(subscriptionId);
6057
6058 String ecclist = (slotId <= 0) ? "ril.ecclist" : ("ril.ecclist" + slotId);
6059 String emergencyNumbers = SystemProperties.get(ecclist, "");
6060 if (TextUtils.isEmpty(emergencyNumbers)) {
6061 // then read-only ecclist property since old RIL only uses this
6062 emergencyNumbers = SystemProperties.get("ro.ril.ecclist");
6063 }
6064 if (!TextUtils.isEmpty(emergencyNumbers)) {
6065 // searches through the comma-separated list for a match,
6066 // return true if one is found.
6067 for (String emergencyNum : emergencyNumbers.split(",")) {
6068 emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "",
6069 EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0));
6070 }
6071 }
6072 emergencyNumbers = ((slotId < 0) ? "112,911,000,08,110,118,119,999" : "112,911");
6073 for (String emergencyNum : emergencyNumbers.split(",")) {
6074 emergencyNumberList.add(new EmergencyNumber(emergencyNum, "", "",
6075 EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, 0));
6076 }
6077 EmergencyNumber.mergeSameNumbersInEmergencyNumberList(emergencyNumberList);
6078 return emergencyNumberList;
6079 }
6080
6081 /**
6082 * Get Emergency number list based on EccList. This util is used for solving backward
6083 * compatibility if device does not support the 1.4 IRadioIndication HAL that reports
6084 * emergency number list.
6085 *
6086 * @return Map including the key as the active subscription ID (Note: if there is no active
6087 * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId})
6088 * and the value as the list of {@link EmergencyNumber}.
6089 */
6090 private Map<Integer, List<EmergencyNumber>> getEmergencyNumberListFromEccList() {
6091 Map<Integer, List<EmergencyNumber>> results = new HashMap<>();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006092 SubscriptionManager sm = (SubscriptionManager) mApp.getSystemService(
sqian11b7a0e2018-12-05 18:48:28 -08006093 Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6094 int[] activeSubscriptionIds = sm.getActiveSubscriptionIdList();
6095
6096 if (activeSubscriptionIds.length == 0) {
6097 int defaultSubscriptionId = getDefaultSubscription();
6098 results.put(defaultSubscriptionId,
6099 getEmergencyNumberListFromEccList(defaultSubscriptionId));
6100 } else {
6101 for (int activeSubscriptionId : activeSubscriptionIds) {
6102 results.put(activeSubscriptionId,
6103 getEmergencyNumberListFromEccList(activeSubscriptionId));
6104 }
6105 }
6106 return results;
sqianc5eccab2018-10-19 18:46:41 -07006107 }
chen xud6b45bd2018-10-30 22:27:10 -07006108
6109 @Override
6110 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6111 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6112 Phone phone = getPhone(subId);
6113 if (phone == null) {
6114 return null;
6115 }
6116 final long identity = Binder.clearCallingIdentity();
6117 try {
6118 UiccProfile profile = UiccController.getInstance()
6119 .getUiccProfileForPhone(phone.getPhoneId());
6120 if (profile != null) {
6121 return profile.getCertsFromCarrierPrivilegeAccessRules();
6122 }
6123 } finally {
6124 Binder.restoreCallingIdentity(identity);
6125 }
6126 return null;
6127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006128}