blob: 81a82d467f16d3f2a3e7232a3ec463cf6b64806a [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;
Tobias Thiererb19e1f12018-12-11 17:54:03 +0000249 private Phone mPhone;
Wink Saville3ab207e2014-11-20 13:07:20 -0800250 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700251 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800252 private AppOpsManager mAppOps;
253 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800254 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800255 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700256 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257
Derek Tan97ebb422014-09-05 16:55:38 -0700258 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
259 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800260 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700261
Derek Tan740e1672017-06-27 14:56:27 -0700262 // The AID of ISD-R.
263 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
264
yinxub1bed742017-04-17 11:45:04 -0700265 private NetworkScanRequestTracker mNetworkScanRequestTracker;
266
David Kelly5e06a7f2018-03-12 14:10:59 +0000267 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
268 private static final int MANUFACTURER_CODE_LENGTH = 8;
269
Derek Tan89e89d42014-07-08 17:00:10 -0700270 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700271 * A request object to use for transmitting data to an ICC.
272 */
273 private static final class IccAPDUArgument {
274 public int channel, cla, command, p1, p2, p3;
275 public String data;
276
277 public IccAPDUArgument(int channel, int cla, int command,
278 int p1, int p2, int p3, String data) {
279 this.channel = channel;
280 this.cla = cla;
281 this.command = command;
282 this.p1 = p1;
283 this.p2 = p2;
284 this.p3 = p3;
285 this.data = data;
286 }
287 }
288
289 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700290 * A request object to use for transmitting data to an ICC.
291 */
292 private static final class ManualNetworkSelectionArgument {
293 public OperatorInfo operatorInfo;
294 public boolean persistSelection;
295
296 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
297 this.operatorInfo = operatorInfo;
298 this.persistSelection = persistSelection;
299 }
300 }
301
302 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
304 * request after sending. The main thread will notify the request when it is complete.
305 */
306 private static final class MainThreadRequest {
307 /** The argument to use for the request */
308 public Object argument;
309 /** The result of the request that is run on the main thread */
310 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800311 // The subscriber id that this request applies to. Defaults to
312 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
313 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314
Nathan Harold92bed182018-10-12 18:16:49 -0700315 // In cases where subId is unavailable, the caller needs to specify the phone.
316 public Phone phone;
317
vagdeviaf9a5b92018-08-15 16:01:53 -0700318 public WorkSource workSource;
319
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700320 public MainThreadRequest(Object argument) {
321 this.argument = argument;
322 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800323
Nathan Harold92bed182018-10-12 18:16:49 -0700324 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
325 this.argument = argument;
326 if (phone != null) {
327 this.phone = phone;
328 }
329 this.workSource = workSource;
330 }
331
vagdeviaf9a5b92018-08-15 16:01:53 -0700332 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800333 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800334 if (subId != null) {
335 this.subId = subId;
336 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700337 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 }
340
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800341 private static final class IncomingThirdPartyCallArgs {
342 public final ComponentName component;
343 public final String callId;
344 public final String callerDisplayName;
345
346 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
347 String callerDisplayName) {
348 this.component = component;
349 this.callId = callId;
350 this.callerDisplayName = callerDisplayName;
351 }
352 }
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 /**
355 * A handler that processes messages on the main thread in the phone process. Since many
356 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
357 * inbound binder threads to the main thread in the phone process. The Binder thread
358 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
359 * on, which will be notified when the operation completes and will contain the result of the
360 * request.
361 *
362 * <p>If a MainThreadRequest object is provided in the msg.obj field,
363 * note that request.result must be set to something non-null for the calling thread to
364 * unblock.
365 */
366 private final class MainThreadHandler extends Handler {
367 @Override
368 public void handleMessage(Message msg) {
369 MainThreadRequest request;
370 Message onCompleted;
371 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800372 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700373 IccAPDUArgument iccArgument;
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);
Tobias Thiererb19e1f12018-12-11 17:54:03 +0000628 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800629 break;
630
631 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 ar = (AsyncResult) msg.obj;
633 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800634 if (ar.exception == null && ar.result != null) {
635 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800637 request.result = "";
638 if (ar.result == null) {
639 loge("nvReadItem: Empty response");
640 } else if (ar.exception instanceof CommandException) {
641 loge("nvReadItem: CommandException: " +
642 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800644 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 }
646 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 break;
649
Jake Hambye994d462014-02-03 13:10:13 -0800650 case CMD_NV_WRITE_ITEM:
651 request = (MainThreadRequest) msg.obj;
652 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
653 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Tobias Thiererb19e1f12018-12-11 17:54:03 +0000654 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700655 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800656 break;
657
658 case EVENT_NV_WRITE_ITEM_DONE:
659 handleNullReturnEvent(msg, "nvWriteItem");
660 break;
661
662 case CMD_NV_WRITE_CDMA_PRL:
663 request = (MainThreadRequest) msg.obj;
664 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Tobias Thiererb19e1f12018-12-11 17:54:03 +0000665 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800666 break;
667
668 case EVENT_NV_WRITE_CDMA_PRL_DONE:
669 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
670 break;
671
chen xu6dac5ab2018-10-26 17:39:23 -0700672 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800673 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700674 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Tobias Thiererb19e1f12018-12-11 17:54:03 +0000675 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800676 break;
677
chen xu6dac5ab2018-10-26 17:39:23 -0700678 case EVENT_RESET_MODEM_CONFIG_DONE:
679 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800680 break;
681
Jake Hamby7c27be32014-03-03 13:25:59 -0800682 case CMD_GET_PREFERRED_NETWORK_TYPE:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700685 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800686 break;
687
688 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
691 if (ar.exception == null && ar.result != null) {
692 request.result = ar.result; // Integer
693 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800694 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800695 if (ar.result == null) {
696 loge("getPreferredNetworkType: Empty response");
697 } else if (ar.exception instanceof CommandException) {
698 loge("getPreferredNetworkType: CommandException: " +
699 ar.exception);
700 } else {
701 loge("getPreferredNetworkType: Unknown exception");
702 }
703 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700704 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800705 break;
706
707 case CMD_SET_PREFERRED_NETWORK_TYPE:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
710 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700711 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800712 break;
713
714 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
715 handleNullReturnEvent(msg, "setPreferredNetworkType");
716 break;
717
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000718 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
719 request = (MainThreadRequest)msg.obj;
720 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Tobias Thiererb19e1f12018-12-11 17:54:03 +0000721 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000722 break;
723
724 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
725 ar = (AsyncResult)msg.obj;
726 request = (MainThreadRequest)ar.userObj;
727 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700728 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000729 break;
730
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800731 case CMD_SET_VOICEMAIL_NUMBER:
732 request = (MainThreadRequest) msg.obj;
733 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
734 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800735 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
736 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800737 break;
738
739 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
740 handleNullReturnEvent(msg, "setVoicemailNumber");
741 break;
742
Stuart Scott54788802015-03-30 13:18:01 -0700743 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
746 request);
747 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
748 break;
749
750 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
751 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
752 break;
753
Shishir Agrawal302c8692015-06-19 13:49:39 -0700754 case CMD_PERFORM_NETWORK_SCAN:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
757 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
758 break;
759
760 case EVENT_PERFORM_NETWORK_SCAN_DONE:
761 ar = (AsyncResult) msg.obj;
762 request = (MainThreadRequest) ar.userObj;
763 CellNetworkScanResult cellScanResult;
764 if (ar.exception == null && ar.result != null) {
765 cellScanResult = new CellNetworkScanResult(
766 CellNetworkScanResult.STATUS_SUCCESS,
767 (List<OperatorInfo>) ar.result);
768 } else {
769 if (ar.result == null) {
770 loge("getCellNetworkScanResults: Empty response");
771 }
772 if (ar.exception != null) {
773 loge("getCellNetworkScanResults: Exception: " + ar.exception);
774 }
775 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
776 if (ar.exception instanceof CommandException) {
777 CommandException.Error error =
778 ((CommandException) (ar.exception)).getCommandError();
779 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
780 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
781 } else if (error == CommandException.Error.GENERIC_FAILURE) {
782 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
783 }
784 }
785 cellScanResult = new CellNetworkScanResult(errorCode, null);
786 }
787 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700788 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700789 break;
790
791 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
792 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700793 ManualNetworkSelectionArgument selArg =
794 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
796 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700797 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
798 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700799 break;
800
801 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 if (ar.exception == null) {
805 request.result = true;
806 } else {
807 request.result = false;
808 loge("setNetworkSelectionModeManual " + ar.exception);
809 }
810 notifyRequester(request);
811 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700812 break;
813
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700814 case CMD_GET_MODEM_ACTIVITY_INFO:
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Tobias Thiererb19e1f12018-12-11 17:54:03 +0000817 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700818 break;
819
820 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
821 ar = (AsyncResult) msg.obj;
822 request = (MainThreadRequest) ar.userObj;
823 if (ar.exception == null && ar.result != null) {
824 request.result = ar.result;
825 } else {
826 if (ar.result == null) {
827 loge("queryModemActivityInfo: Empty response");
828 } else if (ar.exception instanceof CommandException) {
829 loge("queryModemActivityInfo: CommandException: " +
830 ar.exception);
831 } else {
832 loge("queryModemActivityInfo: Unknown exception");
833 }
834 }
Amit Mahajand4766222016-01-28 15:28:28 -0800835 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
836 if (request.result == null) {
837 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
838 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700839 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700840 break;
841
Meng Wang1a7c35a2016-05-05 20:56:15 -0700842 case CMD_SET_ALLOWED_CARRIERS:
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Tobias Thiererb19e1f12018-12-11 17:54:03 +0000845 mPhone.setAllowedCarriers(
Meng Wang1a7c35a2016-05-05 20:56:15 -0700846 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700847 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700848 break;
849
850 case EVENT_SET_ALLOWED_CARRIERS_DONE:
851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null && ar.result != null) {
854 request.result = ar.result;
855 } else {
856 if (ar.result == null) {
857 loge("setAllowedCarriers: Empty response");
858 } else if (ar.exception instanceof CommandException) {
859 loge("setAllowedCarriers: CommandException: " +
860 ar.exception);
861 } else {
862 loge("setAllowedCarriers: Unknown exception");
863 }
864 }
865 // Result cannot be null. Return -1 on error.
866 if (request.result == null) {
867 request.result = new int[]{-1};
868 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700869 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700870 break;
871
872 case CMD_GET_ALLOWED_CARRIERS:
873 request = (MainThreadRequest) msg.obj;
874 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Tobias Thiererb19e1f12018-12-11 17:54:03 +0000875 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 break;
877
878 case EVENT_GET_ALLOWED_CARRIERS_DONE:
879 ar = (AsyncResult) msg.obj;
880 request = (MainThreadRequest) ar.userObj;
881 if (ar.exception == null && ar.result != null) {
882 request.result = ar.result;
883 } else {
884 if (ar.result == null) {
885 loge("getAllowedCarriers: Empty response");
886 } else if (ar.exception instanceof CommandException) {
887 loge("getAllowedCarriers: CommandException: " +
888 ar.exception);
889 } else {
890 loge("getAllowedCarriers: Unknown exception");
891 }
892 }
893 // Result cannot be null. Return empty list of CarrierIdentifier.
894 if (request.result == null) {
895 request.result = new ArrayList<CarrierIdentifier>(0);
896 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700897 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700898 break;
899
Nathan Haroldb3014052017-01-25 15:57:32 -0800900 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null && ar.result != null) {
904 request.result = ar.result;
905 } else {
906 request.result = new IllegalArgumentException(
907 "Failed to retrieve Forbidden Plmns");
908 if (ar.result == null) {
909 loge("getForbiddenPlmns: Empty response");
910 } else {
911 loge("getForbiddenPlmns: Unknown exception");
912 }
913 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800915 break;
916
917 case CMD_GET_FORBIDDEN_PLMNS:
918 request = (MainThreadRequest) msg.obj;
919 uiccCard = getUiccCardFromRequest(request);
920 if (uiccCard == null) {
921 loge("getForbiddenPlmns() UiccCard is null");
922 request.result = new IllegalArgumentException(
923 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700924 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800925 break;
926 }
927 Integer appType = (Integer) request.argument;
928 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
929 if (uiccApp == null) {
930 loge("getForbiddenPlmns() no app with specified type -- "
931 + appType);
932 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700933 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800934 break;
935 } else {
936 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
937 + " specified type -- " + appType);
938 }
939 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
940 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
941 onCompleted);
942 break;
943
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000944 case CMD_SWITCH_SLOTS:
945 request = (MainThreadRequest) msg.obj;
946 int[] physicalSlots = (int[]) request.argument;
947 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
948 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
949 break;
950
951 case EVENT_SWITCH_SLOTS_DONE:
952 ar = (AsyncResult) msg.obj;
953 request = (MainThreadRequest) ar.userObj;
954 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
956 break;
957 case CMD_GET_NETWORK_SELECTION_MODE:
958 request = (MainThreadRequest) msg.obj;
959 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
960 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
961 break;
962
963 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
966 if (ar.exception != null) {
967 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
968 } else {
969 int mode = ((int[]) ar.result)[0];
970 if (mode == 0) {
971 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
972 } else {
973 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
974 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000975 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700976 notifyRequester(request);
977 break;
978 case CMD_GET_CDMA_ROAMING_MODE:
979 request = (MainThreadRequest) msg.obj;
980 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
981 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
982 break;
983 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 if (ar.exception != null) {
987 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
988 } else {
989 request.result = ((int[]) ar.result)[0];
990 }
991 notifyRequester(request);
992 break;
993 case CMD_SET_CDMA_ROAMING_MODE:
994 request = (MainThreadRequest) msg.obj;
995 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
996 int mode = (int) request.argument;
997 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
998 break;
999 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 request.result = ar.exception == null;
1003 notifyRequester(request);
1004 break;
1005 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1006 request = (MainThreadRequest) msg.obj;
1007 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1008 int subscriptionMode = (int) request.argument;
1009 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1010 break;
1011 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1012 ar = (AsyncResult) msg.obj;
1013 request = (MainThreadRequest) ar.userObj;
1014 request.result = ar.exception == null;
1015 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001016 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001017 case CMD_GET_ALL_CELL_INFO:
1018 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001019 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001020 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001021 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001022 case EVENT_GET_ALL_CELL_INFO_DONE:
1023 ar = (AsyncResult) msg.obj;
1024 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001025 // If a timeout occurs, the response will be null
1026 request.result = (ar.exception == null && ar.result != null)
1027 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001028 synchronized (request) {
1029 request.notifyAll();
1030 }
1031 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001032 case CMD_REQUEST_CELL_INFO_UPDATE:
1033 request = (MainThreadRequest) msg.obj;
1034 request.phone.requestCellInfoUpdate(request.workSource,
1035 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1036 break;
1037 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
1040 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1041 try {
1042 if (ar.exception != null) {
1043 // something went wrong... the response is null
1044 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1045 cb.onCellInfo(null);
1046 } else if (ar.result == null) {
1047 // timeout occurred, so force the result to non-null "empty"
1048 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1049 cb.onCellInfo(new ArrayList<CellInfo>());
1050 } else {
1051 // use the result as returned
1052 cb.onCellInfo((List<CellInfo>) ar.result);
1053 }
1054 } catch (RemoteException re) {
1055 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1056 }
1057 break;
1058 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 request = (MainThreadRequest) msg.obj;
1060 WorkSource ws = (WorkSource) request.argument;
1061 Phone phone = getPhoneFromRequest(request);
1062 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1063 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
1067 if (ar.exception == null) {
1068 request.result = ar.result;
1069 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001070 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001071 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1072 ? new CdmaCellLocation() : new GsmCellLocation();
1073 }
1074
1075 synchronized (request) {
1076 request.notifyAll();
1077 }
1078 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001079 case CMD_MODEM_REBOOT:
1080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001082 mPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001083 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001084 case EVENT_CMD_MODEM_REBOOT_DONE:
1085 handleNullReturnEvent(msg, "rebootModem");
1086 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 default:
1088 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1089 break;
1090 }
1091 }
Jake Hambye994d462014-02-03 13:10:13 -08001092
Pengquan Menga1bb6272018-09-06 09:59:22 -07001093 private void notifyRequester(MainThreadRequest request) {
1094 synchronized (request) {
1095 request.notifyAll();
1096 }
1097 }
1098
Jake Hambye994d462014-02-03 13:10:13 -08001099 private void handleNullReturnEvent(Message msg, String command) {
1100 AsyncResult ar = (AsyncResult) msg.obj;
1101 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1102 if (ar.exception == null) {
1103 request.result = true;
1104 } else {
1105 request.result = false;
1106 if (ar.exception instanceof CommandException) {
1107 loge(command + ": CommandException: " + ar.exception);
1108 } else {
1109 loge(command + ": Unknown exception");
1110 }
1111 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001112 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 }
1115
1116 /**
1117 * Posts the specified command to be executed on the main thread,
1118 * waits for the request to complete, and returns the result.
1119 * @see #sendRequestAsync
1120 */
1121 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001122 return sendRequest(
1123 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001124 }
1125
1126 /**
1127 * Posts the specified command to be executed on the main thread,
1128 * waits for the request to complete, and returns the result.
1129 * @see #sendRequestAsync
1130 */
1131 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1132 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001133 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001134 }
1135
1136 /**
1137 * Posts the specified command to be executed on the main thread,
1138 * waits for the request to complete, and returns the result.
1139 * @see #sendRequestAsync
1140 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001141 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001142 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001143 }
1144
1145 /**
1146 * Posts the specified command to be executed on the main thread,
1147 * waits for the request to complete, and returns the result.
1148 * @see #sendRequestAsync
1149 */
Nathan Harold92bed182018-10-12 18:16:49 -07001150 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1151 return sendRequest(command, argument, subId, null, workSource);
1152 }
1153
1154 /**
1155 * Posts the specified command to be executed on the main thread,
1156 * waits for the request to complete, and returns the result.
1157 * @see #sendRequestAsync
1158 */
1159 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1160 return sendRequest(
1161 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1162 }
1163
1164 /**
1165 * Posts the specified command to be executed on the main thread,
1166 * waits for the request to complete, and returns the result.
1167 * @see #sendRequestAsync
1168 */
1169 private Object sendRequest(
1170 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1172 throw new RuntimeException("This method will deadlock if called from the main thread.");
1173 }
1174
Nathan Harold92bed182018-10-12 18:16:49 -07001175 MainThreadRequest request = null;
1176 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1177 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1178 } else if (phone != null) {
1179 request = new MainThreadRequest(argument, phone, workSource);
1180 } else {
1181 request = new MainThreadRequest(argument, subId, workSource);
1182 }
1183
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184 Message msg = mMainThreadHandler.obtainMessage(command, request);
1185 msg.sendToTarget();
1186
1187 // Wait for the request to complete
1188 synchronized (request) {
1189 while (request.result == null) {
1190 try {
1191 request.wait();
1192 } catch (InterruptedException e) {
1193 // Do nothing, go back and wait until the request is complete
1194 }
1195 }
1196 }
1197 return request.result;
1198 }
1199
1200 /**
1201 * Asynchronous ("fire and forget") version of sendRequest():
1202 * Posts the specified command to be executed on the main thread, and
1203 * returns immediately.
1204 * @see #sendRequest
1205 */
1206 private void sendRequestAsync(int command) {
1207 mMainThreadHandler.sendEmptyMessage(command);
1208 }
1209
1210 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001211 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001212 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001213 */
1214 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001215 sendRequestAsync(command, argument, null, null);
1216 }
1217
1218 /**
1219 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1220 * @see {@link #sendRequest(int,Object)}
1221 */
1222 private void sendRequestAsync(
1223 int command, Object argument, Phone phone, WorkSource workSource) {
1224 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001225 Message msg = mMainThreadHandler.obtainMessage(command, request);
1226 msg.sendToTarget();
1227 }
1228
1229 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 * Initialize the singleton PhoneInterfaceManager instance.
1231 * This is only done once, at startup, from PhoneApp.onCreate().
1232 */
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001233 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 synchronized (PhoneInterfaceManager.class) {
1235 if (sInstance == null) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001236 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237 } else {
1238 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1239 }
1240 return sInstance;
1241 }
1242 }
1243
1244 /** Private constructor; @see init() */
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001245 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 mApp = app;
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001247 mPhone = phone;
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();
Nazanin Bakhshia5509e92018-12-06 15:34:22 -08001252 mTelephonySharedPreferences =
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001253 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
1254 mSubscriptionController = SubscriptionController.getInstance();
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
1261 private void publish() {
1262 if (DBG) log("publish: " + this);
1263
1264 ServiceManager.addService("phone", this);
1265 }
1266
Stuart Scott584921c2015-01-15 17:10:34 -08001267 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001268 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001269 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001270 }
1271
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001272 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1273 Phone phone = getPhoneFromRequest(request);
1274 return phone == null ? null :
1275 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1276 }
1277
Wink Saville36469e72014-06-11 15:17:00 -07001278 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001279 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001280 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282
1283 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001284 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001285 }
1286
Wink Savilleb564aae2014-10-23 10:18:09 -07001287 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 if (DBG) log("dial: " + number);
1289 // No permission check needed here: This is just a wrapper around the
1290 // ACTION_DIAL intent, which is available to any app since it puts up
1291 // the UI before it does anything.
1292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001293 final long identity = Binder.clearCallingIdentity();
1294 try {
1295 String url = createTelUrl(number);
1296 if (url == null) {
1297 return;
1298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001300 // PENDING: should we just silently fail if phone is offhook or ringing?
1301 PhoneConstants.State state = mCM.getState(subId);
1302 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1303 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1304 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1305 mApp.startActivity(intent);
1306 }
1307 } finally {
1308 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 }
1310 }
1311
1312 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001313 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Wink Savilleb564aae2014-10-23 10:18:09 -07001316 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 if (DBG) log("call: " + number);
1318
1319 // This is just a wrapper around the ACTION_CALL intent, but we still
1320 // need to do a permission check since we're calling startActivity()
1321 // from the context of the phone app.
1322 enforceCallPermission();
1323
1324 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1325 != AppOpsManager.MODE_ALLOWED) {
1326 return;
1327 }
1328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001329 final long identity = Binder.clearCallingIdentity();
1330 try {
1331 String url = createTelUrl(number);
1332 if (url == null) {
1333 return;
1334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001336 boolean isValid = false;
1337 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1338 if (slist != null) {
1339 for (SubscriptionInfo subInfoRecord : slist) {
1340 if (subInfoRecord.getSubscriptionId() == subId) {
1341 isValid = true;
1342 break;
1343 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001344 }
Wink Saville08874612014-08-31 19:19:58 -07001345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001346 if (!isValid) {
1347 return;
1348 }
Wink Saville08874612014-08-31 19:19:58 -07001349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001350 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1351 intent.putExtra(SUBSCRIPTION_KEY, subId);
1352 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1353 mApp.startActivity(intent);
1354 } finally {
1355 Binder.restoreCallingIdentity(identity);
1356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 }
1358
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001360 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001361 }
1362
Wink Savilleb564aae2014-10-23 10:18:09 -07001363 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001364 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001365 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1366 }
1367
1368 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001369 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001370 }
1371
Wink Savilleb564aae2014-10-23 10:18:09 -07001372 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001373 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001374 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1375 }
1376
1377 /** {@hide} */
1378 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001379 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001380 }
1381
Wink Savilleb564aae2014-10-23 10:18:09 -07001382 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001384
1385 final long identity = Binder.clearCallingIdentity();
1386 try {
1387 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1388 checkSimPin.start();
1389 return checkSimPin.unlockSim(null, pin);
1390 } finally {
1391 Binder.restoreCallingIdentity(identity);
1392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 }
1394
Wink Saville9de0f752013-10-22 19:04:03 -07001395 /** {@hide} */
1396 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001397 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001398 }
1399
Wink Savilleb564aae2014-10-23 10:18:09 -07001400 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001402
1403 final long identity = Binder.clearCallingIdentity();
1404 try {
1405 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1406 checkSimPuk.start();
1407 return checkSimPuk.unlockSim(puk, pin);
1408 } finally {
1409 Binder.restoreCallingIdentity(identity);
1410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 }
1412
1413 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001414 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 * a synchronous one.
1416 */
1417 private static class UnlockSim extends Thread {
1418
1419 private final IccCard mSimCard;
1420
1421 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001422 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1423 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424
1425 // For replies from SimCard interface
1426 private Handler mHandler;
1427
1428 // For async handler to identify request type
1429 private static final int SUPPLY_PIN_COMPLETE = 100;
1430
1431 public UnlockSim(IccCard simCard) {
1432 mSimCard = simCard;
1433 }
1434
1435 @Override
1436 public void run() {
1437 Looper.prepare();
1438 synchronized (UnlockSim.this) {
1439 mHandler = new Handler() {
1440 @Override
1441 public void handleMessage(Message msg) {
1442 AsyncResult ar = (AsyncResult) msg.obj;
1443 switch (msg.what) {
1444 case SUPPLY_PIN_COMPLETE:
1445 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1446 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001447 mRetryCount = msg.arg1;
1448 if (ar.exception != null) {
1449 if (ar.exception instanceof CommandException &&
1450 ((CommandException)(ar.exception)).getCommandError()
1451 == CommandException.Error.PASSWORD_INCORRECT) {
1452 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1453 } else {
1454 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1455 }
1456 } else {
1457 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 mDone = true;
1460 UnlockSim.this.notifyAll();
1461 }
1462 break;
1463 }
1464 }
1465 };
1466 UnlockSim.this.notifyAll();
1467 }
1468 Looper.loop();
1469 }
1470
1471 /*
1472 * Use PIN or PUK to unlock SIM card
1473 *
1474 * If PUK is null, unlock SIM card with PIN
1475 *
1476 * If PUK is not null, unlock SIM card with PUK and set PIN code
1477 */
Wink Saville9de0f752013-10-22 19:04:03 -07001478 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479
1480 while (mHandler == null) {
1481 try {
1482 wait();
1483 } catch (InterruptedException e) {
1484 Thread.currentThread().interrupt();
1485 }
1486 }
1487 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1488
1489 if (puk == null) {
1490 mSimCard.supplyPin(pin, callback);
1491 } else {
1492 mSimCard.supplyPuk(puk, pin, callback);
1493 }
1494
1495 while (!mDone) {
1496 try {
1497 Log.d(LOG_TAG, "wait for done");
1498 wait();
1499 } catch (InterruptedException e) {
1500 // Restore the interrupted status
1501 Thread.currentThread().interrupt();
1502 }
1503 }
1504 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001505 int[] resultArray = new int[2];
1506 resultArray[0] = mResult;
1507 resultArray[1] = mRetryCount;
1508 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 }
1510 }
1511
1512 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001513 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001514
1515 }
1516
Wink Savilleb564aae2014-10-23 10:18:09 -07001517 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001518 // No permission check needed here: this call is harmless, and it's
1519 // needed for the ServiceState.requestStateUpdate() call (which is
1520 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001521 final long identity = Binder.clearCallingIdentity();
1522 try {
1523 final Phone phone = getPhone(subId);
1524 if (phone != null) {
1525 phone.updateServiceLocation();
1526 }
1527 } finally {
1528 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 }
1531
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001532 @Override
1533 public boolean isRadioOn(String callingPackage) {
1534 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001535 }
1536
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001537 @Override
1538 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001540 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001541 return false;
1542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001543
1544 final long identity = Binder.clearCallingIdentity();
1545 try {
1546 return isRadioOnForSubscriber(subId);
1547 } finally {
1548 Binder.restoreCallingIdentity(identity);
1549 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001550 }
1551
1552 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001553 final long identity = Binder.clearCallingIdentity();
1554 try {
1555 final Phone phone = getPhone(subId);
1556 if (phone != null) {
1557 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1558 } else {
1559 return false;
1560 }
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
1566 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001567 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 }
Wink Saville36469e72014-06-11 15:17:00 -07001569
Wink Savilleb564aae2014-10-23 10:18:09 -07001570 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001572
1573 final long identity = Binder.clearCallingIdentity();
1574 try {
1575 final Phone phone = getPhone(subId);
1576 if (phone != null) {
1577 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1578 }
1579 } finally {
1580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001581 }
Wink Saville36469e72014-06-11 15:17:00 -07001582 }
1583
1584 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001585 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001586 }
1587
Wink Savilleb564aae2014-10-23 10:18:09 -07001588 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001590
1591 final long identity = Binder.clearCallingIdentity();
1592 try {
1593 final Phone phone = getPhone(subId);
1594 if (phone == null) {
1595 return false;
1596 }
1597 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1598 toggleRadioOnOffForSubscriber(subId);
1599 }
1600 return true;
1601 } finally {
1602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 }
Wink Saville36469e72014-06-11 15:17:00 -07001605
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001606 public boolean needMobileRadioShutdown() {
1607 /*
1608 * If any of the Radios are available, it will need to be
1609 * shutdown. So return true if any Radio is available.
1610 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001611 final long identity = Binder.clearCallingIdentity();
1612 try {
1613 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1614 Phone phone = PhoneFactory.getPhone(i);
1615 if (phone != null && phone.isRadioAvailable()) return true;
1616 }
1617 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1618 return false;
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001621 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001622 }
1623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001624 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001625 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001626 enforceModifyPermission();
1627
1628 final long identity = Binder.clearCallingIdentity();
1629 try {
1630 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1631 logv("Shutting down Phone " + i);
1632 shutdownRadioUsingPhoneId(i);
1633 }
1634 } finally {
1635 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001636 }
1637 }
1638
1639 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001640 Phone phone = PhoneFactory.getPhone(phoneId);
1641 if (phone != null && phone.isRadioAvailable()) {
1642 phone.shutdownRadio();
1643 }
1644 }
1645
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001647 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001648
1649 final long identity = Binder.clearCallingIdentity();
1650 try {
1651 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1652 if (defaultPhone != null) {
1653 defaultPhone.setRadioPower(turnOn);
1654 return true;
1655 } else {
1656 loge("There's no default phone.");
1657 return false;
1658 }
1659 } finally {
1660 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001661 }
Wink Saville36469e72014-06-11 15:17:00 -07001662 }
1663
Wink Savilleb564aae2014-10-23 10:18:09 -07001664 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001666
1667 final long identity = Binder.clearCallingIdentity();
1668 try {
1669 final Phone phone = getPhone(subId);
1670 if (phone != null) {
1671 phone.setRadioPower(turnOn);
1672 return true;
1673 } else {
1674 return false;
1675 }
1676 } finally {
1677 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 }
1680
Wink Saville36469e72014-06-11 15:17:00 -07001681 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001682 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 public boolean enableDataConnectivity() {
1684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001685
1686 final long identity = Binder.clearCallingIdentity();
1687 try {
1688 int subId = mSubscriptionController.getDefaultDataSubId();
1689 final Phone phone = getPhone(subId);
1690 if (phone != null) {
1691 phone.setUserDataEnabled(true);
1692 return true;
1693 } else {
1694 return false;
1695 }
1696 } finally {
1697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
Wink Saville36469e72014-06-11 15:17:00 -07001701 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 public boolean disableDataConnectivity() {
1704 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001705
1706 final long identity = Binder.clearCallingIdentity();
1707 try {
1708 int subId = mSubscriptionController.getDefaultDataSubId();
1709 final Phone phone = getPhone(subId);
1710 if (phone != null) {
1711 phone.setUserDataEnabled(false);
1712 return true;
1713 } else {
1714 return false;
1715 }
1716 } finally {
1717 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 }
1720
Sanket Padawe356d7632015-06-22 14:03:32 -07001721 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001722 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723 final long identity = Binder.clearCallingIdentity();
1724 try {
1725 final Phone phone = getPhone(subId);
1726 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001727 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728 } else {
1729 return false;
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
1736 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001738 }
1739
pkanwarae03a6b2016-11-06 20:37:09 -08001740 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001741 enforceCallPermission();
1742
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1746 return;
1747 }
1748 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1749 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1750 } finally {
1751 Binder.restoreCallingIdentity(identity);
1752 }
pkanwar32d516d2016-10-14 19:37:38 -07001753 };
1754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1761 return false;
1762 }
1763 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 }
1768
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001770 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001771 }
1772
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001773 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001774 final long identity = Binder.clearCallingIdentity();
1775 try {
1776 Phone phone = PhoneFactory.getPhone(slotIndex);
1777 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1778 PhoneConstantConversions.convertCallState(phone.getState());
1779 } finally {
1780 Binder.restoreCallingIdentity(identity);
1781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 }
1783
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 final long identity = Binder.clearCallingIdentity();
1787 try {
1788 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1789 if (phone != null) {
1790 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1791 } else {
1792 return PhoneConstantConversions.convertDataState(
1793 PhoneConstants.DataState.DISCONNECTED);
1794 }
1795 } finally {
1796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 }
1799
Sanket Padawe356d7632015-06-22 14:03:32 -07001800 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802 final long identity = Binder.clearCallingIdentity();
1803 try {
1804 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1805 if (phone != null) {
1806 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1807 } else {
1808 return TelephonyManager.DATA_ACTIVITY_NONE;
1809 }
1810 } finally {
1811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
1815 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001816 public Bundle getCellLocation(String callingPackage) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001817 mPhone.getContext().getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001818 .checkPackage(Binder.getCallingUid(), callingPackage);
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001819 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
1820 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001821 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 }
1823
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001824 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001825 final long identity = Binder.clearCallingIdentity();
1826 try {
1827 if (DBG_LOC) log("getCellLocation: is active user");
1828 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001829 int subId = mSubscriptionController.getDefaultDataSubId();
1830 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1831 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001832 return data;
1833 } finally {
1834 Binder.restoreCallingIdentity(identity);
1835 }
Svetoslav64fad262015-04-14 14:35:21 -07001836 }
1837
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001839 public String getNetworkCountryIsoForPhone(int phoneId) {
1840 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1841 // registered cell info, so return a NULL country instead.
1842 final long identity = Binder.clearCallingIdentity();
1843 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001844 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1845 // Get default phone in this case.
1846 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1847 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001848 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001849 // Todo: fix this when we can get the actual cellular network info when the device
1850 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001851 if (TelephonyManager.NETWORK_TYPE_IWLAN
1852 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1853 return "";
1854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001855 Phone phone = PhoneFactory.getPhone(phoneId);
1856 if (phone != null) {
1857 ServiceStateTracker sst = phone.getServiceStateTracker();
1858 if (sst != null) {
1859 LocaleTracker lt = sst.getLocaleTracker();
1860 if (lt != null) {
1861 return lt.getCurrentCountry();
1862 }
1863 }
1864 }
1865 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001866 } finally {
1867 Binder.restoreCallingIdentity(identity);
1868 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001869 }
1870
1871 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001873 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001874 }
1875
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001877 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 mApp.enforceCallingOrSelfPermission(
1879 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880
1881 final long identity = Binder.clearCallingIdentity();
1882 try {
1883 final Phone phone = getPhone(subId);
1884 if (phone != null) {
1885 phone.enableLocationUpdates();
1886 }
1887 } finally {
1888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
1892 @Override
1893 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001894 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001895 }
1896
Sanket Padawe356d7632015-06-22 14:03:32 -07001897 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001898 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 mApp.enforceCallingOrSelfPermission(
1900 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001901
1902 final long identity = Binder.clearCallingIdentity();
1903 try {
1904 final Phone phone = getPhone(subId);
1905 if (phone != null) {
1906 phone.disableLocationUpdates();
1907 }
1908 } finally {
1909 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 }
1912
Nathan Harold31d7ff32018-10-15 20:20:30 -07001913 /**
1914 * Returns the target SDK version number for a given package name.
1915 *
1916 * @return target SDK if the package is found or INT_MAX.
1917 */
1918 private int getTargetSdk(String packageName) {
1919 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001920 final ApplicationInfo ai =
1921 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001922 if (ai != null) return ai.targetSdkVersion;
1923 } catch (PackageManager.NameNotFoundException unexpected) {
1924 }
1925 return Integer.MAX_VALUE;
1926 }
1927
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 @Override
1929 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001930 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1931 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001932 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1933 throw new SecurityException(
1934 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1935 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001936
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1938 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1939 return null;
1940 }
Svetoslav64fad262015-04-14 14:35:21 -07001941
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001942 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943
Nathan Haroldf180aac2018-06-01 18:43:55 -07001944 List<CellInfo> info = getAllCellInfo(callingPackage);
1945 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946
Nathan Haroldf180aac2018-06-01 18:43:55 -07001947 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1948 for (CellInfo ci : info) {
1949 if (ci instanceof CellInfoGsm) {
1950 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1951 } else if (ci instanceof CellInfoWcdma) {
1952 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001955 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 }
1957
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001958 private List<CellInfo> getCachedCellInfo() {
1959 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1960 for (Phone phone : PhoneFactory.getPhones()) {
1961 List<CellInfo> info = phone.getAllCellInfo();
1962 if (info != null) cellInfos.addAll(info);
1963 }
1964 return cellInfos;
1965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966
1967 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001968 public List<CellInfo> getAllCellInfo(String callingPackage) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001969 mPhone.getContext().getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001970 .checkPackage(Binder.getCallingUid(), callingPackage);
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001971 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001972 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001973 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 }
1975
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001976 final int targetSdk = getTargetSdk(callingPackage);
1977 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1978 return getCachedCellInfo();
1979 }
1980
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001981 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001982 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983 final long identity = Binder.clearCallingIdentity();
1984 try {
1985 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1986 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001987 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001988 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 if (info != null) cellInfos.addAll(info);
1990 }
1991 return cellInfos;
1992 } finally {
1993 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995 }
1996
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001997 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001998 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
1999 requestCellInfoUpdateInternal(
2000 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2001 }
2002
2003 @Override
2004 public void requestCellInfoUpdateWithWorkSource(
2005 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2006 enforceModifyPermission();
2007 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2008 }
2009
2010 private void requestCellInfoUpdateInternal(
2011 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002012 mPhone.getContext().getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002013 .checkPackage(Binder.getCallingUid(), callingPackage);
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002014 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
2015 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002016 return;
2017 }
2018
2019 final Phone phone = getPhone(subId);
2020 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2021
2022 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2023 }
2024
2025 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002027 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002028 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002029
2030 final long identity = Binder.clearCallingIdentity();
2031 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002032 mPhone.setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002033 } finally {
2034 Binder.restoreCallingIdentity(identity);
2035 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 }
2037
Shishir Agrawala9f32182016-04-12 12:00:16 -07002038 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002039 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002040 Phone phone = PhoneFactory.getPhone(slotIndex);
2041 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002042 return null;
2043 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002044 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002045 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2046 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002047 return null;
2048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002049
2050 final long identity = Binder.clearCallingIdentity();
2051 try {
2052 return phone.getImei();
2053 } finally {
2054 Binder.restoreCallingIdentity(identity);
2055 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002056 }
2057
2058 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002059 public String getTypeAllocationCodeForSlot(int slotIndex) {
2060 Phone phone = PhoneFactory.getPhone(slotIndex);
2061 String tac = null;
2062 if (phone != null) {
2063 String imei = phone.getImei();
2064 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2065 }
2066 return tac;
2067 }
2068
2069 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002070 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002071 Phone phone = PhoneFactory.getPhone(slotIndex);
2072 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002073 return null;
2074 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002075 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002076 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2077 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002078 return null;
2079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080
2081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 return phone.getMeid();
2084 } finally {
2085 Binder.restoreCallingIdentity(identity);
2086 }
Jack Yu2af8d712017-03-15 17:14:14 -07002087 }
2088
2089 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002090 public String getManufacturerCodeForSlot(int slotIndex) {
2091 Phone phone = PhoneFactory.getPhone(slotIndex);
2092 String manufacturerCode = null;
2093 if (phone != null) {
2094 String meid = phone.getMeid();
2095 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2096 }
2097 return manufacturerCode;
2098 }
2099
2100 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002101 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002102 Phone phone = PhoneFactory.getPhone(slotIndex);
2103 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002104 return null;
2105 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002106 int subId = phone.getSubId();
2107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2108 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2109 return null;
2110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002111
2112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 return phone.getDeviceSvn();
2115 } finally {
2116 Binder.restoreCallingIdentity(identity);
2117 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002118 }
2119
fionaxu43304da2017-11-27 22:51:16 -08002120 @Override
2121 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002122 final long identity = Binder.clearCallingIdentity();
2123 try {
2124 final Phone phone = getPhone(subId);
2125 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
2128 }
fionaxu43304da2017-11-27 22:51:16 -08002129 }
2130
2131 @Override
2132 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133 final long identity = Binder.clearCallingIdentity();
2134 try {
2135 final Phone phone = getPhone(subId);
2136 return phone == null ? null : phone.getCarrierName();
2137 } finally {
2138 Binder.restoreCallingIdentity(identity);
2139 }
fionaxu43304da2017-11-27 22:51:16 -08002140 }
2141
calvinpanffe225e2018-11-01 19:43:06 +08002142 @Override
2143 public int getSubscriptionMNOCarrierId(int subId) {
2144 final long identity = Binder.clearCallingIdentity();
2145 try {
2146 final Phone phone = getPhone(subId);
2147 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2148 } finally {
2149 Binder.restoreCallingIdentity(identity);
2150 }
2151 }
2152
chen xu25637222018-11-04 17:17:00 -08002153 @Override
2154 public int getSubscriptionPreciseCarrierId(int subId) {
2155 final long identity = Binder.clearCallingIdentity();
2156 try {
2157 final Phone phone = getPhone(subId);
2158 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2159 : phone.getPreciseCarrierId();
2160 } finally {
2161 Binder.restoreCallingIdentity(identity);
2162 }
2163 }
2164
2165 @Override
2166 public String getSubscriptionPreciseCarrierName(int subId) {
2167 final long identity = Binder.clearCallingIdentity();
2168 try {
2169 final Phone phone = getPhone(subId);
2170 return phone == null ? null : phone.getPreciseCarrierName();
2171 } finally {
2172 Binder.restoreCallingIdentity(identity);
2173 }
2174 }
2175
chen xu651eec72018-11-11 19:03:44 -08002176 @Override
2177 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc) {
2178 final Phone phone = PhoneFactory.getPhone(slotIndex);
2179 if (phone == null) {
2180 return TelephonyManager.UNKNOWN_CARRIER_ID;
2181 }
2182 final long identity = Binder.clearCallingIdentity();
2183 try {
2184 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
2187 }
2188 }
2189
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 //
2191 // Internal helper methods.
2192 //
2193
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002194 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2196 *
2197 * @throws SecurityException if the caller does not have the required permission
2198 */
2199 private void enforceModifyPermission() {
2200 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2201 }
2202
2203 /**
2204 * Make sure the caller has the CALL_PHONE permission.
2205 *
2206 * @throws SecurityException if the caller does not have the required permission
2207 */
2208 private void enforceCallPermission() {
2209 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2210 }
2211
Stuart Scott8eef64f2015-04-08 15:13:54 -07002212 private void enforceConnectivityInternalPermission() {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002213 mApp.enforceCallingOrSelfPermission(
2214 android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002215 "ConnectivityService");
2216 }
2217
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 private String createTelUrl(String number) {
2219 if (TextUtils.isEmpty(number)) {
2220 return null;
2221 }
2222
Jake Hambye994d462014-02-03 13:10:13 -08002223 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 }
2225
Ihab Awadf9e92732013-12-05 18:02:52 -08002226 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2228 }
2229
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002230 private static void logv(String msg) {
2231 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2232 }
2233
Ihab Awadf9e92732013-12-05 18:02:52 -08002234 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2236 }
2237
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002238 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002240 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002241 }
2242
Sanket Padawe356d7632015-06-22 14:03:32 -07002243 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002244 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245 final long identity = Binder.clearCallingIdentity();
2246 try {
2247 final Phone phone = PhoneFactory.getPhone(slotIndex);
2248 if (phone == null) {
2249 return PhoneConstants.PHONE_TYPE_NONE;
2250 } else {
2251 return phone.getPhoneType();
2252 }
2253 } finally {
2254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 }
2257
2258 /**
2259 * Returns the CDMA ERI icon index to display
2260 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002261 @Override
2262 public int getCdmaEriIconIndex(String callingPackage) {
2263 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002264 }
2265
Sanket Padawe356d7632015-06-22 14:03:32 -07002266 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002267 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002269 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002270 return -1;
2271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002272
2273 final long identity = Binder.clearCallingIdentity();
2274 try {
2275 final Phone phone = getPhone(subId);
2276 if (phone != null) {
2277 return phone.getCdmaEriIconIndex();
2278 } else {
2279 return -1;
2280 }
2281 } finally {
2282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 }
2285
2286 /**
2287 * Returns the CDMA ERI icon mode,
2288 * 0 - ON
2289 * 1 - FLASHING
2290 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002291 @Override
2292 public int getCdmaEriIconMode(String callingPackage) {
2293 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002294 }
2295
Sanket Padawe356d7632015-06-22 14:03:32 -07002296 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002297 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002299 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002300 return -1;
2301 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302
2303 final long identity = Binder.clearCallingIdentity();
2304 try {
2305 final Phone phone = getPhone(subId);
2306 if (phone != null) {
2307 return phone.getCdmaEriIconMode();
2308 } else {
2309 return -1;
2310 }
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 }
2315
2316 /**
2317 * Returns the CDMA ERI text,
2318 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002319 @Override
2320 public String getCdmaEriText(String callingPackage) {
2321 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002322 }
2323
Sanket Padawe356d7632015-06-22 14:03:32 -07002324 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002325 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002327 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002328 return null;
2329 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
2333 final Phone phone = getPhone(subId);
2334 if (phone != null) {
2335 return phone.getCdmaEriText();
2336 } else {
2337 return null;
2338 }
2339 } finally {
2340 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
2343
2344 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002345 * Returns the CDMA MDN.
2346 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002347 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002348 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2350 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351
2352 final long identity = Binder.clearCallingIdentity();
2353 try {
2354 final Phone phone = getPhone(subId);
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002355 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356 return phone.getLine1Number();
2357 } else {
2358 return null;
2359 }
2360 } finally {
2361 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002362 }
2363 }
2364
2365 /**
2366 * Returns the CDMA MIN.
2367 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002368 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002369 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2371 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002372
2373 final long identity = Binder.clearCallingIdentity();
2374 try {
2375 final Phone phone = getPhone(subId);
2376 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2377 return phone.getCdmaMin();
2378 } else {
2379 return null;
2380 }
2381 } finally {
2382 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002383 }
2384 }
2385
Hall Liud892bec2018-11-30 14:51:45 -08002386 @Override
2387 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2388 INumberVerificationCallback callback, String callingPackage) {
2389 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2390 != PERMISSION_GRANTED) {
2391 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2392 }
2393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2394
2395 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2396 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2397 throw new SecurityException("Calling package must be configured in the device config");
2398 }
2399
2400 if (range == null) {
2401 throw new NullPointerException("Range must be non-null");
2402 }
2403
2404 timeoutMillis = Math.min(timeoutMillis,
2405 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2406
2407 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2408 }
2409
Junda Liuca05d5d2014-08-14 22:36:34 -07002410 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 * Returns true if CDMA provisioning needs to run.
2412 */
2413 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002414 final long identity = Binder.clearCallingIdentity();
2415 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002416 return mPhone.needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417 } finally {
2418 Binder.restoreCallingIdentity(identity);
2419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 }
2421
2422 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002423 * Sets the voice mail number of a given subId.
2424 */
2425 @Override
2426 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002427 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002428
2429 final long identity = Binder.clearCallingIdentity();
2430 try {
2431 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2432 new Pair<String, String>(alphaTag, number), new Integer(subId));
2433 return success;
2434 } finally {
2435 Binder.restoreCallingIdentity(identity);
2436 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002437 }
2438
Ta-wei Yen87c49842016-05-13 21:19:52 -07002439 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002440 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2441 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002442 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002443 if (!TextUtils.equals(callingPackage, systemDialer)) {
2444 throw new SecurityException("caller must be system dialer");
2445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446
2447 final long identity = Binder.clearCallingIdentity();
2448 try {
2449 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2450 if (phoneAccountHandle == null) {
2451 return null;
2452 }
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002453 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454 } finally {
2455 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002456 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002457 }
2458
2459 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002460 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002463 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002464 return null;
2465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002467 final long identity = Binder.clearCallingIdentity();
2468 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002469 return RemoteVvmTaskManager
2470 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002471 } finally {
2472 Binder.restoreCallingIdentity(identity);
2473 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002474 }
2475
2476 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002477 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2478 VisualVoicemailSmsFilterSettings settings) {
2479 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480
2481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002484 mPhone.getContext(), callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002485 } finally {
2486 Binder.restoreCallingIdentity(identity);
2487 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002488 }
2489
2490 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002491 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2492 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493
2494 final long identity = Binder.clearCallingIdentity();
2495 try {
2496 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002497 mPhone.getContext(), callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 } finally {
2499 Binder.restoreCallingIdentity(identity);
2500 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002501 }
2502
2503 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002504 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2505 String callingPackage, int subId) {
2506 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507
2508 final long identity = Binder.clearCallingIdentity();
2509 try {
2510 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002511 mPhone.getContext(), callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002515 }
2516
2517 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002518 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002519 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002520
2521 final long identity = Binder.clearCallingIdentity();
2522 try {
2523 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002524 mPhone.getContext(), subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002525 } finally {
2526 Binder.restoreCallingIdentity(identity);
2527 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002528 }
2529
2530 @Override
2531 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2532 String number, int port, String text, PendingIntent sentIntent) {
2533 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002534 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002535 enforceSendSmsPermission();
2536 // Make the calls as the phone process.
2537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2540 if (port == 0) {
2541 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2542 sentIntent, null, false);
2543 } else {
2544 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2545 smsManager.sendDataMessageWithSelfPermissions(number, null,
2546 (short) port, data, sentIntent, null);
2547 }
2548 } finally {
2549 Binder.restoreCallingIdentity(identity);
2550 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002551 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002552 /**
fionaxu0152e512016-11-14 13:36:14 -08002553 * Sets the voice activation state of a given subId.
2554 */
2555 @Override
2556 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2558 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559
2560 final long identity = Binder.clearCallingIdentity();
2561 try {
2562 final Phone phone = getPhone(subId);
2563 if (phone != null) {
2564 phone.setVoiceActivationState(activationState);
2565 } else {
2566 loge("setVoiceActivationState fails with invalid subId: " + subId);
2567 }
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002570 }
2571 }
2572
2573 /**
2574 * Sets the data activation state of a given subId.
2575 */
2576 @Override
2577 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2579 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580
2581 final long identity = Binder.clearCallingIdentity();
2582 try {
2583 final Phone phone = getPhone(subId);
2584 if (phone != null) {
2585 phone.setDataActivationState(activationState);
2586 } else {
2587 loge("setVoiceActivationState fails with invalid subId: " + subId);
2588 }
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002591 }
2592 }
2593
2594 /**
2595 * Returns the voice activation state of a given subId.
2596 */
2597 @Override
2598 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002599 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600
fionaxu0152e512016-11-14 13:36:14 -08002601 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 if (phone != null) {
2605 return phone.getVoiceActivationState();
2606 } else {
2607 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2608 }
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002611 }
2612 }
2613
2614 /**
2615 * Returns the data activation state of a given subId.
2616 */
2617 @Override
2618 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002619 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620
fionaxu0152e512016-11-14 13:36:14 -08002621 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 if (phone != null) {
2625 return phone.getDataActivationState();
2626 } else {
2627 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2628 }
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002631 }
2632 }
2633
2634 /**
Wink Saville36469e72014-06-11 15:17:00 -07002635 * Returns the unread count of voicemails for a subId
2636 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002637 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002638 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2640 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2641 return 0;
2642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 final Phone phone = getPhone(subId);
2646 if (phone != null) {
2647 return phone.getVoiceMessageCount();
2648 } else {
2649 return 0;
2650 }
2651 } finally {
2652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 }
2655
2656 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002657 * returns true, if the device is in a state where both voice and data
2658 * are supported simultaneously. This can change based on location or network condition.
2659 */
2660 @Override
2661 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002669 }
2670
2671 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002672 * Send the dialer code if called from the current default dialer or the caller has
2673 * carrier privilege.
2674 * @param inputCode The dialer code to send
2675 */
2676 @Override
2677 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002679 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002680 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002681 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2682 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002687 mPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
fionaxu235cc5e2017-03-06 22:25:57 -08002691 }
2692
2693 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002694 * Returns the data network type.
2695 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 *
2697 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2698 */
2699 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002700 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 final Phone phone = getPhone(getDefaultSubscription());
2704 if (phone != null) {
2705 return phone.getServiceState().getDataNetworkType();
2706 } else {
2707 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2708 }
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002711 }
Wink Saville36469e72014-06-11 15:17:00 -07002712 }
2713
Pengquan Menga1bb6272018-09-06 09:59:22 -07002714 @Override
2715 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002716 if (!isActiveSubscription(subId)) {
2717 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2718 }
2719
Pengquan Menga1bb6272018-09-06 09:59:22 -07002720 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2721 }
2722
Brad Ebinger35c841c2018-10-01 10:40:55 -07002723 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002724 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2725 throws RemoteException {
2726 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002727 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2728 final long token = Binder.clearCallingIdentity();
2729 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002730 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002731 .addRegistrationCallbackForSubscription(c, subId);
2732 } finally {
2733 Binder.restoreCallingIdentity(token);
2734 }
2735 }
2736
2737 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002738 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2739 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2741 Binder.withCleanCallingIdentity(() ->
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002742 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002743 .removeRegistrationCallbackForSubscription(c, subId));
2744 }
2745
2746 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002747 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2748 throws RemoteException {
2749 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002750 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2751 final long token = Binder.clearCallingIdentity();
2752 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002753 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002754 .addCapabilitiesCallbackForSubscription(c, subId);
2755 } finally {
2756 Binder.restoreCallingIdentity(token);
2757 }
2758 }
2759
2760 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002761 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2762 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002763 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2764 Binder.withCleanCallingIdentity(() ->
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002765 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002766 .removeCapabilitiesCallbackForSubscription(c, subId));
2767 }
2768
2769 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002770 public boolean isCapable(int subId, int capability, int regTech) {
2771 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2773 final long token = Binder.clearCallingIdentity();
2774 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002775 return ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002776 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2777 } catch (ImsException e) {
2778 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2779 return false;
2780 } finally {
2781 Binder.restoreCallingIdentity(token);
2782 }
2783 }
2784
2785 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002786 public boolean isAvailable(int subId, int capability, int regTech) {
2787 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002788 final long token = Binder.clearCallingIdentity();
2789 try {
2790 Phone phone = getPhone(subId);
2791 if (phone == null) return false;
2792 return phone.isImsCapabilityAvailable(capability, regTech);
2793 } finally {
2794 Binder.restoreCallingIdentity(token);
2795 }
2796 }
2797
2798 @Override
2799 public boolean isAdvancedCallingSettingEnabled(int subId) {
2800 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2801 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2802 final long token = Binder.clearCallingIdentity();
2803 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002804 return ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002805 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2806 } finally {
2807 Binder.restoreCallingIdentity(token);
2808 }
2809 }
2810
2811 @Override
2812 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2814 "setAdvancedCallingSetting");
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002818 ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002819 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
2822 }
2823 }
2824
2825 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002826 public boolean isVtSettingEnabled(int subId) {
2827 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002828 final long identity = Binder.clearCallingIdentity();
2829 try {
2830 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002831 return ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002832 getSlotIndexOrException(subId)).isVtEnabledByUser();
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
2835 }
2836 }
2837
2838 @Override
2839 public void setVtSetting(int subId, boolean isEnabled) {
2840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2841 "setVtSetting");
2842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002845 ImsManager.getInstance(mPhone.getContext(),
2846 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002847 } finally {
2848 Binder.restoreCallingIdentity(identity);
2849 }
2850 }
2851
2852 @Override
2853 public boolean isVoWiFiSettingEnabled(int subId) {
2854 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002858 return ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002859 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
2862 }
2863 }
2864
2865 @Override
2866 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2868 "setVoWiFiSetting");
2869 final long identity = Binder.clearCallingIdentity();
2870 try {
2871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002872 ImsManager.getInstance(mPhone.getContext(),
2873 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002874 } finally {
2875 Binder.restoreCallingIdentity(identity);
2876 }
2877 }
2878
2879 @Override
2880 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2881 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002885 return ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002886 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
2889 }
2890 }
2891
2892 @Override
2893 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2895 "setVoWiFiRoamingSetting");
2896 final long identity = Binder.clearCallingIdentity();
2897 try {
2898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002899 ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002900 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2901 } finally {
2902 Binder.restoreCallingIdentity(identity);
2903 }
2904 }
2905
2906 @Override
2907 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2909 "setVoWiFiNonPersistent");
2910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002913 ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002914 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
2917 }
2918 }
2919
2920 @Override
2921 public int getVoWiFiModeSetting(int subId) {
2922 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002926 return ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002927 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
2931 }
2932
2933 @Override
2934 public void setVoWiFiModeSetting(int subId, int mode) {
2935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2936 "setVoWiFiModeSetting");
2937 final long identity = Binder.clearCallingIdentity();
2938 try {
2939 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002940 ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002941 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
2945 }
2946
2947 @Override
2948 public int getVoWiFiRoamingModeSetting(int subId) {
2949 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2950 final long identity = Binder.clearCallingIdentity();
2951 try {
2952 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002953 return ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002954 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
2958 }
2959
2960 @Override
2961 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2963 "setVoWiFiRoamingModeSetting");
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002967 ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002968 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
2972 }
2973
2974 @Override
2975 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2977 "setRttCapabilityEnabled");
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002981 ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002982 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
2986 }
2987
2988 @Override
2989 public boolean isTtyOverVolteEnabled(int subId) {
2990 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2991 final long identity = Binder.clearCallingIdentity();
2992 try {
2993 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002994 return ImsManager.getInstance(mPhone.getContext(),
Brad Ebinger35c841c2018-10-01 10:40:55 -07002995 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
2999 }
3000
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003001 @Override
3002 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3003 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003007 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003008 .getConfigInterface().addConfigCallback(callback);
3009 } catch (ImsException e) {
3010 throw new IllegalArgumentException(e.getMessage());
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
3014 }
3015
3016 @Override
3017 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3018 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003022 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003023 .getConfigInterface().removeConfigCallback(callback);
3024 } catch (ImsException e) {
3025 throw new IllegalArgumentException(e.getMessage());
3026 } finally {
3027 Binder.restoreCallingIdentity(identity);
3028 }
3029 }
3030
3031 @Override
3032 public int getImsProvisioningInt(int subId, int key) {
3033 enforceReadPrivilegedPermission("getImsProvisioningInt");
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003037 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3038 .getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003039 } catch (ImsException e) {
3040 throw new IllegalArgumentException(e.getMessage());
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
3043 }
3044 }
3045
3046 @Override
3047 public String getImsProvisioningString(int subId, int key) {
3048 enforceReadPrivilegedPermission("getImsProvisioningString");
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003052 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3053 .getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003054 } catch (ImsException e) {
3055 throw new IllegalArgumentException(e.getMessage());
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
3059 }
3060
3061 @Override
3062 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3064 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003068 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3069 .getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003070 } catch (ImsException e) {
3071 throw new IllegalArgumentException(e.getMessage());
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
3075 }
3076
3077 @Override
3078 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3080 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003084 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3085 .getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003086 } catch (ImsException e) {
3087 throw new IllegalArgumentException(e.getMessage());
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
3091 }
3092
Brad Ebinger35c841c2018-10-01 10:40:55 -07003093 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3094 int slotId = SubscriptionManager.getSlotIndex(subId);
3095 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3096 throw new IllegalArgumentException("Invalid Subscription Id.");
3097 }
3098 return slotId;
3099 }
3100
Wink Saville36469e72014-06-11 15:17:00 -07003101 /**
3102 * Returns the network type for a subId
3103 */
3104 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003105 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003107 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003108 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3109 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 final Phone phone = getPhone(subId);
3114 if (phone != null) {
3115 return phone.getServiceState().getDataNetworkType();
3116 } else {
3117 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3118 }
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003121 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003122 }
3123
3124 /**
3125 * Returns the data network type
3126 */
3127 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003128 public int getDataNetworkType(String callingPackage) {
3129 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003130 }
3131
3132 /**
3133 * Returns the data network type for a subId
3134 */
3135 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003136 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003138 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003139 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3140 }
3141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142 final long identity = Binder.clearCallingIdentity();
3143 try {
3144 final Phone phone = getPhone(subId);
3145 if (phone != null) {
3146 return phone.getServiceState().getDataNetworkType();
3147 } else {
3148 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3149 }
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
3154
3155 /**
Wink Saville36469e72014-06-11 15:17:00 -07003156 * Returns the Voice network type for a subId
3157 */
3158 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003159 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003161 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003162 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3163 }
3164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 final Phone phone = getPhone(subId);
3168 if (phone != null) {
3169 return phone.getServiceState().getVoiceNetworkType();
3170 } else {
3171 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3172 }
3173 } finally {
3174 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003176 }
3177
3178 /**
3179 * @return true if a ICC card is present
3180 */
3181 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003182 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003183 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3184 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003185 }
3186
3187 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003188 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003189 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003190 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003191 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 final Phone phone = PhoneFactory.getPhone(slotIndex);
3195 if (phone != null) {
3196 return phone.getIccCard().hasIccCard();
3197 } else {
3198 return false;
3199 }
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 }
3204
3205 /**
3206 * Return if the current radio is LTE on CDMA. This
3207 * is a tri-state return value as for a period of time
3208 * the mode may be unknown.
3209 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003210 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003212 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003214 @Override
3215 public int getLteOnCdmaMode(String callingPackage) {
3216 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003217 }
3218
Sanket Padawe356d7632015-06-22 14:03:32 -07003219 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003220 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003221 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003222 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003223 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3224 }
3225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 final Phone phone = getPhone(subId);
3229 if (phone == null) {
3230 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3231 } else {
3232 return phone.getLteOnCdmaMode();
3233 }
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003236 }
Wink Saville36469e72014-06-11 15:17:00 -07003237 }
3238
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003239 public void setPhone(Phone phone) {
3240 mPhone = phone;
3241 }
3242
Wink Saville36469e72014-06-11 15:17:00 -07003243 /**
3244 * {@hide}
3245 * Returns Default subId, 0 in the case of single standby.
3246 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003247 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003248 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003249 }
3250
Shishir Agrawala9f32182016-04-12 12:00:16 -07003251 private int getSlotForDefaultSubscription() {
3252 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3253 }
3254
Wink Savilleb564aae2014-10-23 10:18:09 -07003255 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003256 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003258
Pengquan Menge92a50d2018-09-21 15:54:48 -07003259 private boolean isActiveSubscription(int subId) {
3260 return mSubscriptionController.isActiveSubId(subId);
3261 }
3262
Ihab Awadf2177b72013-11-25 13:33:23 -08003263 /**
3264 * @see android.telephony.TelephonyManager.WifiCallingChoices
3265 */
3266 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267 final long identity = Binder.clearCallingIdentity();
3268 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003269 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003270 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3271 getWhenToMakeWifiCallsDefaultPreference());
3272 } finally {
3273 Binder.restoreCallingIdentity(identity);
3274 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003275 }
3276
3277 /**
3278 * @see android.telephony.TelephonyManager.WifiCallingChoices
3279 */
3280 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003284 Settings.System.putInt(mPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003285 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003289 }
3290
Sailesh Nepald1e68152013-12-12 19:08:02 -08003291 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003292 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003293 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003294 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003295
Shishir Agrawal566b7612013-10-28 14:41:00 -07003296 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003297 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3298 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3300 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003301 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303 final long identity = Binder.clearCallingIdentity();
3304 try {
3305 if (TextUtils.equals(ISDR_AID, aid)) {
3306 // Only allows LPA to open logical channel to ISD-R.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003307 ComponentInfo bestComponent =
3308 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 if (bestComponent == null
3310 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3311 loge("The calling package is not allowed to access ISD-R.");
3312 throw new SecurityException(
3313 "The calling package is not allowed to access ISD-R.");
3314 }
Derek Tan740e1672017-06-27 14:56:27 -07003315 }
Derek Tan740e1672017-06-27 14:56:27 -07003316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003317 if (DBG) {
3318 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3319 }
3320 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3321 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3322 if (DBG) log("iccOpenLogicalChannel: " + response);
3323 return response;
3324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003327 }
3328
3329 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003330 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3332 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3337 if (channel < 0) {
3338 return false;
3339 }
3340 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3341 if (DBG) log("iccCloseLogicalChannel: " + success);
3342 return success;
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003345 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003346 }
3347
3348 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003349 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003350 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3352 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 if (DBG) {
3357 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3358 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3359 + p3 + " data=" + data);
3360 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003361
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 if (channel < 0) {
3363 return "";
3364 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003366 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3367 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3368 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003370 // Append the returned status code to the end of the response payload.
3371 String s = Integer.toHexString(
3372 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3373 if (response.payload != null) {
3374 s = IccUtils.bytesToHexString(response.payload) + s;
3375 }
3376 return s;
3377 } finally {
3378 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003379 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003380 }
Jake Hambye994d462014-02-03 13:10:13 -08003381
Evan Charltonc66da362014-05-16 14:06:40 -07003382 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003383 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3384 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3386 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3392 && TextUtils.equals(ISDR_AID, data)) {
3393 // Only allows LPA to select ISD-R.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003394 ComponentInfo bestComponent =
3395 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003396 if (bestComponent == null
3397 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3398 loge("The calling package is not allowed to select ISD-R.");
3399 throw new SecurityException(
3400 "The calling package is not allowed to select ISD-R.");
3401 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003402 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 if (DBG) {
3405 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3406 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3407 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003408
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003409 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3410 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3411 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413 // Append the returned status code to the end of the response payload.
3414 String s = Integer.toHexString(
3415 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3416 if (response.payload != null) {
3417 s = IccUtils.bytesToHexString(response.payload) + s;
3418 }
3419 return s;
3420 } finally {
3421 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003422 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003423 }
3424
3425 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003426 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003427 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3429 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003430
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 if (DBG) {
3434 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3435 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3436 }
3437
3438 IccIoResult response =
3439 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3440 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3441 subId);
3442
3443 if (DBG) {
3444 log("Exchange SIM_IO [R]" + response);
3445 }
3446
3447 byte[] result = null;
3448 int length = 2;
3449 if (response.payload != null) {
3450 length = 2 + response.payload.length;
3451 result = new byte[length];
3452 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3453 } else {
3454 result = new byte[length];
3455 }
3456
3457 result[length - 1] = (byte) response.sw2;
3458 result[length - 2] = (byte) response.sw1;
3459 return result;
3460 } finally {
3461 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003462 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003463 }
3464
Nathan Haroldb3014052017-01-25 15:57:32 -08003465 /**
3466 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3467 * on a particular subscription
3468 */
sqianb6e41952018-03-12 14:54:01 -07003469 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3471 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3472 return null;
3473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003474
3475 final long identity = Binder.clearCallingIdentity();
3476 try {
3477 if (appType != TelephonyManager.APPTYPE_USIM
3478 && appType != TelephonyManager.APPTYPE_SIM) {
3479 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3480 return null;
3481 }
3482 Object response = sendRequest(
3483 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3484 if (response instanceof String[]) {
3485 return (String[]) response;
3486 }
3487 // Response is an Exception of some kind,
3488 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003489 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003490 } finally {
3491 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003492 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003493 }
3494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003495 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003496 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3498 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3503 if (response.payload == null) {
3504 return "";
3505 }
Evan Charltonc66da362014-05-16 14:06:40 -07003506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507 // Append the returned status code to the end of the response payload.
3508 String s = Integer.toHexString(
3509 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3510 s = IccUtils.bytesToHexString(response.payload) + s;
3511 return s;
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
Evan Charltonc66da362014-05-16 14:06:40 -07003515 }
3516
Jake Hambye994d462014-02-03 13:10:13 -08003517 /**
3518 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3519 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3520 *
3521 * @param itemID the ID of the item to read
3522 * @return the NV item as a String, or null on error.
3523 */
3524 @Override
3525 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003526 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3528 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529
3530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003533 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3535 return value;
3536 } finally {
3537 Binder.restoreCallingIdentity(identity);
3538 }
Jake Hambye994d462014-02-03 13:10:13 -08003539 }
3540
3541 /**
3542 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3543 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3544 *
3545 * @param itemID the ID of the item to read
3546 * @param itemValue the value to write, as a String
3547 * @return true on success; false on any failure
3548 */
3549 @Override
3550 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003551 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3553 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554
3555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3558 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003559 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3561 return success;
3562 } finally {
3563 Binder.restoreCallingIdentity(identity);
3564 }
Jake Hambye994d462014-02-03 13:10:13 -08003565 }
3566
3567 /**
3568 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3569 * Used for device configuration by some CDMA operators.
3570 *
3571 * @param preferredRoamingList byte array containing the new PRL
3572 * @return true on success; false on any failure
3573 */
3574 @Override
3575 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3577 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578
3579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3582 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3583 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3584 return success;
3585 } finally {
3586 Binder.restoreCallingIdentity(identity);
3587 }
Jake Hambye994d462014-02-03 13:10:13 -08003588 }
3589
3590 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003591 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003592 * Used for device configuration by some CDMA operators.
3593 *
chen xu6dac5ab2018-10-26 17:39:23 -07003594 * @param slotIndex - device slot.
3595 *
Jake Hambye994d462014-02-03 13:10:13 -08003596 * @return true on success; false on any failure
3597 */
3598 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003599 public boolean resetModemConfig(int slotIndex) {
3600 Phone phone = PhoneFactory.getPhone(slotIndex);
3601 if (phone != null) {
3602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3603 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604
chen xu6dac5ab2018-10-26 17:39:23 -07003605 final long identity = Binder.clearCallingIdentity();
3606 try {
3607 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3608 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3609 return success;
3610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003613 }
chen xu6dac5ab2018-10-26 17:39:23 -07003614 return false;
3615 }
3616
3617 /**
3618 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3619 *
3620 * @param slotIndex - device slot.
3621 *
3622 * @return true on success; false on any failure
3623 */
3624 @Override
3625 public boolean rebootModem(int slotIndex) {
3626 Phone phone = PhoneFactory.getPhone(slotIndex);
3627 if (phone != null) {
3628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3629 mApp, phone.getSubId(), "rebootModem");
3630
3631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3634 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3635 return success;
3636 } finally {
3637 Binder.restoreCallingIdentity(identity);
3638 }
3639 }
3640 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003641 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003642
Svet Ganovb320e182015-04-16 12:30:10 -07003643 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003645 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003646 return new String[0];
3647 }
3648
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 final long identity = Binder.clearCallingIdentity();
3650 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003651 return mPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
Wink Saville36469e72014-06-11 15:17:00 -07003655 }
3656
Brad Ebinger51f743a2017-01-23 13:50:20 -08003657 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003658 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3659 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003660 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003661 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003663
3664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 PhoneFactory.getImsResolver().enableIms(slotId);
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
3669 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003670 }
3671
3672 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003673 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3674 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003675 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003676 public void disableIms(int slotId) {
3677 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003678
3679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 PhoneFactory.getImsResolver().disableIms(slotId);
3682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003685 }
3686
3687 /**
3688 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3689 * feature or {@link null} if the service is not available. If the feature is available, the
3690 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3691 */
3692 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003693 IImsServiceFeatureCallback callback) {
3694 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003695
3696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3699 } finally {
3700 Binder.restoreCallingIdentity(identity);
3701 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003702 }
3703
3704 /**
3705 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3706 * feature during emergency calling or {@link null} if the service is not available. If the
3707 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3708 * listener for feature updates.
3709 */
3710 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712
3713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003719 }
3720
Brad Ebinger5f64b052017-12-14 14:26:15 -08003721 /**
3722 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3723 * specified.
3724 */
3725 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3726 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727
3728 final long identity = Binder.clearCallingIdentity();
3729 try {
3730 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003734 }
3735
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003736 /**
3737 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3738 * specified.
3739 */
3740 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003749 }
3750
Brad Ebinger884c07b2018-02-15 16:17:40 -08003751 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003752 * Sets the ImsService Package Name that Telephony will bind to.
3753 *
3754 * @param slotId the slot ID that the ImsService should bind for.
3755 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3756 * ImsService is the device default ImsService.
3757 * @param packageName The package name of the application that contains the ImsService to bind
3758 * to.
3759 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3760 * @hide
3761 */
3762 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003763 int[] subIds = SubscriptionManager.getSubId(slotId);
3764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3765 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3766 "setImsService");
3767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3771 isCarrierImsService, packageName);
3772 } finally {
3773 Binder.restoreCallingIdentity(identity);
3774 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003775 }
3776
3777 /**
3778 * Return the ImsService configuration.
3779 *
3780 * @param slotId The slot that the ImsService is associated with.
3781 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3782 * the device default.
3783 * @return the package name of the ImsService configuration.
3784 */
3785 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003786 int[] subIds = SubscriptionManager.getSubId(slotId);
3787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3788 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3789 "getImsService");
3790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3794 isCarrierImsService);
3795 } finally {
3796 Binder.restoreCallingIdentity(identity);
3797 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003798 }
3799
Wink Saville36469e72014-06-11 15:17:00 -07003800 public void setImsRegistrationState(boolean registered) {
3801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802
3803 final long identity = Binder.clearCallingIdentity();
3804 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003805 mPhone.setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 } finally {
3807 Binder.restoreCallingIdentity(identity);
3808 }
Wink Saville36469e72014-06-11 15:17:00 -07003809 }
3810
3811 /**
Stuart Scott54788802015-03-30 13:18:01 -07003812 * Set the network selection mode to automatic.
3813 *
3814 */
3815 @Override
3816 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3818 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819
Pengquan Menge92a50d2018-09-21 15:54:48 -07003820 if (!isActiveSubscription(subId)) {
3821 return;
3822 }
3823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3827 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
3830 }
Stuart Scott54788802015-03-30 13:18:01 -07003831 }
3832
Pengquan Mengea84e042018-09-20 14:57:26 -07003833 /**
3834 * Ask the radio to connect to the input network and change selection mode to manual.
3835 *
3836 * @param subId the id of the subscription.
3837 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3838 * the operator to attach to.
3839 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3840 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3841 * normal network selection next time.
3842 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003843 */
3844 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003845 public boolean setNetworkSelectionModeManual(
3846 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3848 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003849
3850 if (!isActiveSubscription(subId)) {
3851 return false;
3852 }
3853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 final long identity = Binder.clearCallingIdentity();
3855 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003856 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003858 if (DBG) {
3859 log("setNetworkSelectionModeManual: subId: " + subId
3860 + " operator: " + operatorInfo);
3861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003862 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3863 } finally {
3864 Binder.restoreCallingIdentity(identity);
3865 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003866 }
3867
3868 /**
3869 * Scans for available networks.
3870 */
3871 @Override
3872 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3874 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003875
Pengquan Menga1bb6272018-09-06 09:59:22 -07003876 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003877 try {
3878 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003879 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003880 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003881 } finally {
3882 Binder.restoreCallingIdentity(identity);
3883 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003884 }
3885
3886 /**
yinxub1bed742017-04-17 11:45:04 -07003887 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003888 *
yinxub1bed742017-04-17 11:45:04 -07003889 * @param subId id of the subscription
3890 * @param request contains the radio access networks with bands/channels to scan
3891 * @param messenger callback messenger for scan results or errors
3892 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003893 * @return the id of the requested scan which can be used to stop the scan.
3894 */
3895 @Override
3896 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3897 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3899 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003900
3901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 return mNetworkScanRequestTracker.startNetworkScan(
3904 request, messenger, binder, getPhone(subId));
3905 } finally {
3906 Binder.restoreCallingIdentity(identity);
3907 }
yinxu504e1392017-04-12 16:03:22 -07003908 }
3909
3910 /**
3911 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003912 *
3913 * @param subId id of the subscription
3914 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003915 */
3916 @Override
3917 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3919 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920
3921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
3926 }
yinxu504e1392017-04-12 16:03:22 -07003927 }
3928
3929 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003930 * Get the calculated preferred network type.
3931 * Used for debugging incorrect network type.
3932 *
3933 * @return the preferred network type, defined in RILConstants.java.
3934 */
3935 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003936 public int getCalculatedPreferredNetworkType(String callingPackage) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3938 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003939 return RILConstants.PREFERRED_NETWORK_MODE;
3940 }
3941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 // FIXME: need to get SubId from somewhere.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003945 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
Junda Liu84d15a22014-07-02 11:21:04 -07003949 }
3950
3951 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003952 * Get the preferred network type.
3953 * Used for device configuration by some CDMA operators.
3954 *
3955 * @return the preferred network type, defined in RILConstants.java.
3956 */
3957 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003958 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3960 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003961
3962 final long identity = Binder.clearCallingIdentity();
3963 try {
3964 if (DBG) log("getPreferredNetworkType");
3965 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3966 int networkType = (result != null ? result[0] : -1);
3967 if (DBG) log("getPreferredNetworkType: " + networkType);
3968 return networkType;
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
3971 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003972 }
3973
3974 /**
3975 * Set the preferred network type.
3976 * Used for device configuration by some CDMA operators.
3977 *
3978 * @param networkType the preferred network type, defined in RILConstants.java.
3979 * @return true on success; false on any failure.
3980 */
3981 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003982 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3984 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003985
3986 final long identity = Binder.clearCallingIdentity();
3987 try {
3988 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3989 Boolean success = (Boolean) sendRequest(
3990 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3991 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3992 if (success) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00003993 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3995 }
3996 return success;
3997 } finally {
3998 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003999 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004000 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004001
4002 /**
Junda Liu475951f2014-11-07 16:45:03 -08004003 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07004004 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004005 * tethering.
4006 *
4007 * @return 0: Not required. 1: required. 2: Not set.
4008 * @hide
4009 */
4010 @Override
4011 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004012 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013
4014 final long identity = Binder.clearCallingIdentity();
4015 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004016 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07004018 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004019 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 dunRequired = 1;
4021 }
4022 return dunRequired;
4023 } finally {
4024 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004025 }
Junda Liu475951f2014-11-07 16:45:03 -08004026 }
4027
4028 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004029 * Set mobile data enabled
4030 * Used by the user through settings etc to turn on/off mobile data
4031 *
4032 * @param enable {@code true} turn turn data on, else {@code false}
4033 */
4034 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004035 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4037 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004038
4039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 int phoneId = mSubscriptionController.getPhoneId(subId);
4042 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4043 Phone phone = PhoneFactory.getPhone(phoneId);
4044 if (phone != null) {
4045 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4046 phone.setUserDataEnabled(enable);
4047 } else {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004048 loge("setUserDataEnabled: no phone for subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 }
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004052 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004053 }
4054
4055 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004056 * Get the user enabled state of Mobile Data.
4057 *
4058 * TODO: remove and use isUserDataEnabled.
4059 * This can't be removed now because some vendor codes
4060 * calls through ITelephony directly while they should
4061 * use TelephonyManager.
4062 *
4063 * @return true on enabled
4064 */
4065 @Override
4066 public boolean getDataEnabled(int subId) {
4067 return isUserDataEnabled(subId);
4068 }
4069
4070 /**
4071 * Get whether mobile data is enabled per user setting.
4072 *
4073 * There are other factors deciding whether mobile data is actually enabled, but they are
4074 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004075 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004076 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004077 *
4078 * @return {@code true} if data is enabled else {@code false}
4079 */
4080 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004081 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004082 try {
4083 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4084 null);
4085 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4087 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004088 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089
4090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 int phoneId = mSubscriptionController.getPhoneId(subId);
4093 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4094 Phone phone = PhoneFactory.getPhone(phoneId);
4095 if (phone != null) {
4096 boolean retVal = phone.isUserDataEnabled();
4097 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4098 return retVal;
4099 } else {
4100 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4101 return false;
4102 }
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004105 }
4106 }
4107
4108 /**
4109 * Get whether mobile data is enabled.
4110 *
4111 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4112 * whether mobile data is actually enabled.
4113 *
4114 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4115 *
4116 * @return {@code true} if data is enabled else {@code false}
4117 */
4118 @Override
4119 public boolean isDataEnabled(int subId) {
4120 try {
4121 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4122 null);
4123 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4125 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127
4128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 int phoneId = mSubscriptionController.getPhoneId(subId);
4131 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4132 Phone phone = PhoneFactory.getPhone(phoneId);
4133 if (phone != null) {
4134 boolean retVal = phone.isDataEnabled();
4135 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4136 return retVal;
4137 } else {
4138 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4139 return false;
4140 }
4141 } finally {
4142 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004143 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004144 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004145
4146 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004147 public int getCarrierPrivilegeStatus(int subId) {
4148 final Phone phone = getPhone(subId);
4149 if (phone == null) {
4150 loge("getCarrierPrivilegeStatus: Invalid subId");
4151 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4152 }
4153 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004154 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004155 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004156 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4157 }
4158 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004159 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004160 }
Junda Liu29340342014-07-10 15:23:27 -07004161
4162 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004163 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4164 final Phone phone = getPhone(subId);
4165 if (phone == null) {
4166 loge("getCarrierPrivilegeStatus: Invalid subId");
4167 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4168 }
4169 UiccProfile profile =
4170 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4171 if (profile == null) {
4172 loge("getCarrierPrivilegeStatus: No UICC");
4173 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4174 }
4175 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4176 }
4177
4178 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004179 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004180 if (TextUtils.isEmpty(pkgName))
4181 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004182 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004183 if (card == null) {
4184 loge("checkCarrierPrivilegesForPackage: No UICC");
4185 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4186 }
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004187 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004188 }
4189
4190 @Override
4191 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004192 if (TextUtils.isEmpty(pkgName))
4193 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004194 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4195 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4196 UiccCard card = UiccController.getInstance().getUiccCard(i);
4197 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004198 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004199 continue;
4200 }
4201
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004202 result = card.getCarrierPrivilegeStatus(
4203 mPhone.getContext().getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004204 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4205 break;
4206 }
4207 }
4208
4209 return result;
Junda Liu29340342014-07-10 15:23:27 -07004210 }
Derek Tan89e89d42014-07-08 17:00:10 -07004211
4212 @Override
Junda Liue64de782015-04-16 17:19:16 -07004213 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4214 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4215 loge("phoneId " + phoneId + " is not valid.");
4216 return null;
4217 }
4218 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004219 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004220 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004221 return null ;
4222 }
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004223 return card.getCarrierPackageNamesForIntent(
4224 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004225 }
4226
Amith Yamasani6e118872016-02-19 12:53:51 -08004227 @Override
4228 public List<String> getPackagesWithCarrierPrivileges() {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004229 PackageManager pm = mPhone.getContext().getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004230 List<String> privilegedPackages = new ArrayList<>();
4231 List<PackageInfo> packages = null;
4232 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4233 UiccCard card = UiccController.getInstance().getUiccCard(i);
4234 if (card == null) {
4235 // No UICC in that slot.
4236 continue;
4237 }
4238 if (card.hasCarrierPrivilegeRules()) {
4239 if (packages == null) {
4240 // Only check packages in user 0 for now
4241 packages = pm.getInstalledPackagesAsUser(
4242 PackageManager.MATCH_DISABLED_COMPONENTS
4243 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4244 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4245 }
4246 for (int p = packages.size() - 1; p >= 0; p--) {
4247 PackageInfo pkgInfo = packages.get(p);
4248 if (pkgInfo != null && pkgInfo.packageName != null
4249 && card.getCarrierPrivilegeStatus(pkgInfo)
4250 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4251 privilegedPackages.add(pkgInfo.packageName);
4252 }
4253 }
4254 }
4255 }
4256 return privilegedPackages;
4257 }
4258
Wink Savilleb564aae2014-10-23 10:18:09 -07004259 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004260 final Phone phone = getPhone(subId);
4261 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004262 if (card == null) {
4263 loge("getIccId: No UICC");
4264 return null;
4265 }
4266 String iccId = card.getIccId();
4267 if (TextUtils.isEmpty(iccId)) {
4268 loge("getIccId: ICC ID is null or empty.");
4269 return null;
4270 }
4271 return iccId;
4272 }
4273
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004274 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004275 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4276 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004277 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4278 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280 final long identity = Binder.clearCallingIdentity();
4281 try {
4282 final String iccId = getIccId(subId);
4283 final Phone phone = getPhone(subId);
4284 if (phone == null) {
4285 return false;
4286 }
4287 final String subscriberId = phone.getSubscriberId();
4288
4289 if (DBG_MERGE) {
4290 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4291 + subscriberId + " to " + number);
4292 }
4293
4294 if (TextUtils.isEmpty(iccId)) {
4295 return false;
4296 }
4297
4298 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4299
4300 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4301 if (alphaTag == null) {
4302 editor.remove(alphaTagPrefKey);
4303 } else {
4304 editor.putString(alphaTagPrefKey, alphaTag);
4305 }
4306
4307 // Record both the line number and IMSI for this ICCID, since we need to
4308 // track all merged IMSIs based on line number
4309 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4310 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4311 if (number == null) {
4312 editor.remove(numberPrefKey);
4313 editor.remove(subscriberPrefKey);
4314 } else {
4315 editor.putString(numberPrefKey, number);
4316 editor.putString(subscriberPrefKey, subscriberId);
4317 }
4318
4319 editor.commit();
4320 return true;
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004323 }
Derek Tan7226c842014-07-02 17:42:23 -07004324 }
4325
4326 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004327 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004328 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004330 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004331 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004332 return null;
4333 }
Derek Tan97ebb422014-09-05 16:55:38 -07004334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335 final long identity = Binder.clearCallingIdentity();
4336 try {
4337 String iccId = getIccId(subId);
4338 if (iccId != null) {
4339 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4340 if (DBG_MERGE) {
4341 log("getLine1NumberForDisplay returning "
4342 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4343 }
4344 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4347 return null;
4348 } finally {
4349 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004350 }
Derek Tan7226c842014-07-02 17:42:23 -07004351 }
4352
4353 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004354 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004356 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004357 return null;
4358 }
Derek Tan97ebb422014-09-05 16:55:38 -07004359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004360 final long identity = Binder.clearCallingIdentity();
4361 try {
4362 String iccId = getIccId(subId);
4363 if (iccId != null) {
4364 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4365 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4366 }
4367 return null;
4368 } finally {
4369 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004370 }
Derek Tan7226c842014-07-02 17:42:23 -07004371 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004372
4373 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004374 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004375 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4376 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004378 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4379 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004380 return null;
4381 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004382
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004383 final long identity = Binder.clearCallingIdentity();
4384 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004385 final Context context = mPhone.getContext();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386 final TelephonyManager tele = TelephonyManager.from(context);
4387 final SubscriptionManager sub = SubscriptionManager.from(context);
4388
4389 // Figure out what subscribers are currently active
4390 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4391 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4392 // the process, where TelephonyManager was instantiated.
4393 // Otherwise AppOps check will fail.
4394
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004395 final int[] subIds = sub.getActiveSubscriptionIdList();
4396 for (int subId : subIds) {
4397 activeSubscriberIds.add(tele.getSubscriberId(subId));
4398 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004399
4400 // First pass, find a number override for an active subscriber
4401 String mergeNumber = null;
4402 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4403 for (String key : prefs.keySet()) {
4404 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4405 final String subscriberId = (String) prefs.get(key);
4406 if (activeSubscriberIds.contains(subscriberId)) {
4407 final String iccId = key.substring(
4408 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4409 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4410 mergeNumber = (String) prefs.get(numberKey);
4411 if (DBG_MERGE) {
4412 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4413 + " for active subscriber " + subscriberId);
4414 }
4415 if (!TextUtils.isEmpty(mergeNumber)) {
4416 break;
4417 }
4418 }
4419 }
4420 }
4421
4422 // Shortcut when no active merged subscribers
4423 if (TextUtils.isEmpty(mergeNumber)) {
4424 return null;
4425 }
4426
4427 // Second pass, find all subscribers under that line override
4428 final ArraySet<String> result = new ArraySet<>();
4429 for (String key : prefs.keySet()) {
4430 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4431 final String number = (String) prefs.get(key);
4432 if (mergeNumber.equals(number)) {
4433 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4434 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4435 final String subscriberId = (String) prefs.get(subscriberKey);
4436 if (!TextUtils.isEmpty(subscriberId)) {
4437 result.add(subscriberId);
4438 }
4439 }
4440 }
4441 }
4442
4443 final String[] resultArray = result.toArray(new String[result.size()]);
4444 Arrays.sort(resultArray);
4445 if (DBG_MERGE) {
4446 Slog.d(LOG_TAG,
4447 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4448 }
4449 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004452 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004453 }
4454
4455 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004456 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004457 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4458 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004459
4460 final long identity = Binder.clearCallingIdentity();
4461 try {
4462 final Phone phone = getPhone(subId);
4463 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004467 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004468
4469 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004470 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004471 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4472 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004473 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 final Phone phone = getPhone(subId);
4478 if (phone == null) {
4479 return false;
4480 }
4481 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4482 cdmaNonRoamingList);
4483 } finally {
4484 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004485 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004486 }
4487
4488 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004489 @Deprecated
4490 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4491 enforceModifyPermission();
4492
4493 int returnValue = 0;
4494 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004495 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004496 if(result.exception == null) {
4497 if (result.result != null) {
4498 byte[] responseData = (byte[])(result.result);
4499 if(responseData.length > oemResp.length) {
4500 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4501 responseData.length + "bytes. Buffer Size is " +
4502 oemResp.length + "bytes.");
4503 }
4504 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4505 returnValue = responseData.length;
4506 }
4507 } else {
4508 CommandException ex = (CommandException) result.exception;
4509 returnValue = ex.getCommandError().ordinal();
4510 if(returnValue > 0) returnValue *= -1;
4511 }
4512 } catch (RuntimeException e) {
4513 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4514 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4515 if(returnValue > 0) returnValue *= -1;
4516 }
4517
4518 return returnValue;
4519 }
4520
4521 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004522 public void setRadioCapability(RadioAccessFamily[] rafs) {
4523 try {
4524 ProxyController.getInstance().setRadioCapability(rafs);
4525 } catch (RuntimeException e) {
4526 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4527 }
4528 }
4529
4530 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004531 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004532 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004533 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004534 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004535 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537 final long identity = Binder.clearCallingIdentity();
4538 try {
chen xub97461a2018-10-26 14:17:57 -07004539 TelephonyPermissions
4540 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4541 mApp, phone.getSubId(), "getRadioAccessFamily");
4542 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
chen xub97461a2018-10-26 14:17:57 -07004546 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004547 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004548
4549 @Override
4550 public void enableVideoCalling(boolean enable) {
4551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004552
4553 final long identity = Binder.clearCallingIdentity();
4554 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004555 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 } finally {
4557 Binder.restoreCallingIdentity(identity);
4558 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004559 }
4560
4561 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004562 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004564 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004565 return false;
4566 }
Svet Ganovb320e182015-04-16 12:30:10 -07004567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 final long identity = Binder.clearCallingIdentity();
4569 try {
4570 // Check the user preference and the system-level IMS setting. Even if the user has
4571 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4572 // In the long run, we may instead need to check if there exists a connection service
4573 // which can support video calling.
4574 ImsManager imsManager =
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004575 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 return imsManager.isVtEnabledByPlatform()
4577 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4578 && imsManager.isVtEnabledByUser();
4579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004582 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004583
Andrew Leea1239f22015-03-02 17:44:07 -08004584 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4587 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4588 return false;
4589 }
4590
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 CarrierConfigManager configManager =
4594 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004595 return configManager.getConfigForSubId(mPhone.getSubId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
Andrew Leea1239f22015-03-02 17:44:07 -08004600 }
4601
4602 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603 public boolean isWorldPhone(int subId, String callingPackage) {
4604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4605 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4606 return false;
4607 }
4608
4609 final long identity = Binder.clearCallingIdentity();
4610 try {
4611 CarrierConfigManager configManager =
4612 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004613 return configManager.getConfigForSubId(mPhone.getSubId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
Andrew Leea1239f22015-03-02 17:44:07 -08004618 }
4619
Andrew Lee9431b832015-03-09 18:46:45 -07004620 @Override
4621 public boolean isTtyModeSupported() {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004622 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004623 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004624 }
4625
4626 @Override
4627 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 final long identity = Binder.clearCallingIdentity();
4629 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004630 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 } finally {
4632 Binder.restoreCallingIdentity(identity);
4633 }
Andrew Lee9431b832015-03-09 18:46:45 -07004634 }
4635
Hall Liuf6668912018-10-31 17:05:23 -07004636 /**
4637 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4638 * support for the feature and device firmware support.
4639 *
4640 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4641 */
4642 @Override
4643 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644 final long identity = Binder.clearCallingIdentity();
4645 try {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004646 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4647 mPhone.getSubId()).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4649 boolean isDeviceSupported =
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004650 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 return isCarrierSupported && isDeviceSupported;
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Hall Liu98187582018-01-22 19:15:32 -08004655 }
4656
Hall Liuf6668912018-10-31 17:05:23 -07004657 /**
4658 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4659 * both also support RTT.
4660 */
4661 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 final long identity = Binder.clearCallingIdentity();
4663 try {
Hall Liuf6668912018-10-31 17:05:23 -07004664 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004665 mPhone.getContext().getContentResolver(),
4666 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667 } finally {
4668 Binder.restoreCallingIdentity(identity);
4669 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004670 }
4671
Sanket Padawe7310cc72015-01-14 09:53:20 -08004672 /**
4673 * Returns the unique device ID of phone, for example, the IMEI for
4674 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4675 *
4676 * <p>Requires Permission:
4677 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4678 */
4679 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004680 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004681 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004682 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004683 return null;
4684 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004685 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004686 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4687 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004688 return null;
4689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690
4691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 return phone.getDeviceId();
4694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004697 }
4698
Ping Sunc67b7c22016-03-02 19:16:45 +08004699 /**
4700 * {@hide}
4701 * Returns the IMS Registration Status on a particular subid
4702 *
4703 * @param subId
4704 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004705 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004706 Phone phone = getPhone(subId);
4707 if (phone != null) {
4708 return phone.isImsRegistered();
4709 } else {
4710 return false;
4711 }
4712 }
4713
Santos Cordon7a1885b2015-02-03 11:15:19 -08004714 @Override
4715 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004716 final long identity = Binder.clearCallingIdentity();
4717 try {
4718 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4719 } finally {
4720 Binder.restoreCallingIdentity(identity);
4721 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004722 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004723
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004724 /**
4725 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004726 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004727 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 final long identity = Binder.clearCallingIdentity();
4729 try {
4730 Phone phone = getPhone(subId);
4731 if (phone != null) {
4732 return phone.isWifiCallingEnabled();
4733 } else {
4734 return false;
4735 }
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004738 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004739 }
4740
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004741 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004742 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004743 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004744 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 final long identity = Binder.clearCallingIdentity();
4746 try {
4747 Phone phone = getPhone(subId);
4748 if (phone != null) {
4749 return phone.isVideoEnabled();
4750 } else {
4751 return false;
4752 }
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004755 }
4756 }
4757
4758 /**
4759 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4760 * defined in {@link ImsRegistrationImplBase}.
4761 */
4762 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 final long identity = Binder.clearCallingIdentity();
4764 try {
4765 Phone phone = getPhone(subId);
4766 if (phone != null) {
4767 return phone.getImsRegistrationTech();
4768 } else {
4769 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4770 }
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004773 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004774 }
4775
Stuart Scott8eef64f2015-04-08 15:13:54 -07004776 @Override
4777 public void factoryReset(int subId) {
4778 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004779 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4780 return;
4781 }
4782
Svet Ganovcc087f82015-05-12 20:35:54 -07004783 final long identity = Binder.clearCallingIdentity();
4784 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004785 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4786 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004787 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004788 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004789 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004790 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
4791 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004792 }
4793 } finally {
4794 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004795 }
4796 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004797
4798 @Override
4799 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800 final long identity = Binder.clearCallingIdentity();
4801 try {
4802 // We query all subscriptions instead of just the active ones, because
4803 // this might be called early on in the provisioning flow when the
4804 // subscriptions potentially aren't active yet.
4805 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4806 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004807 return null;
4808 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 // This function may be called very early, say, from the setup wizard, at
4811 // which point we won't have a default subscription set. If that's the case
4812 // we just choose the first, which will be valid in "most cases".
4813 final int defaultSubId = getDefaultSubscription();
4814 SubscriptionInfo info = null;
4815 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4816 info = slist.get(0);
4817 } else {
4818 for (SubscriptionInfo item : slist) {
4819 if (item.getSubscriptionId() == defaultSubId) {
4820 info = item;
4821 break;
4822 }
4823 }
4824
4825 if (info == null) {
4826 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004827 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004828 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830 // Try and fetch the locale from the carrier properties or from the SIM language
4831 // preferences (EF-PL and EF-LI)...
4832 final int mcc = info.getMcc();
4833 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4834 String simLanguage = null;
4835 if (defaultPhone != null) {
4836 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4837 if (localeFromDefaultSim != null) {
4838 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4839 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4840 return localeFromDefaultSim.toLanguageTag();
4841 } else {
4842 simLanguage = localeFromDefaultSim.getLanguage();
4843 }
4844 }
4845 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 // The SIM language preferences only store a language (e.g. fr = French), not an
4848 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4849 // the SIM and carrier preferences does not include a country we add the country
4850 // determined from the SIM MCC to provide an exact locale.
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004851 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4852 simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 if (mccLocale != null) {
4854 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4855 return mccLocale.toLanguageTag();
4856 }
4857
4858 if (DBG) log("No locale found - returning null");
4859 return null;
4860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004863 }
4864
4865 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004866 return mSubscriptionController.getAllSubInfoList(
4867 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004868 }
4869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 /**
4871 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4872 */
4873 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004874 return mSubscriptionController.getActiveSubscriptionInfoList(
4875 mPhone.getContext().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++) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004904 mergedTxTimeMs[i] =
4905 info.getTxTimeMillis()[i]
4906 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 }
4908 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004909 mLastModemActivityInfo.setSleepTimeMillis(
4910 info.getSleepTimeMillis()
4911 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 mLastModemActivityInfo.setIdleTimeMillis(
4913 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4914 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4915 mLastModemActivityInfo.setRxTimeMillis(
4916 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4917 mLastModemActivityInfo.setEnergyUsed(
4918 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004920 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4921 mLastModemActivityInfo.getSleepTimeMillis(),
4922 mLastModemActivityInfo.getIdleTimeMillis(),
4923 mLastModemActivityInfo.getTxTimeMillis(),
4924 mLastModemActivityInfo.getRxTimeMillis(),
4925 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 Bundle bundle = new Bundle();
4928 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4929 result.send(0, bundle);
4930 } finally {
4931 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004932 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004933 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004934
Siddharth Rayb8114062018-06-17 15:02:38 -07004935 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4936 // less than total activity duration.
4937 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4938 if (info == null) {
4939 return false;
4940 }
4941 int activityDurationMs =
4942 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4943 int totalTxTimeMs = 0;
4944 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4945 totalTxTimeMs += info.getTxTimeMillis()[i];
4946 }
4947 return (info.isValid()
4948 && (info.getSleepTimeMillis() <= activityDurationMs)
4949 && (info.getIdleTimeMillis() <= activityDurationMs)
4950 && (info.getRxTimeMillis() <= activityDurationMs)
4951 && (totalTxTimeMs <= activityDurationMs));
4952 }
4953
Jack Yu85bd38a2015-11-09 11:34:32 -08004954 /**
4955 * {@hide}
4956 * Returns the service state information on specified subscription.
4957 */
4958 @Override
4959 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004961 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004962 return null;
4963 }
4964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965 final long identity = Binder.clearCallingIdentity();
4966 try {
4967 final Phone phone = getPhone(subId);
4968 if (phone == null) {
4969 return null;
4970 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 return phone.getServiceState();
4973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004976 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004977
4978 /**
4979 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4980 *
4981 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4982 * voicemail ringtone.
4983 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4984 * PhoneAccount.
4985 */
4986 @Override
4987 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4991 if (phone == null) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00004992 phone = mPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004999 }
5000
5001 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005002 * Sets the per-account voicemail ringtone.
5003 *
5004 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5005 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5006 *
5007 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5008 * voicemail ringtone.
5009 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5010 * PhoneAccount.
5011 */
5012 @Override
5013 public void setVoicemailRingtoneUri(String callingPackage,
5014 PhoneAccountHandle phoneAccountHandle, Uri uri) {
5015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5016 if (!TextUtils.equals(callingPackage,
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005017 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5019 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5020 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022
5023 final long identity = Binder.clearCallingIdentity();
5024 try {
5025 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5026 if (phone == null) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005027 phone = mPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 }
5029 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005032 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005033 }
5034
5035 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005036 * Returns whether vibration is set for voicemail notification in Phone settings.
5037 *
5038 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5039 * voicemail vibration setting.
5040 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5041 */
5042 @Override
5043 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5047 if (phone == null) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005048 phone = mPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
5054 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005055 }
5056
Youhan Wange64578a2016-05-02 15:32:42 -07005057 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005058 * Sets the per-account voicemail vibration.
5059 *
5060 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5061 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5062 *
5063 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5064 * voicemail vibration setting.
5065 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5066 * specific PhoneAccount.
5067 */
5068 @Override
5069 public void setVoicemailVibrationEnabled(String callingPackage,
5070 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5071 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5072 if (!TextUtils.equals(callingPackage,
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005073 TelecomManager.from(mPhone.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) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005083 phone = mPhone;
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 =
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005120 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), 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) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005373 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5374 != 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 }
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005382 DumpsysHandler.dump(mPhone.getContext(), 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) {
5433 phone.setPolicyDataEnabled(enabled);
5434 }
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) {
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005466 String packageName = mPhone.getContext().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 =
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005499 (CarrierConfigManager) mPhone.getContext().getSystemService(
5500 Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005501 if (configManager == null) {
5502 return false;
5503 }
5504 PersistableBundle pb = configManager.getConfigForSubId(subId);
5505 if (pb == null) {
5506 return false;
5507 }
5508 return pb.getBoolean(
5509 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5510 }
5511
Shuo Qiandd210312017-04-12 22:11:33 +00005512 /**
5513 * Check if phone is in emergency callback mode
5514 * @return true if phone is in emergency callback mode
5515 * @param subId sub id
5516 */
goneil9c5f4872017-12-05 14:07:56 -08005517 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005518 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005519 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005520 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521
5522 final long identity = Binder.clearCallingIdentity();
5523 try {
5524 if (phone != null) {
5525 return phone.isInEcm();
5526 } else {
5527 return false;
5528 }
5529 } finally {
5530 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005531 }
5532 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005533
5534 /**
5535 * Get the current signal strength information for the given subscription.
5536 * Because this information is not updated when the device is in a low power state
5537 * it should not be relied-upon to be current.
5538 * @param subId Subscription index
5539 * @return the most recent cached signal strength info from the modem
5540 */
5541 @Override
5542 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 final long identity = Binder.clearCallingIdentity();
5544 try {
5545 Phone p = getPhone(subId);
5546 if (p == null) {
5547 return null;
5548 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 return p.getSignalStrength();
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005554 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005555
Pengquan Meng77b7f132018-08-22 14:49:57 -07005556 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005557 * Get the current modem radio state for the given slot.
5558 * @param slotIndex slot index.
5559 * @param callingPackage the name of the package making the call.
5560 * @return the current radio power state from the modem
5561 */
5562 @Override
5563 public int getRadioPowerState(int slotIndex, String callingPackage) {
5564 Phone phone = PhoneFactory.getPhone(slotIndex);
5565 if (phone != null) {
5566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5567 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5568 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5569 }
5570
5571 final long identity = Binder.clearCallingIdentity();
5572 try {
5573 return phone.getRadioPowerState();
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
5577 }
5578 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5579 }
5580
5581 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005582 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5583 *
5584 * <p>Requires one of the following permissions:
5585 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5586 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5587 * privileges.
5588 *
5589 * @param subId subscription id
5590 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5591 * {@code false}.
5592 */
5593 @Override
5594 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005595 boolean isEnabled = false;
5596 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005597 try {
5598 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005599 null /* message */);
5600 Phone phone = getPhone(subId);
5601 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005602 } catch (Exception e) {
5603 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5604 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005605 } finally {
5606 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005607 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005608 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005609 }
5610
5611
5612 /**
5613 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5614 *
5615 * <p> Requires permission:
5616 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5617 * privileges.
5618 *
5619 * @param subId subscription id
5620 * @param isEnabled {@code true} means enable, {@code false} means disable.
5621 */
5622 @Override
5623 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005624 final long identity = Binder.clearCallingIdentity();
5625 try {
5626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5627 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005628
Pengquan Menga1bb6272018-09-06 09:59:22 -07005629 Phone phone = getPhone(subId);
5630 if (phone != null) {
5631 phone.setDataRoamingEnabled(isEnabled);
5632 }
5633 } finally {
5634 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005635 }
5636 }
5637
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005638 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005639 public boolean isManualNetworkSelectionAllowed(int subId) {
5640 boolean isAllowed = true;
5641 final long identity = Binder.clearCallingIdentity();
5642 try {
5643 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5644 mApp, subId, "isManualNetworkSelectionAllowed");
5645 Phone phone = getPhone(subId);
5646 if (phone != null) {
5647 isAllowed = phone.isCspPlmnEnabled();
5648 }
5649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
5652 return isAllowed;
5653 }
5654
5655 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005656 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005657 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5662 if (slots == null) {
5663 Rlog.i(LOG_TAG, "slots is null.");
5664 return null;
5665 }
5666
5667 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5668 for (int i = 0; i < slots.length; i++) {
5669 UiccSlot slot = slots[i];
5670 if (slot == null) {
5671 continue;
5672 }
5673
5674 String cardId;
5675 UiccCard card = slot.getUiccCard();
5676 if (card != null) {
5677 cardId = card.getCardId();
5678 } else {
5679 cardId = slot.getIccId();
5680 }
5681
5682 int cardState = 0;
5683 switch (slot.getCardState()) {
5684 case CARDSTATE_ABSENT:
5685 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5686 break;
5687 case CARDSTATE_PRESENT:
5688 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5689 break;
5690 case CARDSTATE_ERROR:
5691 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5692 break;
5693 case CARDSTATE_RESTRICTED:
5694 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5695 break;
5696 default:
5697 break;
5698
5699 }
5700
5701 infos[i] = new UiccSlotInfo(
5702 slot.isActive(),
5703 slot.isEuicc(),
5704 cardId,
5705 cardState,
5706 slot.getPhoneId(),
5707 slot.isExtendedApduSupported());
5708 }
5709 return infos;
5710 } finally {
5711 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005712 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005713 }
5714
5715 @Override
5716 public boolean switchSlots(int[] physicalSlots) {
5717 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718
5719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005725 }
Jack Yu4c988042018-02-27 15:30:01 -08005726
5727 @Override
5728 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5729 enforceModifyPermission();
5730 final Phone phone = getPhone(subId);
5731 if (phone == null) {
5732 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5733 return;
5734 }
5735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 phone.setRadioIndicationUpdateMode(filters, mode);
5739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
Jack Yu4c988042018-02-27 15:30:01 -08005742 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005743
5744 /**
goneil47ffb6e2018-04-06 15:40:58 -07005745 * A test API to reload the UICC profile.
5746 *
5747 * <p>Requires that the calling app has permission
5748 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5749 * @hide
5750 */
5751 @Override
5752 public void refreshUiccProfile(int subId) {
5753 enforceModifyPermission();
5754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 Phone phone = getPhone(subId);
5758 if (phone == null) {
5759 return;
5760 }
5761 UiccCard uiccCard = phone.getUiccCard();
5762 if (uiccCard == null) {
5763 return;
5764 }
5765 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5766 if (uiccProfile == null) {
5767 return;
5768 }
5769 uiccProfile.refresh();
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
5773 }
5774
5775 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005776 * Returns false if the mobile data is disabled by default, otherwise return true.
5777 */
5778 private boolean getDefaultDataEnabled() {
5779 return "true".equalsIgnoreCase(
5780 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5781 }
5782
5783 /**
5784 * Returns true if the data roaming is enabled by default, i.e the system property
5785 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5786 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5787 */
5788 private boolean getDefaultDataRoamingEnabled(int subId) {
5789 final CarrierConfigManager configMgr = (CarrierConfigManager)
Tobias Thiererb19e1f12018-12-11 17:54:03 +00005790 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005791 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5792 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5793 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5794 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5795 return isDataRoamingEnabled;
5796 }
5797
5798 /**
5799 * Returns the default network type for the given {@code subId}, if the default network type is
5800 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5801 */
5802 private int getDefaultNetworkType(int subId) {
5803 return Integer.parseInt(
5804 TelephonyManager.getTelephonyProperty(
5805 mSubscriptionController.getPhoneId(subId),
5806 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5807 String.valueOf(Phone.PREFERRED_NT_MODE)));
5808 }
fionaxua13278b2018-03-21 00:08:13 -07005809
5810 @Override
5811 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5812 gid1, String gid2, String plmn, String spn) {
5813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814
5815 final long identity = Binder.clearCallingIdentity();
5816 try {
5817 final Phone phone = getPhone(subId);
5818 if (phone == null) {
5819 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5820 return;
5821 }
5822 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005825 }
fionaxua13278b2018-03-21 00:08:13 -07005826 }
5827
5828 @Override
5829 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005830 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831
5832 final long identity = Binder.clearCallingIdentity();
5833 try {
5834 final Phone phone = getPhone(subId);
5835 if (phone == null) {
5836 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5837 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5838 }
5839 return phone.getCarrierIdListVersion();
5840 } finally {
5841 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005842 }
fionaxua13278b2018-03-21 00:08:13 -07005843 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005844
5845 @Override
5846 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5847 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5848 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5849 return -1;
5850 }
5851
5852 final long identity = Binder.clearCallingIdentity();
5853 try {
5854 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
5857 }
5858 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005859
5860 @Override
5861 public int getCdmaRoamingMode(int subId) {
5862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5863 mApp, subId, "getCdmaRoamingMode");
5864
5865 final long identity = Binder.clearCallingIdentity();
5866 try {
5867 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
5871 }
5872
5873 @Override
5874 public boolean setCdmaRoamingMode(int subId, int mode) {
5875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5876 mApp, subId, "setCdmaRoamingMode");
5877
5878 final long identity = Binder.clearCallingIdentity();
5879 try {
5880 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
5884 }
5885
5886 @Override
5887 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5889 mApp, subId, "setCdmaSubscriptionMode");
5890
5891 final long identity = Binder.clearCallingIdentity();
5892 try {
5893 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
5897 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005898
5899 private void ensureUserRunning(int userId) {
5900 if (!mUserManager.isUserRunning(userId)) {
5901 throw new IllegalStateException("User " + userId + " does not exist or not running");
5902 }
5903 }
5904
5905 /**
5906 * Returns a list of SMS apps on a given user.
5907 *
5908 * Only the shell user (UID 2000 or 0) can call it.
5909 * Target user must be running.
5910 */
5911 @Override
5912 public String[] getSmsApps(int userId) {
5913 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5914 ensureUserRunning(userId);
5915
5916 final Collection<SmsApplicationData> apps =
5917 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5918
5919 String[] ret = new String[apps.size()];
5920 int i = 0;
5921 for (SmsApplicationData app : apps) {
5922 ret[i++] = app.mPackageName;
5923 }
5924 return ret;
5925 }
5926
5927 /**
5928 * Returns the default SMS app package name on a given user.
5929 *
5930 * Only the shell user (UID 2000 or 0) can call it.
5931 * Target user must be running.
5932 */
5933 @Override
5934 public String getDefaultSmsApp(int userId) {
5935 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5936 ensureUserRunning(userId);
5937
5938 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5939 /* updateIfNeeded= */ true, userId);
5940 return cn == null ? null : cn.getPackageName();
5941 }
5942
5943 /**
5944 * Set a package as the default SMS app on a given user.
5945 *
5946 * Only the shell user (UID 2000 or 0) can call it.
5947 * Target user must be running.
5948 */
5949 @Override
5950 public void setDefaultSmsApp(int userId, String packageName) {
5951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5952 ensureUserRunning(userId);
5953
5954 boolean found = false;
5955 for (String pkg : getSmsApps(userId)) {
5956 if (TextUtils.equals(packageName, pkg)) {
5957 found = true;
5958 break;
5959 }
5960 }
5961 if (!found) {
5962 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5963 }
5964
5965 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5966 }
sqianc5eccab2018-10-19 18:46:41 -07005967
5968 @Override
5969 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5970 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08005971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5972 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
5973 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5974 }
5975 final long identity = Binder.clearCallingIdentity();
5976 try {
5977 Map<Integer, List<EmergencyNumber>> results = getEmergencyNumberListInternal();
5978 // Use ecclist to construct Emergency number list for backward compatibality
5979 if (results.isEmpty()) {
5980 results = getEmergencyNumberListFromEccList();
5981 }
5982 return results;
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
sqianc5eccab2018-10-19 18:46:41 -07005986 }
5987
5988 @Override
sqian11b7a0e2018-12-05 18:48:28 -08005989 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
5990 if (!exactMatch) {
5991 TelephonyPermissions
5992 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5993 mApp, mPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
5994 }
5995 final long identity = Binder.clearCallingIdentity();
5996 try {
5997 Map<Integer, List<EmergencyNumber>> emergencyNumberLists =
5998 getEmergencyNumberListInternal();
5999
6000 String defaultCountryIso = getNetworkCountryIsoForPhone(mPhone.getPhoneId());
6001
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) {
6053 SubscriptionManager sm = (SubscriptionManager) mPhone.getContext().getSystemService(
6054 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<>();
6092 SubscriptionManager sm = (SubscriptionManager) mPhone.getContext().getSystemService(
6093 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}