blob: 0115cd9334c8f48a3c6f7bfe9607aec3491b72fa [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
2145 public int getSubscriptionMNOCarrierId(int subId) {
2146 final long identity = Binder.clearCallingIdentity();
2147 try {
2148 final Phone phone = getPhone(subId);
2149 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2150 } finally {
2151 Binder.restoreCallingIdentity(identity);
2152 }
2153 }
2154
chen xuc93cc282018-11-04 17:17:00 -08002155 @Override
2156 public int getSubscriptionPreciseCarrierId(int subId) {
2157 final long identity = Binder.clearCallingIdentity();
2158 try {
2159 final Phone phone = getPhone(subId);
2160 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2161 : phone.getPreciseCarrierId();
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
2164 }
2165 }
2166
2167 @Override
2168 public String getSubscriptionPreciseCarrierName(int subId) {
2169 final long identity = Binder.clearCallingIdentity();
2170 try {
2171 final Phone phone = getPhone(subId);
2172 return phone == null ? null : phone.getPreciseCarrierName();
2173 } finally {
2174 Binder.restoreCallingIdentity(identity);
2175 }
2176 }
2177
chen xu02581692018-11-11 19:03:44 -08002178 @Override
2179 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc) {
2180 final Phone phone = PhoneFactory.getPhone(slotIndex);
2181 if (phone == null) {
2182 return TelephonyManager.UNKNOWN_CARRIER_ID;
2183 }
2184 final long identity = Binder.clearCallingIdentity();
2185 try {
2186 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
2189 }
2190 }
2191
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 //
2193 // Internal helper methods.
2194 //
2195
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002196 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2198 *
2199 * @throws SecurityException if the caller does not have the required permission
2200 */
2201 private void enforceModifyPermission() {
2202 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2203 }
2204
2205 /**
2206 * Make sure the caller has the CALL_PHONE permission.
2207 *
2208 * @throws SecurityException if the caller does not have the required permission
2209 */
2210 private void enforceCallPermission() {
2211 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2212 }
2213
Stuart Scott8eef64f2015-04-08 15:13:54 -07002214 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002215 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002216 "ConnectivityService");
2217 }
2218
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 private String createTelUrl(String number) {
2220 if (TextUtils.isEmpty(number)) {
2221 return null;
2222 }
2223
Jake Hambye994d462014-02-03 13:10:13 -08002224 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 }
2226
Ihab Awadf9e92732013-12-05 18:02:52 -08002227 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2229 }
2230
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002231 private static void logv(String msg) {
2232 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2233 }
2234
Ihab Awadf9e92732013-12-05 18:02:52 -08002235 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2237 }
2238
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002239 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002241 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002242 }
2243
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002245 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002246 final long identity = Binder.clearCallingIdentity();
2247 try {
2248 final Phone phone = PhoneFactory.getPhone(slotIndex);
2249 if (phone == null) {
2250 return PhoneConstants.PHONE_TYPE_NONE;
2251 } else {
2252 return phone.getPhoneType();
2253 }
2254 } finally {
2255 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 }
2258
2259 /**
2260 * Returns the CDMA ERI icon index to display
2261 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 @Override
2263 public int getCdmaEriIconIndex(String callingPackage) {
2264 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002265 }
2266
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002268 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002270 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002271 return -1;
2272 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002273
2274 final long identity = Binder.clearCallingIdentity();
2275 try {
2276 final Phone phone = getPhone(subId);
2277 if (phone != null) {
2278 return phone.getCdmaEriIconIndex();
2279 } else {
2280 return -1;
2281 }
2282 } finally {
2283 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286
2287 /**
2288 * Returns the CDMA ERI icon mode,
2289 * 0 - ON
2290 * 1 - FLASHING
2291 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002292 @Override
2293 public int getCdmaEriIconMode(String callingPackage) {
2294 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002295 }
2296
Sanket Padawe356d7632015-06-22 14:03:32 -07002297 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002298 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002300 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 return -1;
2302 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002303
2304 final long identity = Binder.clearCallingIdentity();
2305 try {
2306 final Phone phone = getPhone(subId);
2307 if (phone != null) {
2308 return phone.getCdmaEriIconMode();
2309 } else {
2310 return -1;
2311 }
2312 } finally {
2313 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 }
2316
2317 /**
2318 * Returns the CDMA ERI text,
2319 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002320 @Override
2321 public String getCdmaEriText(String callingPackage) {
2322 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002323 }
2324
Sanket Padawe356d7632015-06-22 14:03:32 -07002325 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002326 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002328 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002329 return null;
2330 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002331
2332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 final Phone phone = getPhone(subId);
2335 if (phone != null) {
2336 return phone.getCdmaEriText();
2337 } else {
2338 return null;
2339 }
2340 } finally {
2341 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 }
2344
2345 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002346 * Returns the CDMA MDN.
2347 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002348 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002349 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2351 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002352
2353 final long identity = Binder.clearCallingIdentity();
2354 try {
2355 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002356 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002357 return phone.getLine1Number();
2358 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002359 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002360 return null;
2361 }
2362 } finally {
2363 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002364 }
2365 }
2366
2367 /**
2368 * Returns the CDMA MIN.
2369 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002370 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002371 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2373 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002374
2375 final long identity = Binder.clearCallingIdentity();
2376 try {
2377 final Phone phone = getPhone(subId);
2378 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2379 return phone.getCdmaMin();
2380 } else {
2381 return null;
2382 }
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002385 }
2386 }
2387
Hall Liud892bec2018-11-30 14:51:45 -08002388 @Override
2389 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2390 INumberVerificationCallback callback, String callingPackage) {
2391 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2392 != PERMISSION_GRANTED) {
2393 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2394 }
2395 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2396
2397 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2398 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2399 throw new SecurityException("Calling package must be configured in the device config");
2400 }
2401
2402 if (range == null) {
2403 throw new NullPointerException("Range must be non-null");
2404 }
2405
2406 timeoutMillis = Math.min(timeoutMillis,
2407 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2408
2409 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2410 }
2411
Junda Liuca05d5d2014-08-14 22:36:34 -07002412 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 * Returns true if CDMA provisioning needs to run.
2414 */
2415 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002416 final long identity = Binder.clearCallingIdentity();
2417 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002418 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002419 } finally {
2420 Binder.restoreCallingIdentity(identity);
2421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 }
2423
2424 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002425 * Sets the voice mail number of a given subId.
2426 */
2427 @Override
2428 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002429 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002430
2431 final long identity = Binder.clearCallingIdentity();
2432 try {
2433 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2434 new Pair<String, String>(alphaTag, number), new Integer(subId));
2435 return success;
2436 } finally {
2437 Binder.restoreCallingIdentity(identity);
2438 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002439 }
2440
Ta-wei Yen87c49842016-05-13 21:19:52 -07002441 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002442 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002444 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002445 if (!TextUtils.equals(callingPackage, systemDialer)) {
2446 throw new SecurityException("caller must be system dialer");
2447 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002448
2449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2452 if (phoneAccountHandle == null) {
2453 return null;
2454 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002455 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002456 } finally {
2457 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002458 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002459 }
2460
2461 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002462 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002463 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002465 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002466 return null;
2467 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002468
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002469 final long identity = Binder.clearCallingIdentity();
2470 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002471 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002472 } finally {
2473 Binder.restoreCallingIdentity(identity);
2474 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002475 }
2476
2477 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002478 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2479 VisualVoicemailSmsFilterSettings settings) {
2480 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002481
2482 final long identity = Binder.clearCallingIdentity();
2483 try {
2484 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002485 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002486 } finally {
2487 Binder.restoreCallingIdentity(identity);
2488 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002489 }
2490
2491 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002492 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002494
2495 final long identity = Binder.clearCallingIdentity();
2496 try {
2497 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002498 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002499 } finally {
2500 Binder.restoreCallingIdentity(identity);
2501 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002502 }
2503
2504 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002505 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2506 String callingPackage, int subId) {
2507 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002512 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002513 } finally {
2514 Binder.restoreCallingIdentity(identity);
2515 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002516 }
2517
2518 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002519 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002520 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002521
2522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002525 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002526 } finally {
2527 Binder.restoreCallingIdentity(identity);
2528 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002529 }
2530
2531 @Override
2532 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2533 String number, int port, String text, PendingIntent sentIntent) {
2534 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002535 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002536 enforceSendSmsPermission();
2537 // Make the calls as the phone process.
2538 final long identity = Binder.clearCallingIdentity();
2539 try {
2540 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2541 if (port == 0) {
2542 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2543 sentIntent, null, false);
2544 } else {
2545 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2546 smsManager.sendDataMessageWithSelfPermissions(number, null,
2547 (short) port, data, sentIntent, null);
2548 }
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
2551 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002552 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002553 /**
fionaxu0152e512016-11-14 13:36:14 -08002554 * Sets the voice activation state of a given subId.
2555 */
2556 @Override
2557 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2559 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002560
2561 final long identity = Binder.clearCallingIdentity();
2562 try {
2563 final Phone phone = getPhone(subId);
2564 if (phone != null) {
2565 phone.setVoiceActivationState(activationState);
2566 } else {
2567 loge("setVoiceActivationState fails with invalid subId: " + subId);
2568 }
2569 } finally {
2570 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002571 }
2572 }
2573
2574 /**
2575 * Sets the data activation state of a given subId.
2576 */
2577 @Override
2578 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2580 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002581
2582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 final Phone phone = getPhone(subId);
2585 if (phone != null) {
2586 phone.setDataActivationState(activationState);
2587 } else {
2588 loge("setVoiceActivationState fails with invalid subId: " + subId);
2589 }
2590 } finally {
2591 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002592 }
2593 }
2594
2595 /**
2596 * Returns the voice activation state of a given subId.
2597 */
2598 @Override
2599 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002600 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002601
fionaxu0152e512016-11-14 13:36:14 -08002602 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 if (phone != null) {
2606 return phone.getVoiceActivationState();
2607 } else {
2608 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2609 }
2610 } finally {
2611 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002612 }
2613 }
2614
2615 /**
2616 * Returns the data activation state of a given subId.
2617 */
2618 @Override
2619 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002620 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002621
fionaxu0152e512016-11-14 13:36:14 -08002622 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 if (phone != null) {
2626 return phone.getDataActivationState();
2627 } else {
2628 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2629 }
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002632 }
2633 }
2634
2635 /**
Wink Saville36469e72014-06-11 15:17:00 -07002636 * Returns the unread count of voicemails for a subId
2637 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002638 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002639 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2641 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2642 return 0;
2643 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
2647 if (phone != null) {
2648 return phone.getVoiceMessageCount();
2649 } else {
2650 return 0;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 }
2656
2657 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002658 * returns true, if the device is in a state where both voice and data
2659 * are supported simultaneously. This can change based on location or network condition.
2660 */
2661 @Override
2662 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002670 }
2671
2672 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002673 * Send the dialer code if called from the current default dialer or the caller has
2674 * carrier privilege.
2675 * @param inputCode The dialer code to send
2676 */
2677 @Override
2678 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002679 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002681 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2682 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002683 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002684 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2685 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002686 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002690 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002691 } finally {
2692 Binder.restoreCallingIdentity(identity);
2693 }
fionaxu235cc5e2017-03-06 22:25:57 -08002694 }
2695
2696 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002697 * Returns the data network type.
2698 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 *
2700 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2701 */
2702 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002703 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 final Phone phone = getPhone(getDefaultSubscription());
2707 if (phone != null) {
2708 return phone.getServiceState().getDataNetworkType();
2709 } else {
2710 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2711 }
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002714 }
Wink Saville36469e72014-06-11 15:17:00 -07002715 }
2716
Pengquan Meng0c05b502018-09-06 09:59:22 -07002717 @Override
2718 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002719 if (!isActiveSubscription(subId)) {
2720 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2721 }
2722
Pengquan Meng0c05b502018-09-06 09:59:22 -07002723 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2724 }
2725
Brad Ebinger4c460712018-10-01 10:40:55 -07002726 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002727 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2728 throws RemoteException {
2729 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002730 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2731 final long token = Binder.clearCallingIdentity();
2732 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002733 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002734 .addRegistrationCallbackForSubscription(c, subId);
2735 } finally {
2736 Binder.restoreCallingIdentity(token);
2737 }
2738 }
2739
2740 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002741 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2742 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002743 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2744 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002745 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002746 .removeRegistrationCallbackForSubscription(c, subId));
2747 }
2748
2749 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002750 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2751 throws RemoteException {
2752 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002753 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2754 final long token = Binder.clearCallingIdentity();
2755 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002756 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002757 .addCapabilitiesCallbackForSubscription(c, subId);
2758 } finally {
2759 Binder.restoreCallingIdentity(token);
2760 }
2761 }
2762
2763 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002764 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2765 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002766 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2767 Binder.withCleanCallingIdentity(() ->
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002768 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002769 .removeCapabilitiesCallbackForSubscription(c, subId));
2770 }
2771
2772 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002773 public boolean isCapable(int subId, int capability, int regTech) {
2774 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002775 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2776 final long token = Binder.clearCallingIdentity();
2777 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002778 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002779 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2780 } catch (ImsException e) {
2781 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2782 return false;
2783 } finally {
2784 Binder.restoreCallingIdentity(token);
2785 }
2786 }
2787
2788 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002789 public boolean isAvailable(int subId, int capability, int regTech) {
2790 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002791 final long token = Binder.clearCallingIdentity();
2792 try {
2793 Phone phone = getPhone(subId);
2794 if (phone == null) return false;
2795 return phone.isImsCapabilityAvailable(capability, regTech);
2796 } finally {
2797 Binder.restoreCallingIdentity(token);
2798 }
2799 }
2800
2801 @Override
2802 public boolean isAdvancedCallingSettingEnabled(int subId) {
2803 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2804 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2805 final long token = Binder.clearCallingIdentity();
2806 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002807 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002808 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2809 } finally {
2810 Binder.restoreCallingIdentity(token);
2811 }
2812 }
2813
2814 @Override
2815 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2817 "setAdvancedCallingSetting");
2818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002821 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002822 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2823 } finally {
2824 Binder.restoreCallingIdentity(identity);
2825 }
2826 }
2827
2828 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002829 public boolean isVtSettingEnabled(int subId) {
2830 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002834 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002835 getSlotIndexOrException(subId)).isVtEnabledByUser();
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
2838 }
2839 }
2840
2841 @Override
2842 public void setVtSetting(int subId, boolean isEnabled) {
2843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2844 "setVtSetting");
2845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002848 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002849 } finally {
2850 Binder.restoreCallingIdentity(identity);
2851 }
2852 }
2853
2854 @Override
2855 public boolean isVoWiFiSettingEnabled(int subId) {
2856 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2857 final long identity = Binder.clearCallingIdentity();
2858 try {
2859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002860 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002861 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
2865 }
2866
2867 @Override
2868 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2870 "setVoWiFiSetting");
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002874 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002875 } finally {
2876 Binder.restoreCallingIdentity(identity);
2877 }
2878 }
2879
2880 @Override
2881 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2882 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002886 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002887 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
2890 }
2891 }
2892
2893 @Override
2894 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2896 "setVoWiFiRoamingSetting");
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002900 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002901 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
2904 }
2905 }
2906
2907 @Override
2908 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2910 "setVoWiFiNonPersistent");
2911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002914 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002915 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
2918 }
2919 }
2920
2921 @Override
2922 public int getVoWiFiModeSetting(int subId) {
2923 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2924 final long identity = Binder.clearCallingIdentity();
2925 try {
2926 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002927 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002928 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
2931 }
2932 }
2933
2934 @Override
2935 public void setVoWiFiModeSetting(int subId, int mode) {
2936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2937 "setVoWiFiModeSetting");
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002941 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002942 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2943 } finally {
2944 Binder.restoreCallingIdentity(identity);
2945 }
2946 }
2947
2948 @Override
2949 public int getVoWiFiRoamingModeSetting(int subId) {
2950 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002954 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002955 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
2959 }
2960
2961 @Override
2962 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2964 "setVoWiFiRoamingModeSetting");
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002968 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002969 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
2972 }
2973 }
2974
2975 @Override
2976 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2978 "setRttCapabilityEnabled");
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002982 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002983 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
2987 }
2988
2989 @Override
2990 public boolean isTtyOverVolteEnabled(int subId) {
2991 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002995 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002996 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2997 } finally {
2998 Binder.restoreCallingIdentity(identity);
2999 }
3000 }
3001
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003002 @Override
3003 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3004 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3005 final long identity = Binder.clearCallingIdentity();
3006 try {
3007 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003008 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003009 .getConfigInterface().addConfigCallback(callback);
3010 } catch (ImsException e) {
3011 throw new IllegalArgumentException(e.getMessage());
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
3014 }
3015 }
3016
3017 @Override
3018 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3019 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003023 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003024 .getConfigInterface().removeConfigCallback(callback);
3025 } catch (ImsException e) {
3026 throw new IllegalArgumentException(e.getMessage());
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
3029 }
3030 }
3031
3032 @Override
3033 public int getImsProvisioningInt(int subId, int key) {
3034 enforceReadPrivilegedPermission("getImsProvisioningInt");
3035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003038 return ImsManager.getInstance(mApp,
3039 getSlotIndexOrException(subId)).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003040 } catch (ImsException e) {
3041 throw new IllegalArgumentException(e.getMessage());
3042 } finally {
3043 Binder.restoreCallingIdentity(identity);
3044 }
3045 }
3046
3047 @Override
3048 public String getImsProvisioningString(int subId, int key) {
3049 enforceReadPrivilegedPermission("getImsProvisioningString");
3050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003053 return ImsManager.getInstance(mApp,
3054 getSlotIndexOrException(subId)).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003055 } catch (ImsException e) {
3056 throw new IllegalArgumentException(e.getMessage());
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
3059 }
3060 }
3061
3062 @Override
3063 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3065 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003069 return ImsManager.getInstance(mApp,
3070 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003071 } catch (ImsException e) {
3072 throw new IllegalArgumentException(e.getMessage());
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
3076 }
3077
3078 @Override
3079 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3081 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003085 return ImsManager.getInstance(mApp,
3086 getSlotIndexOrException(subId)).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003087 } catch (ImsException e) {
3088 throw new IllegalArgumentException(e.getMessage());
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
3092 }
3093
Brad Ebinger4c460712018-10-01 10:40:55 -07003094 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3095 int slotId = SubscriptionManager.getSlotIndex(subId);
3096 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3097 throw new IllegalArgumentException("Invalid Subscription Id.");
3098 }
3099 return slotId;
3100 }
3101
Wink Saville36469e72014-06-11 15:17:00 -07003102 /**
3103 * Returns the network type for a subId
3104 */
3105 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003106 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003108 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003109 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3110 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003111
Malcolm Chend965c8b2018-02-28 15:00:40 -08003112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 final Phone phone = getPhone(subId);
3115 if (phone != null) {
3116 return phone.getServiceState().getDataNetworkType();
3117 } else {
3118 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3119 }
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003122 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 }
3124
3125 /**
3126 * Returns the data network type
3127 */
3128 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003129 public int getDataNetworkType(String callingPackage) {
3130 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003131 }
3132
3133 /**
3134 * Returns the data network type for a subId
3135 */
3136 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003137 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003138 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003139 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003140 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3141 }
3142
Malcolm Chend965c8b2018-02-28 15:00:40 -08003143 final long identity = Binder.clearCallingIdentity();
3144 try {
3145 final Phone phone = getPhone(subId);
3146 if (phone != null) {
3147 return phone.getServiceState().getDataNetworkType();
3148 } else {
3149 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3150 }
3151 } finally {
3152 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003154 }
3155
3156 /**
Wink Saville36469e72014-06-11 15:17:00 -07003157 * Returns the Voice network type for a subId
3158 */
3159 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003160 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003162 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003163 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3164 }
3165
Malcolm Chend965c8b2018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 final Phone phone = getPhone(subId);
3169 if (phone != null) {
3170 return phone.getServiceState().getVoiceNetworkType();
3171 } else {
3172 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3173 }
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177 }
3178
3179 /**
3180 * @return true if a ICC card is present
3181 */
3182 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003183 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003184 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3185 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003186 }
3187
3188 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003189 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003190 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003191 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003192 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 final Phone phone = PhoneFactory.getPhone(slotIndex);
3196 if (phone != null) {
3197 return phone.getIccCard().hasIccCard();
3198 } else {
3199 return false;
3200 }
3201 } finally {
3202 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 }
3205
3206 /**
3207 * Return if the current radio is LTE on CDMA. This
3208 * is a tri-state return value as for a period of time
3209 * the mode may be unknown.
3210 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003211 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003213 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003215 @Override
3216 public int getLteOnCdmaMode(String callingPackage) {
3217 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003218 }
3219
Sanket Padawe356d7632015-06-22 14:03:32 -07003220 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003221 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003223 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003224 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3225 }
3226
Malcolm Chend965c8b2018-02-28 15:00:40 -08003227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 final Phone phone = getPhone(subId);
3230 if (phone == null) {
3231 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3232 } else {
3233 return phone.getLteOnCdmaMode();
3234 }
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003237 }
Wink Saville36469e72014-06-11 15:17:00 -07003238 }
3239
Wink Saville36469e72014-06-11 15:17:00 -07003240 /**
3241 * {@hide}
3242 * Returns Default subId, 0 in the case of single standby.
3243 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003244 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003245 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003246 }
3247
Shishir Agrawala9f32182016-04-12 12:00:16 -07003248 private int getSlotForDefaultSubscription() {
3249 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3250 }
3251
Wink Savilleb564aae2014-10-23 10:18:09 -07003252 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003253 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003255
Pengquan Meng466e2482018-09-21 15:54:48 -07003256 private boolean isActiveSubscription(int subId) {
3257 return mSubscriptionController.isActiveSubId(subId);
3258 }
3259
Ihab Awadf2177b72013-11-25 13:33:23 -08003260 /**
3261 * @see android.telephony.TelephonyManager.WifiCallingChoices
3262 */
3263 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003264 final long identity = Binder.clearCallingIdentity();
3265 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003266 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003267 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3268 getWhenToMakeWifiCallsDefaultPreference());
3269 } finally {
3270 Binder.restoreCallingIdentity(identity);
3271 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003272 }
3273
3274 /**
3275 * @see android.telephony.TelephonyManager.WifiCallingChoices
3276 */
3277 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003281 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003282 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003286 }
3287
Sailesh Nepald1e68152013-12-12 19:08:02 -08003288 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003289 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003290 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003291 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003292
Shishir Agrawal566b7612013-10-28 14:41:00 -07003293 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003294 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3295 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3297 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003298 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003299
Malcolm Chend965c8b2018-02-28 15:00:40 -08003300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 if (TextUtils.equals(ISDR_AID, aid)) {
3303 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003304 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3305 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003306 if (bestComponent == null
3307 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3308 loge("The calling package is not allowed to access ISD-R.");
3309 throw new SecurityException(
3310 "The calling package is not allowed to access ISD-R.");
3311 }
Derek Tan740e1672017-06-27 14:56:27 -07003312 }
Derek Tan740e1672017-06-27 14:56:27 -07003313
Malcolm Chend965c8b2018-02-28 15:00:40 -08003314 if (DBG) {
3315 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3316 }
3317 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3318 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3319 if (DBG) log("iccOpenLogicalChannel: " + response);
3320 return response;
3321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003324 }
3325
3326 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003327 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3329 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003330
Malcolm Chend965c8b2018-02-28 15:00:40 -08003331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3334 if (channel < 0) {
3335 return false;
3336 }
3337 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3338 if (DBG) log("iccCloseLogicalChannel: " + success);
3339 return success;
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003342 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003343 }
3344
3345 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003346 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003347 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3349 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003350
Malcolm Chend965c8b2018-02-28 15:00:40 -08003351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 if (DBG) {
3354 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3355 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3356 + p3 + " data=" + data);
3357 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003358
Malcolm Chend965c8b2018-02-28 15:00:40 -08003359 if (channel < 0) {
3360 return "";
3361 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003362
Malcolm Chend965c8b2018-02-28 15:00:40 -08003363 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3364 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3365 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003366
Malcolm Chend965c8b2018-02-28 15:00:40 -08003367 // Append the returned status code to the end of the response payload.
3368 String s = Integer.toHexString(
3369 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3370 if (response.payload != null) {
3371 s = IccUtils.bytesToHexString(response.payload) + s;
3372 }
3373 return s;
3374 } finally {
3375 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003376 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003377 }
Jake Hambye994d462014-02-03 13:10:13 -08003378
Evan Charltonc66da362014-05-16 14:06:40 -07003379 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003380 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3381 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3383 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003384 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003385
Malcolm Chend965c8b2018-02-28 15:00:40 -08003386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3389 && TextUtils.equals(ISDR_AID, data)) {
3390 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003391 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3392 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003393 if (bestComponent == null
3394 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3395 loge("The calling package is not allowed to select ISD-R.");
3396 throw new SecurityException(
3397 "The calling package is not allowed to select ISD-R.");
3398 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003399 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003400
Malcolm Chend965c8b2018-02-28 15:00:40 -08003401 if (DBG) {
3402 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3403 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3404 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003405
Malcolm Chend965c8b2018-02-28 15:00:40 -08003406 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3407 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3408 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003409
Malcolm Chend965c8b2018-02-28 15:00:40 -08003410 // Append the returned status code to the end of the response payload.
3411 String s = Integer.toHexString(
3412 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3413 if (response.payload != null) {
3414 s = IccUtils.bytesToHexString(response.payload) + s;
3415 }
3416 return s;
3417 } finally {
3418 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003419 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003420 }
3421
3422 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003423 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003424 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3426 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003427
Malcolm Chend965c8b2018-02-28 15:00:40 -08003428 final long identity = Binder.clearCallingIdentity();
3429 try {
3430 if (DBG) {
3431 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3432 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3433 }
3434
3435 IccIoResult response =
3436 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3437 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3438 subId);
3439
3440 if (DBG) {
3441 log("Exchange SIM_IO [R]" + response);
3442 }
3443
3444 byte[] result = null;
3445 int length = 2;
3446 if (response.payload != null) {
3447 length = 2 + response.payload.length;
3448 result = new byte[length];
3449 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3450 } else {
3451 result = new byte[length];
3452 }
3453
3454 result[length - 1] = (byte) response.sw2;
3455 result[length - 2] = (byte) response.sw1;
3456 return result;
3457 } finally {
3458 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003459 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003460 }
3461
Nathan Haroldb3014052017-01-25 15:57:32 -08003462 /**
3463 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3464 * on a particular subscription
3465 */
sqianb6e41952018-03-12 14:54:01 -07003466 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3468 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3469 return null;
3470 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003471
3472 final long identity = Binder.clearCallingIdentity();
3473 try {
3474 if (appType != TelephonyManager.APPTYPE_USIM
3475 && appType != TelephonyManager.APPTYPE_SIM) {
3476 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3477 return null;
3478 }
3479 Object response = sendRequest(
3480 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3481 if (response instanceof String[]) {
3482 return (String[]) response;
3483 }
3484 // Response is an Exception of some kind,
3485 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003486 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003487 } finally {
3488 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003489 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003490 }
3491
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003492 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003493 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3495 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003496
Malcolm Chend965c8b2018-02-28 15:00:40 -08003497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3500 if (response.payload == null) {
3501 return "";
3502 }
Evan Charltonc66da362014-05-16 14:06:40 -07003503
Malcolm Chend965c8b2018-02-28 15:00:40 -08003504 // Append the returned status code to the end of the response payload.
3505 String s = Integer.toHexString(
3506 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3507 s = IccUtils.bytesToHexString(response.payload) + s;
3508 return s;
3509 } finally {
3510 Binder.restoreCallingIdentity(identity);
3511 }
Evan Charltonc66da362014-05-16 14:06:40 -07003512 }
3513
Jake Hambye994d462014-02-03 13:10:13 -08003514 /**
3515 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3516 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3517 *
3518 * @param itemID the ID of the item to read
3519 * @return the NV item as a String, or null on error.
3520 */
3521 @Override
3522 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003523 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3525 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003526
3527 final long identity = Binder.clearCallingIdentity();
3528 try {
3529 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003530 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003531 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3532 return value;
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
Jake Hambye994d462014-02-03 13:10:13 -08003536 }
3537
3538 /**
3539 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3540 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3541 *
3542 * @param itemID the ID of the item to read
3543 * @param itemValue the value to write, as a String
3544 * @return true on success; false on any failure
3545 */
3546 @Override
3547 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003548 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3550 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003551
3552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3555 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003556 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003557 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3558 return success;
3559 } finally {
3560 Binder.restoreCallingIdentity(identity);
3561 }
Jake Hambye994d462014-02-03 13:10:13 -08003562 }
3563
3564 /**
3565 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3566 * Used for device configuration by some CDMA operators.
3567 *
3568 * @param preferredRoamingList byte array containing the new PRL
3569 * @return true on success; false on any failure
3570 */
3571 @Override
3572 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3574 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003575
3576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3579 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3580 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3581 return success;
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
3584 }
Jake Hambye994d462014-02-03 13:10:13 -08003585 }
3586
3587 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003588 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003589 * Used for device configuration by some CDMA operators.
3590 *
chen xu1cc0abe2018-10-26 17:39:23 -07003591 * @param slotIndex - device slot.
3592 *
Jake Hambye994d462014-02-03 13:10:13 -08003593 * @return true on success; false on any failure
3594 */
3595 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003596 public boolean resetModemConfig(int slotIndex) {
3597 Phone phone = PhoneFactory.getPhone(slotIndex);
3598 if (phone != null) {
3599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3600 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003601
chen xu1cc0abe2018-10-26 17:39:23 -07003602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3605 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3606 return success;
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
3609 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003610 }
chen xu1cc0abe2018-10-26 17:39:23 -07003611 return false;
3612 }
3613
3614 /**
3615 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3616 *
3617 * @param slotIndex - device slot.
3618 *
3619 * @return true on success; false on any failure
3620 */
3621 @Override
3622 public boolean rebootModem(int slotIndex) {
3623 Phone phone = PhoneFactory.getPhone(slotIndex);
3624 if (phone != null) {
3625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3626 mApp, phone.getSubId(), "rebootModem");
3627
3628 final long identity = Binder.clearCallingIdentity();
3629 try {
3630 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3631 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3632 return success;
3633 } finally {
3634 Binder.restoreCallingIdentity(identity);
3635 }
3636 }
3637 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003638 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003639
Svet Ganovb320e182015-04-16 12:30:10 -07003640 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003641 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003643 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003644 return new String[0];
3645 }
3646
Malcolm Chend965c8b2018-02-28 15:00:40 -08003647 final long identity = Binder.clearCallingIdentity();
3648 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003649 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
Wink Saville36469e72014-06-11 15:17:00 -07003653 }
3654
Brad Ebinger51f743a2017-01-23 13:50:20 -08003655 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003656 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3657 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003658 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003659 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003660 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003661
3662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 PhoneFactory.getImsResolver().enableIms(slotId);
3665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003668 }
3669
3670 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003671 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3672 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003673 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003674 public void disableIms(int slotId) {
3675 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003676
3677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 PhoneFactory.getImsResolver().disableIms(slotId);
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003683 }
3684
3685 /**
3686 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3687 * feature or {@link null} if the service is not available. If the feature is available, the
3688 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3689 */
3690 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003691 IImsServiceFeatureCallback callback) {
3692 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003693
3694 final long identity = Binder.clearCallingIdentity();
3695 try {
3696 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3697 } finally {
3698 Binder.restoreCallingIdentity(identity);
3699 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003700 }
3701
3702 /**
3703 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3704 * feature during emergency calling or {@link null} if the service is not available. If the
3705 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3706 * listener for feature updates.
3707 */
3708 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3709 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003710
3711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003717 }
3718
Brad Ebinger5f64b052017-12-14 14:26:15 -08003719 /**
3720 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3721 * specified.
3722 */
3723 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3724 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003725
3726 final long identity = Binder.clearCallingIdentity();
3727 try {
3728 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003732 }
3733
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003734 /**
3735 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3736 * specified.
3737 */
3738 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3739 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003740
3741 final long identity = Binder.clearCallingIdentity();
3742 try {
3743 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003747 }
3748
Brad Ebinger884c07b2018-02-15 16:17:40 -08003749 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003750 * Sets the ImsService Package Name that Telephony will bind to.
3751 *
3752 * @param slotId the slot ID that the ImsService should bind for.
3753 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3754 * ImsService is the device default ImsService.
3755 * @param packageName The package name of the application that contains the ImsService to bind
3756 * to.
3757 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3758 * @hide
3759 */
3760 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003761 int[] subIds = SubscriptionManager.getSubId(slotId);
3762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3763 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3764 "setImsService");
3765
Malcolm Chend965c8b2018-02-28 15:00:40 -08003766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3769 isCarrierImsService, packageName);
3770 } finally {
3771 Binder.restoreCallingIdentity(identity);
3772 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003773 }
3774
3775 /**
3776 * Return the ImsService configuration.
3777 *
3778 * @param slotId The slot that the ImsService is associated with.
3779 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3780 * the device default.
3781 * @return the package name of the ImsService configuration.
3782 */
3783 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003784 int[] subIds = SubscriptionManager.getSubId(slotId);
3785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3786 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3787 "getImsService");
3788
Malcolm Chend965c8b2018-02-28 15:00:40 -08003789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3792 isCarrierImsService);
3793 } finally {
3794 Binder.restoreCallingIdentity(identity);
3795 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003796 }
3797
Wink Saville36469e72014-06-11 15:17:00 -07003798 public void setImsRegistrationState(boolean registered) {
3799 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003800
3801 final long identity = Binder.clearCallingIdentity();
3802 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003803 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
Wink Saville36469e72014-06-11 15:17:00 -07003807 }
3808
3809 /**
Stuart Scott54788802015-03-30 13:18:01 -07003810 * Set the network selection mode to automatic.
3811 *
3812 */
3813 @Override
3814 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3816 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003817
Pengquan Meng466e2482018-09-21 15:54:48 -07003818 if (!isActiveSubscription(subId)) {
3819 return;
3820 }
3821
Malcolm Chend965c8b2018-02-28 15:00:40 -08003822 final long identity = Binder.clearCallingIdentity();
3823 try {
3824 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3825 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
Stuart Scott54788802015-03-30 13:18:01 -07003829 }
3830
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003831 /**
3832 * Ask the radio to connect to the input network and change selection mode to manual.
3833 *
3834 * @param subId the id of the subscription.
3835 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3836 * the operator to attach to.
3837 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3838 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3839 * normal network selection next time.
3840 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003841 */
3842 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003843 public boolean setNetworkSelectionModeManual(
3844 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3846 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003847
3848 if (!isActiveSubscription(subId)) {
3849 return false;
3850 }
3851
Malcolm Chend965c8b2018-02-28 15:00:40 -08003852 final long identity = Binder.clearCallingIdentity();
3853 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003854 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003855 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003856 if (DBG) {
3857 log("setNetworkSelectionModeManual: subId: " + subId
3858 + " operator: " + operatorInfo);
3859 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003860 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3861 } finally {
3862 Binder.restoreCallingIdentity(identity);
3863 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003864 }
3865
3866 /**
3867 * Scans for available networks.
3868 */
3869 @Override
3870 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3872 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003873
Pengquan Meng0c05b502018-09-06 09:59:22 -07003874 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003875 try {
3876 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003877 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003878 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003882 }
3883
3884 /**
yinxub1bed742017-04-17 11:45:04 -07003885 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003886 *
yinxub1bed742017-04-17 11:45:04 -07003887 * @param subId id of the subscription
3888 * @param request contains the radio access networks with bands/channels to scan
3889 * @param messenger callback messenger for scan results or errors
3890 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003891 * @return the id of the requested scan which can be used to stop the scan.
3892 */
3893 @Override
3894 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3895 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3897 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003898
3899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 return mNetworkScanRequestTracker.startNetworkScan(
3902 request, messenger, binder, getPhone(subId));
3903 } finally {
3904 Binder.restoreCallingIdentity(identity);
3905 }
yinxu504e1392017-04-12 16:03:22 -07003906 }
3907
3908 /**
3909 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003910 *
3911 * @param subId id of the subscription
3912 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003913 */
3914 @Override
3915 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3917 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003918
3919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3922 } finally {
3923 Binder.restoreCallingIdentity(identity);
3924 }
yinxu504e1392017-04-12 16:03:22 -07003925 }
3926
3927 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003928 * Get the calculated preferred network type.
3929 * Used for debugging incorrect network type.
3930 *
3931 * @return the preferred network type, defined in RILConstants.java.
3932 */
3933 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003934 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003935 final Phone defaultPhone = getDefaultPhone();
3936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
3937 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003938 return RILConstants.PREFERRED_NETWORK_MODE;
3939 }
3940
Malcolm Chend965c8b2018-02-28 15:00:40 -08003941 final long identity = Binder.clearCallingIdentity();
3942 try {
3943 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003944 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003945 } finally {
3946 Binder.restoreCallingIdentity(identity);
3947 }
Junda Liu84d15a22014-07-02 11:21:04 -07003948 }
3949
3950 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003951 * Get the preferred network type.
3952 * Used for device configuration by some CDMA operators.
3953 *
3954 * @return the preferred network type, defined in RILConstants.java.
3955 */
3956 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003957 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3959 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003960
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 if (DBG) log("getPreferredNetworkType");
3964 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3965 int networkType = (result != null ? result[0] : -1);
3966 if (DBG) log("getPreferredNetworkType: " + networkType);
3967 return networkType;
3968 } finally {
3969 Binder.restoreCallingIdentity(identity);
3970 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003971 }
3972
3973 /**
3974 * Set the preferred network type.
3975 * Used for device configuration by some CDMA operators.
3976 *
3977 * @param networkType the preferred network type, defined in RILConstants.java.
3978 * @return true on success; false on any failure.
3979 */
3980 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003981 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3983 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003984
3985 final long identity = Binder.clearCallingIdentity();
3986 try {
3987 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3988 Boolean success = (Boolean) sendRequest(
3989 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3990 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3991 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003992 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003993 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3994 }
3995 return success;
3996 } finally {
3997 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003998 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003999 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004000
4001 /**
Junda Liu475951f2014-11-07 16:45:03 -08004002 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004003 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004004 * tethering.
4005 *
4006 * @return 0: Not required. 1: required. 2: Not set.
4007 * @hide
4008 */
4009 @Override
4010 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004011 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004012
4013 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004014 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004015 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004016 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004017 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004018 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004019 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004020 dunRequired = 1;
4021 }
4022 return dunRequired;
4023 } finally {
4024 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004025 }
Junda Liu475951f2014-11-07 16:45:03 -08004026 }
4027
4028 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004029 * Set mobile data enabled
4030 * Used by the user through settings etc to turn on/off mobile data
4031 *
4032 * @param enable {@code true} turn turn data on, else {@code false}
4033 */
4034 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004035 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4037 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004038
4039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 int phoneId = mSubscriptionController.getPhoneId(subId);
4042 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4043 Phone phone = PhoneFactory.getPhone(phoneId);
4044 if (phone != null) {
4045 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4046 phone.setUserDataEnabled(enable);
4047 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004048 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004049 }
4050 } finally {
4051 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004052 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004053 }
4054
4055 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004056 * Get the user enabled state of Mobile Data.
4057 *
4058 * TODO: remove and use isUserDataEnabled.
4059 * This can't be removed now because some vendor codes
4060 * calls through ITelephony directly while they should
4061 * use TelephonyManager.
4062 *
4063 * @return true on enabled
4064 */
4065 @Override
4066 public boolean getDataEnabled(int subId) {
4067 return isUserDataEnabled(subId);
4068 }
4069
4070 /**
4071 * Get whether mobile data is enabled per user setting.
4072 *
4073 * There are other factors deciding whether mobile data is actually enabled, but they are
4074 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004075 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004076 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004077 *
4078 * @return {@code true} if data is enabled else {@code false}
4079 */
4080 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004081 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004082 try {
4083 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4084 null);
4085 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4087 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004088 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004089
4090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 int phoneId = mSubscriptionController.getPhoneId(subId);
4093 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4094 Phone phone = PhoneFactory.getPhone(phoneId);
4095 if (phone != null) {
4096 boolean retVal = phone.isUserDataEnabled();
4097 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4098 return retVal;
4099 } else {
4100 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4101 return false;
4102 }
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004105 }
4106 }
4107
4108 /**
4109 * Get whether mobile data is enabled.
4110 *
4111 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4112 * whether mobile data is actually enabled.
4113 *
4114 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4115 *
4116 * @return {@code true} if data is enabled else {@code false}
4117 */
4118 @Override
4119 public boolean isDataEnabled(int subId) {
4120 try {
4121 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4122 null);
4123 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4125 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004126 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004127
4128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 int phoneId = mSubscriptionController.getPhoneId(subId);
4131 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4132 Phone phone = PhoneFactory.getPhone(phoneId);
4133 if (phone != null) {
4134 boolean retVal = phone.isDataEnabled();
4135 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4136 return retVal;
4137 } else {
4138 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4139 return false;
4140 }
4141 } finally {
4142 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004143 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004144 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004145
4146 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004147 public int getCarrierPrivilegeStatus(int subId) {
4148 final Phone phone = getPhone(subId);
4149 if (phone == null) {
4150 loge("getCarrierPrivilegeStatus: Invalid subId");
4151 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4152 }
4153 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004154 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004155 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004156 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4157 }
4158 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004159 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004160 }
Junda Liu29340342014-07-10 15:23:27 -07004161
4162 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004163 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4164 final Phone phone = getPhone(subId);
4165 if (phone == null) {
4166 loge("getCarrierPrivilegeStatus: Invalid subId");
4167 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4168 }
4169 UiccProfile profile =
4170 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4171 if (profile == null) {
4172 loge("getCarrierPrivilegeStatus: No UICC");
4173 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4174 }
4175 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4176 }
4177
4178 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004179 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004180 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004181 if (TextUtils.isEmpty(pkgName))
4182 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004183 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004184 if (card == null) {
4185 loge("checkCarrierPrivilegesForPackage: No UICC");
4186 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4187 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004188 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4189 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004190 }
4191
4192 @Override
4193 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004194 if (TextUtils.isEmpty(pkgName))
4195 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004196 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4197 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4198 UiccCard card = UiccController.getInstance().getUiccCard(i);
4199 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004200 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004201 continue;
4202 }
4203
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004204 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004205 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4206 break;
4207 }
4208 }
4209
4210 return result;
Junda Liu29340342014-07-10 15:23:27 -07004211 }
Derek Tan89e89d42014-07-08 17:00:10 -07004212
4213 @Override
Junda Liue64de782015-04-16 17:19:16 -07004214 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4215 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4216 loge("phoneId " + phoneId + " is not valid.");
4217 return null;
4218 }
4219 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004220 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004221 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004222 return null ;
4223 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004224 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004225 }
4226
Amith Yamasani6e118872016-02-19 12:53:51 -08004227 @Override
4228 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004229 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004230 List<String> privilegedPackages = new ArrayList<>();
4231 List<PackageInfo> packages = null;
4232 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4233 UiccCard card = UiccController.getInstance().getUiccCard(i);
4234 if (card == null) {
4235 // No UICC in that slot.
4236 continue;
4237 }
4238 if (card.hasCarrierPrivilegeRules()) {
4239 if (packages == null) {
4240 // Only check packages in user 0 for now
4241 packages = pm.getInstalledPackagesAsUser(
4242 PackageManager.MATCH_DISABLED_COMPONENTS
4243 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4244 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4245 }
4246 for (int p = packages.size() - 1; p >= 0; p--) {
4247 PackageInfo pkgInfo = packages.get(p);
4248 if (pkgInfo != null && pkgInfo.packageName != null
4249 && card.getCarrierPrivilegeStatus(pkgInfo)
4250 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4251 privilegedPackages.add(pkgInfo.packageName);
4252 }
4253 }
4254 }
4255 }
4256 return privilegedPackages;
4257 }
4258
Wink Savilleb564aae2014-10-23 10:18:09 -07004259 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004260 final Phone phone = getPhone(subId);
4261 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004262 if (card == null) {
4263 loge("getIccId: No UICC");
4264 return null;
4265 }
4266 String iccId = card.getIccId();
4267 if (TextUtils.isEmpty(iccId)) {
4268 loge("getIccId: ICC ID is null or empty.");
4269 return null;
4270 }
4271 return iccId;
4272 }
4273
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004274 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004275 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4276 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004277 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4278 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004279
Malcolm Chend965c8b2018-02-28 15:00:40 -08004280 final long identity = Binder.clearCallingIdentity();
4281 try {
4282 final String iccId = getIccId(subId);
4283 final Phone phone = getPhone(subId);
4284 if (phone == null) {
4285 return false;
4286 }
4287 final String subscriberId = phone.getSubscriberId();
4288
4289 if (DBG_MERGE) {
4290 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4291 + subscriberId + " to " + number);
4292 }
4293
4294 if (TextUtils.isEmpty(iccId)) {
4295 return false;
4296 }
4297
4298 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4299
4300 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4301 if (alphaTag == null) {
4302 editor.remove(alphaTagPrefKey);
4303 } else {
4304 editor.putString(alphaTagPrefKey, alphaTag);
4305 }
4306
4307 // Record both the line number and IMSI for this ICCID, since we need to
4308 // track all merged IMSIs based on line number
4309 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4310 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4311 if (number == null) {
4312 editor.remove(numberPrefKey);
4313 editor.remove(subscriberPrefKey);
4314 } else {
4315 editor.putString(numberPrefKey, number);
4316 editor.putString(subscriberPrefKey, subscriberId);
4317 }
4318
4319 editor.commit();
4320 return true;
4321 } finally {
4322 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004323 }
Derek Tan7226c842014-07-02 17:42:23 -07004324 }
4325
4326 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004327 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004328 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004330 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004331 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004332 return null;
4333 }
Derek Tan97ebb422014-09-05 16:55:38 -07004334
Malcolm Chend965c8b2018-02-28 15:00:40 -08004335 final long identity = Binder.clearCallingIdentity();
4336 try {
4337 String iccId = getIccId(subId);
4338 if (iccId != null) {
4339 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4340 if (DBG_MERGE) {
4341 log("getLine1NumberForDisplay returning "
4342 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4343 }
4344 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004345 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004346 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4347 return null;
4348 } finally {
4349 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004350 }
Derek Tan7226c842014-07-02 17:42:23 -07004351 }
4352
4353 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004354 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004356 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004357 return null;
4358 }
Derek Tan97ebb422014-09-05 16:55:38 -07004359
Malcolm Chend965c8b2018-02-28 15:00:40 -08004360 final long identity = Binder.clearCallingIdentity();
4361 try {
4362 String iccId = getIccId(subId);
4363 if (iccId != null) {
4364 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4365 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4366 }
4367 return null;
4368 } finally {
4369 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004370 }
Derek Tan7226c842014-07-02 17:42:23 -07004371 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004372
4373 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004374 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004375 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4376 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004378 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4379 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004380 return null;
4381 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004382
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004383 final long identity = Binder.clearCallingIdentity();
4384 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004385 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004386 final TelephonyManager tele = TelephonyManager.from(context);
4387 final SubscriptionManager sub = SubscriptionManager.from(context);
4388
4389 // Figure out what subscribers are currently active
4390 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4391 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4392 // the process, where TelephonyManager was instantiated.
4393 // Otherwise AppOps check will fail.
4394
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004395 final int[] subIds = sub.getActiveSubscriptionIdList();
4396 for (int subId : subIds) {
4397 activeSubscriberIds.add(tele.getSubscriberId(subId));
4398 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004399
4400 // First pass, find a number override for an active subscriber
4401 String mergeNumber = null;
4402 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4403 for (String key : prefs.keySet()) {
4404 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4405 final String subscriberId = (String) prefs.get(key);
4406 if (activeSubscriberIds.contains(subscriberId)) {
4407 final String iccId = key.substring(
4408 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4409 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4410 mergeNumber = (String) prefs.get(numberKey);
4411 if (DBG_MERGE) {
4412 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4413 + " for active subscriber " + subscriberId);
4414 }
4415 if (!TextUtils.isEmpty(mergeNumber)) {
4416 break;
4417 }
4418 }
4419 }
4420 }
4421
4422 // Shortcut when no active merged subscribers
4423 if (TextUtils.isEmpty(mergeNumber)) {
4424 return null;
4425 }
4426
4427 // Second pass, find all subscribers under that line override
4428 final ArraySet<String> result = new ArraySet<>();
4429 for (String key : prefs.keySet()) {
4430 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4431 final String number = (String) prefs.get(key);
4432 if (mergeNumber.equals(number)) {
4433 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4434 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4435 final String subscriberId = (String) prefs.get(subscriberKey);
4436 if (!TextUtils.isEmpty(subscriberId)) {
4437 result.add(subscriberId);
4438 }
4439 }
4440 }
4441 }
4442
4443 final String[] resultArray = result.toArray(new String[result.size()]);
4444 Arrays.sort(resultArray);
4445 if (DBG_MERGE) {
4446 Slog.d(LOG_TAG,
4447 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4448 }
4449 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004452 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004453 }
4454
4455 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004456 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004457 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4458 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004459
4460 final long identity = Binder.clearCallingIdentity();
4461 try {
4462 final Phone phone = getPhone(subId);
4463 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004467 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004468
4469 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004470 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004471 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4472 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004473 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004474
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 final Phone phone = getPhone(subId);
4478 if (phone == null) {
4479 return false;
4480 }
4481 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4482 cdmaNonRoamingList);
4483 } finally {
4484 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004485 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004486 }
4487
4488 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004489 @Deprecated
4490 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4491 enforceModifyPermission();
4492
4493 int returnValue = 0;
4494 try {
vagdevie435a3e2018-08-15 16:01:53 -07004495 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004496 if(result.exception == null) {
4497 if (result.result != null) {
4498 byte[] responseData = (byte[])(result.result);
4499 if(responseData.length > oemResp.length) {
4500 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4501 responseData.length + "bytes. Buffer Size is " +
4502 oemResp.length + "bytes.");
4503 }
4504 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4505 returnValue = responseData.length;
4506 }
4507 } else {
4508 CommandException ex = (CommandException) result.exception;
4509 returnValue = ex.getCommandError().ordinal();
4510 if(returnValue > 0) returnValue *= -1;
4511 }
4512 } catch (RuntimeException e) {
4513 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4514 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4515 if(returnValue > 0) returnValue *= -1;
4516 }
4517
4518 return returnValue;
4519 }
4520
4521 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004522 public void setRadioCapability(RadioAccessFamily[] rafs) {
4523 try {
4524 ProxyController.getInstance().setRadioCapability(rafs);
4525 } catch (RuntimeException e) {
4526 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4527 }
4528 }
4529
4530 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004531 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004532 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004533 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004534 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004535 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004536 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004537 final long identity = Binder.clearCallingIdentity();
4538 try {
chen xufeeed752018-10-26 14:17:57 -07004539 TelephonyPermissions
4540 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4541 mApp, phone.getSubId(), "getRadioAccessFamily");
4542 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
chen xufeeed752018-10-26 14:17:57 -07004546 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004547 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004548
4549 @Override
4550 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004551 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004552 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004553
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004556 ImsManager.getInstance(defaultPhone.getContext(),
4557 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004558 } finally {
4559 Binder.restoreCallingIdentity(identity);
4560 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004561 }
4562
4563 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004564 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004565 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004567 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004568 return false;
4569 }
Svet Ganovb320e182015-04-16 12:30:10 -07004570
Malcolm Chend965c8b2018-02-28 15:00:40 -08004571 final long identity = Binder.clearCallingIdentity();
4572 try {
4573 // Check the user preference and the system-level IMS setting. Even if the user has
4574 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4575 // In the long run, we may instead need to check if there exists a connection service
4576 // which can support video calling.
4577 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004578 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004579 return imsManager.isVtEnabledByPlatform()
4580 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4581 && imsManager.isVtEnabledByUser();
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004585 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004586
Andrew Leea1239f22015-03-02 17:44:07 -08004587 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004588 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4590 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4591 return false;
4592 }
4593
4594 final long identity = Binder.clearCallingIdentity();
4595 try {
4596 CarrierConfigManager configManager =
4597 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004598 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004599 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4600 } finally {
4601 Binder.restoreCallingIdentity(identity);
4602 }
Andrew Leea1239f22015-03-02 17:44:07 -08004603 }
4604
4605 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004606 public boolean isWorldPhone(int subId, String callingPackage) {
4607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4608 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4609 return false;
4610 }
4611
4612 final long identity = Binder.clearCallingIdentity();
4613 try {
4614 CarrierConfigManager configManager =
4615 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004616 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004617 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
Andrew Leea1239f22015-03-02 17:44:07 -08004621 }
4622
Andrew Lee9431b832015-03-09 18:46:45 -07004623 @Override
4624 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004625 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004626 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004627 }
4628
4629 @Override
4630 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004631 final long identity = Binder.clearCallingIdentity();
4632 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004633 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
Andrew Lee9431b832015-03-09 18:46:45 -07004637 }
4638
Hall Liuf6668912018-10-31 17:05:23 -07004639 /**
4640 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4641 * support for the feature and device firmware support.
4642 *
4643 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4644 */
4645 @Override
4646 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004647 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004648 final Phone phone = getPhone(subscriptionId);
4649 if (phone == null) {
4650 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
4651 return false;
4652 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004653 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004654 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004655 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4656 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004657 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004658 return isCarrierSupported && isDeviceSupported;
4659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
Hall Liu98187582018-01-22 19:15:32 -08004662 }
4663
Hall Liuf6668912018-10-31 17:05:23 -07004664 /**
4665 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4666 * both also support RTT.
4667 */
4668 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004669 final long identity = Binder.clearCallingIdentity();
4670 try {
Hall Liuf6668912018-10-31 17:05:23 -07004671 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004672 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004676 }
4677
Sanket Padawe7310cc72015-01-14 09:53:20 -08004678 /**
4679 * Returns the unique device ID of phone, for example, the IMEI for
4680 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4681 *
4682 * <p>Requires Permission:
4683 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4684 */
4685 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004686 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004687 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004688 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004689 return null;
4690 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004691 int subId = phone.getSubId();
4692 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4693 mApp, subId, callingPackage, "getDeviceId")) {
4694 return null;
4695 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004696
4697 final long identity = Binder.clearCallingIdentity();
4698 try {
4699 return phone.getDeviceId();
4700 } finally {
4701 Binder.restoreCallingIdentity(identity);
4702 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004703 }
4704
Ping Sunc67b7c22016-03-02 19:16:45 +08004705 /**
4706 * {@hide}
4707 * Returns the IMS Registration Status on a particular subid
4708 *
4709 * @param subId
4710 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004711 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004712 Phone phone = getPhone(subId);
4713 if (phone != null) {
4714 return phone.isImsRegistered();
4715 } else {
4716 return false;
4717 }
4718 }
4719
Santos Cordon7a1885b2015-02-03 11:15:19 -08004720 @Override
4721 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004722 final long identity = Binder.clearCallingIdentity();
4723 try {
4724 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004728 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004729
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004730 /**
4731 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004732 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004733 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004734 final long identity = Binder.clearCallingIdentity();
4735 try {
4736 Phone phone = getPhone(subId);
4737 if (phone != null) {
4738 return phone.isWifiCallingEnabled();
4739 } else {
4740 return false;
4741 }
4742 } finally {
4743 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004744 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004745 }
4746
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004747 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004748 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004749 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004750 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004751 final long identity = Binder.clearCallingIdentity();
4752 try {
4753 Phone phone = getPhone(subId);
4754 if (phone != null) {
4755 return phone.isVideoEnabled();
4756 } else {
4757 return false;
4758 }
4759 } finally {
4760 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004761 }
4762 }
4763
4764 /**
4765 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4766 * defined in {@link ImsRegistrationImplBase}.
4767 */
4768 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 Phone phone = getPhone(subId);
4772 if (phone != null) {
4773 return phone.getImsRegistrationTech();
4774 } else {
4775 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4776 }
4777 } finally {
4778 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004779 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004780 }
4781
Stuart Scott8eef64f2015-04-08 15:13:54 -07004782 @Override
4783 public void factoryReset(int subId) {
4784 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004785 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4786 return;
4787 }
4788
Svet Ganovcc087f82015-05-12 20:35:54 -07004789 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004790
Svet Ganovcc087f82015-05-12 20:35:54 -07004791 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004792 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4793 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004794 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004795 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004796 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004797 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
4798 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07004799 }
4800 } finally {
4801 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004802 }
4803 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004804
4805 @Override
4806 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004807 final long identity = Binder.clearCallingIdentity();
4808 try {
4809 // We query all subscriptions instead of just the active ones, because
4810 // this might be called early on in the provisioning flow when the
4811 // subscriptions potentially aren't active yet.
4812 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4813 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004814 return null;
4815 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004816
Malcolm Chend965c8b2018-02-28 15:00:40 -08004817 // This function may be called very early, say, from the setup wizard, at
4818 // which point we won't have a default subscription set. If that's the case
4819 // we just choose the first, which will be valid in "most cases".
4820 final int defaultSubId = getDefaultSubscription();
4821 SubscriptionInfo info = null;
4822 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4823 info = slist.get(0);
4824 } else {
4825 for (SubscriptionInfo item : slist) {
4826 if (item.getSubscriptionId() == defaultSubId) {
4827 info = item;
4828 break;
4829 }
4830 }
4831
4832 if (info == null) {
4833 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004834 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004835 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004836
Malcolm Chend965c8b2018-02-28 15:00:40 -08004837 // Try and fetch the locale from the carrier properties or from the SIM language
4838 // preferences (EF-PL and EF-LI)...
4839 final int mcc = info.getMcc();
4840 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4841 String simLanguage = null;
4842 if (defaultPhone != null) {
4843 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4844 if (localeFromDefaultSim != null) {
4845 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4846 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4847 return localeFromDefaultSim.toLanguageTag();
4848 } else {
4849 simLanguage = localeFromDefaultSim.getLanguage();
4850 }
4851 }
4852 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004853
Malcolm Chend965c8b2018-02-28 15:00:40 -08004854 // The SIM language preferences only store a language (e.g. fr = French), not an
4855 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4856 // the SIM and carrier preferences does not include a country we add the country
4857 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004858 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004859 if (mccLocale != null) {
4860 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4861 return mccLocale.toLanguageTag();
4862 }
4863
4864 if (DBG) log("No locale found - returning null");
4865 return null;
4866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004869 }
4870
4871 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004872 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004873 }
4874
Malcolm Chend965c8b2018-02-28 15:00:40 -08004875 /**
4876 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4877 */
4878 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004879 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004880 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004881
Chenjie Yu1ba97252018-01-11 18:16:20 -08004882 private final ModemActivityInfo mLastModemActivityInfo =
4883 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4884
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004885 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004886 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4887 * representing the state of the modem.
4888 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004889 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4890 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004891 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004892 */
4893 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004894 public void requestModemActivityInfo(ResultReceiver result) {
4895 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004896 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004897
4898 final long identity = Binder.clearCallingIdentity();
4899 try {
4900 ModemActivityInfo ret = null;
4901 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004902 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4903 CMD_GET_MODEM_ACTIVITY_INFO,
4904 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004905 if (isModemActivityInfoValid(info)) {
4906 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4907 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4908 mergedTxTimeMs[i] =
4909 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4910 }
4911 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4912 mLastModemActivityInfo.setSleepTimeMillis(
4913 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4914 mLastModemActivityInfo.setIdleTimeMillis(
4915 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4916 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4917 mLastModemActivityInfo.setRxTimeMillis(
4918 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4919 mLastModemActivityInfo.setEnergyUsed(
4920 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004921 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004922 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4923 mLastModemActivityInfo.getSleepTimeMillis(),
4924 mLastModemActivityInfo.getIdleTimeMillis(),
4925 mLastModemActivityInfo.getTxTimeMillis(),
4926 mLastModemActivityInfo.getRxTimeMillis(),
4927 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004928 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004929 Bundle bundle = new Bundle();
4930 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4931 result.send(0, bundle);
4932 } finally {
4933 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004934 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004935 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004936
Siddharth Rayf5d29552018-06-17 15:02:38 -07004937 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4938 // less than total activity duration.
4939 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4940 if (info == null) {
4941 return false;
4942 }
4943 int activityDurationMs =
4944 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4945 int totalTxTimeMs = 0;
4946 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4947 totalTxTimeMs += info.getTxTimeMillis()[i];
4948 }
4949 return (info.isValid()
4950 && (info.getSleepTimeMillis() <= activityDurationMs)
4951 && (info.getIdleTimeMillis() <= activityDurationMs)
4952 && (info.getRxTimeMillis() <= activityDurationMs)
4953 && (totalTxTimeMs <= activityDurationMs));
4954 }
4955
Jack Yu85bd38a2015-11-09 11:34:32 -08004956 /**
4957 * {@hide}
4958 * Returns the service state information on specified subscription.
4959 */
4960 @Override
4961 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004963 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004964 return null;
4965 }
4966
Malcolm Chend965c8b2018-02-28 15:00:40 -08004967 final long identity = Binder.clearCallingIdentity();
4968 try {
4969 final Phone phone = getPhone(subId);
4970 if (phone == null) {
4971 return null;
4972 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004973
Malcolm Chend965c8b2018-02-28 15:00:40 -08004974 return phone.getServiceState();
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004978 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004979
4980 /**
4981 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4982 *
4983 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4984 * voicemail ringtone.
4985 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4986 * PhoneAccount.
4987 */
4988 @Override
4989 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004990 final long identity = Binder.clearCallingIdentity();
4991 try {
4992 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4993 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004994 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004995 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004996
Malcolm Chend965c8b2018-02-28 15:00:40 -08004997 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4998 } finally {
4999 Binder.restoreCallingIdentity(identity);
5000 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005001 }
5002
5003 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005004 * Sets the per-account voicemail ringtone.
5005 *
5006 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5007 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5008 *
5009 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5010 * voicemail ringtone.
5011 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5012 * PhoneAccount.
5013 */
5014 @Override
5015 public void setVoicemailRingtoneUri(String callingPackage,
5016 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005017 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005018 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5019 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005020 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5022 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5023 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005024 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005025
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5029 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005030 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005031 }
5032 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5033 } finally {
5034 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005035 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005036 }
5037
5038 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005039 * Returns whether vibration is set for voicemail notification in Phone settings.
5040 *
5041 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5042 * voicemail vibration setting.
5043 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5044 */
5045 @Override
5046 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5050 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005051 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005052 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005053
Malcolm Chend965c8b2018-02-28 15:00:40 -08005054 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
5057 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005058 }
5059
Youhan Wange64578a2016-05-02 15:32:42 -07005060 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005061 * Sets the per-account voicemail vibration.
5062 *
5063 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5064 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5065 *
5066 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5067 * voicemail vibration setting.
5068 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5069 * specific PhoneAccount.
5070 */
5071 @Override
5072 public void setVoicemailVibrationEnabled(String callingPackage,
5073 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005074 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005075 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5076 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005077 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5079 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5080 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005081 }
5082
Malcolm Chend965c8b2018-02-28 15:00:40 -08005083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5086 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005087 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005088 }
5089 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005092 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005093 }
5094
5095 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005096 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5097 *
5098 * @throws SecurityException if the caller does not have the required permission
5099 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005100 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005101 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005102 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005103 }
5104
5105 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005106 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5107 * permission.
5108 *
5109 * @throws SecurityException if the caller does not have the required permission
5110 */
5111 private void enforceSendSmsPermission() {
5112 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5113 }
5114
5115 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005116 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005117 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005118 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005119 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005120 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005124 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005125 if (componentName == null) {
5126 throw new SecurityException(
5127 "Caller not current active visual voicemail package[null]");
5128 }
5129 String vvmPackage = componentName.getPackageName();
5130 if (!callingPackage.equals(vvmPackage)) {
5131 throw new SecurityException("Caller not current active visual voicemail package["
5132 + vvmPackage + "]");
5133 }
5134 } finally {
5135 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005136 }
5137 }
5138
5139 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005140 * Return the application ID for the app type.
5141 *
5142 * @param subId the subscription ID that this request applies to.
5143 * @param appType the uicc app type.
5144 * @return Application ID for specificied app type, or null if no uicc.
5145 */
5146 @Override
5147 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005148 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005149 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005150
5151 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005152 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005153 if (phone == null) {
5154 return null;
5155 }
5156 String aid = null;
5157 try {
5158 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5159 .getApplicationByType(appType).getAid();
5160 } catch (Exception e) {
5161 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5162 }
5163 return aid;
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005166 }
Youhan Wange64578a2016-05-02 15:32:42 -07005167 }
5168
Youhan Wang4001d252016-05-11 10:29:41 -07005169 /**
5170 * Return the Electronic Serial Number.
5171 *
5172 * @param subId the subscription ID that this request applies to.
5173 * @return ESN or null if error.
5174 */
5175 @Override
5176 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005177 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005178 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005179
5180 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005181 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005182 if (phone == null) {
5183 return null;
5184 }
5185 String esn = null;
5186 try {
5187 esn = phone.getEsn();
5188 } catch (Exception e) {
5189 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5190 }
5191 return esn;
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005194 }
Youhan Wang4001d252016-05-11 10:29:41 -07005195 }
5196
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005197 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005198 * Return the Preferred Roaming List Version.
5199 *
5200 * @param subId the subscription ID that this request applies to.
5201 * @return PRLVersion or null if error.
5202 */
5203 @Override
5204 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005205 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005206 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005207
5208 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005209 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005210 if (phone == null) {
5211 return null;
5212 }
5213 String cdmaPrlVersion = null;
5214 try {
5215 cdmaPrlVersion = phone.getCdmaPrlVersion();
5216 } catch (Exception e) {
5217 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5218 }
5219 return cdmaPrlVersion;
5220 } finally {
5221 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005222 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005223 }
5224
5225 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005226 * Get snapshot of Telephony histograms
5227 * @return List of Telephony histograms
5228 * @hide
5229 */
5230 @Override
5231 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5233 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005234
5235 final long identity = Binder.clearCallingIdentity();
5236 try {
5237 return RIL.getTelephonyRILTimingHistograms();
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
5240 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005241 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005242
5243 /**
5244 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005245 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005246 * Require system privileges. In the future we may add this to carrier APIs.
5247 *
5248 * @return The number of carriers set successfully, should match length of carriers
5249 */
5250 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005251 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005252 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005253 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005254
Meng Wang9b7c4e92017-02-17 11:41:27 -08005255 if (carriers == null) {
5256 throw new NullPointerException("carriers cannot be null");
5257 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005258
Malcolm Chend965c8b2018-02-28 15:00:40 -08005259 final long identity = Binder.clearCallingIdentity();
5260 try {
5261 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005262 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5263 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005264 return retVal[0];
5265 } finally {
5266 Binder.restoreCallingIdentity(identity);
5267 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005268 }
5269
5270 /**
5271 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005272 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005273 * Require system privileges. In the future we may add this to carrier APIs.
5274 *
5275 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5276 * means all carriers are allowed.
5277 */
5278 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005279 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005280 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005281 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005282
5283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005286 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5287 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005288 } finally {
5289 Binder.restoreCallingIdentity(identity);
5290 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005291 }
5292
fionaxu59545b42016-05-25 15:53:37 -07005293 /**
5294 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5295 * @param subId the subscription ID that this action applies to.
5296 * @param enabled control enable or disable metered apns.
5297 * {@hide}
5298 */
5299 @Override
5300 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5301 enforceModifyPermission();
5302 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005303
5304 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005305 if (phone == null) {
5306 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5307 return;
5308 }
5309 try {
5310 phone.carrierActionSetMeteredApnsEnabled(enabled);
5311 } catch (Exception e) {
5312 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005313 } finally {
5314 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005315 }
5316 }
5317
5318 /**
5319 * Action set from carrier signalling broadcast receivers to enable/disable radio
5320 * @param subId the subscription ID that this action applies to.
5321 * @param enabled control enable or disable radio.
5322 * {@hide}
5323 */
5324 @Override
5325 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5326 enforceModifyPermission();
5327 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005328
5329 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005330 if (phone == null) {
5331 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5332 return;
5333 }
5334 try {
5335 phone.carrierActionSetRadioEnabled(enabled);
5336 } catch (Exception e) {
5337 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005338 } finally {
5339 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005340 }
5341 }
5342
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005343 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005344 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5345 * network status based on which carrier apps could apply actions accordingly,
5346 * enable/disable default url handler for example.
5347 *
5348 * @param subId the subscription ID that this action applies to.
5349 * @param report control start/stop reporting the default network status.
5350 * {@hide}
5351 */
5352 @Override
5353 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5354 enforceModifyPermission();
5355 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005356
5357 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005358 if (phone == null) {
5359 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5360 return;
5361 }
5362 try {
5363 phone.carrierActionReportDefaultNetworkStatus(report);
5364 } catch (Exception e) {
5365 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005366 } finally {
5367 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005368 }
5369 }
5370
5371 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005372 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5373 * bug report is being generated.
5374 */
5375 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005376 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005377 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5378 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005379 writer.println("Permission Denial: can't dump Phone from pid="
5380 + Binder.getCallingPid()
5381 + ", uid=" + Binder.getCallingUid()
5382 + "without permission "
5383 + android.Manifest.permission.DUMP);
5384 return;
5385 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005386 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005387 }
Jack Yueb89b242016-06-22 13:27:47 -07005388
Brad Ebingerdac2f002018-04-03 15:17:52 -07005389 @Override
5390 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5391 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5392 throws RemoteException {
5393 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5394 }
5395
Jack Yueb89b242016-06-22 13:27:47 -07005396 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005397 * Get aggregated video call data usage since boot.
5398 *
5399 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5400 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005401 * {@hide}
5402 */
5403 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005404 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005405 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5406 null);
5407
Malcolm Chend965c8b2018-02-28 15:00:40 -08005408 final long identity = Binder.clearCallingIdentity();
5409 try {
5410 // NetworkStatsService keeps tracking the active network interface and identity. It
5411 // records the delta with the corresponding network identity.
5412 // We just return the total video call data usage snapshot since boot.
5413 Phone phone = getPhone(subId);
5414 if (phone != null) {
5415 return phone.getVtDataUsage(perUidStats);
5416 }
5417 return null;
5418 } finally {
5419 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005420 }
Jack Yueb89b242016-06-22 13:27:47 -07005421 }
Jack Yu75ab2952016-07-08 14:29:33 -07005422
5423 /**
5424 * Policy control of data connection. Usually used when data limit is passed.
5425 * @param enabled True if enabling the data, otherwise disabling.
5426 * @param subId Subscription index
5427 * {@hide}
5428 */
5429 @Override
5430 public void setPolicyDataEnabled(boolean enabled, int subId) {
5431 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005432
5433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 Phone phone = getPhone(subId);
5436 if (phone != null) {
5437 phone.setPolicyDataEnabled(enabled);
5438 }
5439 } finally {
5440 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005441 }
5442 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005443
5444 /**
5445 * Get Client request stats
5446 * @return List of Client Request Stats
5447 * @hide
5448 */
5449 @Override
5450 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005452 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005453 return null;
5454 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005455 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005456
Malcolm Chend965c8b2018-02-28 15:00:40 -08005457 final long identity = Binder.clearCallingIdentity();
5458 try {
5459 if (phone != null) {
5460 return phone.getClientRequestStats();
5461 }
5462
5463 return null;
5464 } finally {
5465 Binder.restoreCallingIdentity(identity);
5466 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005467 }
5468
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005469 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005470 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005471 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005472 }
Jack Yueb4124c2017-02-16 15:32:43 -08005473
5474 /**
Grace Chen70990072017-03-24 17:21:30 -07005475 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005476 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005477 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005478 * @param state State of SIM (power down, power up, pass through)
5479 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5480 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5481 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005482 *
5483 **/
5484 @Override
Grace Chen70990072017-03-24 17:21:30 -07005485 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005486 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005487 Phone phone = PhoneFactory.getPhone(slotIndex);
5488
vagdevie435a3e2018-08-15 16:01:53 -07005489 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5490
Malcolm Chend965c8b2018-02-28 15:00:40 -08005491 final long identity = Binder.clearCallingIdentity();
5492 try {
5493 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005494 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005495 }
5496 } finally {
5497 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005498 }
5499 }
Shuo Qiandd210312017-04-12 22:11:33 +00005500
Tyler Gunn65d45c22017-06-05 11:22:26 -07005501 private boolean isUssdApiAllowed(int subId) {
5502 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005503 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005504 if (configManager == null) {
5505 return false;
5506 }
5507 PersistableBundle pb = configManager.getConfigForSubId(subId);
5508 if (pb == null) {
5509 return false;
5510 }
5511 return pb.getBoolean(
5512 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5513 }
5514
Shuo Qiandd210312017-04-12 22:11:33 +00005515 /**
5516 * Check if phone is in emergency callback mode
5517 * @return true if phone is in emergency callback mode
5518 * @param subId sub id
5519 */
goneil9c5f4872017-12-05 14:07:56 -08005520 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005521 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005522 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005523 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005524
5525 final long identity = Binder.clearCallingIdentity();
5526 try {
5527 if (phone != null) {
5528 return phone.isInEcm();
5529 } else {
5530 return false;
5531 }
5532 } finally {
5533 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005534 }
5535 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005536
5537 /**
5538 * Get the current signal strength information for the given subscription.
5539 * Because this information is not updated when the device is in a low power state
5540 * it should not be relied-upon to be current.
5541 * @param subId Subscription index
5542 * @return the most recent cached signal strength info from the modem
5543 */
5544 @Override
5545 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 Phone p = getPhone(subId);
5549 if (p == null) {
5550 return null;
5551 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005552
Malcolm Chend965c8b2018-02-28 15:00:40 -08005553 return p.getSignalStrength();
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005557 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005558
Pengquan Meng9140aec2018-08-22 14:49:57 -07005559 /**
chen xu907e5a22018-10-11 13:21:04 -07005560 * Get the current modem radio state for the given slot.
5561 * @param slotIndex slot index.
5562 * @param callingPackage the name of the package making the call.
5563 * @return the current radio power state from the modem
5564 */
5565 @Override
5566 public int getRadioPowerState(int slotIndex, String callingPackage) {
5567 Phone phone = PhoneFactory.getPhone(slotIndex);
5568 if (phone != null) {
5569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5570 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5571 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5572 }
5573
5574 final long identity = Binder.clearCallingIdentity();
5575 try {
5576 return phone.getRadioPowerState();
5577 } finally {
5578 Binder.restoreCallingIdentity(identity);
5579 }
5580 }
5581 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5582 }
5583
5584 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005585 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5586 *
5587 * <p>Requires one of the following permissions:
5588 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5589 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5590 * privileges.
5591 *
5592 * @param subId subscription id
5593 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5594 * {@code false}.
5595 */
5596 @Override
5597 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005598 boolean isEnabled = false;
5599 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005600 try {
5601 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005602 null /* message */);
5603 Phone phone = getPhone(subId);
5604 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005605 } catch (Exception e) {
5606 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5607 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005608 } finally {
5609 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005610 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005611 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005612 }
5613
5614
5615 /**
5616 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5617 *
5618 * <p> Requires permission:
5619 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5620 * privileges.
5621 *
5622 * @param subId subscription id
5623 * @param isEnabled {@code true} means enable, {@code false} means disable.
5624 */
5625 @Override
5626 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005627 final long identity = Binder.clearCallingIdentity();
5628 try {
5629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5630 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005631
Pengquan Meng0c05b502018-09-06 09:59:22 -07005632 Phone phone = getPhone(subId);
5633 if (phone != null) {
5634 phone.setDataRoamingEnabled(isEnabled);
5635 }
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005638 }
5639 }
5640
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005641 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005642 public boolean isManualNetworkSelectionAllowed(int subId) {
5643 boolean isAllowed = true;
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
5646 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5647 mApp, subId, "isManualNetworkSelectionAllowed");
5648 Phone phone = getPhone(subId);
5649 if (phone != null) {
5650 isAllowed = phone.isCspPlmnEnabled();
5651 }
5652 } finally {
5653 Binder.restoreCallingIdentity(identity);
5654 }
5655 return isAllowed;
5656 }
5657
5658 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005659 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005660 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005661
Malcolm Chend965c8b2018-02-28 15:00:40 -08005662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5665 if (slots == null) {
5666 Rlog.i(LOG_TAG, "slots is null.");
5667 return null;
5668 }
5669
5670 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5671 for (int i = 0; i < slots.length; i++) {
5672 UiccSlot slot = slots[i];
5673 if (slot == null) {
5674 continue;
5675 }
5676
5677 String cardId;
5678 UiccCard card = slot.getUiccCard();
5679 if (card != null) {
5680 cardId = card.getCardId();
5681 } else {
5682 cardId = slot.getIccId();
5683 }
5684
5685 int cardState = 0;
5686 switch (slot.getCardState()) {
5687 case CARDSTATE_ABSENT:
5688 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5689 break;
5690 case CARDSTATE_PRESENT:
5691 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5692 break;
5693 case CARDSTATE_ERROR:
5694 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5695 break;
5696 case CARDSTATE_RESTRICTED:
5697 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5698 break;
5699 default:
5700 break;
5701
5702 }
5703
5704 infos[i] = new UiccSlotInfo(
5705 slot.isActive(),
5706 slot.isEuicc(),
5707 cardId,
5708 cardState,
5709 slot.getPhoneId(),
5710 slot.isExtendedApduSupported());
5711 }
5712 return infos;
5713 } finally {
5714 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005715 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005716 }
5717
5718 @Override
5719 public boolean switchSlots(int[] physicalSlots) {
5720 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005721
5722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5725 } finally {
5726 Binder.restoreCallingIdentity(identity);
5727 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005728 }
Jack Yu4c988042018-02-27 15:30:01 -08005729
5730 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08005731 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
5732 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5733 mApp, subId, callingPackage, "getCardIdForDefaultEuicc")) {
5734 return TelephonyManager.INVALID_CARD_ID;
5735 }
5736
5737 final long identity = Binder.clearCallingIdentity();
5738 try {
5739 return UiccController.getInstance().getCardIdForDefaultEuicc();
5740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
5743 }
5744
5745 @Override
Jack Yu4c988042018-02-27 15:30:01 -08005746 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5747 enforceModifyPermission();
5748 final Phone phone = getPhone(subId);
5749 if (phone == null) {
5750 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5751 return;
5752 }
5753
Malcolm Chend965c8b2018-02-28 15:00:40 -08005754 final long identity = Binder.clearCallingIdentity();
5755 try {
5756 phone.setRadioIndicationUpdateMode(filters, mode);
5757 } finally {
5758 Binder.restoreCallingIdentity(identity);
5759 }
Jack Yu4c988042018-02-27 15:30:01 -08005760 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005761
5762 /**
goneil47ffb6e2018-04-06 15:40:58 -07005763 * A test API to reload the UICC profile.
5764 *
5765 * <p>Requires that the calling app has permission
5766 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5767 * @hide
5768 */
5769 @Override
5770 public void refreshUiccProfile(int subId) {
5771 enforceModifyPermission();
5772
5773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 Phone phone = getPhone(subId);
5776 if (phone == null) {
5777 return;
5778 }
5779 UiccCard uiccCard = phone.getUiccCard();
5780 if (uiccCard == null) {
5781 return;
5782 }
5783 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5784 if (uiccProfile == null) {
5785 return;
5786 }
5787 uiccProfile.refresh();
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
5791 }
5792
5793 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005794 * Returns false if the mobile data is disabled by default, otherwise return true.
5795 */
5796 private boolean getDefaultDataEnabled() {
5797 return "true".equalsIgnoreCase(
5798 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5799 }
5800
5801 /**
5802 * Returns true if the data roaming is enabled by default, i.e the system property
5803 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5804 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5805 */
5806 private boolean getDefaultDataRoamingEnabled(int subId) {
5807 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005808 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005809 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5810 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5811 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5812 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5813 return isDataRoamingEnabled;
5814 }
5815
5816 /**
5817 * Returns the default network type for the given {@code subId}, if the default network type is
5818 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5819 */
5820 private int getDefaultNetworkType(int subId) {
5821 return Integer.parseInt(
5822 TelephonyManager.getTelephonyProperty(
5823 mSubscriptionController.getPhoneId(subId),
5824 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5825 String.valueOf(Phone.PREFERRED_NT_MODE)));
5826 }
fionaxua13278b2018-03-21 00:08:13 -07005827
5828 @Override
5829 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5830 gid1, String gid2, String plmn, String spn) {
5831 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005832
5833 final long identity = Binder.clearCallingIdentity();
5834 try {
5835 final Phone phone = getPhone(subId);
5836 if (phone == null) {
5837 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5838 return;
5839 }
5840 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5841 } finally {
5842 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005843 }
fionaxua13278b2018-03-21 00:08:13 -07005844 }
5845
5846 @Override
5847 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005848 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005849
5850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 final Phone phone = getPhone(subId);
5853 if (phone == null) {
5854 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5855 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5856 }
5857 return phone.getCarrierIdListVersion();
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005860 }
fionaxua13278b2018-03-21 00:08:13 -07005861 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005862
5863 @Override
5864 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5866 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5867 return -1;
5868 }
5869
5870 final long identity = Binder.clearCallingIdentity();
5871 try {
5872 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5873 } finally {
5874 Binder.restoreCallingIdentity(identity);
5875 }
5876 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005877
5878 @Override
5879 public int getCdmaRoamingMode(int subId) {
5880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5881 mApp, subId, "getCdmaRoamingMode");
5882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
5885 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5886 } finally {
5887 Binder.restoreCallingIdentity(identity);
5888 }
5889 }
5890
5891 @Override
5892 public boolean setCdmaRoamingMode(int subId, int mode) {
5893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5894 mApp, subId, "setCdmaRoamingMode");
5895
5896 final long identity = Binder.clearCallingIdentity();
5897 try {
5898 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5899 } finally {
5900 Binder.restoreCallingIdentity(identity);
5901 }
5902 }
5903
5904 @Override
5905 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5907 mApp, subId, "setCdmaSubscriptionMode");
5908
5909 final long identity = Binder.clearCallingIdentity();
5910 try {
5911 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5912 } finally {
5913 Binder.restoreCallingIdentity(identity);
5914 }
5915 }
chen xu7ee67862018-10-30 22:27:10 -07005916
sqian2fff4a32018-11-05 14:18:37 -08005917 private void ensureUserRunning(int userId) {
5918 if (!mUserManager.isUserRunning(userId)) {
5919 throw new IllegalStateException("User " + userId + " does not exist or not running");
5920 }
5921 }
5922
5923 /**
5924 * Returns a list of SMS apps on a given user.
5925 *
5926 * Only the shell user (UID 2000 or 0) can call it.
5927 * Target user must be running.
5928 */
5929 @Override
5930 public String[] getSmsApps(int userId) {
5931 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5932 ensureUserRunning(userId);
5933
5934 final Collection<SmsApplicationData> apps =
5935 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5936
5937 String[] ret = new String[apps.size()];
5938 int i = 0;
5939 for (SmsApplicationData app : apps) {
5940 ret[i++] = app.mPackageName;
5941 }
5942 return ret;
5943 }
5944
5945 /**
5946 * Returns the default SMS app package name on a given user.
5947 *
5948 * Only the shell user (UID 2000 or 0) can call it.
5949 * Target user must be running.
5950 */
5951 @Override
5952 public String getDefaultSmsApp(int userId) {
5953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5954 ensureUserRunning(userId);
5955
5956 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5957 /* updateIfNeeded= */ true, userId);
5958 return cn == null ? null : cn.getPackageName();
5959 }
5960
5961 /**
5962 * Set a package as the default SMS app on a given user.
5963 *
5964 * Only the shell user (UID 2000 or 0) can call it.
5965 * Target user must be running.
5966 */
5967 @Override
5968 public void setDefaultSmsApp(int userId, String packageName) {
5969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5970 ensureUserRunning(userId);
5971
5972 boolean found = false;
5973 for (String pkg : getSmsApps(userId)) {
5974 if (TextUtils.equals(packageName, pkg)) {
5975 found = true;
5976 break;
5977 }
5978 }
5979 if (!found) {
5980 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5981 }
5982
5983 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5984 }
5985
chen xu7ee67862018-10-30 22:27:10 -07005986 @Override
sqian04b86072018-11-07 14:02:21 -08005987 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5988 String callingPackage) {
5989 // TODO connect with internal content
5990 return null;
5991 }
5992
5993 @Override
5994 public boolean isCurrentEmergencyNumber(String number) {
5995 // TODO connect with internal content
5996 return false;
5997 }
5998
5999 @Override
chen xu7ee67862018-10-30 22:27:10 -07006000 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6001 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6002 Phone phone = getPhone(subId);
6003 if (phone == null) {
6004 return null;
6005 }
6006 final long identity = Binder.clearCallingIdentity();
6007 try {
6008 UiccProfile profile = UiccController.getInstance()
6009 .getUiccProfileForPhone(phone.getPhoneId());
6010 if (profile != null) {
6011 return profile.getCertsFromCarrierPrivilegeAccessRules();
6012 }
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
6016 return null;
6017 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006018}