blob: 2f3dd4673f6062aaaf93680bb4f2409d20749671 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
38import android.os.Bundle;
39import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Looper;
42import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070044import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080045import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070046import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070048import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070049import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070051import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070052import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070053import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080054import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070055import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070061import android.telephony.CellInfoGsm;
62import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070063import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070064import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070065import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070066import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080067import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070068import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080069import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070070import android.telephony.NetworkScanRequest;
Hall Liud892bec2018-11-30 14:51:45 -080071import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070072import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080075import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070076import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080077import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070079import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000081import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070082import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070083import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070084import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080085import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080086import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070087import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070088import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080089import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070090import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080091import android.telephony.ims.aidl.IImsMmTelFeature;
92import android.telephony.ims.aidl.IImsRcsFeature;
93import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070094import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080095import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080099import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800101
Brad Ebinger4c460712018-10-01 10:40:55 -0700102import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700103import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800104import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700105import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700106import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700107import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800108import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700109import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700110import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import com.android.internal.telephony.DefaultPhoneNotifier;
Hall Liud892bec2018-11-30 14:51:45 -0800112import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800114import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700115import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100116import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700117import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700118import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700120import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800121import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700122import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700123import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700124import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700125import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700126import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700127import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800128import com.android.internal.telephony.SmsApplication;
129import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800130import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800131import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700132import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700133import com.android.internal.telephony.uicc.IccIoResult;
134import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800135import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700136import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800137import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700138import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800139import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000140import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700141import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800142import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700143import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800144import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700145import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700146import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800147
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700148import java.io.FileDescriptor;
149import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800150import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800152import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800153import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800154import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100155import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800156import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157
158/**
159 * Implementation of the ITelephony interface.
160 */
Santos Cordon117fee72014-05-16 17:56:12 -0700161public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162 private static final String LOG_TAG = "PhoneInterfaceManager";
163 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
164 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800165 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166
167 // Message codes used with mMainThreadHandler
168 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700169 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
170 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700171 private static final int CMD_OPEN_CHANNEL = 9;
172 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
173 private static final int CMD_CLOSE_CHANNEL = 11;
174 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800175 private static final int CMD_NV_READ_ITEM = 13;
176 private static final int EVENT_NV_READ_ITEM_DONE = 14;
177 private static final int CMD_NV_WRITE_ITEM = 15;
178 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
179 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
180 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700181 private static final int CMD_RESET_MODEM_CONFIG = 19;
182 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800183 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
184 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
185 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
186 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800187 private static final int CMD_SEND_ENVELOPE = 25;
188 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000189 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
190 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700191 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
192 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
193 private static final int CMD_EXCHANGE_SIM_IO = 31;
194 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800195 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
196 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700197 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
198 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700199 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
200 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700201 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
202 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
203 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
204 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700205 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
206 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
207 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
208 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700209 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800210 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
211 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000212 private static final int CMD_SWITCH_SLOTS = 50;
213 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700214 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
215 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
216 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
217 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
218 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
219 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
220 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
221 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700222 private static final int CMD_GET_ALL_CELL_INFO = 60;
223 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
224 private static final int CMD_GET_CELL_LOCATION = 62;
225 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700226 private static final int CMD_MODEM_REBOOT = 64;
227 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700228 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
229 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800231 // Parameters of select command.
232 private static final int SELECT_COMMAND = 0xA4;
233 private static final int SELECT_P1 = 0x04;
234 private static final int SELECT_P2 = 0;
235 private static final int SELECT_P3 = 0x10;
236
Pengquan Meng85728fb2018-03-12 16:31:21 -0700237 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
238 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
239 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
240
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241 /** The singleton instance. */
242 private static PhoneInterfaceManager sInstance;
243
Wink Saville3ab207e2014-11-20 13:07:20 -0800244 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800245 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700246 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800247 private AppOpsManager mAppOps;
248 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800249 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800250 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700251 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252
Derek Tan97ebb422014-09-05 16:55:38 -0700253 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
254 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800255 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700256
Derek Tan740e1672017-06-27 14:56:27 -0700257 // The AID of ISD-R.
258 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
259
yinxub1bed742017-04-17 11:45:04 -0700260 private NetworkScanRequestTracker mNetworkScanRequestTracker;
261
David Kelly5e06a7f2018-03-12 14:10:59 +0000262 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
263 private static final int MANUFACTURER_CODE_LENGTH = 8;
264
Derek Tan89e89d42014-07-08 17:00:10 -0700265 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700266 * A request object to use for transmitting data to an ICC.
267 */
268 private static final class IccAPDUArgument {
269 public int channel, cla, command, p1, p2, p3;
270 public String data;
271
272 public IccAPDUArgument(int channel, int cla, int command,
273 int p1, int p2, int p3, String data) {
274 this.channel = channel;
275 this.cla = cla;
276 this.command = command;
277 this.p1 = p1;
278 this.p2 = p2;
279 this.p3 = p3;
280 this.data = data;
281 }
282 }
283
284 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700285 * A request object to use for transmitting data to an ICC.
286 */
287 private static final class ManualNetworkSelectionArgument {
288 public OperatorInfo operatorInfo;
289 public boolean persistSelection;
290
291 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
292 this.operatorInfo = operatorInfo;
293 this.persistSelection = persistSelection;
294 }
295 }
296
297 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
299 * request after sending. The main thread will notify the request when it is complete.
300 */
301 private static final class MainThreadRequest {
302 /** The argument to use for the request */
303 public Object argument;
304 /** The result of the request that is run on the main thread */
305 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800306 // The subscriber id that this request applies to. Defaults to
307 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
308 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309
Nathan Harold92bed182018-10-12 18:16:49 -0700310 // In cases where subId is unavailable, the caller needs to specify the phone.
311 public Phone phone;
312
vagdevie435a3e2018-08-15 16:01:53 -0700313 public WorkSource workSource;
314
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 public MainThreadRequest(Object argument) {
316 this.argument = argument;
317 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800318
Nathan Harold92bed182018-10-12 18:16:49 -0700319 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
320 this.argument = argument;
321 if (phone != null) {
322 this.phone = phone;
323 }
324 this.workSource = workSource;
325 }
326
vagdevie435a3e2018-08-15 16:01:53 -0700327 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800328 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800329 if (subId != null) {
330 this.subId = subId;
331 }
vagdevie435a3e2018-08-15 16:01:53 -0700332 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 }
335
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800336 private static final class IncomingThirdPartyCallArgs {
337 public final ComponentName component;
338 public final String callId;
339 public final String callerDisplayName;
340
341 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
342 String callerDisplayName) {
343 this.component = component;
344 this.callId = callId;
345 this.callerDisplayName = callerDisplayName;
346 }
347 }
348
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 /**
350 * A handler that processes messages on the main thread in the phone process. Since many
351 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
352 * inbound binder threads to the main thread in the phone process. The Binder thread
353 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
354 * on, which will be notified when the operation completes and will contain the result of the
355 * request.
356 *
357 * <p>If a MainThreadRequest object is provided in the msg.obj field,
358 * note that request.result must be set to something non-null for the calling thread to
359 * unblock.
360 */
361 private final class MainThreadHandler extends Handler {
362 @Override
363 public void handleMessage(Message msg) {
364 MainThreadRequest request;
365 Message onCompleted;
366 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800367 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700368 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800369 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
371 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700372 case CMD_HANDLE_USSD_REQUEST: {
373 request = (MainThreadRequest) msg.obj;
374 final Phone phone = getPhoneFromRequest(request);
375 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
376 String ussdRequest = ussdObject.first;
377 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700378
Pengquan Meng0c05b502018-09-06 09:59:22 -0700379 if (!isUssdApiAllowed(request.subId)) {
380 // Carrier does not support use of this API, return failure.
381 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
382 UssdResponse response = new UssdResponse(ussdRequest, null);
383 Bundle returnData = new Bundle();
384 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
385 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700386
Pengquan Meng0c05b502018-09-06 09:59:22 -0700387 request.result = true;
388 notifyRequester(request);
389 return;
390 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700391
Pengquan Meng0c05b502018-09-06 09:59:22 -0700392 try {
393 request.result = phone != null
394 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
395 } catch (CallStateException cse) {
396 request.result = false;
397 }
398 // Wake up the requesting thread
399 notifyRequester(request);
400 break;
pkanwar32d516d2016-10-14 19:37:38 -0700401 }
402
Yorke Lee716f67e2015-06-17 15:39:16 -0700403 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700405 final Phone phone = getPhoneFromRequest(request);
406 request.result = phone != null ?
407 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
408 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700410 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700411 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700415 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800417 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 if (uiccCard == null) {
419 loge("iccTransmitApduLogicalChannel: No UICC");
420 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700421 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
424 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700425 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 iccArgument.channel, iccArgument.cla, iccArgument.command,
427 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 break;
431
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 ar = (AsyncResult) msg.obj;
434 request = (MainThreadRequest) ar.userObj;
435 if (ar.exception == null && ar.result != null) {
436 request.result = ar.result;
437 } else {
438 request.result = new IccIoResult(0x6F, 0, (byte[])null);
439 if (ar.result == null) {
440 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800441 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800443 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 } else {
445 loge("iccTransmitApduLogicalChannel: Unknown exception");
446 }
447 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700448 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 break;
450
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
452 request = (MainThreadRequest) msg.obj;
453 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800454 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 if (uiccCard == null) {
456 loge("iccTransmitApduBasicChannel: No UICC");
457 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700458 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 } else {
460 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
461 request);
462 uiccCard.iccTransmitApduBasicChannel(
463 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
464 iccArgument.p3, iccArgument.data, onCompleted);
465 }
466 break;
467
468 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
469 ar = (AsyncResult) msg.obj;
470 request = (MainThreadRequest) ar.userObj;
471 if (ar.exception == null && ar.result != null) {
472 request.result = ar.result;
473 } else {
474 request.result = new IccIoResult(0x6F, 0, (byte[])null);
475 if (ar.result == null) {
476 loge("iccTransmitApduBasicChannel: Empty response");
477 } else if (ar.exception instanceof CommandException) {
478 loge("iccTransmitApduBasicChannel: CommandException: " +
479 ar.exception);
480 } else {
481 loge("iccTransmitApduBasicChannel: Unknown exception");
482 }
483 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700484 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 break;
486
487 case CMD_EXCHANGE_SIM_IO:
488 request = (MainThreadRequest) msg.obj;
489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 if (uiccCard == null) {
492 loge("iccExchangeSimIO: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 } else {
496 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
497 request);
498 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
499 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
500 iccArgument.data, onCompleted);
501 }
502 break;
503
504 case EVENT_EXCHANGE_SIM_IO_DONE:
505 ar = (AsyncResult) msg.obj;
506 request = (MainThreadRequest) ar.userObj;
507 if (ar.exception == null && ar.result != null) {
508 request.result = ar.result;
509 } else {
510 request.result = new IccIoResult(0x6f, 0, (byte[])null);
511 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 break;
514
Derek Tan4d5e5c12014-02-04 11:54:58 -0800515 case CMD_SEND_ENVELOPE:
516 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800517 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 if (uiccCard == null) {
519 loge("sendEnvelopeWithStatus: No UICC");
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 } else {
523 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
524 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
525 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 break;
527
528 case EVENT_SEND_ENVELOPE_DONE:
529 ar = (AsyncResult) msg.obj;
530 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700531 if (ar.exception == null && ar.result != null) {
532 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
535 if (ar.result == null) {
536 loge("sendEnvelopeWithStatus: Empty response");
537 } else if (ar.exception instanceof CommandException) {
538 loge("sendEnvelopeWithStatus: CommandException: " +
539 ar.exception);
540 } else {
541 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
542 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700544 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 break;
546
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 case CMD_OPEN_CHANNEL:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800550 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 if (uiccCard == null) {
552 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800553 request.result = new IccOpenLogicalChannelResponse(-1,
554 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 } else {
557 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800558 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
559 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 break;
562
563 case EVENT_OPEN_CHANNEL_DONE:
564 ar = (AsyncResult) msg.obj;
565 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 int[] result = (int[]) ar.result;
569 int channelId = result[0];
570 byte[] selectResponse = null;
571 if (result.length > 1) {
572 selectResponse = new byte[result.length - 1];
573 for (int i = 1; i < result.length; ++i) {
574 selectResponse[i - 1] = (byte) result[i];
575 }
576 }
577 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700578 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 if (ar.result == null) {
581 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 if (ar.exception != null) {
584 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
585 }
586
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700587 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700588 if (ar.exception instanceof CommandException) {
589 CommandException.Error error =
590 ((CommandException) (ar.exception)).getCommandError();
591 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700593 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 }
596 }
597 openChannelResp = new IccOpenLogicalChannelResponse(
598 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700600 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700601 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
604 case CMD_CLOSE_CHANNEL:
605 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800606 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 if (uiccCard == null) {
608 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900609 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 } else {
612 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
613 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
614 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 break;
616
617 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800618 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
619 break;
620
621 case CMD_NV_READ_ITEM:
622 request = (MainThreadRequest) msg.obj;
623 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800624 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
625 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800626 break;
627
628 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800634 request.result = "";
635 if (ar.result == null) {
636 loge("nvReadItem: Empty response");
637 } else if (ar.exception instanceof CommandException) {
638 loge("nvReadItem: CommandException: " +
639 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800641 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 }
643 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 break;
646
Jake Hambye994d462014-02-03 13:10:13 -0800647 case CMD_NV_WRITE_ITEM:
648 request = (MainThreadRequest) msg.obj;
649 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
650 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800651 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700652 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800653 break;
654
655 case EVENT_NV_WRITE_ITEM_DONE:
656 handleNullReturnEvent(msg, "nvWriteItem");
657 break;
658
659 case CMD_NV_WRITE_CDMA_PRL:
660 request = (MainThreadRequest) msg.obj;
661 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800662 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800663 break;
664
665 case EVENT_NV_WRITE_CDMA_PRL_DONE:
666 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
667 break;
668
chen xu1cc0abe2018-10-26 17:39:23 -0700669 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800670 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700671 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800672 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800673 break;
674
chen xu1cc0abe2018-10-26 17:39:23 -0700675 case EVENT_RESET_MODEM_CONFIG_DONE:
676 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800677 break;
678
Jake Hamby7c27be32014-03-03 13:25:59 -0800679 case CMD_GET_PREFERRED_NETWORK_TYPE:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700682 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800683 break;
684
685 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
686 ar = (AsyncResult) msg.obj;
687 request = (MainThreadRequest) ar.userObj;
688 if (ar.exception == null && ar.result != null) {
689 request.result = ar.result; // Integer
690 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800691 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800692 if (ar.result == null) {
693 loge("getPreferredNetworkType: Empty response");
694 } else if (ar.exception instanceof CommandException) {
695 loge("getPreferredNetworkType: CommandException: " +
696 ar.exception);
697 } else {
698 loge("getPreferredNetworkType: Unknown exception");
699 }
700 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700701 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 break;
703
704 case CMD_SET_PREFERRED_NETWORK_TYPE:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
707 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700708 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800709 break;
710
711 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
712 handleNullReturnEvent(msg, "setPreferredNetworkType");
713 break;
714
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000715 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
716 request = (MainThreadRequest)msg.obj;
717 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800718 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000719 break;
720
721 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
722 ar = (AsyncResult)msg.obj;
723 request = (MainThreadRequest)ar.userObj;
724 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700725 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000726 break;
727
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800728 case CMD_SET_VOICEMAIL_NUMBER:
729 request = (MainThreadRequest) msg.obj;
730 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
731 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800732 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
733 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800734 break;
735
736 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
737 handleNullReturnEvent(msg, "setVoicemailNumber");
738 break;
739
Stuart Scott54788802015-03-30 13:18:01 -0700740 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
743 request);
744 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
745 break;
746
747 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
748 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
749 break;
750
Shishir Agrawal302c8692015-06-19 13:49:39 -0700751 case CMD_PERFORM_NETWORK_SCAN:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
754 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
755 break;
756
757 case EVENT_PERFORM_NETWORK_SCAN_DONE:
758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
760 CellNetworkScanResult cellScanResult;
761 if (ar.exception == null && ar.result != null) {
762 cellScanResult = new CellNetworkScanResult(
763 CellNetworkScanResult.STATUS_SUCCESS,
764 (List<OperatorInfo>) ar.result);
765 } else {
766 if (ar.result == null) {
767 loge("getCellNetworkScanResults: Empty response");
768 }
769 if (ar.exception != null) {
770 loge("getCellNetworkScanResults: Exception: " + ar.exception);
771 }
772 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
773 if (ar.exception instanceof CommandException) {
774 CommandException.Error error =
775 ((CommandException) (ar.exception)).getCommandError();
776 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
777 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
778 } else if (error == CommandException.Error.GENERIC_FAILURE) {
779 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
780 }
781 }
782 cellScanResult = new CellNetworkScanResult(errorCode, null);
783 }
784 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700785 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700786 break;
787
788 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
789 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700790 ManualNetworkSelectionArgument selArg =
791 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700792 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
793 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700794 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
795 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 break;
797
798 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700799 ar = (AsyncResult) msg.obj;
800 request = (MainThreadRequest) ar.userObj;
801 if (ar.exception == null) {
802 request.result = true;
803 } else {
804 request.result = false;
805 loge("setNetworkSelectionModeManual " + ar.exception);
806 }
807 notifyRequester(request);
808 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700809 break;
810
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700811 case CMD_GET_MODEM_ACTIVITY_INFO:
812 request = (MainThreadRequest) msg.obj;
813 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800814 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700815 break;
816
817 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
818 ar = (AsyncResult) msg.obj;
819 request = (MainThreadRequest) ar.userObj;
820 if (ar.exception == null && ar.result != null) {
821 request.result = ar.result;
822 } else {
823 if (ar.result == null) {
824 loge("queryModemActivityInfo: Empty response");
825 } else if (ar.exception instanceof CommandException) {
826 loge("queryModemActivityInfo: CommandException: " +
827 ar.exception);
828 } else {
829 loge("queryModemActivityInfo: Unknown exception");
830 }
831 }
Amit Mahajand4766222016-01-28 15:28:28 -0800832 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
833 if (request.result == null) {
834 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
835 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700836 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700837 break;
838
Meng Wang1a7c35a2016-05-05 20:56:15 -0700839 case CMD_SET_ALLOWED_CARRIERS:
840 request = (MainThreadRequest) msg.obj;
841 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800842 defaultPhone.setAllowedCarriers(
Meng Wang1a7c35a2016-05-05 20:56:15 -0700843 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700844 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700845 break;
846
847 case EVENT_SET_ALLOWED_CARRIERS_DONE:
848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
850 if (ar.exception == null && ar.result != null) {
851 request.result = ar.result;
852 } else {
853 if (ar.result == null) {
854 loge("setAllowedCarriers: Empty response");
855 } else if (ar.exception instanceof CommandException) {
856 loge("setAllowedCarriers: CommandException: " +
857 ar.exception);
858 } else {
859 loge("setAllowedCarriers: Unknown exception");
860 }
861 }
862 // Result cannot be null. Return -1 on error.
863 if (request.result == null) {
864 request.result = new int[]{-1};
865 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700866 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700867 break;
868
869 case CMD_GET_ALLOWED_CARRIERS:
870 request = (MainThreadRequest) msg.obj;
871 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800872 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 break;
874
875 case EVENT_GET_ALLOWED_CARRIERS_DONE:
876 ar = (AsyncResult) msg.obj;
877 request = (MainThreadRequest) ar.userObj;
878 if (ar.exception == null && ar.result != null) {
879 request.result = ar.result;
880 } else {
881 if (ar.result == null) {
882 loge("getAllowedCarriers: Empty response");
883 } else if (ar.exception instanceof CommandException) {
884 loge("getAllowedCarriers: CommandException: " +
885 ar.exception);
886 } else {
887 loge("getAllowedCarriers: Unknown exception");
888 }
889 }
890 // Result cannot be null. Return empty list of CarrierIdentifier.
891 if (request.result == null) {
892 request.result = new ArrayList<CarrierIdentifier>(0);
893 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700894 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700895 break;
896
Nathan Haroldb3014052017-01-25 15:57:32 -0800897 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
903 request.result = new IllegalArgumentException(
904 "Failed to retrieve Forbidden Plmns");
905 if (ar.result == null) {
906 loge("getForbiddenPlmns: Empty response");
907 } else {
908 loge("getForbiddenPlmns: Unknown exception");
909 }
910 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700911 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800912 break;
913
914 case CMD_GET_FORBIDDEN_PLMNS:
915 request = (MainThreadRequest) msg.obj;
916 uiccCard = getUiccCardFromRequest(request);
917 if (uiccCard == null) {
918 loge("getForbiddenPlmns() UiccCard is null");
919 request.result = new IllegalArgumentException(
920 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700921 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800922 break;
923 }
924 Integer appType = (Integer) request.argument;
925 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
926 if (uiccApp == null) {
927 loge("getForbiddenPlmns() no app with specified type -- "
928 + appType);
929 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700930 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800931 break;
932 } else {
933 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
934 + " specified type -- " + appType);
935 }
936 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
937 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
938 onCompleted);
939 break;
940
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000941 case CMD_SWITCH_SLOTS:
942 request = (MainThreadRequest) msg.obj;
943 int[] physicalSlots = (int[]) request.argument;
944 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
945 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
946 break;
947
948 case EVENT_SWITCH_SLOTS_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700952 notifyRequester(request);
953 break;
954 case CMD_GET_NETWORK_SELECTION_MODE:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
957 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
958 break;
959
960 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 if (ar.exception != null) {
964 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
965 } else {
966 int mode = ((int[]) ar.result)[0];
967 if (mode == 0) {
968 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
969 } else {
970 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
971 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000972 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700973 notifyRequester(request);
974 break;
975 case CMD_GET_CDMA_ROAMING_MODE:
976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
978 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
979 break;
980 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 if (ar.exception != null) {
984 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
985 } else {
986 request.result = ((int[]) ar.result)[0];
987 }
988 notifyRequester(request);
989 break;
990 case CMD_SET_CDMA_ROAMING_MODE:
991 request = (MainThreadRequest) msg.obj;
992 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
993 int mode = (int) request.argument;
994 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
995 break;
996 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = ar.exception == null;
1000 notifyRequester(request);
1001 break;
1002 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1005 int subscriptionMode = (int) request.argument;
1006 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1007 break;
1008 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1009 ar = (AsyncResult) msg.obj;
1010 request = (MainThreadRequest) ar.userObj;
1011 request.result = ar.exception == null;
1012 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001013 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001014 case CMD_GET_ALL_CELL_INFO:
1015 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001016 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001017 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001019 case EVENT_GET_ALL_CELL_INFO_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001022 // If a timeout occurs, the response will be null
1023 request.result = (ar.exception == null && ar.result != null)
1024 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001025 synchronized (request) {
1026 request.notifyAll();
1027 }
1028 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001029 case CMD_REQUEST_CELL_INFO_UPDATE:
1030 request = (MainThreadRequest) msg.obj;
1031 request.phone.requestCellInfoUpdate(request.workSource,
1032 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1033 break;
1034 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
1037 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1038 try {
1039 if (ar.exception != null) {
1040 // something went wrong... the response is null
1041 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1042 cb.onCellInfo(null);
1043 } else if (ar.result == null) {
1044 // timeout occurred, so force the result to non-null "empty"
1045 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1046 cb.onCellInfo(new ArrayList<CellInfo>());
1047 } else {
1048 // use the result as returned
1049 cb.onCellInfo((List<CellInfo>) ar.result);
1050 }
1051 } catch (RemoteException re) {
1052 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1053 }
1054 break;
1055 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 request = (MainThreadRequest) msg.obj;
1057 WorkSource ws = (WorkSource) request.argument;
1058 Phone phone = getPhoneFromRequest(request);
1059 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1060 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 ar = (AsyncResult) msg.obj;
1063 request = (MainThreadRequest) ar.userObj;
1064 if (ar.exception == null) {
1065 request.result = ar.result;
1066 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001067 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001068 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1069 ? new CdmaCellLocation() : new GsmCellLocation();
1070 }
1071
1072 synchronized (request) {
1073 request.notifyAll();
1074 }
1075 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001076 case CMD_MODEM_REBOOT:
1077 request = (MainThreadRequest) msg.obj;
1078 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001079 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001080 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001081 case EVENT_CMD_MODEM_REBOOT_DONE:
1082 handleNullReturnEvent(msg, "rebootModem");
1083 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001084 default:
1085 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1086 break;
1087 }
1088 }
Jake Hambye994d462014-02-03 13:10:13 -08001089
Pengquan Meng0c05b502018-09-06 09:59:22 -07001090 private void notifyRequester(MainThreadRequest request) {
1091 synchronized (request) {
1092 request.notifyAll();
1093 }
1094 }
1095
Jake Hambye994d462014-02-03 13:10:13 -08001096 private void handleNullReturnEvent(Message msg, String command) {
1097 AsyncResult ar = (AsyncResult) msg.obj;
1098 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null) {
1100 request.result = true;
1101 } else {
1102 request.result = false;
1103 if (ar.exception instanceof CommandException) {
1104 loge(command + ": CommandException: " + ar.exception);
1105 } else {
1106 loge(command + ": Unknown exception");
1107 }
1108 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001109 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001111 }
1112
1113 /**
1114 * Posts the specified command to be executed on the main thread,
1115 * waits for the request to complete, and returns the result.
1116 * @see #sendRequestAsync
1117 */
1118 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001119 return sendRequest(
1120 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001121 }
1122
1123 /**
1124 * Posts the specified command to be executed on the main thread,
1125 * waits for the request to complete, and returns the result.
1126 * @see #sendRequestAsync
1127 */
1128 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1129 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001130 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001131 }
1132
1133 /**
1134 * Posts the specified command to be executed on the main thread,
1135 * waits for the request to complete, and returns the result.
1136 * @see #sendRequestAsync
1137 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001138 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001139 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001140 }
1141
1142 /**
1143 * Posts the specified command to be executed on the main thread,
1144 * waits for the request to complete, and returns the result.
1145 * @see #sendRequestAsync
1146 */
Nathan Harold92bed182018-10-12 18:16:49 -07001147 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1148 return sendRequest(command, argument, subId, null, workSource);
1149 }
1150
1151 /**
1152 * Posts the specified command to be executed on the main thread,
1153 * waits for the request to complete, and returns the result.
1154 * @see #sendRequestAsync
1155 */
1156 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1157 return sendRequest(
1158 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1159 }
1160
1161 /**
1162 * Posts the specified command to be executed on the main thread,
1163 * waits for the request to complete, and returns the result.
1164 * @see #sendRequestAsync
1165 */
1166 private Object sendRequest(
1167 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1169 throw new RuntimeException("This method will deadlock if called from the main thread.");
1170 }
1171
Nathan Harold92bed182018-10-12 18:16:49 -07001172 MainThreadRequest request = null;
1173 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1174 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1175 } else if (phone != null) {
1176 request = new MainThreadRequest(argument, phone, workSource);
1177 } else {
1178 request = new MainThreadRequest(argument, subId, workSource);
1179 }
1180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001181 Message msg = mMainThreadHandler.obtainMessage(command, request);
1182 msg.sendToTarget();
1183
1184 // Wait for the request to complete
1185 synchronized (request) {
1186 while (request.result == null) {
1187 try {
1188 request.wait();
1189 } catch (InterruptedException e) {
1190 // Do nothing, go back and wait until the request is complete
1191 }
1192 }
1193 }
1194 return request.result;
1195 }
1196
1197 /**
1198 * Asynchronous ("fire and forget") version of sendRequest():
1199 * Posts the specified command to be executed on the main thread, and
1200 * returns immediately.
1201 * @see #sendRequest
1202 */
1203 private void sendRequestAsync(int command) {
1204 mMainThreadHandler.sendEmptyMessage(command);
1205 }
1206
1207 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001208 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001209 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001210 */
1211 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001212 sendRequestAsync(command, argument, null, null);
1213 }
1214
1215 /**
1216 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1217 * @see {@link #sendRequest(int,Object)}
1218 */
1219 private void sendRequestAsync(
1220 int command, Object argument, Phone phone, WorkSource workSource) {
1221 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001222 Message msg = mMainThreadHandler.obtainMessage(command, request);
1223 msg.sendToTarget();
1224 }
1225
1226 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001227 * Initialize the singleton PhoneInterfaceManager instance.
1228 * This is only done once, at startup, from PhoneApp.onCreate().
1229 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001230 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 synchronized (PhoneInterfaceManager.class) {
1232 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001233 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 } else {
1235 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1236 }
1237 return sInstance;
1238 }
1239 }
1240
1241 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001242 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001245 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1247 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001248 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001249 mTelephonySharedPreferences =
1250 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001251 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001252 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001253
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 publish();
1255 }
1256
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001257 private Phone getDefaultPhone() {
1258 Phone thePhone = getPhone(getDefaultSubscription());
1259 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1260 }
1261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 private void publish() {
1263 if (DBG) log("publish: " + this);
1264
1265 ServiceManager.addService("phone", this);
1266 }
1267
Stuart Scott584921c2015-01-15 17:10:34 -08001268 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001269 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001270 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001271 }
1272
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001273 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1274 Phone phone = getPhoneFromRequest(request);
1275 return phone == null ? null :
1276 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1277 }
1278
Wink Saville36469e72014-06-11 15:17:00 -07001279 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001280 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001281 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283
1284 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001285 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
1287
Wink Savilleb564aae2014-10-23 10:18:09 -07001288 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001289 if (DBG) log("dial: " + number);
1290 // No permission check needed here: This is just a wrapper around the
1291 // ACTION_DIAL intent, which is available to any app since it puts up
1292 // the UI before it does anything.
1293
Malcolm Chend965c8b2018-02-28 15:00:40 -08001294 final long identity = Binder.clearCallingIdentity();
1295 try {
1296 String url = createTelUrl(number);
1297 if (url == null) {
1298 return;
1299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300
Malcolm Chend965c8b2018-02-28 15:00:40 -08001301 // PENDING: should we just silently fail if phone is offhook or ringing?
1302 PhoneConstants.State state = mCM.getState(subId);
1303 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1304 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1305 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1306 mApp.startActivity(intent);
1307 }
1308 } finally {
1309 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 }
1311 }
1312
1313 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001314 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001315 }
1316
Wink Savilleb564aae2014-10-23 10:18:09 -07001317 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (DBG) log("call: " + number);
1319
1320 // This is just a wrapper around the ACTION_CALL intent, but we still
1321 // need to do a permission check since we're calling startActivity()
1322 // from the context of the phone app.
1323 enforceCallPermission();
1324
1325 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1326 != AppOpsManager.MODE_ALLOWED) {
1327 return;
1328 }
1329
Malcolm Chend965c8b2018-02-28 15:00:40 -08001330 final long identity = Binder.clearCallingIdentity();
1331 try {
1332 String url = createTelUrl(number);
1333 if (url == null) {
1334 return;
1335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336
Malcolm Chend965c8b2018-02-28 15:00:40 -08001337 boolean isValid = false;
1338 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1339 if (slist != null) {
1340 for (SubscriptionInfo subInfoRecord : slist) {
1341 if (subInfoRecord.getSubscriptionId() == subId) {
1342 isValid = true;
1343 break;
1344 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001345 }
Wink Saville08874612014-08-31 19:19:58 -07001346 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001347 if (!isValid) {
1348 return;
1349 }
Wink Saville08874612014-08-31 19:19:58 -07001350
Malcolm Chend965c8b2018-02-28 15:00:40 -08001351 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1352 intent.putExtra(SUBSCRIPTION_KEY, subId);
1353 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1354 mApp.startActivity(intent);
1355 } finally {
1356 Binder.restoreCallingIdentity(identity);
1357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 }
1359
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001361 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001362 }
1363
Wink Savilleb564aae2014-10-23 10:18:09 -07001364 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001365 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001366 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1367 }
1368
1369 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001370 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
1372
Wink Savilleb564aae2014-10-23 10:18:09 -07001373 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001375 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1376 }
1377
1378 /** {@hide} */
1379 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001380 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001381 }
1382
Wink Savilleb564aae2014-10-23 10:18:09 -07001383 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001385
1386 final long identity = Binder.clearCallingIdentity();
1387 try {
1388 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1389 checkSimPin.start();
1390 return checkSimPin.unlockSim(null, pin);
1391 } finally {
1392 Binder.restoreCallingIdentity(identity);
1393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 }
1395
Wink Saville9de0f752013-10-22 19:04:03 -07001396 /** {@hide} */
1397 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001399 }
1400
Wink Savilleb564aae2014-10-23 10:18:09 -07001401 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001403
1404 final long identity = Binder.clearCallingIdentity();
1405 try {
1406 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1407 checkSimPuk.start();
1408 return checkSimPuk.unlockSim(puk, pin);
1409 } finally {
1410 Binder.restoreCallingIdentity(identity);
1411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 }
1413
1414 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001415 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 * a synchronous one.
1417 */
1418 private static class UnlockSim extends Thread {
1419
1420 private final IccCard mSimCard;
1421
1422 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001423 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1424 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
1426 // For replies from SimCard interface
1427 private Handler mHandler;
1428
1429 // For async handler to identify request type
1430 private static final int SUPPLY_PIN_COMPLETE = 100;
1431
1432 public UnlockSim(IccCard simCard) {
1433 mSimCard = simCard;
1434 }
1435
1436 @Override
1437 public void run() {
1438 Looper.prepare();
1439 synchronized (UnlockSim.this) {
1440 mHandler = new Handler() {
1441 @Override
1442 public void handleMessage(Message msg) {
1443 AsyncResult ar = (AsyncResult) msg.obj;
1444 switch (msg.what) {
1445 case SUPPLY_PIN_COMPLETE:
1446 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1447 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001448 mRetryCount = msg.arg1;
1449 if (ar.exception != null) {
1450 if (ar.exception instanceof CommandException &&
1451 ((CommandException)(ar.exception)).getCommandError()
1452 == CommandException.Error.PASSWORD_INCORRECT) {
1453 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1454 } else {
1455 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1456 }
1457 } else {
1458 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 mDone = true;
1461 UnlockSim.this.notifyAll();
1462 }
1463 break;
1464 }
1465 }
1466 };
1467 UnlockSim.this.notifyAll();
1468 }
1469 Looper.loop();
1470 }
1471
1472 /*
1473 * Use PIN or PUK to unlock SIM card
1474 *
1475 * If PUK is null, unlock SIM card with PIN
1476 *
1477 * If PUK is not null, unlock SIM card with PUK and set PIN code
1478 */
Wink Saville9de0f752013-10-22 19:04:03 -07001479 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480
1481 while (mHandler == null) {
1482 try {
1483 wait();
1484 } catch (InterruptedException e) {
1485 Thread.currentThread().interrupt();
1486 }
1487 }
1488 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1489
1490 if (puk == null) {
1491 mSimCard.supplyPin(pin, callback);
1492 } else {
1493 mSimCard.supplyPuk(puk, pin, callback);
1494 }
1495
1496 while (!mDone) {
1497 try {
1498 Log.d(LOG_TAG, "wait for done");
1499 wait();
1500 } catch (InterruptedException e) {
1501 // Restore the interrupted status
1502 Thread.currentThread().interrupt();
1503 }
1504 }
1505 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001506 int[] resultArray = new int[2];
1507 resultArray[0] = mResult;
1508 resultArray[1] = mRetryCount;
1509 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 }
1511 }
1512
1513 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001514 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001515
1516 }
1517
Wink Savilleb564aae2014-10-23 10:18:09 -07001518 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001519 // No permission check needed here: this call is harmless, and it's
1520 // needed for the ServiceState.requestStateUpdate() call (which is
1521 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001522 final long identity = Binder.clearCallingIdentity();
1523 try {
1524 final Phone phone = getPhone(subId);
1525 if (phone != null) {
1526 phone.updateServiceLocation();
1527 }
1528 } finally {
1529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 }
1532
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001533 @Override
1534 public boolean isRadioOn(String callingPackage) {
1535 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001536 }
1537
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001538 @Override
1539 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001541 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001542 return false;
1543 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001544
1545 final long identity = Binder.clearCallingIdentity();
1546 try {
1547 return isRadioOnForSubscriber(subId);
1548 } finally {
1549 Binder.restoreCallingIdentity(identity);
1550 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001551 }
1552
1553 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001554 final long identity = Binder.clearCallingIdentity();
1555 try {
1556 final Phone phone = getPhone(subId);
1557 if (phone != null) {
1558 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1559 } else {
1560 return false;
1561 }
1562 } finally {
1563 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
1566
1567 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001568 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
Wink Saville36469e72014-06-11 15:17:00 -07001570
Wink Savilleb564aae2014-10-23 10:18:09 -07001571 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001573
1574 final long identity = Binder.clearCallingIdentity();
1575 try {
1576 final Phone phone = getPhone(subId);
1577 if (phone != null) {
1578 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1579 }
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001582 }
Wink Saville36469e72014-06-11 15:17:00 -07001583 }
1584
1585 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001586 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001587 }
1588
Wink Savilleb564aae2014-10-23 10:18:09 -07001589 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001590 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001591
1592 final long identity = Binder.clearCallingIdentity();
1593 try {
1594 final Phone phone = getPhone(subId);
1595 if (phone == null) {
1596 return false;
1597 }
1598 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1599 toggleRadioOnOffForSubscriber(subId);
1600 }
1601 return true;
1602 } finally {
1603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 }
Wink Saville36469e72014-06-11 15:17:00 -07001606
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001607 public boolean needMobileRadioShutdown() {
1608 /*
1609 * If any of the Radios are available, it will need to be
1610 * shutdown. So return true if any Radio is available.
1611 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001612 final long identity = Binder.clearCallingIdentity();
1613 try {
1614 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1615 Phone phone = PhoneFactory.getPhone(i);
1616 if (phone != null && phone.isRadioAvailable()) return true;
1617 }
1618 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1619 return false;
1620 } finally {
1621 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001622 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001623 }
1624
Malcolm Chend965c8b2018-02-28 15:00:40 -08001625 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001626 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001627 enforceModifyPermission();
1628
1629 final long identity = Binder.clearCallingIdentity();
1630 try {
1631 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1632 logv("Shutting down Phone " + i);
1633 shutdownRadioUsingPhoneId(i);
1634 }
1635 } finally {
1636 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001637 }
1638 }
1639
1640 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001641 Phone phone = PhoneFactory.getPhone(phoneId);
1642 if (phone != null && phone.isRadioAvailable()) {
1643 phone.shutdownRadio();
1644 }
1645 }
1646
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001648 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001649
1650 final long identity = Binder.clearCallingIdentity();
1651 try {
1652 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1653 if (defaultPhone != null) {
1654 defaultPhone.setRadioPower(turnOn);
1655 return true;
1656 } else {
1657 loge("There's no default phone.");
1658 return false;
1659 }
1660 } finally {
1661 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001662 }
Wink Saville36469e72014-06-11 15:17:00 -07001663 }
1664
Wink Savilleb564aae2014-10-23 10:18:09 -07001665 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001667
1668 final long identity = Binder.clearCallingIdentity();
1669 try {
1670 final Phone phone = getPhone(subId);
1671 if (phone != null) {
1672 phone.setRadioPower(turnOn);
1673 return true;
1674 } else {
1675 return false;
1676 }
1677 } finally {
1678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681
Wink Saville36469e72014-06-11 15:17:00 -07001682 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001683 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 public boolean enableDataConnectivity() {
1685 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001686
1687 final long identity = Binder.clearCallingIdentity();
1688 try {
1689 int subId = mSubscriptionController.getDefaultDataSubId();
1690 final Phone phone = getPhone(subId);
1691 if (phone != null) {
1692 phone.setUserDataEnabled(true);
1693 return true;
1694 } else {
1695 return false;
1696 }
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 }
1701
Wink Saville36469e72014-06-11 15:17:00 -07001702 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 public boolean disableDataConnectivity() {
1705 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001706
1707 final long identity = Binder.clearCallingIdentity();
1708 try {
1709 int subId = mSubscriptionController.getDefaultDataSubId();
1710 final Phone phone = getPhone(subId);
1711 if (phone != null) {
1712 phone.setUserDataEnabled(false);
1713 return true;
1714 } else {
1715 return false;
1716 }
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 }
1721
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001723 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001724 final long identity = Binder.clearCallingIdentity();
1725 try {
1726 final Phone phone = getPhone(subId);
1727 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001728 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001729 } else {
1730 return false;
1731 }
1732 } finally {
1733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 }
1736
1737 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001738 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001739 }
1740
pkanwarae03a6b2016-11-06 20:37:09 -08001741 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001742 enforceCallPermission();
1743
1744 final long identity = Binder.clearCallingIdentity();
1745 try {
1746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1747 return;
1748 }
1749 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1750 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1751 } finally {
1752 Binder.restoreCallingIdentity(identity);
1753 }
pkanwar32d516d2016-10-14 19:37:38 -07001754 };
1755
Wink Savilleb564aae2014-10-23 10:18:09 -07001756 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001758
1759 final long identity = Binder.clearCallingIdentity();
1760 try {
1761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1762 return false;
1763 }
1764 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001771 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001772 }
1773
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001774 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 Phone phone = PhoneFactory.getPhone(slotIndex);
1778 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1779 PhoneConstantConversions.convertCallState(phone.getState());
1780 } finally {
1781 Binder.restoreCallingIdentity(identity);
1782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 }
1784
Sanket Padawe356d7632015-06-22 14:03:32 -07001785 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001787 final long identity = Binder.clearCallingIdentity();
1788 try {
1789 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1790 if (phone != null) {
1791 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1792 } else {
1793 return PhoneConstantConversions.convertDataState(
1794 PhoneConstants.DataState.DISCONNECTED);
1795 }
1796 } finally {
1797 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 }
1800
Sanket Padawe356d7632015-06-22 14:03:32 -07001801 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1806 if (phone != null) {
1807 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1808 } else {
1809 return TelephonyManager.DATA_ACTIVITY_NONE;
1810 }
1811 } finally {
1812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 }
1815
1816 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001817 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001818 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001819 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001820 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
1821 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001822 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001825 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001826 final long identity = Binder.clearCallingIdentity();
1827 try {
1828 if (DBG_LOC) log("getCellLocation: is active user");
1829 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001830 int subId = mSubscriptionController.getDefaultDataSubId();
1831 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1832 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001833 return data;
1834 } finally {
1835 Binder.restoreCallingIdentity(identity);
1836 }
Svetoslav64fad262015-04-14 14:35:21 -07001837 }
1838
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001840 public String getNetworkCountryIsoForPhone(int phoneId) {
1841 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1842 // registered cell info, so return a NULL country instead.
1843 final long identity = Binder.clearCallingIdentity();
1844 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001845 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1846 // Get default phone in this case.
1847 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1848 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001849 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001850 // Todo: fix this when we can get the actual cellular network info when the device
1851 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001852 if (TelephonyManager.NETWORK_TYPE_IWLAN
1853 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1854 return "";
1855 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001856 Phone phone = PhoneFactory.getPhone(phoneId);
1857 if (phone != null) {
1858 ServiceStateTracker sst = phone.getServiceStateTracker();
1859 if (sst != null) {
1860 LocaleTracker lt = sst.getLocaleTracker();
1861 if (lt != null) {
1862 return lt.getCurrentCountry();
1863 }
1864 }
1865 }
1866 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001867 } finally {
1868 Binder.restoreCallingIdentity(identity);
1869 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001870 }
1871
1872 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001874 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001875 }
1876
Sanket Padawe356d7632015-06-22 14:03:32 -07001877 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001878 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 mApp.enforceCallingOrSelfPermission(
1880 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001881
1882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 final Phone phone = getPhone(subId);
1885 if (phone != null) {
1886 phone.enableLocationUpdates();
1887 }
1888 } finally {
1889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 }
1892
1893 @Override
1894 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001895 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001896 }
1897
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001899 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001900 mApp.enforceCallingOrSelfPermission(
1901 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001902
1903 final long identity = Binder.clearCallingIdentity();
1904 try {
1905 final Phone phone = getPhone(subId);
1906 if (phone != null) {
1907 phone.disableLocationUpdates();
1908 }
1909 } finally {
1910 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 }
1913
Nathan Harold31d7ff32018-10-15 20:20:30 -07001914 /**
1915 * Returns the target SDK version number for a given package name.
1916 *
1917 * @return target SDK if the package is found or INT_MAX.
1918 */
1919 private int getTargetSdk(String packageName) {
1920 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001921 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1922 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001923 if (ai != null) return ai.targetSdkVersion;
1924 } catch (PackageManager.NameNotFoundException unexpected) {
1925 }
1926 return Integer.MAX_VALUE;
1927 }
1928
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 @Override
1930 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001931 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1932 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001933 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1934 throw new SecurityException(
1935 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1936 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001937
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1939 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1940 return null;
1941 }
Svetoslav64fad262015-04-14 14:35:21 -07001942
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001943 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944
Nathan Haroldf180aac2018-06-01 18:43:55 -07001945 List<CellInfo> info = getAllCellInfo(callingPackage);
1946 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947
Nathan Haroldf180aac2018-06-01 18:43:55 -07001948 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1949 for (CellInfo ci : info) {
1950 if (ci instanceof CellInfoGsm) {
1951 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1952 } else if (ci instanceof CellInfoWcdma) {
1953 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001956 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 }
1958
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001959 private List<CellInfo> getCachedCellInfo() {
1960 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1961 for (Phone phone : PhoneFactory.getPhones()) {
1962 List<CellInfo> info = phone.getAllCellInfo();
1963 if (info != null) cellInfos.addAll(info);
1964 }
1965 return cellInfos;
1966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967
1968 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001969 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001970 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001971 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001972 if (!LocationAccessPolicy.canAccessCellLocation(mApp,
Svet Ganov4af66282018-03-07 19:57:05 -08001973 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001974 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 }
1976
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001977 final int targetSdk = getTargetSdk(callingPackage);
1978 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1979 return getCachedCellInfo();
1980 }
1981
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001982 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001983 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001984 final long identity = Binder.clearCallingIdentity();
1985 try {
1986 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1987 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001988 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001989 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001990 if (info != null) cellInfos.addAll(info);
1991 }
1992 return cellInfos;
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
1996 }
1997
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001998 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001999 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2000 requestCellInfoUpdateInternal(
2001 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2002 }
2003
2004 @Override
2005 public void requestCellInfoUpdateWithWorkSource(
2006 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2007 enforceModifyPermission();
2008 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2009 }
2010
2011 private void requestCellInfoUpdateInternal(
2012 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002013 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002014 .checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002015 if (!LocationAccessPolicy.canAccessCellLocation(mApp, callingPackage,
2016 Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002017 return;
2018 }
2019
2020 final Phone phone = getPhone(subId);
2021 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2022
2023 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2024 }
2025
2026 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002028 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002029 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002030
2031 final long identity = Binder.clearCallingIdentity();
2032 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002033 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002034 } finally {
2035 Binder.restoreCallingIdentity(identity);
2036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 }
2038
Shishir Agrawala9f32182016-04-12 12:00:16 -07002039 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002040 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002041 Phone phone = PhoneFactory.getPhone(slotIndex);
2042 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002043 return null;
2044 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002045 int subId = phone.getSubId();
2046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2047 mApp, subId, callingPackage, "getImeiForSlot")) {
2048 return null;
2049 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002050
2051 final long identity = Binder.clearCallingIdentity();
2052 try {
2053 return phone.getImei();
2054 } finally {
2055 Binder.restoreCallingIdentity(identity);
2056 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002057 }
2058
2059 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002060 public String getTypeAllocationCodeForSlot(int slotIndex) {
2061 Phone phone = PhoneFactory.getPhone(slotIndex);
2062 String tac = null;
2063 if (phone != null) {
2064 String imei = phone.getImei();
2065 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2066 }
2067 return tac;
2068 }
2069
2070 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002071 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002072 Phone phone = PhoneFactory.getPhone(slotIndex);
2073 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002074 return null;
2075 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002076
Jeff Davidson913390f2018-02-23 17:11:49 -08002077 int subId = phone.getSubId();
2078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2079 mApp, subId, callingPackage, "getMeidForSlot")) {
2080 return null;
2081 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002082
2083 final long identity = Binder.clearCallingIdentity();
2084 try {
2085 return phone.getMeid();
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
2088 }
Jack Yu2af8d712017-03-15 17:14:14 -07002089 }
2090
2091 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002092 public String getManufacturerCodeForSlot(int slotIndex) {
2093 Phone phone = PhoneFactory.getPhone(slotIndex);
2094 String manufacturerCode = null;
2095 if (phone != null) {
2096 String meid = phone.getMeid();
2097 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2098 }
2099 return manufacturerCode;
2100 }
2101
2102 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002103 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002104 Phone phone = PhoneFactory.getPhone(slotIndex);
2105 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002106 return null;
2107 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002108 int subId = phone.getSubId();
2109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2110 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2111 return null;
2112 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 return phone.getDeviceSvn();
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002120 }
2121
fionaxu43304da2017-11-27 22:51:16 -08002122 @Override
2123 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002124 final long identity = Binder.clearCallingIdentity();
2125 try {
2126 final Phone phone = getPhone(subId);
2127 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2128 } finally {
2129 Binder.restoreCallingIdentity(identity);
2130 }
fionaxu43304da2017-11-27 22:51:16 -08002131 }
2132
2133 @Override
2134 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final Phone phone = getPhone(subId);
2138 return phone == null ? null : phone.getCarrierName();
2139 } finally {
2140 Binder.restoreCallingIdentity(identity);
2141 }
fionaxu43304da2017-11-27 22:51:16 -08002142 }
2143
calvinpaneed9ae82018-11-01 19:43:06 +08002144 @Override
chen xuc93cc282018-11-04 17:17:00 -08002145 public int getSubscriptionPreciseCarrierId(int subId) {
2146 final long identity = Binder.clearCallingIdentity();
2147 try {
2148 final Phone phone = getPhone(subId);
2149 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2150 : phone.getPreciseCarrierId();
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
2153 }
2154 }
2155
2156 @Override
2157 public String getSubscriptionPreciseCarrierName(int subId) {
2158 final long identity = Binder.clearCallingIdentity();
2159 try {
2160 final Phone phone = getPhone(subId);
2161 return phone == null ? null : phone.getPreciseCarrierName();
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
2164 }
2165 }
2166
chen xu02581692018-11-11 19:03:44 -08002167 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002168 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2169 if (!isSubscriptionMccMnc) {
2170 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2171 }
chen xu02581692018-11-11 19:03:44 -08002172 final Phone phone = PhoneFactory.getPhone(slotIndex);
2173 if (phone == null) {
2174 return TelephonyManager.UNKNOWN_CARRIER_ID;
2175 }
2176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
2181 }
2182 }
2183
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 //
2185 // Internal helper methods.
2186 //
2187
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002188 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2190 *
2191 * @throws SecurityException if the caller does not have the required permission
2192 */
2193 private void enforceModifyPermission() {
2194 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2195 }
2196
2197 /**
2198 * Make sure the caller has the CALL_PHONE permission.
2199 *
2200 * @throws SecurityException if the caller does not have the required permission
2201 */
2202 private void enforceCallPermission() {
2203 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2204 }
2205
Stuart Scott8eef64f2015-04-08 15:13:54 -07002206 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002207 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002208 "ConnectivityService");
2209 }
2210
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 private String createTelUrl(String number) {
2212 if (TextUtils.isEmpty(number)) {
2213 return null;
2214 }
2215
Jake Hambye994d462014-02-03 13:10:13 -08002216 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Ihab Awadf9e92732013-12-05 18:02:52 -08002219 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2221 }
2222
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002223 private static void logv(String msg) {
2224 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2225 }
2226
Ihab Awadf9e92732013-12-05 18:02:52 -08002227 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2229 }
2230
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002231 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002233 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002234 }
2235
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002237 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002238 final long identity = Binder.clearCallingIdentity();
2239 try {
2240 final Phone phone = PhoneFactory.getPhone(slotIndex);
2241 if (phone == null) {
2242 return PhoneConstants.PHONE_TYPE_NONE;
2243 } else {
2244 return phone.getPhoneType();
2245 }
2246 } finally {
2247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 }
2250
2251 /**
2252 * Returns the CDMA ERI icon index to display
2253 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002254 @Override
2255 public int getCdmaEriIconIndex(String callingPackage) {
2256 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002257 }
2258
Sanket Padawe356d7632015-06-22 14:03:32 -07002259 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002260 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002262 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002263 return -1;
2264 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002265
2266 final long identity = Binder.clearCallingIdentity();
2267 try {
2268 final Phone phone = getPhone(subId);
2269 if (phone != null) {
2270 return phone.getCdmaEriIconIndex();
2271 } else {
2272 return -1;
2273 }
2274 } finally {
2275 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 }
2278
2279 /**
2280 * Returns the CDMA ERI icon mode,
2281 * 0 - ON
2282 * 1 - FLASHING
2283 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002284 @Override
2285 public int getCdmaEriIconMode(String callingPackage) {
2286 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002287 }
2288
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002290 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002292 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002293 return -1;
2294 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 final Phone phone = getPhone(subId);
2299 if (phone != null) {
2300 return phone.getCdmaEriIconMode();
2301 } else {
2302 return -1;
2303 }
2304 } finally {
2305 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 }
2308
2309 /**
2310 * Returns the CDMA ERI text,
2311 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002312 @Override
2313 public String getCdmaEriText(String callingPackage) {
2314 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002315 }
2316
Sanket Padawe356d7632015-06-22 14:03:32 -07002317 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002318 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002320 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002321 return null;
2322 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002323
2324 final long identity = Binder.clearCallingIdentity();
2325 try {
2326 final Phone phone = getPhone(subId);
2327 if (phone != null) {
2328 return phone.getCdmaEriText();
2329 } else {
2330 return null;
2331 }
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 }
2336
2337 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002338 * Returns the CDMA MDN.
2339 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002341 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2343 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002348 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002349 return phone.getLine1Number();
2350 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002351 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002352 return null;
2353 }
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002356 }
2357 }
2358
2359 /**
2360 * Returns the CDMA MIN.
2361 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002362 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002363 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2365 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002366
2367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 final Phone phone = getPhone(subId);
2370 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2371 return phone.getCdmaMin();
2372 } else {
2373 return null;
2374 }
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002377 }
2378 }
2379
Hall Liud892bec2018-11-30 14:51:45 -08002380 @Override
2381 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2382 INumberVerificationCallback callback, String callingPackage) {
2383 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2384 != PERMISSION_GRANTED) {
2385 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2386 }
2387 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2388
2389 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2390 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2391 throw new SecurityException("Calling package must be configured in the device config");
2392 }
2393
2394 if (range == null) {
2395 throw new NullPointerException("Range must be non-null");
2396 }
2397
2398 timeoutMillis = Math.min(timeoutMillis,
2399 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2400
2401 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2402 }
2403
Junda Liuca05d5d2014-08-14 22:36:34 -07002404 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 * Returns true if CDMA provisioning needs to run.
2406 */
2407 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002408 final long identity = Binder.clearCallingIdentity();
2409 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002410 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002411 } finally {
2412 Binder.restoreCallingIdentity(identity);
2413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 }
2415
2416 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002417 * Sets the voice mail number of a given subId.
2418 */
2419 @Override
2420 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002421 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002422
2423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2426 new Pair<String, String>(alphaTag, number), new Integer(subId));
2427 return success;
2428 } finally {
2429 Binder.restoreCallingIdentity(identity);
2430 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002431 }
2432
Ta-wei Yen87c49842016-05-13 21:19:52 -07002433 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002434 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2435 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002436 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002437 if (!TextUtils.equals(callingPackage, systemDialer)) {
2438 throw new SecurityException("caller must be system dialer");
2439 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
2443 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2444 if (phoneAccountHandle == null) {
2445 return null;
2446 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002447 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002448 } finally {
2449 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002450 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002451 }
2452
2453 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002454 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002457 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002458 return null;
2459 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002460
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002461 final long identity = Binder.clearCallingIdentity();
2462 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002463 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002464 } finally {
2465 Binder.restoreCallingIdentity(identity);
2466 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002467 }
2468
2469 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002470 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2471 VisualVoicemailSmsFilterSettings settings) {
2472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002473
2474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002477 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002478 } finally {
2479 Binder.restoreCallingIdentity(identity);
2480 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002481 }
2482
2483 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002484 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002486
2487 final long identity = Binder.clearCallingIdentity();
2488 try {
2489 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002490 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002491 } finally {
2492 Binder.restoreCallingIdentity(identity);
2493 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002494 }
2495
2496 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002497 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2498 String callingPackage, int subId) {
2499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
2503 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002504 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002505 } finally {
2506 Binder.restoreCallingIdentity(identity);
2507 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002508 }
2509
2510 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002511 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002512 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002513
2514 final long identity = Binder.clearCallingIdentity();
2515 try {
2516 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002517 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002518 } finally {
2519 Binder.restoreCallingIdentity(identity);
2520 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002521 }
2522
2523 @Override
2524 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2525 String number, int port, String text, PendingIntent sentIntent) {
2526 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002527 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002528 enforceSendSmsPermission();
2529 // Make the calls as the phone process.
2530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2533 if (port == 0) {
2534 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2535 sentIntent, null, false);
2536 } else {
2537 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2538 smsManager.sendDataMessageWithSelfPermissions(number, null,
2539 (short) port, data, sentIntent, null);
2540 }
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
2543 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002544 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002545 /**
fionaxu0152e512016-11-14 13:36:14 -08002546 * Sets the voice activation state of a given subId.
2547 */
2548 @Override
2549 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2551 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 phone.setVoiceActivationState(activationState);
2558 } else {
2559 loge("setVoiceActivationState fails with invalid subId: " + subId);
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002563 }
2564 }
2565
2566 /**
2567 * Sets the data activation state of a given subId.
2568 */
2569 @Override
2570 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2572 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone phone = getPhone(subId);
2577 if (phone != null) {
2578 phone.setDataActivationState(activationState);
2579 } else {
2580 loge("setVoiceActivationState fails with invalid subId: " + subId);
2581 }
2582 } finally {
2583 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002584 }
2585 }
2586
2587 /**
2588 * Returns the voice activation state of a given subId.
2589 */
2590 @Override
2591 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002592 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002593
fionaxu0152e512016-11-14 13:36:14 -08002594 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 if (phone != null) {
2598 return phone.getVoiceActivationState();
2599 } else {
2600 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002604 }
2605 }
2606
2607 /**
2608 * Returns the data activation state of a given subId.
2609 */
2610 @Override
2611 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002612 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002613
fionaxu0152e512016-11-14 13:36:14 -08002614 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002615 final long identity = Binder.clearCallingIdentity();
2616 try {
2617 if (phone != null) {
2618 return phone.getDataActivationState();
2619 } else {
2620 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002624 }
2625 }
2626
2627 /**
Wink Saville36469e72014-06-11 15:17:00 -07002628 * Returns the unread count of voicemails for a subId
2629 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002630 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002631 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2633 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2634 return 0;
2635 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 final Phone phone = getPhone(subId);
2639 if (phone != null) {
2640 return phone.getVoiceMessageCount();
2641 } else {
2642 return 0;
2643 }
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648
2649 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002650 * returns true, if the device is in a state where both voice and data
2651 * are supported simultaneously. This can change based on location or network condition.
2652 */
2653 @Override
2654 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 final Phone phone = getPhone(subId);
2658 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002662 }
2663
2664 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002665 * Send the dialer code if called from the current default dialer or the caller has
2666 * carrier privilege.
2667 * @param inputCode The dialer code to send
2668 */
2669 @Override
2670 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002671 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002672 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002673 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2674 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002675 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002676 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2677 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002678 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002679
2680 final long identity = Binder.clearCallingIdentity();
2681 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002682 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
fionaxu235cc5e2017-03-06 22:25:57 -08002686 }
2687
2688 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002689 * Returns the data network type.
2690 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 *
2692 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2693 */
2694 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002695 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 final Phone phone = getPhone(getDefaultSubscription());
2699 if (phone != null) {
2700 return phone.getServiceState().getDataNetworkType();
2701 } else {
2702 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002706 }
Wink Saville36469e72014-06-11 15:17:00 -07002707 }
2708
Pengquan Meng0c05b502018-09-06 09:59:22 -07002709 @Override
2710 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002711 if (!isActiveSubscription(subId)) {
2712 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2713 }
2714
Pengquan Meng0c05b502018-09-06 09:59:22 -07002715 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2716 }
2717
Brad Ebinger4c460712018-10-01 10:40:55 -07002718 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002719 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2720 throws RemoteException {
2721 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2723 final long token = Binder.clearCallingIdentity();
2724 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002725 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002726 .addRegistrationCallbackForSubscription(c, subId);
2727 } finally {
2728 Binder.restoreCallingIdentity(token);
2729 }
2730 }
2731
2732 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002733 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2734 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002735 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2736 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002737 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002738 .removeRegistrationCallbackForSubscription(c, subId));
2739 }
2740
2741 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002742 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2743 throws RemoteException {
2744 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2746 final long token = Binder.clearCallingIdentity();
2747 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002748 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002749 .addCapabilitiesCallbackForSubscription(c, subId);
2750 } finally {
2751 Binder.restoreCallingIdentity(token);
2752 }
2753 }
2754
2755 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002756 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2757 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2759 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002760 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002761 .removeCapabilitiesCallbackForSubscription(c, subId));
2762 }
2763
2764 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002765 public boolean isCapable(int subId, int capability, int regTech) {
2766 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002767 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2768 final long token = Binder.clearCallingIdentity();
2769 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002770 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002771 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2772 } catch (ImsException e) {
2773 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2774 return false;
2775 } finally {
2776 Binder.restoreCallingIdentity(token);
2777 }
2778 }
2779
2780 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002781 public boolean isAvailable(int subId, int capability, int regTech) {
2782 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002783 final long token = Binder.clearCallingIdentity();
2784 try {
2785 Phone phone = getPhone(subId);
2786 if (phone == null) return false;
2787 return phone.isImsCapabilityAvailable(capability, regTech);
2788 } finally {
2789 Binder.restoreCallingIdentity(token);
2790 }
2791 }
2792
2793 @Override
2794 public boolean isAdvancedCallingSettingEnabled(int subId) {
2795 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2797 final long token = Binder.clearCallingIdentity();
2798 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002799 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002800 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2801 } finally {
2802 Binder.restoreCallingIdentity(token);
2803 }
2804 }
2805
2806 @Override
2807 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2809 "setAdvancedCallingSetting");
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002813 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002814 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
2818 }
2819
2820 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002821 public boolean isVtSettingEnabled(int subId) {
2822 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002826 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002827 getSlotIndexOrException(subId)).isVtEnabledByUser();
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
2830 }
2831 }
2832
2833 @Override
2834 public void setVtSetting(int subId, boolean isEnabled) {
2835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2836 "setVtSetting");
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002840 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002841 } finally {
2842 Binder.restoreCallingIdentity(identity);
2843 }
2844 }
2845
2846 @Override
2847 public boolean isVoWiFiSettingEnabled(int subId) {
2848 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002852 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002853 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
2856 }
2857 }
2858
2859 @Override
2860 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2862 "setVoWiFiSetting");
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002866 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
2870 }
2871
2872 @Override
2873 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2874 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002878 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002879 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2880 } finally {
2881 Binder.restoreCallingIdentity(identity);
2882 }
2883 }
2884
2885 @Override
2886 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2888 "setVoWiFiRoamingSetting");
2889 final long identity = Binder.clearCallingIdentity();
2890 try {
2891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002892 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002893 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2894 } finally {
2895 Binder.restoreCallingIdentity(identity);
2896 }
2897 }
2898
2899 @Override
2900 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2902 "setVoWiFiNonPersistent");
2903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002906 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002907 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
2910 }
2911 }
2912
2913 @Override
2914 public int getVoWiFiModeSetting(int subId) {
2915 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2916 final long identity = Binder.clearCallingIdentity();
2917 try {
2918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002919 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002920 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
2923 }
2924 }
2925
2926 @Override
2927 public void setVoWiFiModeSetting(int subId, int mode) {
2928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2929 "setVoWiFiModeSetting");
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002933 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002934 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
2938 }
2939
2940 @Override
2941 public int getVoWiFiRoamingModeSetting(int subId) {
2942 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2943 final long identity = Binder.clearCallingIdentity();
2944 try {
2945 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002946 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002947 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
2951 }
2952
2953 @Override
2954 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2956 "setVoWiFiRoamingModeSetting");
2957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002960 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002961 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 }
2966
2967 @Override
2968 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2970 "setRttCapabilityEnabled");
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002974 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002975 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
2979 }
2980
2981 @Override
2982 public boolean isTtyOverVolteEnabled(int subId) {
2983 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002987 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002988 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
2992 }
2993
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002994 @Override
2995 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2996 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003000 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003001 .getConfigInterface().addConfigCallback(callback);
3002 } catch (ImsException e) {
3003 throw new IllegalArgumentException(e.getMessage());
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
3007 }
3008
3009 @Override
3010 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3011 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003015 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003016 .getConfigInterface().removeConfigCallback(callback);
3017 } catch (ImsException e) {
3018 throw new IllegalArgumentException(e.getMessage());
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public int getImsProvisioningInt(int subId, int key) {
3026 enforceReadPrivilegedPermission("getImsProvisioningInt");
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003030 return ImsManager.getInstance(mApp,
3031 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003032 } catch (ImsException e) {
3033 throw new IllegalArgumentException(e.getMessage());
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 @Override
3040 public String getImsProvisioningString(int subId, int key) {
3041 enforceReadPrivilegedPermission("getImsProvisioningString");
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003045 return ImsManager.getInstance(mApp,
3046 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003047 } catch (ImsException e) {
3048 throw new IllegalArgumentException(e.getMessage());
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
3052 }
3053
3054 @Override
3055 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3057 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003058 final long identity = Binder.clearCallingIdentity();
3059 try {
3060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003061 return ImsManager.getInstance(mApp,
3062 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003063 } catch (ImsException e) {
3064 throw new IllegalArgumentException(e.getMessage());
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
3071 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3073 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003077 return ImsManager.getInstance(mApp,
3078 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003079 } catch (ImsException e) {
3080 throw new IllegalArgumentException(e.getMessage());
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
3084 }
3085
Brad Ebinger4c460712018-10-01 10:40:55 -07003086 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3087 int slotId = SubscriptionManager.getSlotIndex(subId);
3088 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3089 throw new IllegalArgumentException("Invalid Subscription Id.");
3090 }
3091 return slotId;
3092 }
3093
Wink Saville36469e72014-06-11 15:17:00 -07003094 /**
3095 * Returns the network type for a subId
3096 */
3097 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003098 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003100 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003101 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3102 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003103
Malcolm Chend965c8b2018-02-28 15:00:40 -08003104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 final Phone phone = getPhone(subId);
3107 if (phone != null) {
3108 return phone.getServiceState().getDataNetworkType();
3109 } else {
3110 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3111 }
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003115 }
3116
3117 /**
3118 * Returns the data network type
3119 */
3120 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003121 public int getDataNetworkType(String callingPackage) {
3122 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003123 }
3124
3125 /**
3126 * Returns the data network type for a subId
3127 */
3128 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003129 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003131 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003132 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3133 }
3134
Malcolm Chend965c8b2018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 final Phone phone = getPhone(subId);
3138 if (phone != null) {
3139 return phone.getServiceState().getDataNetworkType();
3140 } else {
3141 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3142 }
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146 }
3147
3148 /**
Wink Saville36469e72014-06-11 15:17:00 -07003149 * Returns the Voice network type for a subId
3150 */
3151 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003152 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003154 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3156 }
3157
Malcolm Chend965c8b2018-02-28 15:00:40 -08003158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 final Phone phone = getPhone(subId);
3161 if (phone != null) {
3162 return phone.getServiceState().getVoiceNetworkType();
3163 } else {
3164 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3165 }
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003169 }
3170
3171 /**
3172 * @return true if a ICC card is present
3173 */
3174 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003175 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003176 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3177 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003178 }
3179
3180 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003181 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003182 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003183 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003184 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = PhoneFactory.getPhone(slotIndex);
3188 if (phone != null) {
3189 return phone.getIccCard().hasIccCard();
3190 } else {
3191 return false;
3192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
3198 /**
3199 * Return if the current radio is LTE on CDMA. This
3200 * is a tri-state return value as for a period of time
3201 * the mode may be unknown.
3202 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003203 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003205 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003207 @Override
3208 public int getLteOnCdmaMode(String callingPackage) {
3209 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003210 }
3211
Sanket Padawe356d7632015-06-22 14:03:32 -07003212 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003213 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003215 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003216 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3217 }
3218
Malcolm Chend965c8b2018-02-28 15:00:40 -08003219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 final Phone phone = getPhone(subId);
3222 if (phone == null) {
3223 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3224 } else {
3225 return phone.getLteOnCdmaMode();
3226 }
3227 } finally {
3228 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003229 }
Wink Saville36469e72014-06-11 15:17:00 -07003230 }
3231
Wink Saville36469e72014-06-11 15:17:00 -07003232 /**
3233 * {@hide}
3234 * Returns Default subId, 0 in the case of single standby.
3235 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003236 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003237 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003238 }
3239
Shishir Agrawala9f32182016-04-12 12:00:16 -07003240 private int getSlotForDefaultSubscription() {
3241 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3242 }
3243
Wink Savilleb564aae2014-10-23 10:18:09 -07003244 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003245 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003246 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003247
Pengquan Meng466e2482018-09-21 15:54:48 -07003248 private boolean isActiveSubscription(int subId) {
3249 return mSubscriptionController.isActiveSubId(subId);
3250 }
3251
Ihab Awadf2177b72013-11-25 13:33:23 -08003252 /**
3253 * @see android.telephony.TelephonyManager.WifiCallingChoices
3254 */
3255 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003256 final long identity = Binder.clearCallingIdentity();
3257 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003258 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003259 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3260 getWhenToMakeWifiCallsDefaultPreference());
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
3263 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003264 }
3265
3266 /**
3267 * @see android.telephony.TelephonyManager.WifiCallingChoices
3268 */
3269 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003270 final long identity = Binder.clearCallingIdentity();
3271 try {
3272 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003273 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003274 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003278 }
3279
Sailesh Nepald1e68152013-12-12 19:08:02 -08003280 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003281 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003282 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003283 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003284
Shishir Agrawal566b7612013-10-28 14:41:00 -07003285 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003286 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3287 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3289 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003290 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003291
Malcolm Chend965c8b2018-02-28 15:00:40 -08003292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 if (TextUtils.equals(ISDR_AID, aid)) {
3295 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003296 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3297 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003298 if (bestComponent == null
3299 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3300 loge("The calling package is not allowed to access ISD-R.");
3301 throw new SecurityException(
3302 "The calling package is not allowed to access ISD-R.");
3303 }
Derek Tan740e1672017-06-27 14:56:27 -07003304 }
Derek Tan740e1672017-06-27 14:56:27 -07003305
Malcolm Chend965c8b2018-02-28 15:00:40 -08003306 if (DBG) {
3307 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3308 }
3309 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3310 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3311 if (DBG) log("iccOpenLogicalChannel: " + response);
3312 return response;
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003316 }
3317
3318 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003319 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3321 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003322
Malcolm Chend965c8b2018-02-28 15:00:40 -08003323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3326 if (channel < 0) {
3327 return false;
3328 }
3329 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3330 if (DBG) log("iccCloseLogicalChannel: " + success);
3331 return success;
3332 } finally {
3333 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003334 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003335 }
3336
3337 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003338 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003339 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3341 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003342
Malcolm Chend965c8b2018-02-28 15:00:40 -08003343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 if (DBG) {
3346 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3347 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3348 + p3 + " data=" + data);
3349 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003350
Malcolm Chend965c8b2018-02-28 15:00:40 -08003351 if (channel < 0) {
3352 return "";
3353 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003354
Malcolm Chend965c8b2018-02-28 15:00:40 -08003355 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3356 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3357 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003358
Malcolm Chend965c8b2018-02-28 15:00:40 -08003359 // Append the returned status code to the end of the response payload.
3360 String s = Integer.toHexString(
3361 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3362 if (response.payload != null) {
3363 s = IccUtils.bytesToHexString(response.payload) + s;
3364 }
3365 return s;
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003368 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003369 }
Jake Hambye994d462014-02-03 13:10:13 -08003370
Evan Charltonc66da362014-05-16 14:06:40 -07003371 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003372 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3373 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3375 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003376 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003377
Malcolm Chend965c8b2018-02-28 15:00:40 -08003378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3381 && TextUtils.equals(ISDR_AID, data)) {
3382 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003383 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3384 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003385 if (bestComponent == null
3386 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3387 loge("The calling package is not allowed to select ISD-R.");
3388 throw new SecurityException(
3389 "The calling package is not allowed to select ISD-R.");
3390 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003391 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003392
Malcolm Chend965c8b2018-02-28 15:00:40 -08003393 if (DBG) {
3394 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3395 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3396 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003397
Malcolm Chend965c8b2018-02-28 15:00:40 -08003398 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3399 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3400 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003401
Malcolm Chend965c8b2018-02-28 15:00:40 -08003402 // Append the returned status code to the end of the response payload.
3403 String s = Integer.toHexString(
3404 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3405 if (response.payload != null) {
3406 s = IccUtils.bytesToHexString(response.payload) + s;
3407 }
3408 return s;
3409 } finally {
3410 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003411 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003412 }
3413
3414 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003415 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003416 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3418 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003419
Malcolm Chend965c8b2018-02-28 15:00:40 -08003420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 if (DBG) {
3423 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3424 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3425 }
3426
3427 IccIoResult response =
3428 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3429 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3430 subId);
3431
3432 if (DBG) {
3433 log("Exchange SIM_IO [R]" + response);
3434 }
3435
3436 byte[] result = null;
3437 int length = 2;
3438 if (response.payload != null) {
3439 length = 2 + response.payload.length;
3440 result = new byte[length];
3441 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3442 } else {
3443 result = new byte[length];
3444 }
3445
3446 result[length - 1] = (byte) response.sw2;
3447 result[length - 2] = (byte) response.sw1;
3448 return result;
3449 } finally {
3450 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003451 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003452 }
3453
Nathan Haroldb3014052017-01-25 15:57:32 -08003454 /**
3455 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3456 * on a particular subscription
3457 */
sqianb6e41952018-03-12 14:54:01 -07003458 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3460 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3461 return null;
3462 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003463
3464 final long identity = Binder.clearCallingIdentity();
3465 try {
3466 if (appType != TelephonyManager.APPTYPE_USIM
3467 && appType != TelephonyManager.APPTYPE_SIM) {
3468 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3469 return null;
3470 }
3471 Object response = sendRequest(
3472 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3473 if (response instanceof String[]) {
3474 return (String[]) response;
3475 }
3476 // Response is an Exception of some kind,
3477 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003478 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003481 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003482 }
3483
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003484 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003485 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3487 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003488
Malcolm Chend965c8b2018-02-28 15:00:40 -08003489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3492 if (response.payload == null) {
3493 return "";
3494 }
Evan Charltonc66da362014-05-16 14:06:40 -07003495
Malcolm Chend965c8b2018-02-28 15:00:40 -08003496 // Append the returned status code to the end of the response payload.
3497 String s = Integer.toHexString(
3498 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3499 s = IccUtils.bytesToHexString(response.payload) + s;
3500 return s;
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
3503 }
Evan Charltonc66da362014-05-16 14:06:40 -07003504 }
3505
Jake Hambye994d462014-02-03 13:10:13 -08003506 /**
3507 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3508 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3509 *
3510 * @param itemID the ID of the item to read
3511 * @return the NV item as a String, or null on error.
3512 */
3513 @Override
3514 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003515 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3517 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003518
3519 final long identity = Binder.clearCallingIdentity();
3520 try {
3521 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003522 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003523 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3524 return value;
3525 } finally {
3526 Binder.restoreCallingIdentity(identity);
3527 }
Jake Hambye994d462014-02-03 13:10:13 -08003528 }
3529
3530 /**
3531 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3532 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3533 *
3534 * @param itemID the ID of the item to read
3535 * @param itemValue the value to write, as a String
3536 * @return true on success; false on any failure
3537 */
3538 @Override
3539 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003540 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3542 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3547 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003548 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003549 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3550 return success;
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
Jake Hambye994d462014-02-03 13:10:13 -08003554 }
3555
3556 /**
3557 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3558 * Used for device configuration by some CDMA operators.
3559 *
3560 * @param preferredRoamingList byte array containing the new PRL
3561 * @return true on success; false on any failure
3562 */
3563 @Override
3564 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3566 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003567
3568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3571 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3572 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3573 return success;
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
3576 }
Jake Hambye994d462014-02-03 13:10:13 -08003577 }
3578
3579 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003580 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003581 * Used for device configuration by some CDMA operators.
3582 *
chen xu1cc0abe2018-10-26 17:39:23 -07003583 * @param slotIndex - device slot.
3584 *
Jake Hambye994d462014-02-03 13:10:13 -08003585 * @return true on success; false on any failure
3586 */
3587 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003588 public boolean resetModemConfig(int slotIndex) {
3589 Phone phone = PhoneFactory.getPhone(slotIndex);
3590 if (phone != null) {
3591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3592 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003593
chen xu1cc0abe2018-10-26 17:39:23 -07003594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3597 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3598 return success;
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
3601 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003602 }
chen xu1cc0abe2018-10-26 17:39:23 -07003603 return false;
3604 }
3605
3606 /**
3607 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3608 *
3609 * @param slotIndex - device slot.
3610 *
3611 * @return true on success; false on any failure
3612 */
3613 @Override
3614 public boolean rebootModem(int slotIndex) {
3615 Phone phone = PhoneFactory.getPhone(slotIndex);
3616 if (phone != null) {
3617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3618 mApp, phone.getSubId(), "rebootModem");
3619
3620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3623 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3624 return success;
3625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
3628 }
3629 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003630 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003631
Svet Ganovb320e182015-04-16 12:30:10 -07003632 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003633 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003635 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003636 return new String[0];
3637 }
3638
Malcolm Chend965c8b2018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003641 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
Wink Saville36469e72014-06-11 15:17:00 -07003645 }
3646
Brad Ebinger51f743a2017-01-23 13:50:20 -08003647 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003648 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3649 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003650 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003651 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003652 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003653
3654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 PhoneFactory.getImsResolver().enableIms(slotId);
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003660 }
3661
3662 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003663 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3664 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003665 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003666 public void disableIms(int slotId) {
3667 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003668
3669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 PhoneFactory.getImsResolver().disableIms(slotId);
3672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003675 }
3676
3677 /**
3678 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3679 * feature or {@link null} if the service is not available. If the feature is available, the
3680 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3681 */
3682 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003683 IImsServiceFeatureCallback callback) {
3684 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003685
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003692 }
3693
3694 /**
3695 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3696 * feature during emergency calling or {@link null} if the service is not available. If the
3697 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3698 * listener for feature updates.
3699 */
3700 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3701 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003702
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003709 }
3710
Brad Ebinger5f64b052017-12-14 14:26:15 -08003711 /**
3712 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3713 * specified.
3714 */
3715 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3716 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003717
3718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003724 }
3725
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003726 /**
3727 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3728 * specified.
3729 */
3730 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3731 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003732
3733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003739 }
3740
Brad Ebinger884c07b2018-02-15 16:17:40 -08003741 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003742 * Sets the ImsService Package Name that Telephony will bind to.
3743 *
3744 * @param slotId the slot ID that the ImsService should bind for.
3745 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3746 * ImsService is the device default ImsService.
3747 * @param packageName The package name of the application that contains the ImsService to bind
3748 * to.
3749 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3750 * @hide
3751 */
3752 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003753 int[] subIds = SubscriptionManager.getSubId(slotId);
3754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3755 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3756 "setImsService");
3757
Malcolm Chend965c8b2018-02-28 15:00:40 -08003758 final long identity = Binder.clearCallingIdentity();
3759 try {
3760 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3761 isCarrierImsService, packageName);
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003765 }
3766
3767 /**
3768 * Return the ImsService configuration.
3769 *
3770 * @param slotId The slot that the ImsService is associated with.
3771 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3772 * the device default.
3773 * @return the package name of the ImsService configuration.
3774 */
3775 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003776 int[] subIds = SubscriptionManager.getSubId(slotId);
3777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3778 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3779 "getImsService");
3780
Malcolm Chend965c8b2018-02-28 15:00:40 -08003781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3784 isCarrierImsService);
3785 } finally {
3786 Binder.restoreCallingIdentity(identity);
3787 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003788 }
3789
Wink Saville36469e72014-06-11 15:17:00 -07003790 public void setImsRegistrationState(boolean registered) {
3791 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003792
3793 final long identity = Binder.clearCallingIdentity();
3794 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003795 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003796 } finally {
3797 Binder.restoreCallingIdentity(identity);
3798 }
Wink Saville36469e72014-06-11 15:17:00 -07003799 }
3800
3801 /**
Stuart Scott54788802015-03-30 13:18:01 -07003802 * Set the network selection mode to automatic.
3803 *
3804 */
3805 @Override
3806 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3808 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003809
Pengquan Meng466e2482018-09-21 15:54:48 -07003810 if (!isActiveSubscription(subId)) {
3811 return;
3812 }
3813
Malcolm Chend965c8b2018-02-28 15:00:40 -08003814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3817 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
Stuart Scott54788802015-03-30 13:18:01 -07003821 }
3822
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003823 /**
3824 * Ask the radio to connect to the input network and change selection mode to manual.
3825 *
3826 * @param subId the id of the subscription.
3827 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3828 * the operator to attach to.
3829 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3830 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3831 * normal network selection next time.
3832 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003833 */
3834 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003835 public boolean setNetworkSelectionModeManual(
3836 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3838 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003839
3840 if (!isActiveSubscription(subId)) {
3841 return false;
3842 }
3843
Malcolm Chend965c8b2018-02-28 15:00:40 -08003844 final long identity = Binder.clearCallingIdentity();
3845 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003846 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003847 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003848 if (DBG) {
3849 log("setNetworkSelectionModeManual: subId: " + subId
3850 + " operator: " + operatorInfo);
3851 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003852 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
3855 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003856 }
3857
3858 /**
3859 * Scans for available networks.
3860 */
3861 @Override
3862 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3864 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003865
Pengquan Meng0c05b502018-09-06 09:59:22 -07003866 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003867 try {
3868 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003869 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003870 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003874 }
3875
3876 /**
yinxub1bed742017-04-17 11:45:04 -07003877 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003878 *
yinxub1bed742017-04-17 11:45:04 -07003879 * @param subId id of the subscription
3880 * @param request contains the radio access networks with bands/channels to scan
3881 * @param messenger callback messenger for scan results or errors
3882 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003883 * @return the id of the requested scan which can be used to stop the scan.
3884 */
3885 @Override
3886 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3887 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3889 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003890
3891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 return mNetworkScanRequestTracker.startNetworkScan(
3894 request, messenger, binder, getPhone(subId));
3895 } finally {
3896 Binder.restoreCallingIdentity(identity);
3897 }
yinxu504e1392017-04-12 16:03:22 -07003898 }
3899
3900 /**
3901 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003902 *
3903 * @param subId id of the subscription
3904 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003905 */
3906 @Override
3907 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3909 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003910
3911 final long identity = Binder.clearCallingIdentity();
3912 try {
3913 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3914 } finally {
3915 Binder.restoreCallingIdentity(identity);
3916 }
yinxu504e1392017-04-12 16:03:22 -07003917 }
3918
3919 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003920 * Get the calculated preferred network type.
3921 * Used for debugging incorrect network type.
3922 *
3923 * @return the preferred network type, defined in RILConstants.java.
3924 */
3925 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003926 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003927 final Phone defaultPhone = getDefaultPhone();
3928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3929 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003930 return RILConstants.PREFERRED_NETWORK_MODE;
3931 }
3932
Malcolm Chend965c8b2018-02-28 15:00:40 -08003933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003936 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
Junda Liu84d15a22014-07-02 11:21:04 -07003940 }
3941
3942 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003943 * Get the preferred network type.
3944 * Used for device configuration by some CDMA operators.
3945 *
3946 * @return the preferred network type, defined in RILConstants.java.
3947 */
3948 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003949 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3951 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003952
3953 final long identity = Binder.clearCallingIdentity();
3954 try {
3955 if (DBG) log("getPreferredNetworkType");
3956 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3957 int networkType = (result != null ? result[0] : -1);
3958 if (DBG) log("getPreferredNetworkType: " + networkType);
3959 return networkType;
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
3962 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003963 }
3964
3965 /**
3966 * Set the preferred network type.
3967 * Used for device configuration by some CDMA operators.
3968 *
3969 * @param networkType the preferred network type, defined in RILConstants.java.
3970 * @return true on success; false on any failure.
3971 */
3972 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003973 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3975 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003976
3977 final long identity = Binder.clearCallingIdentity();
3978 try {
3979 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3980 Boolean success = (Boolean) sendRequest(
3981 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3982 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3983 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003984 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003985 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3986 }
3987 return success;
3988 } finally {
3989 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003990 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003991 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003992
3993 /**
Junda Liu475951f2014-11-07 16:45:03 -08003994 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003995 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003996 * tethering.
3997 *
3998 * @return 0: Not required. 1: required. 2: Not set.
3999 * @hide
4000 */
4001 @Override
4002 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004003 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004004
4005 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004006 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004007 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004008 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004009 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004010 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004011 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004012 dunRequired = 1;
4013 }
4014 return dunRequired;
4015 } finally {
4016 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004017 }
Junda Liu475951f2014-11-07 16:45:03 -08004018 }
4019
4020 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004021 * Set mobile data enabled
4022 * Used by the user through settings etc to turn on/off mobile data
4023 *
4024 * @param enable {@code true} turn turn data on, else {@code false}
4025 */
4026 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004027 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4029 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004030
4031 final long identity = Binder.clearCallingIdentity();
4032 try {
4033 int phoneId = mSubscriptionController.getPhoneId(subId);
4034 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4035 Phone phone = PhoneFactory.getPhone(phoneId);
4036 if (phone != null) {
4037 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4038 phone.setUserDataEnabled(enable);
4039 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004040 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004041 }
4042 } finally {
4043 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004044 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004045 }
4046
4047 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004048 * Get the user enabled state of Mobile Data.
4049 *
4050 * TODO: remove and use isUserDataEnabled.
4051 * This can't be removed now because some vendor codes
4052 * calls through ITelephony directly while they should
4053 * use TelephonyManager.
4054 *
4055 * @return true on enabled
4056 */
4057 @Override
4058 public boolean getDataEnabled(int subId) {
4059 return isUserDataEnabled(subId);
4060 }
4061
4062 /**
4063 * Get whether mobile data is enabled per user setting.
4064 *
4065 * There are other factors deciding whether mobile data is actually enabled, but they are
4066 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004067 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004068 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004069 *
4070 * @return {@code true} if data is enabled else {@code false}
4071 */
4072 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004073 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004074 try {
4075 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4076 null);
4077 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4079 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004080 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004081
4082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 int phoneId = mSubscriptionController.getPhoneId(subId);
4085 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4086 Phone phone = PhoneFactory.getPhone(phoneId);
4087 if (phone != null) {
4088 boolean retVal = phone.isUserDataEnabled();
4089 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4090 return retVal;
4091 } else {
4092 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4093 return false;
4094 }
4095 } finally {
4096 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004097 }
4098 }
4099
4100 /**
4101 * Get whether mobile data is enabled.
4102 *
4103 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4104 * whether mobile data is actually enabled.
4105 *
4106 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4107 *
4108 * @return {@code true} if data is enabled else {@code false}
4109 */
4110 @Override
4111 public boolean isDataEnabled(int subId) {
4112 try {
4113 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4114 null);
4115 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4117 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004118 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004119
4120 final long identity = Binder.clearCallingIdentity();
4121 try {
4122 int phoneId = mSubscriptionController.getPhoneId(subId);
4123 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4124 Phone phone = PhoneFactory.getPhone(phoneId);
4125 if (phone != null) {
4126 boolean retVal = phone.isDataEnabled();
4127 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4128 return retVal;
4129 } else {
4130 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4131 return false;
4132 }
4133 } finally {
4134 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004135 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004136 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004137
4138 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004139 public int getCarrierPrivilegeStatus(int subId) {
4140 final Phone phone = getPhone(subId);
4141 if (phone == null) {
4142 loge("getCarrierPrivilegeStatus: Invalid subId");
4143 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4144 }
4145 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004146 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004147 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004148 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4149 }
4150 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004151 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004152 }
Junda Liu29340342014-07-10 15:23:27 -07004153
4154 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004155 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4156 final Phone phone = getPhone(subId);
4157 if (phone == null) {
4158 loge("getCarrierPrivilegeStatus: Invalid subId");
4159 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4160 }
4161 UiccProfile profile =
4162 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4163 if (profile == null) {
4164 loge("getCarrierPrivilegeStatus: No UICC");
4165 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4166 }
4167 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4168 }
4169
4170 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004171 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004172 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004173 if (TextUtils.isEmpty(pkgName))
4174 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004175 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004176 if (card == null) {
4177 loge("checkCarrierPrivilegesForPackage: No UICC");
4178 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4179 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004180 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4181 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004182 }
4183
4184 @Override
4185 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004186 if (TextUtils.isEmpty(pkgName))
4187 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004188 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4189 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4190 UiccCard card = UiccController.getInstance().getUiccCard(i);
4191 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004192 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004193 continue;
4194 }
4195
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004196 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004197 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4198 break;
4199 }
4200 }
4201
4202 return result;
Junda Liu29340342014-07-10 15:23:27 -07004203 }
Derek Tan89e89d42014-07-08 17:00:10 -07004204
4205 @Override
Junda Liue64de782015-04-16 17:19:16 -07004206 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4207 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4208 loge("phoneId " + phoneId + " is not valid.");
4209 return null;
4210 }
4211 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004212 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004213 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004214 return null ;
4215 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004216 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004217 }
4218
Amith Yamasani6e118872016-02-19 12:53:51 -08004219 @Override
4220 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004221 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004222 List<String> privilegedPackages = new ArrayList<>();
4223 List<PackageInfo> packages = null;
4224 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4225 UiccCard card = UiccController.getInstance().getUiccCard(i);
4226 if (card == null) {
4227 // No UICC in that slot.
4228 continue;
4229 }
4230 if (card.hasCarrierPrivilegeRules()) {
4231 if (packages == null) {
4232 // Only check packages in user 0 for now
4233 packages = pm.getInstalledPackagesAsUser(
4234 PackageManager.MATCH_DISABLED_COMPONENTS
4235 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4236 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4237 }
4238 for (int p = packages.size() - 1; p >= 0; p--) {
4239 PackageInfo pkgInfo = packages.get(p);
4240 if (pkgInfo != null && pkgInfo.packageName != null
4241 && card.getCarrierPrivilegeStatus(pkgInfo)
4242 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4243 privilegedPackages.add(pkgInfo.packageName);
4244 }
4245 }
4246 }
4247 }
4248 return privilegedPackages;
4249 }
4250
Wink Savilleb564aae2014-10-23 10:18:09 -07004251 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004252 final Phone phone = getPhone(subId);
4253 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004254 if (card == null) {
4255 loge("getIccId: No UICC");
4256 return null;
4257 }
4258 String iccId = card.getIccId();
4259 if (TextUtils.isEmpty(iccId)) {
4260 loge("getIccId: ICC ID is null or empty.");
4261 return null;
4262 }
4263 return iccId;
4264 }
4265
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004266 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004267 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4268 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004269 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4270 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004271
Malcolm Chend965c8b2018-02-28 15:00:40 -08004272 final long identity = Binder.clearCallingIdentity();
4273 try {
4274 final String iccId = getIccId(subId);
4275 final Phone phone = getPhone(subId);
4276 if (phone == null) {
4277 return false;
4278 }
4279 final String subscriberId = phone.getSubscriberId();
4280
4281 if (DBG_MERGE) {
4282 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4283 + subscriberId + " to " + number);
4284 }
4285
4286 if (TextUtils.isEmpty(iccId)) {
4287 return false;
4288 }
4289
4290 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4291
4292 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4293 if (alphaTag == null) {
4294 editor.remove(alphaTagPrefKey);
4295 } else {
4296 editor.putString(alphaTagPrefKey, alphaTag);
4297 }
4298
4299 // Record both the line number and IMSI for this ICCID, since we need to
4300 // track all merged IMSIs based on line number
4301 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4302 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4303 if (number == null) {
4304 editor.remove(numberPrefKey);
4305 editor.remove(subscriberPrefKey);
4306 } else {
4307 editor.putString(numberPrefKey, number);
4308 editor.putString(subscriberPrefKey, subscriberId);
4309 }
4310
4311 editor.commit();
4312 return true;
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004315 }
Derek Tan7226c842014-07-02 17:42:23 -07004316 }
4317
4318 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004319 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004320 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004322 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004323 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004324 return null;
4325 }
Derek Tan97ebb422014-09-05 16:55:38 -07004326
Malcolm Chend965c8b2018-02-28 15:00:40 -08004327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 String iccId = getIccId(subId);
4330 if (iccId != null) {
4331 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4332 if (DBG_MERGE) {
4333 log("getLine1NumberForDisplay returning "
4334 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4335 }
4336 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004337 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004338 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4339 return null;
4340 } finally {
4341 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004342 }
Derek Tan7226c842014-07-02 17:42:23 -07004343 }
4344
4345 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004346 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004348 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004349 return null;
4350 }
Derek Tan97ebb422014-09-05 16:55:38 -07004351
Malcolm Chend965c8b2018-02-28 15:00:40 -08004352 final long identity = Binder.clearCallingIdentity();
4353 try {
4354 String iccId = getIccId(subId);
4355 if (iccId != null) {
4356 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4357 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4358 }
4359 return null;
4360 } finally {
4361 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004362 }
Derek Tan7226c842014-07-02 17:42:23 -07004363 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004364
4365 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004366 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004367 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4368 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004370 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4371 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004372 return null;
4373 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004374
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004375 final long identity = Binder.clearCallingIdentity();
4376 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004377 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004378 final TelephonyManager tele = TelephonyManager.from(context);
4379 final SubscriptionManager sub = SubscriptionManager.from(context);
4380
4381 // Figure out what subscribers are currently active
4382 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4383 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4384 // the process, where TelephonyManager was instantiated.
4385 // Otherwise AppOps check will fail.
4386
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004387 final int[] subIds = sub.getActiveSubscriptionIdList();
4388 for (int subId : subIds) {
4389 activeSubscriberIds.add(tele.getSubscriberId(subId));
4390 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004391
4392 // First pass, find a number override for an active subscriber
4393 String mergeNumber = null;
4394 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4395 for (String key : prefs.keySet()) {
4396 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4397 final String subscriberId = (String) prefs.get(key);
4398 if (activeSubscriberIds.contains(subscriberId)) {
4399 final String iccId = key.substring(
4400 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4401 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4402 mergeNumber = (String) prefs.get(numberKey);
4403 if (DBG_MERGE) {
4404 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4405 + " for active subscriber " + subscriberId);
4406 }
4407 if (!TextUtils.isEmpty(mergeNumber)) {
4408 break;
4409 }
4410 }
4411 }
4412 }
4413
4414 // Shortcut when no active merged subscribers
4415 if (TextUtils.isEmpty(mergeNumber)) {
4416 return null;
4417 }
4418
4419 // Second pass, find all subscribers under that line override
4420 final ArraySet<String> result = new ArraySet<>();
4421 for (String key : prefs.keySet()) {
4422 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4423 final String number = (String) prefs.get(key);
4424 if (mergeNumber.equals(number)) {
4425 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4426 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4427 final String subscriberId = (String) prefs.get(subscriberKey);
4428 if (!TextUtils.isEmpty(subscriberId)) {
4429 result.add(subscriberId);
4430 }
4431 }
4432 }
4433 }
4434
4435 final String[] resultArray = result.toArray(new String[result.size()]);
4436 Arrays.sort(resultArray);
4437 if (DBG_MERGE) {
4438 Slog.d(LOG_TAG,
4439 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4440 }
4441 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004442 } finally {
4443 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004444 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004445 }
4446
4447 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004448 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004449 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4450 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004451
4452 final long identity = Binder.clearCallingIdentity();
4453 try {
4454 final Phone phone = getPhone(subId);
4455 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004459 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004460
4461 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004462 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004463 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4464 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004465 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004466
4467 final long identity = Binder.clearCallingIdentity();
4468 try {
4469 final Phone phone = getPhone(subId);
4470 if (phone == null) {
4471 return false;
4472 }
4473 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4474 cdmaNonRoamingList);
4475 } finally {
4476 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004477 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004478 }
4479
4480 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004481 @Deprecated
4482 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4483 enforceModifyPermission();
4484
4485 int returnValue = 0;
4486 try {
vagdevie435a3e2018-08-15 16:01:53 -07004487 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004488 if(result.exception == null) {
4489 if (result.result != null) {
4490 byte[] responseData = (byte[])(result.result);
4491 if(responseData.length > oemResp.length) {
4492 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4493 responseData.length + "bytes. Buffer Size is " +
4494 oemResp.length + "bytes.");
4495 }
4496 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4497 returnValue = responseData.length;
4498 }
4499 } else {
4500 CommandException ex = (CommandException) result.exception;
4501 returnValue = ex.getCommandError().ordinal();
4502 if(returnValue > 0) returnValue *= -1;
4503 }
4504 } catch (RuntimeException e) {
4505 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4506 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4507 if(returnValue > 0) returnValue *= -1;
4508 }
4509
4510 return returnValue;
4511 }
4512
4513 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004514 public void setRadioCapability(RadioAccessFamily[] rafs) {
4515 try {
4516 ProxyController.getInstance().setRadioCapability(rafs);
4517 } catch (RuntimeException e) {
4518 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4519 }
4520 }
4521
4522 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004523 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004524 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004525 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004526 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004527 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004528 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004529 final long identity = Binder.clearCallingIdentity();
4530 try {
chen xufeeed752018-10-26 14:17:57 -07004531 TelephonyPermissions
4532 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4533 mApp, phone.getSubId(), "getRadioAccessFamily");
4534 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
chen xufeeed752018-10-26 14:17:57 -07004538 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004539 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004540
4541 @Override
4542 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004543 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004544 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004545
4546 final long identity = Binder.clearCallingIdentity();
4547 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004548 ImsManager.getInstance(defaultPhone.getContext(),
4549 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004553 }
4554
4555 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004556 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004557 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004559 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004560 return false;
4561 }
Svet Ganovb320e182015-04-16 12:30:10 -07004562
Malcolm Chend965c8b2018-02-28 15:00:40 -08004563 final long identity = Binder.clearCallingIdentity();
4564 try {
4565 // Check the user preference and the system-level IMS setting. Even if the user has
4566 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4567 // In the long run, we may instead need to check if there exists a connection service
4568 // which can support video calling.
4569 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004570 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004571 return imsManager.isVtEnabledByPlatform()
4572 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4573 && imsManager.isVtEnabledByUser();
4574 } finally {
4575 Binder.restoreCallingIdentity(identity);
4576 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004577 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004578
Andrew Leea1239f22015-03-02 17:44:07 -08004579 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004580 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4582 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4583 return false;
4584 }
4585
4586 final long identity = Binder.clearCallingIdentity();
4587 try {
4588 CarrierConfigManager configManager =
4589 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004590 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004591 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4592 } finally {
4593 Binder.restoreCallingIdentity(identity);
4594 }
Andrew Leea1239f22015-03-02 17:44:07 -08004595 }
4596
4597 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004598 public boolean isWorldPhone(int subId, String callingPackage) {
4599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4600 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4601 return false;
4602 }
4603
4604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 CarrierConfigManager configManager =
4607 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004608 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004609 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4610 } finally {
4611 Binder.restoreCallingIdentity(identity);
4612 }
Andrew Leea1239f22015-03-02 17:44:07 -08004613 }
4614
Andrew Lee9431b832015-03-09 18:46:45 -07004615 @Override
4616 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004617 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004618 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004619 }
4620
4621 @Override
4622 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004623 final long identity = Binder.clearCallingIdentity();
4624 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004625 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004626 } finally {
4627 Binder.restoreCallingIdentity(identity);
4628 }
Andrew Lee9431b832015-03-09 18:46:45 -07004629 }
4630
Hall Liuf6668912018-10-31 17:05:23 -07004631 /**
4632 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4633 * support for the feature and device firmware support.
4634 *
4635 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4636 */
4637 @Override
4638 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004639 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004640 final Phone phone = getPhone(subscriptionId);
4641 if (phone == null) {
4642 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4643 return false;
4644 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004645 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004646 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004647 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4648 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004649 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004650 return isCarrierSupported && isDeviceSupported;
4651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
Hall Liu98187582018-01-22 19:15:32 -08004654 }
4655
Hall Liuf6668912018-10-31 17:05:23 -07004656 /**
4657 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4658 * both also support RTT.
4659 */
4660 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004661 final long identity = Binder.clearCallingIdentity();
4662 try {
Hall Liuf6668912018-10-31 17:05:23 -07004663 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004664 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004668 }
4669
Sanket Padawe7310cc72015-01-14 09:53:20 -08004670 /**
4671 * Returns the unique device ID of phone, for example, the IMEI for
4672 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4673 *
4674 * <p>Requires Permission:
4675 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4676 */
4677 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004678 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004679 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004680 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004681 return null;
4682 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004683 int subId = phone.getSubId();
4684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4685 mApp, subId, callingPackage, "getDeviceId")) {
4686 return null;
4687 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004688
4689 final long identity = Binder.clearCallingIdentity();
4690 try {
4691 return phone.getDeviceId();
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
4694 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004695 }
4696
Ping Sunc67b7c22016-03-02 19:16:45 +08004697 /**
4698 * {@hide}
4699 * Returns the IMS Registration Status on a particular subid
4700 *
4701 * @param subId
4702 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004703 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004704 Phone phone = getPhone(subId);
4705 if (phone != null) {
4706 return phone.isImsRegistered();
4707 } else {
4708 return false;
4709 }
4710 }
4711
Santos Cordon7a1885b2015-02-03 11:15:19 -08004712 @Override
4713 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004714 final long identity = Binder.clearCallingIdentity();
4715 try {
4716 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004720 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004721
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004722 /**
4723 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004724 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004725 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004726 final long identity = Binder.clearCallingIdentity();
4727 try {
4728 Phone phone = getPhone(subId);
4729 if (phone != null) {
4730 return phone.isWifiCallingEnabled();
4731 } else {
4732 return false;
4733 }
4734 } finally {
4735 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004736 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004737 }
4738
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004739 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004740 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004741 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004742 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004743 final long identity = Binder.clearCallingIdentity();
4744 try {
4745 Phone phone = getPhone(subId);
4746 if (phone != null) {
4747 return phone.isVideoEnabled();
4748 } else {
4749 return false;
4750 }
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004753 }
4754 }
4755
4756 /**
4757 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4758 * defined in {@link ImsRegistrationImplBase}.
4759 */
4760 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004761 final long identity = Binder.clearCallingIdentity();
4762 try {
4763 Phone phone = getPhone(subId);
4764 if (phone != null) {
4765 return phone.getImsRegistrationTech();
4766 } else {
4767 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4768 }
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004771 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004772 }
4773
Stuart Scott8eef64f2015-04-08 15:13:54 -07004774 @Override
4775 public void factoryReset(int subId) {
4776 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004777 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4778 return;
4779 }
4780
Svet Ganovcc087f82015-05-12 20:35:54 -07004781 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004782
Svet Ganovcc087f82015-05-12 20:35:54 -07004783 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004784 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4785 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004786 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004787 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004788 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004789 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4790 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004791 }
4792 } finally {
4793 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004794 }
4795 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004796
4797 @Override
4798 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004799 final long identity = Binder.clearCallingIdentity();
4800 try {
4801 // We query all subscriptions instead of just the active ones, because
4802 // this might be called early on in the provisioning flow when the
4803 // subscriptions potentially aren't active yet.
4804 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4805 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004806 return null;
4807 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004808
Malcolm Chend965c8b2018-02-28 15:00:40 -08004809 // This function may be called very early, say, from the setup wizard, at
4810 // which point we won't have a default subscription set. If that's the case
4811 // we just choose the first, which will be valid in "most cases".
4812 final int defaultSubId = getDefaultSubscription();
4813 SubscriptionInfo info = null;
4814 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4815 info = slist.get(0);
4816 } else {
4817 for (SubscriptionInfo item : slist) {
4818 if (item.getSubscriptionId() == defaultSubId) {
4819 info = item;
4820 break;
4821 }
4822 }
4823
4824 if (info == null) {
4825 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004826 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004827 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004828
Malcolm Chend965c8b2018-02-28 15:00:40 -08004829 // Try and fetch the locale from the carrier properties or from the SIM language
4830 // preferences (EF-PL and EF-LI)...
4831 final int mcc = info.getMcc();
4832 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4833 String simLanguage = null;
4834 if (defaultPhone != null) {
4835 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4836 if (localeFromDefaultSim != null) {
4837 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4838 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4839 return localeFromDefaultSim.toLanguageTag();
4840 } else {
4841 simLanguage = localeFromDefaultSim.getLanguage();
4842 }
4843 }
4844 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004845
Malcolm Chend965c8b2018-02-28 15:00:40 -08004846 // The SIM language preferences only store a language (e.g. fr = French), not an
4847 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4848 // the SIM and carrier preferences does not include a country we add the country
4849 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004850 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004851 if (mccLocale != null) {
4852 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4853 return mccLocale.toLanguageTag();
4854 }
4855
4856 if (DBG) log("No locale found - returning null");
4857 return null;
4858 } finally {
4859 Binder.restoreCallingIdentity(identity);
4860 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004861 }
4862
4863 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004864 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004865 }
4866
Malcolm Chend965c8b2018-02-28 15:00:40 -08004867 /**
4868 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4869 */
4870 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004871 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004872 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004873
Chenjie Yu1ba97252018-01-11 18:16:20 -08004874 private final ModemActivityInfo mLastModemActivityInfo =
4875 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4876
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004877 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004878 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4879 * representing the state of the modem.
4880 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004881 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4882 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004883 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004884 */
4885 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004886 public void requestModemActivityInfo(ResultReceiver result) {
4887 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004889
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 ModemActivityInfo ret = null;
4893 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004894 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4895 CMD_GET_MODEM_ACTIVITY_INFO,
4896 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004897 if (isModemActivityInfoValid(info)) {
4898 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4899 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4900 mergedTxTimeMs[i] =
4901 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4902 }
4903 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4904 mLastModemActivityInfo.setSleepTimeMillis(
4905 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4906 mLastModemActivityInfo.setIdleTimeMillis(
4907 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4908 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4909 mLastModemActivityInfo.setRxTimeMillis(
4910 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4911 mLastModemActivityInfo.setEnergyUsed(
4912 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004913 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004914 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4915 mLastModemActivityInfo.getSleepTimeMillis(),
4916 mLastModemActivityInfo.getIdleTimeMillis(),
4917 mLastModemActivityInfo.getTxTimeMillis(),
4918 mLastModemActivityInfo.getRxTimeMillis(),
4919 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004920 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004921 Bundle bundle = new Bundle();
4922 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4923 result.send(0, bundle);
4924 } finally {
4925 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004926 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004927 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004928
Siddharth Rayf5d29552018-06-17 15:02:38 -07004929 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4930 // less than total activity duration.
4931 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4932 if (info == null) {
4933 return false;
4934 }
4935 int activityDurationMs =
4936 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4937 int totalTxTimeMs = 0;
4938 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4939 totalTxTimeMs += info.getTxTimeMillis()[i];
4940 }
4941 return (info.isValid()
4942 && (info.getSleepTimeMillis() <= activityDurationMs)
4943 && (info.getIdleTimeMillis() <= activityDurationMs)
4944 && (info.getRxTimeMillis() <= activityDurationMs)
4945 && (totalTxTimeMs <= activityDurationMs));
4946 }
4947
Jack Yu85bd38a2015-11-09 11:34:32 -08004948 /**
4949 * {@hide}
4950 * Returns the service state information on specified subscription.
4951 */
4952 @Override
4953 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004955 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004956 return null;
4957 }
4958
Malcolm Chend965c8b2018-02-28 15:00:40 -08004959 final long identity = Binder.clearCallingIdentity();
4960 try {
4961 final Phone phone = getPhone(subId);
4962 if (phone == null) {
4963 return null;
4964 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004965
Malcolm Chend965c8b2018-02-28 15:00:40 -08004966 return phone.getServiceState();
4967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004970 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004971
4972 /**
4973 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4974 *
4975 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4976 * voicemail ringtone.
4977 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4978 * PhoneAccount.
4979 */
4980 @Override
4981 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004982 final long identity = Binder.clearCallingIdentity();
4983 try {
4984 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4985 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004986 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004987 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004988
Malcolm Chend965c8b2018-02-28 15:00:40 -08004989 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004993 }
4994
4995 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004996 * Sets the per-account voicemail ringtone.
4997 *
4998 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4999 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5000 *
5001 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5002 * voicemail ringtone.
5003 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5004 * PhoneAccount.
5005 */
5006 @Override
5007 public void setVoicemailRingtoneUri(String callingPackage,
5008 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005009 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005010 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5011 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005012 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5014 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5015 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005016 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005017
5018 final long identity = Binder.clearCallingIdentity();
5019 try {
5020 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5021 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005022 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005023 }
5024 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005027 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005028 }
5029
5030 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005031 * Returns whether vibration is set for voicemail notification in Phone settings.
5032 *
5033 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5034 * voicemail vibration setting.
5035 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5036 */
5037 @Override
5038 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005039 final long identity = Binder.clearCallingIdentity();
5040 try {
5041 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5042 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005043 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005044 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005045
Malcolm Chend965c8b2018-02-28 15:00:40 -08005046 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005050 }
5051
Youhan Wange64578a2016-05-02 15:32:42 -07005052 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005053 * Sets the per-account voicemail vibration.
5054 *
5055 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5056 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5057 *
5058 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5059 * voicemail vibration setting.
5060 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5061 * specific PhoneAccount.
5062 */
5063 @Override
5064 public void setVoicemailVibrationEnabled(String callingPackage,
5065 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005066 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005067 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5068 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005069 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5071 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5072 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005073 }
5074
Malcolm Chend965c8b2018-02-28 15:00:40 -08005075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5078 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005079 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005080 }
5081 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5082 } finally {
5083 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005084 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005085 }
5086
5087 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005088 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5089 *
5090 * @throws SecurityException if the caller does not have the required permission
5091 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005092 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005093 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005094 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005095 }
5096
5097 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005098 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5099 * permission.
5100 *
5101 * @throws SecurityException if the caller does not have the required permission
5102 */
5103 private void enforceSendSmsPermission() {
5104 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5105 }
5106
5107 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005108 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005109 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005110 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005111 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005112 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005116 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005117 if (componentName == null) {
5118 throw new SecurityException(
5119 "Caller not current active visual voicemail package[null]");
5120 }
5121 String vvmPackage = componentName.getPackageName();
5122 if (!callingPackage.equals(vvmPackage)) {
5123 throw new SecurityException("Caller not current active visual voicemail package["
5124 + vvmPackage + "]");
5125 }
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005128 }
5129 }
5130
5131 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005132 * Return the application ID for the app type.
5133 *
5134 * @param subId the subscription ID that this request applies to.
5135 * @param appType the uicc app type.
5136 * @return Application ID for specificied app type, or null if no uicc.
5137 */
5138 @Override
5139 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005140 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005141 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005142
5143 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005144 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005145 if (phone == null) {
5146 return null;
5147 }
5148 String aid = null;
5149 try {
5150 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5151 .getApplicationByType(appType).getAid();
5152 } catch (Exception e) {
5153 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5154 }
5155 return aid;
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005158 }
Youhan Wange64578a2016-05-02 15:32:42 -07005159 }
5160
Youhan Wang4001d252016-05-11 10:29:41 -07005161 /**
5162 * Return the Electronic Serial Number.
5163 *
5164 * @param subId the subscription ID that this request applies to.
5165 * @return ESN or null if error.
5166 */
5167 @Override
5168 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005169 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005170 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005171
5172 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005173 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005174 if (phone == null) {
5175 return null;
5176 }
5177 String esn = null;
5178 try {
5179 esn = phone.getEsn();
5180 } catch (Exception e) {
5181 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5182 }
5183 return esn;
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005186 }
Youhan Wang4001d252016-05-11 10:29:41 -07005187 }
5188
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005189 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005190 * Return the Preferred Roaming List Version.
5191 *
5192 * @param subId the subscription ID that this request applies to.
5193 * @return PRLVersion or null if error.
5194 */
5195 @Override
5196 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005197 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005198 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005199
5200 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005201 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005202 if (phone == null) {
5203 return null;
5204 }
5205 String cdmaPrlVersion = null;
5206 try {
5207 cdmaPrlVersion = phone.getCdmaPrlVersion();
5208 } catch (Exception e) {
5209 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5210 }
5211 return cdmaPrlVersion;
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005214 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005215 }
5216
5217 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005218 * Get snapshot of Telephony histograms
5219 * @return List of Telephony histograms
5220 * @hide
5221 */
5222 @Override
5223 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5225 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005226
5227 final long identity = Binder.clearCallingIdentity();
5228 try {
5229 return RIL.getTelephonyRILTimingHistograms();
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
5232 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005233 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005234
5235 /**
5236 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005237 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005238 * Require system privileges. In the future we may add this to carrier APIs.
5239 *
5240 * @return The number of carriers set successfully, should match length of carriers
5241 */
5242 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005243 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005244 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005245 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005246
Meng Wang9b7c4e92017-02-17 11:41:27 -08005247 if (carriers == null) {
5248 throw new NullPointerException("carriers cannot be null");
5249 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005250
Malcolm Chend965c8b2018-02-28 15:00:40 -08005251 final long identity = Binder.clearCallingIdentity();
5252 try {
5253 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005254 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5255 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005256 return retVal[0];
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005260 }
5261
5262 /**
5263 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005264 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005265 * Require system privileges. In the future we may add this to carrier APIs.
5266 *
5267 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5268 * means all carriers are allowed.
5269 */
5270 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005271 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005272 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005274
5275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005278 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5279 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005283 }
5284
fionaxu59545b42016-05-25 15:53:37 -07005285 /**
5286 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5287 * @param subId the subscription ID that this action applies to.
5288 * @param enabled control enable or disable metered apns.
5289 * {@hide}
5290 */
5291 @Override
5292 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5293 enforceModifyPermission();
5294 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005295
5296 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005297 if (phone == null) {
5298 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5299 return;
5300 }
5301 try {
5302 phone.carrierActionSetMeteredApnsEnabled(enabled);
5303 } catch (Exception e) {
5304 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005305 } finally {
5306 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005307 }
5308 }
5309
5310 /**
5311 * Action set from carrier signalling broadcast receivers to enable/disable radio
5312 * @param subId the subscription ID that this action applies to.
5313 * @param enabled control enable or disable radio.
5314 * {@hide}
5315 */
5316 @Override
5317 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5318 enforceModifyPermission();
5319 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005320
5321 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005322 if (phone == null) {
5323 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5324 return;
5325 }
5326 try {
5327 phone.carrierActionSetRadioEnabled(enabled);
5328 } catch (Exception e) {
5329 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005330 } finally {
5331 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005332 }
5333 }
5334
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005335 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005336 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5337 * network status based on which carrier apps could apply actions accordingly,
5338 * enable/disable default url handler for example.
5339 *
5340 * @param subId the subscription ID that this action applies to.
5341 * @param report control start/stop reporting the default network status.
5342 * {@hide}
5343 */
5344 @Override
5345 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5346 enforceModifyPermission();
5347 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005348
5349 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005350 if (phone == null) {
5351 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5352 return;
5353 }
5354 try {
5355 phone.carrierActionReportDefaultNetworkStatus(report);
5356 } catch (Exception e) {
5357 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005358 } finally {
5359 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005360 }
5361 }
5362
5363 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005364 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5365 * bug report is being generated.
5366 */
5367 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005368 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005369 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5370 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005371 writer.println("Permission Denial: can't dump Phone from pid="
5372 + Binder.getCallingPid()
5373 + ", uid=" + Binder.getCallingUid()
5374 + "without permission "
5375 + android.Manifest.permission.DUMP);
5376 return;
5377 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005378 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005379 }
Jack Yueb89b242016-06-22 13:27:47 -07005380
Brad Ebingerdac2f002018-04-03 15:17:52 -07005381 @Override
5382 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5383 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5384 throws RemoteException {
5385 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5386 }
5387
Jack Yueb89b242016-06-22 13:27:47 -07005388 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005389 * Get aggregated video call data usage since boot.
5390 *
5391 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5392 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005393 * {@hide}
5394 */
5395 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005396 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005397 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5398 null);
5399
Malcolm Chend965c8b2018-02-28 15:00:40 -08005400 final long identity = Binder.clearCallingIdentity();
5401 try {
5402 // NetworkStatsService keeps tracking the active network interface and identity. It
5403 // records the delta with the corresponding network identity.
5404 // We just return the total video call data usage snapshot since boot.
5405 Phone phone = getPhone(subId);
5406 if (phone != null) {
5407 return phone.getVtDataUsage(perUidStats);
5408 }
5409 return null;
5410 } finally {
5411 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005412 }
Jack Yueb89b242016-06-22 13:27:47 -07005413 }
Jack Yu75ab2952016-07-08 14:29:33 -07005414
5415 /**
5416 * Policy control of data connection. Usually used when data limit is passed.
5417 * @param enabled True if enabling the data, otherwise disabling.
5418 * @param subId Subscription index
5419 * {@hide}
5420 */
5421 @Override
5422 public void setPolicyDataEnabled(boolean enabled, int subId) {
5423 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005424
5425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 Phone phone = getPhone(subId);
5428 if (phone != null) {
5429 phone.setPolicyDataEnabled(enabled);
5430 }
5431 } finally {
5432 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005433 }
5434 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005435
5436 /**
5437 * Get Client request stats
5438 * @return List of Client Request Stats
5439 * @hide
5440 */
5441 @Override
5442 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005444 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005445 return null;
5446 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005447 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005448
Malcolm Chend965c8b2018-02-28 15:00:40 -08005449 final long identity = Binder.clearCallingIdentity();
5450 try {
5451 if (phone != null) {
5452 return phone.getClientRequestStats();
5453 }
5454
5455 return null;
5456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005459 }
5460
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005461 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005462 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005463 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005464 }
Jack Yueb4124c2017-02-16 15:32:43 -08005465
5466 /**
Grace Chen70990072017-03-24 17:21:30 -07005467 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005468 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005469 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005470 * @param state State of SIM (power down, power up, pass through)
5471 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5472 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5473 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005474 *
5475 **/
5476 @Override
Grace Chen70990072017-03-24 17:21:30 -07005477 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005478 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005479 Phone phone = PhoneFactory.getPhone(slotIndex);
5480
vagdevie435a3e2018-08-15 16:01:53 -07005481 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5482
Malcolm Chend965c8b2018-02-28 15:00:40 -08005483 final long identity = Binder.clearCallingIdentity();
5484 try {
5485 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005486 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005487 }
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005490 }
5491 }
Shuo Qiandd210312017-04-12 22:11:33 +00005492
Tyler Gunn65d45c22017-06-05 11:22:26 -07005493 private boolean isUssdApiAllowed(int subId) {
5494 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005495 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005496 if (configManager == null) {
5497 return false;
5498 }
5499 PersistableBundle pb = configManager.getConfigForSubId(subId);
5500 if (pb == null) {
5501 return false;
5502 }
5503 return pb.getBoolean(
5504 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5505 }
5506
Shuo Qiandd210312017-04-12 22:11:33 +00005507 /**
5508 * Check if phone is in emergency callback mode
5509 * @return true if phone is in emergency callback mode
5510 * @param subId sub id
5511 */
goneil9c5f4872017-12-05 14:07:56 -08005512 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005513 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005514 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005515 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 if (phone != null) {
5520 return phone.isInEcm();
5521 } else {
5522 return false;
5523 }
5524 } finally {
5525 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005526 }
5527 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005528
5529 /**
5530 * Get the current signal strength information for the given subscription.
5531 * Because this information is not updated when the device is in a low power state
5532 * it should not be relied-upon to be current.
5533 * @param subId Subscription index
5534 * @return the most recent cached signal strength info from the modem
5535 */
5536 @Override
5537 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005538 final long identity = Binder.clearCallingIdentity();
5539 try {
5540 Phone p = getPhone(subId);
5541 if (p == null) {
5542 return null;
5543 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005544
Malcolm Chend965c8b2018-02-28 15:00:40 -08005545 return p.getSignalStrength();
5546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005549 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005550
Pengquan Meng9140aec2018-08-22 14:49:57 -07005551 /**
chen xu907e5a22018-10-11 13:21:04 -07005552 * Get the current modem radio state for the given slot.
5553 * @param slotIndex slot index.
5554 * @param callingPackage the name of the package making the call.
5555 * @return the current radio power state from the modem
5556 */
5557 @Override
5558 public int getRadioPowerState(int slotIndex, String callingPackage) {
5559 Phone phone = PhoneFactory.getPhone(slotIndex);
5560 if (phone != null) {
5561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5562 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5563 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5564 }
5565
5566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 return phone.getRadioPowerState();
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
5572 }
5573 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5574 }
5575
5576 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005577 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5578 *
5579 * <p>Requires one of the following permissions:
5580 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5581 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5582 * privileges.
5583 *
5584 * @param subId subscription id
5585 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5586 * {@code false}.
5587 */
5588 @Override
5589 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005590 boolean isEnabled = false;
5591 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005592 try {
5593 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005594 null /* message */);
5595 Phone phone = getPhone(subId);
5596 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005597 } catch (Exception e) {
5598 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5599 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005600 } finally {
5601 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005602 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005603 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005604 }
5605
5606
5607 /**
5608 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5609 *
5610 * <p> Requires permission:
5611 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5612 * privileges.
5613 *
5614 * @param subId subscription id
5615 * @param isEnabled {@code true} means enable, {@code false} means disable.
5616 */
5617 @Override
5618 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5622 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005623
Pengquan Meng0c05b502018-09-06 09:59:22 -07005624 Phone phone = getPhone(subId);
5625 if (phone != null) {
5626 phone.setDataRoamingEnabled(isEnabled);
5627 }
5628 } finally {
5629 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005630 }
5631 }
5632
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005633 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005634 public boolean isManualNetworkSelectionAllowed(int subId) {
5635 boolean isAllowed = true;
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5639 mApp, subId, "isManualNetworkSelectionAllowed");
5640 Phone phone = getPhone(subId);
5641 if (phone != null) {
5642 isAllowed = phone.isCspPlmnEnabled();
5643 }
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
5647 return isAllowed;
5648 }
5649
5650 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005651 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005652 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005653
Malcolm Chend965c8b2018-02-28 15:00:40 -08005654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5657 if (slots == null) {
5658 Rlog.i(LOG_TAG, "slots is null.");
5659 return null;
5660 }
5661
5662 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5663 for (int i = 0; i < slots.length; i++) {
5664 UiccSlot slot = slots[i];
5665 if (slot == null) {
5666 continue;
5667 }
5668
5669 String cardId;
5670 UiccCard card = slot.getUiccCard();
5671 if (card != null) {
5672 cardId = card.getCardId();
5673 } else {
5674 cardId = slot.getIccId();
5675 }
5676
5677 int cardState = 0;
5678 switch (slot.getCardState()) {
5679 case CARDSTATE_ABSENT:
5680 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5681 break;
5682 case CARDSTATE_PRESENT:
5683 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5684 break;
5685 case CARDSTATE_ERROR:
5686 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5687 break;
5688 case CARDSTATE_RESTRICTED:
5689 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5690 break;
5691 default:
5692 break;
5693
5694 }
5695
5696 infos[i] = new UiccSlotInfo(
5697 slot.isActive(),
5698 slot.isEuicc(),
5699 cardId,
5700 cardState,
5701 slot.getPhoneId(),
5702 slot.isExtendedApduSupported());
5703 }
5704 return infos;
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005707 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005708 }
5709
5710 @Override
5711 public boolean switchSlots(int[] physicalSlots) {
5712 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005713
5714 final long identity = Binder.clearCallingIdentity();
5715 try {
5716 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005720 }
Jack Yu4c988042018-02-27 15:30:01 -08005721
5722 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005723 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5725 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5726 return TelephonyManager.INVALID_CARD_ID;
5727 }
5728
5729 final long identity = Binder.clearCallingIdentity();
5730 try {
5731 return UiccController.getInstance().getCardIdForDefaultEuicc();
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
5735 }
5736
5737 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005738 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5739 enforceModifyPermission();
5740 final Phone phone = getPhone(subId);
5741 if (phone == null) {
5742 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5743 return;
5744 }
5745
Malcolm Chend965c8b2018-02-28 15:00:40 -08005746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 phone.setRadioIndicationUpdateMode(filters, mode);
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Jack Yu4c988042018-02-27 15:30:01 -08005752 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005753
5754 /**
goneil47ffb6e2018-04-06 15:40:58 -07005755 * A test API to reload the UICC profile.
5756 *
5757 * <p>Requires that the calling app has permission
5758 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5759 * @hide
5760 */
5761 @Override
5762 public void refreshUiccProfile(int subId) {
5763 enforceModifyPermission();
5764
5765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 Phone phone = getPhone(subId);
5768 if (phone == null) {
5769 return;
5770 }
5771 UiccCard uiccCard = phone.getUiccCard();
5772 if (uiccCard == null) {
5773 return;
5774 }
5775 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5776 if (uiccProfile == null) {
5777 return;
5778 }
5779 uiccProfile.refresh();
5780 } finally {
5781 Binder.restoreCallingIdentity(identity);
5782 }
5783 }
5784
5785 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005786 * Returns false if the mobile data is disabled by default, otherwise return true.
5787 */
5788 private boolean getDefaultDataEnabled() {
5789 return "true".equalsIgnoreCase(
5790 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5791 }
5792
5793 /**
5794 * Returns true if the data roaming is enabled by default, i.e the system property
5795 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5796 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5797 */
5798 private boolean getDefaultDataRoamingEnabled(int subId) {
5799 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005800 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005801 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5802 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5803 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5804 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5805 return isDataRoamingEnabled;
5806 }
5807
5808 /**
5809 * Returns the default network type for the given {@code subId}, if the default network type is
5810 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5811 */
5812 private int getDefaultNetworkType(int subId) {
5813 return Integer.parseInt(
5814 TelephonyManager.getTelephonyProperty(
5815 mSubscriptionController.getPhoneId(subId),
5816 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5817 String.valueOf(Phone.PREFERRED_NT_MODE)));
5818 }
fionaxua13278b2018-03-21 00:08:13 -07005819
5820 @Override
5821 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5822 gid1, String gid2, String plmn, String spn) {
5823 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005824
5825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 final Phone phone = getPhone(subId);
5828 if (phone == null) {
5829 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5830 return;
5831 }
5832 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005835 }
fionaxua13278b2018-03-21 00:08:13 -07005836 }
5837
5838 @Override
5839 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005840 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005841
5842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 final Phone phone = getPhone(subId);
5845 if (phone == null) {
5846 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5847 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5848 }
5849 return phone.getCarrierIdListVersion();
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005852 }
fionaxua13278b2018-03-21 00:08:13 -07005853 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005854
5855 @Override
5856 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5858 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5859 return -1;
5860 }
5861
5862 final long identity = Binder.clearCallingIdentity();
5863 try {
5864 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5865 } finally {
5866 Binder.restoreCallingIdentity(identity);
5867 }
5868 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005869
5870 @Override
5871 public int getCdmaRoamingMode(int subId) {
5872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5873 mApp, subId, "getCdmaRoamingMode");
5874
5875 final long identity = Binder.clearCallingIdentity();
5876 try {
5877 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5878 } finally {
5879 Binder.restoreCallingIdentity(identity);
5880 }
5881 }
5882
5883 @Override
5884 public boolean setCdmaRoamingMode(int subId, int mode) {
5885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5886 mApp, subId, "setCdmaRoamingMode");
5887
5888 final long identity = Binder.clearCallingIdentity();
5889 try {
5890 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
5894 }
5895
5896 @Override
5897 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5899 mApp, subId, "setCdmaSubscriptionMode");
5900
5901 final long identity = Binder.clearCallingIdentity();
5902 try {
5903 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5904 } finally {
5905 Binder.restoreCallingIdentity(identity);
5906 }
5907 }
chen xu7ee67862018-10-30 22:27:10 -07005908
sqian2fff4a32018-11-05 14:18:37 -08005909 private void ensureUserRunning(int userId) {
5910 if (!mUserManager.isUserRunning(userId)) {
5911 throw new IllegalStateException("User " + userId + " does not exist or not running");
5912 }
5913 }
5914
5915 /**
5916 * Returns a list of SMS apps on a given user.
5917 *
5918 * Only the shell user (UID 2000 or 0) can call it.
5919 * Target user must be running.
5920 */
5921 @Override
5922 public String[] getSmsApps(int userId) {
5923 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5924 ensureUserRunning(userId);
5925
5926 final Collection<SmsApplicationData> apps =
5927 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5928
5929 String[] ret = new String[apps.size()];
5930 int i = 0;
5931 for (SmsApplicationData app : apps) {
5932 ret[i++] = app.mPackageName;
5933 }
5934 return ret;
5935 }
5936
5937 /**
5938 * Returns the default SMS app package name on a given user.
5939 *
5940 * Only the shell user (UID 2000 or 0) can call it.
5941 * Target user must be running.
5942 */
5943 @Override
5944 public String getDefaultSmsApp(int userId) {
5945 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5946 ensureUserRunning(userId);
5947
5948 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5949 /* updateIfNeeded= */ true, userId);
5950 return cn == null ? null : cn.getPackageName();
5951 }
5952
5953 /**
5954 * Set a package as the default SMS app on a given user.
5955 *
5956 * Only the shell user (UID 2000 or 0) can call it.
5957 * Target user must be running.
5958 */
5959 @Override
5960 public void setDefaultSmsApp(int userId, String packageName) {
5961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5962 ensureUserRunning(userId);
5963
5964 boolean found = false;
5965 for (String pkg : getSmsApps(userId)) {
5966 if (TextUtils.equals(packageName, pkg)) {
5967 found = true;
5968 break;
5969 }
5970 }
5971 if (!found) {
5972 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5973 }
5974
5975 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5976 }
5977
chen xu7ee67862018-10-30 22:27:10 -07005978 @Override
sqian04b86072018-11-07 14:02:21 -08005979 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5980 String callingPackage) {
5981 // TODO connect with internal content
5982 return null;
5983 }
5984
5985 @Override
5986 public boolean isCurrentEmergencyNumber(String number) {
5987 // TODO connect with internal content
5988 return false;
5989 }
5990
5991 @Override
chen xu7ee67862018-10-30 22:27:10 -07005992 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5993 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5994 Phone phone = getPhone(subId);
5995 if (phone == null) {
5996 return null;
5997 }
5998 final long identity = Binder.clearCallingIdentity();
5999 try {
6000 UiccProfile profile = UiccController.getInstance()
6001 .getUiccProfileForPhone(phone.getPhoneId());
6002 if (profile != null) {
6003 return profile.getCertsFromCarrierPrivilegeAccessRules();
6004 }
6005 } finally {
6006 Binder.restoreCallingIdentity(identity);
6007 }
6008 return null;
6009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006010}