blob: bf0ce15e82d8d02b5654810bb5e1ae17db56519d [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
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070028import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080043import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070046import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070047import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070049import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070050import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080052import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070053import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080054import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080055import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070056import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070057import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070059import android.telephony.CellInfoGsm;
60import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070061import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070063import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070064import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080065import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070066import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080067import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070068import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070069import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080072import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070073import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080074import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070076import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000078import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070079import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070080import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070081import android.telephony.cdma.CdmaCellLocation;
calvinpaneed9ae82018-11-01 19:43:06 +080082import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070083import android.telephony.gsm.GsmCellLocation;
Brad Ebinger4c460712018-10-01 10:40:55 -070084import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080085import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070086import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080087import android.telephony.ims.aidl.IImsMmTelFeature;
88import android.telephony.ims.aidl.IImsRcsFeature;
89import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070090import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080091import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080093import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080095import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080097
Brad Ebinger4c460712018-10-01 10:40:55 -070098import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070099import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800100import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700101import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700102import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700103import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700104import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700105import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800108import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700109import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100110import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700111import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700112import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700114import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800115import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700116import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700117import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700118import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700119import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700120import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700121import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800122import com.android.internal.telephony.SmsApplication;
123import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800124import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800125import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700126import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.uicc.IccIoResult;
128import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800129import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700130import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800131import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700132import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800133import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000134import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700135import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800136import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700137import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800138import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700139import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700140import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800141
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700142import java.io.FileDescriptor;
143import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800144import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800146import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800147import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800148import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100149import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800150import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151
152/**
153 * Implementation of the ITelephony interface.
154 */
Santos Cordon117fee72014-05-16 17:56:12 -0700155public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156 private static final String LOG_TAG = "PhoneInterfaceManager";
157 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
158 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800159 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160
161 // Message codes used with mMainThreadHandler
162 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700163 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
164 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165 private static final int CMD_OPEN_CHANNEL = 9;
166 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
167 private static final int CMD_CLOSE_CHANNEL = 11;
168 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800169 private static final int CMD_NV_READ_ITEM = 13;
170 private static final int EVENT_NV_READ_ITEM_DONE = 14;
171 private static final int CMD_NV_WRITE_ITEM = 15;
172 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
173 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
174 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700175 private static final int CMD_RESET_MODEM_CONFIG = 19;
176 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800177 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
178 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
179 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
180 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800181 private static final int CMD_SEND_ENVELOPE = 25;
182 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000183 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
184 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700185 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
186 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
187 private static final int CMD_EXCHANGE_SIM_IO = 31;
188 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800189 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
190 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700191 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
192 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700193 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
194 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700195 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
196 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
197 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
198 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700199 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
200 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
201 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
202 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700203 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800204 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
205 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000206 private static final int CMD_SWITCH_SLOTS = 50;
207 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700208 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
209 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
210 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
211 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
212 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
213 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
214 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
215 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700216 private static final int CMD_GET_ALL_CELL_INFO = 60;
217 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
218 private static final int CMD_GET_CELL_LOCATION = 62;
219 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700220 private static final int CMD_MODEM_REBOOT = 64;
221 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700222 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
223 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800225 // Parameters of select command.
226 private static final int SELECT_COMMAND = 0xA4;
227 private static final int SELECT_P1 = 0x04;
228 private static final int SELECT_P2 = 0;
229 private static final int SELECT_P3 = 0x10;
230
Pengquan Meng85728fb2018-03-12 16:31:21 -0700231 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
232 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
233 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
234
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 /** The singleton instance. */
236 private static PhoneInterfaceManager sInstance;
237
Wink Saville3ab207e2014-11-20 13:07:20 -0800238 private PhoneGlobals mApp;
239 private Phone mPhone;
240 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700241 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800242 private AppOpsManager mAppOps;
243 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800244 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800245 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700246 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
Derek Tan97ebb422014-09-05 16:55:38 -0700248 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
249 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800250 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700251
Derek Tan740e1672017-06-27 14:56:27 -0700252 // The AID of ISD-R.
253 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
254
yinxub1bed742017-04-17 11:45:04 -0700255 private NetworkScanRequestTracker mNetworkScanRequestTracker;
256
David Kelly5e06a7f2018-03-12 14:10:59 +0000257 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
258 private static final int MANUFACTURER_CODE_LENGTH = 8;
259
Derek Tan89e89d42014-07-08 17:00:10 -0700260 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700261 * A request object to use for transmitting data to an ICC.
262 */
263 private static final class IccAPDUArgument {
264 public int channel, cla, command, p1, p2, p3;
265 public String data;
266
267 public IccAPDUArgument(int channel, int cla, int command,
268 int p1, int p2, int p3, String data) {
269 this.channel = channel;
270 this.cla = cla;
271 this.command = command;
272 this.p1 = p1;
273 this.p2 = p2;
274 this.p3 = p3;
275 this.data = data;
276 }
277 }
278
279 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700280 * A request object to use for transmitting data to an ICC.
281 */
282 private static final class ManualNetworkSelectionArgument {
283 public OperatorInfo operatorInfo;
284 public boolean persistSelection;
285
286 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
287 this.operatorInfo = operatorInfo;
288 this.persistSelection = persistSelection;
289 }
290 }
291
292 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
294 * request after sending. The main thread will notify the request when it is complete.
295 */
296 private static final class MainThreadRequest {
297 /** The argument to use for the request */
298 public Object argument;
299 /** The result of the request that is run on the main thread */
300 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800301 // The subscriber id that this request applies to. Defaults to
302 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
303 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304
Nathan Harold92bed182018-10-12 18:16:49 -0700305 // In cases where subId is unavailable, the caller needs to specify the phone.
306 public Phone phone;
307
vagdevie435a3e2018-08-15 16:01:53 -0700308 public WorkSource workSource;
309
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310 public MainThreadRequest(Object argument) {
311 this.argument = argument;
312 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800313
Nathan Harold92bed182018-10-12 18:16:49 -0700314 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
315 this.argument = argument;
316 if (phone != null) {
317 this.phone = phone;
318 }
319 this.workSource = workSource;
320 }
321
vagdevie435a3e2018-08-15 16:01:53 -0700322 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800323 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800324 if (subId != null) {
325 this.subId = subId;
326 }
vagdevie435a3e2018-08-15 16:01:53 -0700327 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 }
330
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800331 private static final class IncomingThirdPartyCallArgs {
332 public final ComponentName component;
333 public final String callId;
334 public final String callerDisplayName;
335
336 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
337 String callerDisplayName) {
338 this.component = component;
339 this.callId = callId;
340 this.callerDisplayName = callerDisplayName;
341 }
342 }
343
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 /**
345 * A handler that processes messages on the main thread in the phone process. Since many
346 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
347 * inbound binder threads to the main thread in the phone process. The Binder thread
348 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
349 * on, which will be notified when the operation completes and will contain the result of the
350 * request.
351 *
352 * <p>If a MainThreadRequest object is provided in the msg.obj field,
353 * note that request.result must be set to something non-null for the calling thread to
354 * unblock.
355 */
356 private final class MainThreadHandler extends Handler {
357 @Override
358 public void handleMessage(Message msg) {
359 MainThreadRequest request;
360 Message onCompleted;
361 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800362 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700363 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364
365 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700366 case CMD_HANDLE_USSD_REQUEST: {
367 request = (MainThreadRequest) msg.obj;
368 final Phone phone = getPhoneFromRequest(request);
369 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
370 String ussdRequest = ussdObject.first;
371 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700372
Pengquan Meng0c05b502018-09-06 09:59:22 -0700373 if (!isUssdApiAllowed(request.subId)) {
374 // Carrier does not support use of this API, return failure.
375 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
376 UssdResponse response = new UssdResponse(ussdRequest, null);
377 Bundle returnData = new Bundle();
378 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
379 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700380
Pengquan Meng0c05b502018-09-06 09:59:22 -0700381 request.result = true;
382 notifyRequester(request);
383 return;
384 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700385
Pengquan Meng0c05b502018-09-06 09:59:22 -0700386 try {
387 request.result = phone != null
388 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
389 } catch (CallStateException cse) {
390 request.result = false;
391 }
392 // Wake up the requesting thread
393 notifyRequester(request);
394 break;
pkanwar32d516d2016-10-14 19:37:38 -0700395 }
396
Yorke Lee716f67e2015-06-17 15:39:16 -0700397 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700399 final Phone phone = getPhoneFromRequest(request);
400 request.result = phone != null ?
401 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
402 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700404 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700408 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700409 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700410 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800411 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700412 if (uiccCard == null) {
413 loge("iccTransmitApduLogicalChannel: No UICC");
414 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700415 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700416 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
418 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700419 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 iccArgument.channel, iccArgument.cla, iccArgument.command,
421 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700422 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700423 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 break;
425
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700427 ar = (AsyncResult) msg.obj;
428 request = (MainThreadRequest) ar.userObj;
429 if (ar.exception == null && ar.result != null) {
430 request.result = ar.result;
431 } else {
432 request.result = new IccIoResult(0x6F, 0, (byte[])null);
433 if (ar.result == null) {
434 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800435 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800437 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 } else {
439 loge("iccTransmitApduLogicalChannel: Unknown exception");
440 }
441 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700442 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 break;
444
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
446 request = (MainThreadRequest) msg.obj;
447 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800448 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 if (uiccCard == null) {
450 loge("iccTransmitApduBasicChannel: No UICC");
451 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700452 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 } else {
454 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
455 request);
456 uiccCard.iccTransmitApduBasicChannel(
457 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
458 iccArgument.p3, iccArgument.data, onCompleted);
459 }
460 break;
461
462 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
463 ar = (AsyncResult) msg.obj;
464 request = (MainThreadRequest) ar.userObj;
465 if (ar.exception == null && ar.result != null) {
466 request.result = ar.result;
467 } else {
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
469 if (ar.result == null) {
470 loge("iccTransmitApduBasicChannel: Empty response");
471 } else if (ar.exception instanceof CommandException) {
472 loge("iccTransmitApduBasicChannel: CommandException: " +
473 ar.exception);
474 } else {
475 loge("iccTransmitApduBasicChannel: Unknown exception");
476 }
477 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700478 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 break;
480
481 case CMD_EXCHANGE_SIM_IO:
482 request = (MainThreadRequest) msg.obj;
483 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800484 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 if (uiccCard == null) {
486 loge("iccExchangeSimIO: No UICC");
487 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700488 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 } else {
490 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
491 request);
492 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
493 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
494 iccArgument.data, onCompleted);
495 }
496 break;
497
498 case EVENT_EXCHANGE_SIM_IO_DONE:
499 ar = (AsyncResult) msg.obj;
500 request = (MainThreadRequest) ar.userObj;
501 if (ar.exception == null && ar.result != null) {
502 request.result = ar.result;
503 } else {
504 request.result = new IccIoResult(0x6f, 0, (byte[])null);
505 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700506 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 break;
508
Derek Tan4d5e5c12014-02-04 11:54:58 -0800509 case CMD_SEND_ENVELOPE:
510 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800511 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700512 if (uiccCard == null) {
513 loge("sendEnvelopeWithStatus: No UICC");
514 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700515 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700516 } else {
517 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
518 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
519 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800520 break;
521
522 case EVENT_SEND_ENVELOPE_DONE:
523 ar = (AsyncResult) msg.obj;
524 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700525 if (ar.exception == null && ar.result != null) {
526 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800527 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
529 if (ar.result == null) {
530 loge("sendEnvelopeWithStatus: Empty response");
531 } else if (ar.exception instanceof CommandException) {
532 loge("sendEnvelopeWithStatus: CommandException: " +
533 ar.exception);
534 } else {
535 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
536 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700538 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 break;
540
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 case CMD_OPEN_CHANNEL:
542 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800543 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800544 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 if (uiccCard == null) {
546 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800547 request.result = new IccOpenLogicalChannelResponse(-1,
548 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700549 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 } else {
551 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800552 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
553 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 break;
556
557 case EVENT_OPEN_CHANNEL_DONE:
558 ar = (AsyncResult) msg.obj;
559 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 int[] result = (int[]) ar.result;
563 int channelId = result[0];
564 byte[] selectResponse = null;
565 if (result.length > 1) {
566 selectResponse = new byte[result.length - 1];
567 for (int i = 1; i < result.length; ++i) {
568 selectResponse[i - 1] = (byte) result[i];
569 }
570 }
571 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700572 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 if (ar.result == null) {
575 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 if (ar.exception != null) {
578 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
579 }
580
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700581 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700582 if (ar.exception instanceof CommandException) {
583 CommandException.Error error =
584 ((CommandException) (ar.exception)).getCommandError();
585 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700586 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700587 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700588 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 }
590 }
591 openChannelResp = new IccOpenLogicalChannelResponse(
592 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700594 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 break;
597
598 case CMD_CLOSE_CHANNEL:
599 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800600 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 if (uiccCard == null) {
602 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900603 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700604 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 } else {
606 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
607 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
608 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
611 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800612 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
613 break;
614
615 case CMD_NV_READ_ITEM:
616 request = (MainThreadRequest) msg.obj;
617 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700618 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800619 break;
620
621 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 ar = (AsyncResult) msg.obj;
623 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800624 if (ar.exception == null && ar.result != null) {
625 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800627 request.result = "";
628 if (ar.result == null) {
629 loge("nvReadItem: Empty response");
630 } else if (ar.exception instanceof CommandException) {
631 loge("nvReadItem: CommandException: " +
632 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800634 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 }
636 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 break;
639
Jake Hambye994d462014-02-03 13:10:13 -0800640 case CMD_NV_WRITE_ITEM:
641 request = (MainThreadRequest) msg.obj;
642 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
643 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdevie435a3e2018-08-15 16:01:53 -0700644 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
645 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800646 break;
647
648 case EVENT_NV_WRITE_ITEM_DONE:
649 handleNullReturnEvent(msg, "nvWriteItem");
650 break;
651
652 case CMD_NV_WRITE_CDMA_PRL:
653 request = (MainThreadRequest) msg.obj;
654 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
655 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
656 break;
657
658 case EVENT_NV_WRITE_CDMA_PRL_DONE:
659 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
660 break;
661
chen xu1cc0abe2018-10-26 17:39:23 -0700662 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800663 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700664 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
665 mPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800666 break;
667
chen xu1cc0abe2018-10-26 17:39:23 -0700668 case EVENT_RESET_MODEM_CONFIG_DONE:
669 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800670 break;
671
Jake Hamby7c27be32014-03-03 13:25:59 -0800672 case CMD_GET_PREFERRED_NETWORK_TYPE:
673 request = (MainThreadRequest) msg.obj;
674 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700675 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800676 break;
677
678 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
679 ar = (AsyncResult) msg.obj;
680 request = (MainThreadRequest) ar.userObj;
681 if (ar.exception == null && ar.result != null) {
682 request.result = ar.result; // Integer
683 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800684 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800685 if (ar.result == null) {
686 loge("getPreferredNetworkType: Empty response");
687 } else if (ar.exception instanceof CommandException) {
688 loge("getPreferredNetworkType: CommandException: " +
689 ar.exception);
690 } else {
691 loge("getPreferredNetworkType: Unknown exception");
692 }
693 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700694 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800695 break;
696
697 case CMD_SET_PREFERRED_NETWORK_TYPE:
698 request = (MainThreadRequest) msg.obj;
699 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
700 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700701 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 break;
703
704 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
705 handleNullReturnEvent(msg, "setPreferredNetworkType");
706 break;
707
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000708 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
709 request = (MainThreadRequest)msg.obj;
710 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700711 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000712 break;
713
714 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
715 ar = (AsyncResult)msg.obj;
716 request = (MainThreadRequest)ar.userObj;
717 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700718 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000719 break;
720
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800721 case CMD_SET_VOICEMAIL_NUMBER:
722 request = (MainThreadRequest) msg.obj;
723 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
724 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800725 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
726 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800727 break;
728
729 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
730 handleNullReturnEvent(msg, "setVoicemailNumber");
731 break;
732
Stuart Scott54788802015-03-30 13:18:01 -0700733 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
734 request = (MainThreadRequest) msg.obj;
735 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
736 request);
737 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
738 break;
739
740 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
741 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
742 break;
743
Shishir Agrawal302c8692015-06-19 13:49:39 -0700744 case CMD_PERFORM_NETWORK_SCAN:
745 request = (MainThreadRequest) msg.obj;
746 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
747 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
748 break;
749
750 case EVENT_PERFORM_NETWORK_SCAN_DONE:
751 ar = (AsyncResult) msg.obj;
752 request = (MainThreadRequest) ar.userObj;
753 CellNetworkScanResult cellScanResult;
754 if (ar.exception == null && ar.result != null) {
755 cellScanResult = new CellNetworkScanResult(
756 CellNetworkScanResult.STATUS_SUCCESS,
757 (List<OperatorInfo>) ar.result);
758 } else {
759 if (ar.result == null) {
760 loge("getCellNetworkScanResults: Empty response");
761 }
762 if (ar.exception != null) {
763 loge("getCellNetworkScanResults: Exception: " + ar.exception);
764 }
765 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
766 if (ar.exception instanceof CommandException) {
767 CommandException.Error error =
768 ((CommandException) (ar.exception)).getCommandError();
769 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
770 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
771 } else if (error == CommandException.Error.GENERIC_FAILURE) {
772 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
773 }
774 }
775 cellScanResult = new CellNetworkScanResult(errorCode, null);
776 }
777 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700778 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700779 break;
780
781 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
782 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700783 ManualNetworkSelectionArgument selArg =
784 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700785 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
786 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700787 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
788 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700789 break;
790
791 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700792 ar = (AsyncResult) msg.obj;
793 request = (MainThreadRequest) ar.userObj;
794 if (ar.exception == null) {
795 request.result = true;
796 } else {
797 request.result = false;
798 loge("setNetworkSelectionModeManual " + ar.exception);
799 }
800 notifyRequester(request);
801 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700802 break;
803
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700804 case CMD_GET_MODEM_ACTIVITY_INFO:
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700807 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700808 break;
809
810 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
811 ar = (AsyncResult) msg.obj;
812 request = (MainThreadRequest) ar.userObj;
813 if (ar.exception == null && ar.result != null) {
814 request.result = ar.result;
815 } else {
816 if (ar.result == null) {
817 loge("queryModemActivityInfo: Empty response");
818 } else if (ar.exception instanceof CommandException) {
819 loge("queryModemActivityInfo: CommandException: " +
820 ar.exception);
821 } else {
822 loge("queryModemActivityInfo: Unknown exception");
823 }
824 }
Amit Mahajand4766222016-01-28 15:28:28 -0800825 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
826 if (request.result == null) {
827 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
828 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700829 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700830 break;
831
Meng Wang1a7c35a2016-05-05 20:56:15 -0700832 case CMD_SET_ALLOWED_CARRIERS:
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
835 mPhone.setAllowedCarriers(
836 (List<CarrierIdentifier>) request.argument,
vagdevie435a3e2018-08-15 16:01:53 -0700837 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700838 break;
839
840 case EVENT_SET_ALLOWED_CARRIERS_DONE:
841 ar = (AsyncResult) msg.obj;
842 request = (MainThreadRequest) ar.userObj;
843 if (ar.exception == null && ar.result != null) {
844 request.result = ar.result;
845 } else {
846 if (ar.result == null) {
847 loge("setAllowedCarriers: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("setAllowedCarriers: CommandException: " +
850 ar.exception);
851 } else {
852 loge("setAllowedCarriers: Unknown exception");
853 }
854 }
855 // Result cannot be null. Return -1 on error.
856 if (request.result == null) {
857 request.result = new int[]{-1};
858 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700859 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700860 break;
861
862 case CMD_GET_ALLOWED_CARRIERS:
863 request = (MainThreadRequest) msg.obj;
864 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdevie435a3e2018-08-15 16:01:53 -0700865 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 break;
867
868 case EVENT_GET_ALLOWED_CARRIERS_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
874 if (ar.result == null) {
875 loge("getAllowedCarriers: Empty response");
876 } else if (ar.exception instanceof CommandException) {
877 loge("getAllowedCarriers: CommandException: " +
878 ar.exception);
879 } else {
880 loge("getAllowedCarriers: Unknown exception");
881 }
882 }
883 // Result cannot be null. Return empty list of CarrierIdentifier.
884 if (request.result == null) {
885 request.result = new ArrayList<CarrierIdentifier>(0);
886 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700887 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 break;
889
Nathan Haroldb3014052017-01-25 15:57:32 -0800890 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
891 ar = (AsyncResult) msg.obj;
892 request = (MainThreadRequest) ar.userObj;
893 if (ar.exception == null && ar.result != null) {
894 request.result = ar.result;
895 } else {
896 request.result = new IllegalArgumentException(
897 "Failed to retrieve Forbidden Plmns");
898 if (ar.result == null) {
899 loge("getForbiddenPlmns: Empty response");
900 } else {
901 loge("getForbiddenPlmns: Unknown exception");
902 }
903 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700904 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800905 break;
906
907 case CMD_GET_FORBIDDEN_PLMNS:
908 request = (MainThreadRequest) msg.obj;
909 uiccCard = getUiccCardFromRequest(request);
910 if (uiccCard == null) {
911 loge("getForbiddenPlmns() UiccCard is null");
912 request.result = new IllegalArgumentException(
913 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700914 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800915 break;
916 }
917 Integer appType = (Integer) request.argument;
918 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
919 if (uiccApp == null) {
920 loge("getForbiddenPlmns() no app with specified type -- "
921 + appType);
922 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700923 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800924 break;
925 } else {
926 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
927 + " specified type -- " + appType);
928 }
929 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
930 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
931 onCompleted);
932 break;
933
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000934 case CMD_SWITCH_SLOTS:
935 request = (MainThreadRequest) msg.obj;
936 int[] physicalSlots = (int[]) request.argument;
937 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
938 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
939 break;
940
941 case EVENT_SWITCH_SLOTS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700945 notifyRequester(request);
946 break;
947 case CMD_GET_NETWORK_SELECTION_MODE:
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
950 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
951 break;
952
953 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
956 if (ar.exception != null) {
957 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
958 } else {
959 int mode = ((int[]) ar.result)[0];
960 if (mode == 0) {
961 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
962 } else {
963 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
964 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000965 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700966 notifyRequester(request);
967 break;
968 case CMD_GET_CDMA_ROAMING_MODE:
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
971 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
972 break;
973 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
976 if (ar.exception != null) {
977 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
978 } else {
979 request.result = ((int[]) ar.result)[0];
980 }
981 notifyRequester(request);
982 break;
983 case CMD_SET_CDMA_ROAMING_MODE:
984 request = (MainThreadRequest) msg.obj;
985 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
986 int mode = (int) request.argument;
987 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
988 break;
989 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 request.result = ar.exception == null;
993 notifyRequester(request);
994 break;
995 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
996 request = (MainThreadRequest) msg.obj;
997 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
998 int subscriptionMode = (int) request.argument;
999 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1000 break;
1001 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 request.result = ar.exception == null;
1005 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001006 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001007 case CMD_GET_ALL_CELL_INFO:
1008 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001009 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001010 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001011 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001012 case EVENT_GET_ALL_CELL_INFO_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001015 // If a timeout occurs, the response will be null
1016 request.result = (ar.exception == null && ar.result != null)
1017 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001018 synchronized (request) {
1019 request.notifyAll();
1020 }
1021 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001022 case CMD_REQUEST_CELL_INFO_UPDATE:
1023 request = (MainThreadRequest) msg.obj;
1024 request.phone.requestCellInfoUpdate(request.workSource,
1025 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1026 break;
1027 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1031 try {
1032 if (ar.exception != null) {
1033 // something went wrong... the response is null
1034 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
1035 cb.onCellInfo(null);
1036 } else if (ar.result == null) {
1037 // timeout occurred, so force the result to non-null "empty"
1038 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
1039 cb.onCellInfo(new ArrayList<CellInfo>());
1040 } else {
1041 // use the result as returned
1042 cb.onCellInfo((List<CellInfo>) ar.result);
1043 }
1044 } catch (RemoteException re) {
1045 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1046 }
1047 break;
1048 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 request = (MainThreadRequest) msg.obj;
1050 WorkSource ws = (WorkSource) request.argument;
1051 Phone phone = getPhoneFromRequest(request);
1052 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1053 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001054 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
1057 if (ar.exception == null) {
1058 request.result = ar.result;
1059 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1062 ? new CdmaCellLocation() : new GsmCellLocation();
1063 }
1064
1065 synchronized (request) {
1066 request.notifyAll();
1067 }
1068 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001069 case CMD_MODEM_REBOOT:
1070 request = (MainThreadRequest) msg.obj;
1071 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
1072 mPhone.rebootModem(onCompleted);
1073 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001074 case EVENT_CMD_MODEM_REBOOT_DONE:
1075 handleNullReturnEvent(msg, "rebootModem");
1076 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001077 default:
1078 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1079 break;
1080 }
1081 }
Jake Hambye994d462014-02-03 13:10:13 -08001082
Pengquan Meng0c05b502018-09-06 09:59:22 -07001083 private void notifyRequester(MainThreadRequest request) {
1084 synchronized (request) {
1085 request.notifyAll();
1086 }
1087 }
1088
Jake Hambye994d462014-02-03 13:10:13 -08001089 private void handleNullReturnEvent(Message msg, String command) {
1090 AsyncResult ar = (AsyncResult) msg.obj;
1091 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1092 if (ar.exception == null) {
1093 request.result = true;
1094 } else {
1095 request.result = false;
1096 if (ar.exception instanceof CommandException) {
1097 loge(command + ": CommandException: " + ar.exception);
1098 } else {
1099 loge(command + ": Unknown exception");
1100 }
1101 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001102 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001104 }
1105
1106 /**
1107 * Posts the specified command to be executed on the main thread,
1108 * waits for the request to complete, and returns the result.
1109 * @see #sendRequestAsync
1110 */
1111 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001112 return sendRequest(
1113 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001114 }
1115
1116 /**
1117 * Posts the specified command to be executed on the main thread,
1118 * waits for the request to complete, and returns the result.
1119 * @see #sendRequestAsync
1120 */
1121 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1122 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001123 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001124 }
1125
1126 /**
1127 * Posts the specified command to be executed on the main thread,
1128 * waits for the request to complete, and returns the result.
1129 * @see #sendRequestAsync
1130 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001131 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001132 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001133 }
1134
1135 /**
1136 * Posts the specified command to be executed on the main thread,
1137 * waits for the request to complete, and returns the result.
1138 * @see #sendRequestAsync
1139 */
Nathan Harold92bed182018-10-12 18:16:49 -07001140 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1141 return sendRequest(command, argument, subId, null, workSource);
1142 }
1143
1144 /**
1145 * Posts the specified command to be executed on the main thread,
1146 * waits for the request to complete, and returns the result.
1147 * @see #sendRequestAsync
1148 */
1149 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1150 return sendRequest(
1151 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1152 }
1153
1154 /**
1155 * Posts the specified command to be executed on the main thread,
1156 * waits for the request to complete, and returns the result.
1157 * @see #sendRequestAsync
1158 */
1159 private Object sendRequest(
1160 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001161 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1162 throw new RuntimeException("This method will deadlock if called from the main thread.");
1163 }
1164
Nathan Harold92bed182018-10-12 18:16:49 -07001165 MainThreadRequest request = null;
1166 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1167 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1168 } else if (phone != null) {
1169 request = new MainThreadRequest(argument, phone, workSource);
1170 } else {
1171 request = new MainThreadRequest(argument, subId, workSource);
1172 }
1173
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 Message msg = mMainThreadHandler.obtainMessage(command, request);
1175 msg.sendToTarget();
1176
1177 // Wait for the request to complete
1178 synchronized (request) {
1179 while (request.result == null) {
1180 try {
1181 request.wait();
1182 } catch (InterruptedException e) {
1183 // Do nothing, go back and wait until the request is complete
1184 }
1185 }
1186 }
1187 return request.result;
1188 }
1189
1190 /**
1191 * Asynchronous ("fire and forget") version of sendRequest():
1192 * Posts the specified command to be executed on the main thread, and
1193 * returns immediately.
1194 * @see #sendRequest
1195 */
1196 private void sendRequestAsync(int command) {
1197 mMainThreadHandler.sendEmptyMessage(command);
1198 }
1199
1200 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001201 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001202 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001203 */
1204 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001205 sendRequestAsync(command, argument, null, null);
1206 }
1207
1208 /**
1209 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1210 * @see {@link #sendRequest(int,Object)}
1211 */
1212 private void sendRequestAsync(
1213 int command, Object argument, Phone phone, WorkSource workSource) {
1214 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001215 Message msg = mMainThreadHandler.obtainMessage(command, request);
1216 msg.sendToTarget();
1217 }
1218
1219 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 * Initialize the singleton PhoneInterfaceManager instance.
1221 * This is only done once, at startup, from PhoneApp.onCreate().
1222 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001223 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001224 synchronized (PhoneInterfaceManager.class) {
1225 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001226 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001227 } else {
1228 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1229 }
1230 return sInstance;
1231 }
1232 }
1233
1234 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001235 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 mApp = app;
1237 mPhone = phone;
1238 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001239 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001240 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1241 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001242 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001243 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001244 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001245 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001246 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001247
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 publish();
1249 }
1250
1251 private void publish() {
1252 if (DBG) log("publish: " + this);
1253
1254 ServiceManager.addService("phone", this);
1255 }
1256
Stuart Scott584921c2015-01-15 17:10:34 -08001257 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001258 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1259 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001260 }
1261
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001262 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1263 Phone phone = getPhoneFromRequest(request);
1264 return phone == null ? null :
1265 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1266 }
1267
Wink Saville36469e72014-06-11 15:17:00 -07001268 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001269 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001270 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272
1273 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001274 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001275 }
1276
Wink Savilleb564aae2014-10-23 10:18:09 -07001277 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 if (DBG) log("dial: " + number);
1279 // No permission check needed here: This is just a wrapper around the
1280 // ACTION_DIAL intent, which is available to any app since it puts up
1281 // the UI before it does anything.
1282
Malcolm Chend965c8b2018-02-28 15:00:40 -08001283 final long identity = Binder.clearCallingIdentity();
1284 try {
1285 String url = createTelUrl(number);
1286 if (url == null) {
1287 return;
1288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001289
Malcolm Chend965c8b2018-02-28 15:00:40 -08001290 // PENDING: should we just silently fail if phone is offhook or ringing?
1291 PhoneConstants.State state = mCM.getState(subId);
1292 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1293 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1294 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1295 mApp.startActivity(intent);
1296 }
1297 } finally {
1298 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299 }
1300 }
1301
1302 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001303 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001304 }
1305
Wink Savilleb564aae2014-10-23 10:18:09 -07001306 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 if (DBG) log("call: " + number);
1308
1309 // This is just a wrapper around the ACTION_CALL intent, but we still
1310 // need to do a permission check since we're calling startActivity()
1311 // from the context of the phone app.
1312 enforceCallPermission();
1313
1314 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1315 != AppOpsManager.MODE_ALLOWED) {
1316 return;
1317 }
1318
Malcolm Chend965c8b2018-02-28 15:00:40 -08001319 final long identity = Binder.clearCallingIdentity();
1320 try {
1321 String url = createTelUrl(number);
1322 if (url == null) {
1323 return;
1324 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325
Malcolm Chend965c8b2018-02-28 15:00:40 -08001326 boolean isValid = false;
1327 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1328 if (slist != null) {
1329 for (SubscriptionInfo subInfoRecord : slist) {
1330 if (subInfoRecord.getSubscriptionId() == subId) {
1331 isValid = true;
1332 break;
1333 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001334 }
Wink Saville08874612014-08-31 19:19:58 -07001335 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001336 if (!isValid) {
1337 return;
1338 }
Wink Saville08874612014-08-31 19:19:58 -07001339
Malcolm Chend965c8b2018-02-28 15:00:40 -08001340 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1341 intent.putExtra(SUBSCRIPTION_KEY, subId);
1342 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1343 mApp.startActivity(intent);
1344 } finally {
1345 Binder.restoreCallingIdentity(identity);
1346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001347 }
1348
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001350 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001351 }
1352
Wink Savilleb564aae2014-10-23 10:18:09 -07001353 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001354 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001355 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1356 }
1357
1358 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001359 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001360 }
1361
Wink Savilleb564aae2014-10-23 10:18:09 -07001362 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001363 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001364 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1365 }
1366
1367 /** {@hide} */
1368 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001369 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001370 }
1371
Wink Savilleb564aae2014-10-23 10:18:09 -07001372 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001374
1375 final long identity = Binder.clearCallingIdentity();
1376 try {
1377 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1378 checkSimPin.start();
1379 return checkSimPin.unlockSim(null, pin);
1380 } finally {
1381 Binder.restoreCallingIdentity(identity);
1382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 }
1384
Wink Saville9de0f752013-10-22 19:04:03 -07001385 /** {@hide} */
1386 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001387 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001388 }
1389
Wink Savilleb564aae2014-10-23 10:18:09 -07001390 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001392
1393 final long identity = Binder.clearCallingIdentity();
1394 try {
1395 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1396 checkSimPuk.start();
1397 return checkSimPuk.unlockSim(puk, pin);
1398 } finally {
1399 Binder.restoreCallingIdentity(identity);
1400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 }
1402
1403 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001404 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001405 * a synchronous one.
1406 */
1407 private static class UnlockSim extends Thread {
1408
1409 private final IccCard mSimCard;
1410
1411 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001412 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1413 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414
1415 // For replies from SimCard interface
1416 private Handler mHandler;
1417
1418 // For async handler to identify request type
1419 private static final int SUPPLY_PIN_COMPLETE = 100;
1420
1421 public UnlockSim(IccCard simCard) {
1422 mSimCard = simCard;
1423 }
1424
1425 @Override
1426 public void run() {
1427 Looper.prepare();
1428 synchronized (UnlockSim.this) {
1429 mHandler = new Handler() {
1430 @Override
1431 public void handleMessage(Message msg) {
1432 AsyncResult ar = (AsyncResult) msg.obj;
1433 switch (msg.what) {
1434 case SUPPLY_PIN_COMPLETE:
1435 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1436 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001437 mRetryCount = msg.arg1;
1438 if (ar.exception != null) {
1439 if (ar.exception instanceof CommandException &&
1440 ((CommandException)(ar.exception)).getCommandError()
1441 == CommandException.Error.PASSWORD_INCORRECT) {
1442 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1443 } else {
1444 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1445 }
1446 } else {
1447 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 mDone = true;
1450 UnlockSim.this.notifyAll();
1451 }
1452 break;
1453 }
1454 }
1455 };
1456 UnlockSim.this.notifyAll();
1457 }
1458 Looper.loop();
1459 }
1460
1461 /*
1462 * Use PIN or PUK to unlock SIM card
1463 *
1464 * If PUK is null, unlock SIM card with PIN
1465 *
1466 * If PUK is not null, unlock SIM card with PUK and set PIN code
1467 */
Wink Saville9de0f752013-10-22 19:04:03 -07001468 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469
1470 while (mHandler == null) {
1471 try {
1472 wait();
1473 } catch (InterruptedException e) {
1474 Thread.currentThread().interrupt();
1475 }
1476 }
1477 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1478
1479 if (puk == null) {
1480 mSimCard.supplyPin(pin, callback);
1481 } else {
1482 mSimCard.supplyPuk(puk, pin, callback);
1483 }
1484
1485 while (!mDone) {
1486 try {
1487 Log.d(LOG_TAG, "wait for done");
1488 wait();
1489 } catch (InterruptedException e) {
1490 // Restore the interrupted status
1491 Thread.currentThread().interrupt();
1492 }
1493 }
1494 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001495 int[] resultArray = new int[2];
1496 resultArray[0] = mResult;
1497 resultArray[1] = mRetryCount;
1498 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 }
1500 }
1501
1502 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001503 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001504
1505 }
1506
Wink Savilleb564aae2014-10-23 10:18:09 -07001507 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 // No permission check needed here: this call is harmless, and it's
1509 // needed for the ServiceState.requestStateUpdate() call (which is
1510 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001511 final long identity = Binder.clearCallingIdentity();
1512 try {
1513 final Phone phone = getPhone(subId);
1514 if (phone != null) {
1515 phone.updateServiceLocation();
1516 }
1517 } finally {
1518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 }
1521
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001522 @Override
1523 public boolean isRadioOn(String callingPackage) {
1524 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001525 }
1526
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001527 @Override
1528 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001530 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001531 return false;
1532 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001533
1534 final long identity = Binder.clearCallingIdentity();
1535 try {
1536 return isRadioOnForSubscriber(subId);
1537 } finally {
1538 Binder.restoreCallingIdentity(identity);
1539 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001540 }
1541
1542 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001543 final long identity = Binder.clearCallingIdentity();
1544 try {
1545 final Phone phone = getPhone(subId);
1546 if (phone != null) {
1547 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1548 } else {
1549 return false;
1550 }
1551 } finally {
1552 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
1556 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001557 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 }
Wink Saville36469e72014-06-11 15:17:00 -07001559
Wink Savilleb564aae2014-10-23 10:18:09 -07001560 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001562
1563 final long identity = Binder.clearCallingIdentity();
1564 try {
1565 final Phone phone = getPhone(subId);
1566 if (phone != null) {
1567 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1568 }
1569 } finally {
1570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001571 }
Wink Saville36469e72014-06-11 15:17:00 -07001572 }
1573
1574 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001575 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001576 }
1577
Wink Savilleb564aae2014-10-23 10:18:09 -07001578 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001579 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001580
1581 final long identity = Binder.clearCallingIdentity();
1582 try {
1583 final Phone phone = getPhone(subId);
1584 if (phone == null) {
1585 return false;
1586 }
1587 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1588 toggleRadioOnOffForSubscriber(subId);
1589 }
1590 return true;
1591 } finally {
1592 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 }
Wink Saville36469e72014-06-11 15:17:00 -07001595
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001596 public boolean needMobileRadioShutdown() {
1597 /*
1598 * If any of the Radios are available, it will need to be
1599 * shutdown. So return true if any Radio is available.
1600 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001601 final long identity = Binder.clearCallingIdentity();
1602 try {
1603 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1604 Phone phone = PhoneFactory.getPhone(i);
1605 if (phone != null && phone.isRadioAvailable()) return true;
1606 }
1607 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1608 return false;
1609 } finally {
1610 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001611 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001612 }
1613
Malcolm Chend965c8b2018-02-28 15:00:40 -08001614 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001615 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001616 enforceModifyPermission();
1617
1618 final long identity = Binder.clearCallingIdentity();
1619 try {
1620 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1621 logv("Shutting down Phone " + i);
1622 shutdownRadioUsingPhoneId(i);
1623 }
1624 } finally {
1625 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001626 }
1627 }
1628
1629 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001630 Phone phone = PhoneFactory.getPhone(phoneId);
1631 if (phone != null && phone.isRadioAvailable()) {
1632 phone.shutdownRadio();
1633 }
1634 }
1635
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001637 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001638
1639 final long identity = Binder.clearCallingIdentity();
1640 try {
1641 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1642 if (defaultPhone != null) {
1643 defaultPhone.setRadioPower(turnOn);
1644 return true;
1645 } else {
1646 loge("There's no default phone.");
1647 return false;
1648 }
1649 } finally {
1650 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001651 }
Wink Saville36469e72014-06-11 15:17:00 -07001652 }
1653
Wink Savilleb564aae2014-10-23 10:18:09 -07001654 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001656
1657 final long identity = Binder.clearCallingIdentity();
1658 try {
1659 final Phone phone = getPhone(subId);
1660 if (phone != null) {
1661 phone.setRadioPower(turnOn);
1662 return true;
1663 } else {
1664 return false;
1665 }
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 }
1670
Wink Saville36469e72014-06-11 15:17:00 -07001671 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 public boolean enableDataConnectivity() {
1674 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001675
1676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 int subId = mSubscriptionController.getDefaultDataSubId();
1679 final Phone phone = getPhone(subId);
1680 if (phone != null) {
1681 phone.setUserDataEnabled(true);
1682 return true;
1683 } else {
1684 return false;
1685 }
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 }
1690
Wink Saville36469e72014-06-11 15:17:00 -07001691 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001692 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 public boolean disableDataConnectivity() {
1694 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001695
1696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 int subId = mSubscriptionController.getDefaultDataSubId();
1699 final Phone phone = getPhone(subId);
1700 if (phone != null) {
1701 phone.setUserDataEnabled(false);
1702 return true;
1703 } else {
1704 return false;
1705 }
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 }
1710
Sanket Padawe356d7632015-06-22 14:03:32 -07001711 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001712 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 final Phone phone = getPhone(subId);
1716 if (phone != null) {
1717 return phone.isDataAllowed();
1718 } else {
1719 return false;
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
1726 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001727 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001728 }
1729
pkanwarae03a6b2016-11-06 20:37:09 -08001730 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001731 enforceCallPermission();
1732
1733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1736 return;
1737 }
1738 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1739 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1740 } finally {
1741 Binder.restoreCallingIdentity(identity);
1742 }
pkanwar32d516d2016-10-14 19:37:38 -07001743 };
1744
Wink Savilleb564aae2014-10-23 10:18:09 -07001745 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001747
1748 final long identity = Binder.clearCallingIdentity();
1749 try {
1750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1751 return false;
1752 }
1753 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1754 } finally {
1755 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 }
1758
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001760 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001761 }
1762
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001763 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001764 final long identity = Binder.clearCallingIdentity();
1765 try {
1766 Phone phone = PhoneFactory.getPhone(slotIndex);
1767 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1768 PhoneConstantConversions.convertCallState(phone.getState());
1769 } finally {
1770 Binder.restoreCallingIdentity(identity);
1771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
Sanket Padawe356d7632015-06-22 14:03:32 -07001774 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1779 if (phone != null) {
1780 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1781 } else {
1782 return PhoneConstantConversions.convertDataState(
1783 PhoneConstants.DataState.DISCONNECTED);
1784 }
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001787 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
1789
Sanket Padawe356d7632015-06-22 14:03:32 -07001790 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1795 if (phone != null) {
1796 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1797 } else {
1798 return TelephonyManager.DATA_ACTIVITY_NONE;
1799 }
1800 } finally {
1801 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001802 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 }
1804
1805 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001806 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001807 mPhone.getContext().getSystemService(AppOpsManager.class)
1808 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001809 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001810 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001811 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 }
1813
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001814 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 if (DBG_LOC) log("getCellLocation: is active user");
1818 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001819 int subId = mSubscriptionController.getDefaultDataSubId();
1820 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1821 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001822 return data;
1823 } finally {
1824 Binder.restoreCallingIdentity(identity);
1825 }
Svetoslav64fad262015-04-14 14:35:21 -07001826 }
1827
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001829 public String getNetworkCountryIsoForPhone(int phoneId) {
1830 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1831 // registered cell info, so return a NULL country instead.
1832 final long identity = Binder.clearCallingIdentity();
1833 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001834 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1835 // Get default phone in this case.
1836 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1837 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001838 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001839 // Todo: fix this when we can get the actual cellular network info when the device
1840 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001841 if (TelephonyManager.NETWORK_TYPE_IWLAN
1842 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1843 return "";
1844 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001845 Phone phone = PhoneFactory.getPhone(phoneId);
1846 if (phone != null) {
1847 ServiceStateTracker sst = phone.getServiceStateTracker();
1848 if (sst != null) {
1849 LocaleTracker lt = sst.getLocaleTracker();
1850 if (lt != null) {
1851 return lt.getCurrentCountry();
1852 }
1853 }
1854 }
1855 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001856 } finally {
1857 Binder.restoreCallingIdentity(identity);
1858 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001859 }
1860
1861 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001863 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001864 }
1865
Sanket Padawe356d7632015-06-22 14:03:32 -07001866 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001867 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 mApp.enforceCallingOrSelfPermission(
1869 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001870
1871 final long identity = Binder.clearCallingIdentity();
1872 try {
1873 final Phone phone = getPhone(subId);
1874 if (phone != null) {
1875 phone.enableLocationUpdates();
1876 }
1877 } finally {
1878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 }
1881
1882 @Override
1883 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001884 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001885 }
1886
Sanket Padawe356d7632015-06-22 14:03:32 -07001887 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001888 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 mApp.enforceCallingOrSelfPermission(
1890 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001891
1892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 final Phone phone = getPhone(subId);
1895 if (phone != null) {
1896 phone.disableLocationUpdates();
1897 }
1898 } finally {
1899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 }
1902
Nathan Harold31d7ff32018-10-15 20:20:30 -07001903 /**
1904 * Returns the target SDK version number for a given package name.
1905 *
1906 * @return target SDK if the package is found or INT_MAX.
1907 */
1908 private int getTargetSdk(String packageName) {
1909 try {
1910 final ApplicationInfo ai =
1911 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1912 if (ai != null) return ai.targetSdkVersion;
1913 } catch (PackageManager.NameNotFoundException unexpected) {
1914 }
1915 return Integer.MAX_VALUE;
1916 }
1917
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 @Override
1919 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001920 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1921 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001922 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1923 throw new SecurityException(
1924 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1925 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001926
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1928 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1929 return null;
1930 }
Svetoslav64fad262015-04-14 14:35:21 -07001931
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001932 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933
Nathan Haroldf180aac2018-06-01 18:43:55 -07001934 List<CellInfo> info = getAllCellInfo(callingPackage);
1935 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936
Nathan Haroldf180aac2018-06-01 18:43:55 -07001937 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1938 for (CellInfo ci : info) {
1939 if (ci instanceof CellInfoGsm) {
1940 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1941 } else if (ci instanceof CellInfoWcdma) {
1942 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001945 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001948 private List<CellInfo> getCachedCellInfo() {
1949 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1950 for (Phone phone : PhoneFactory.getPhones()) {
1951 List<CellInfo> info = phone.getAllCellInfo();
1952 if (info != null) cellInfos.addAll(info);
1953 }
1954 return cellInfos;
1955 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956
1957 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001958 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001959 mPhone.getContext().getSystemService(AppOpsManager.class)
1960 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001961 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001962 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001963 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964 }
1965
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001966 final int targetSdk = getTargetSdk(callingPackage);
1967 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1968 return getCachedCellInfo();
1969 }
1970
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001971 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001972 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001973 final long identity = Binder.clearCallingIdentity();
1974 try {
1975 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1976 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001977 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001978 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001979 if (info != null) cellInfos.addAll(info);
1980 }
1981 return cellInfos;
1982 } finally {
1983 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985 }
1986
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001987 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001988 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
1989 requestCellInfoUpdateInternal(
1990 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
1991 }
1992
1993 @Override
1994 public void requestCellInfoUpdateWithWorkSource(
1995 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
1996 enforceModifyPermission();
1997 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
1998 }
1999
2000 private void requestCellInfoUpdateInternal(
2001 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2002 mPhone.getContext().getSystemService(AppOpsManager.class)
2003 .checkPackage(Binder.getCallingUid(), callingPackage);
2004 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
2005 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
2006 return;
2007 }
2008
2009 final Phone phone = getPhone(subId);
2010 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2011
2012 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2013 }
2014
2015 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002017 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002018 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002019
2020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 mPhone.setCellInfoListRate(rateInMillis, workSource);
2023 } finally {
2024 Binder.restoreCallingIdentity(identity);
2025 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 }
2027
Shishir Agrawala9f32182016-04-12 12:00:16 -07002028 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002029 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002030 Phone phone = PhoneFactory.getPhone(slotIndex);
2031 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002032 return null;
2033 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002034 int subId = phone.getSubId();
2035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2036 mApp, subId, callingPackage, "getImeiForSlot")) {
2037 return null;
2038 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002039
2040 final long identity = Binder.clearCallingIdentity();
2041 try {
2042 return phone.getImei();
2043 } finally {
2044 Binder.restoreCallingIdentity(identity);
2045 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002046 }
2047
2048 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002049 public String getTypeAllocationCodeForSlot(int slotIndex) {
2050 Phone phone = PhoneFactory.getPhone(slotIndex);
2051 String tac = null;
2052 if (phone != null) {
2053 String imei = phone.getImei();
2054 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2055 }
2056 return tac;
2057 }
2058
2059 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002060 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002061 Phone phone = PhoneFactory.getPhone(slotIndex);
2062 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002063 return null;
2064 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002065 int subId = phone.getSubId();
2066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2067 mApp, subId, callingPackage, "getMeidForSlot")) {
2068 return null;
2069 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002070
2071 final long identity = Binder.clearCallingIdentity();
2072 try {
2073 return phone.getMeid();
2074 } finally {
2075 Binder.restoreCallingIdentity(identity);
2076 }
Jack Yu2af8d712017-03-15 17:14:14 -07002077 }
2078
2079 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002080 public String getManufacturerCodeForSlot(int slotIndex) {
2081 Phone phone = PhoneFactory.getPhone(slotIndex);
2082 String manufacturerCode = null;
2083 if (phone != null) {
2084 String meid = phone.getMeid();
2085 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2086 }
2087 return manufacturerCode;
2088 }
2089
2090 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002091 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002092 Phone phone = PhoneFactory.getPhone(slotIndex);
2093 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002094 return null;
2095 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002096 int subId = phone.getSubId();
2097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2098 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2099 return null;
2100 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002101
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 return phone.getDeviceSvn();
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
2107 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002108 }
2109
fionaxu43304da2017-11-27 22:51:16 -08002110 @Override
2111 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 final Phone phone = getPhone(subId);
2115 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2116 } finally {
2117 Binder.restoreCallingIdentity(identity);
2118 }
fionaxu43304da2017-11-27 22:51:16 -08002119 }
2120
2121 @Override
2122 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002123 final long identity = Binder.clearCallingIdentity();
2124 try {
2125 final Phone phone = getPhone(subId);
2126 return phone == null ? null : phone.getCarrierName();
2127 } finally {
2128 Binder.restoreCallingIdentity(identity);
2129 }
fionaxu43304da2017-11-27 22:51:16 -08002130 }
2131
calvinpaneed9ae82018-11-01 19:43:06 +08002132 @Override
2133 public int getSubscriptionMNOCarrierId(int subId) {
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 final Phone phone = getPhone(subId);
2137 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2138 } finally {
2139 Binder.restoreCallingIdentity(identity);
2140 }
2141 }
2142
chen xuc93cc282018-11-04 17:17:00 -08002143 @Override
2144 public int getSubscriptionPreciseCarrierId(int subId) {
2145 final long identity = Binder.clearCallingIdentity();
2146 try {
2147 final Phone phone = getPhone(subId);
2148 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2149 : phone.getPreciseCarrierId();
2150 } finally {
2151 Binder.restoreCallingIdentity(identity);
2152 }
2153 }
2154
2155 @Override
2156 public String getSubscriptionPreciseCarrierName(int subId) {
2157 final long identity = Binder.clearCallingIdentity();
2158 try {
2159 final Phone phone = getPhone(subId);
2160 return phone == null ? null : phone.getPreciseCarrierName();
2161 } finally {
2162 Binder.restoreCallingIdentity(identity);
2163 }
2164 }
2165
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 //
2167 // Internal helper methods.
2168 //
2169
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002170 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2172 *
2173 * @throws SecurityException if the caller does not have the required permission
2174 */
2175 private void enforceModifyPermission() {
2176 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2177 }
2178
2179 /**
2180 * Make sure the caller has the CALL_PHONE permission.
2181 *
2182 * @throws SecurityException if the caller does not have the required permission
2183 */
2184 private void enforceCallPermission() {
2185 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2186 }
2187
Stuart Scott8eef64f2015-04-08 15:13:54 -07002188 private void enforceConnectivityInternalPermission() {
2189 mApp.enforceCallingOrSelfPermission(
2190 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2191 "ConnectivityService");
2192 }
2193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 private String createTelUrl(String number) {
2195 if (TextUtils.isEmpty(number)) {
2196 return null;
2197 }
2198
Jake Hambye994d462014-02-03 13:10:13 -08002199 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
Ihab Awadf9e92732013-12-05 18:02:52 -08002202 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2204 }
2205
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002206 private static void logv(String msg) {
2207 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2208 }
2209
Ihab Awadf9e92732013-12-05 18:02:52 -08002210 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2212 }
2213
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002214 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002216 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002217 }
2218
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002220 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002221 final long identity = Binder.clearCallingIdentity();
2222 try {
2223 final Phone phone = PhoneFactory.getPhone(slotIndex);
2224 if (phone == null) {
2225 return PhoneConstants.PHONE_TYPE_NONE;
2226 } else {
2227 return phone.getPhoneType();
2228 }
2229 } finally {
2230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 }
2233
2234 /**
2235 * Returns the CDMA ERI icon index to display
2236 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002237 @Override
2238 public int getCdmaEriIconIndex(String callingPackage) {
2239 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002240 }
2241
Sanket Padawe356d7632015-06-22 14:03:32 -07002242 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002243 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002245 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002246 return -1;
2247 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002248
2249 final long identity = Binder.clearCallingIdentity();
2250 try {
2251 final Phone phone = getPhone(subId);
2252 if (phone != null) {
2253 return phone.getCdmaEriIconIndex();
2254 } else {
2255 return -1;
2256 }
2257 } finally {
2258 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 }
2261
2262 /**
2263 * Returns the CDMA ERI icon mode,
2264 * 0 - ON
2265 * 1 - FLASHING
2266 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002267 @Override
2268 public int getCdmaEriIconMode(String callingPackage) {
2269 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002270 }
2271
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002273 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002275 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002276 return -1;
2277 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002278
2279 final long identity = Binder.clearCallingIdentity();
2280 try {
2281 final Phone phone = getPhone(subId);
2282 if (phone != null) {
2283 return phone.getCdmaEriIconMode();
2284 } else {
2285 return -1;
2286 }
2287 } finally {
2288 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 }
2291
2292 /**
2293 * Returns the CDMA ERI text,
2294 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002295 @Override
2296 public String getCdmaEriText(String callingPackage) {
2297 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002298 }
2299
Sanket Padawe356d7632015-06-22 14:03:32 -07002300 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002303 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002304 return null;
2305 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002306
2307 final long identity = Binder.clearCallingIdentity();
2308 try {
2309 final Phone phone = getPhone(subId);
2310 if (phone != null) {
2311 return phone.getCdmaEriText();
2312 } else {
2313 return null;
2314 }
2315 } finally {
2316 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 }
2319
2320 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002321 * Returns the CDMA MDN.
2322 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002323 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002324 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2326 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 final Phone phone = getPhone(subId);
2331 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2332 return phone.getLine1Number();
2333 } else {
2334 return null;
2335 }
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002338 }
2339 }
2340
2341 /**
2342 * Returns the CDMA MIN.
2343 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002344 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002345 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2347 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002348
2349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 final Phone phone = getPhone(subId);
2352 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2353 return phone.getCdmaMin();
2354 } else {
2355 return null;
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002359 }
2360 }
2361
2362 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 * Returns true if CDMA provisioning needs to run.
2364 */
2365 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 return mPhone.needsOtaServiceProvisioning();
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
2371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
2374 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002375 * Sets the voice mail number of a given subId.
2376 */
2377 @Override
2378 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002379 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002380
2381 final long identity = Binder.clearCallingIdentity();
2382 try {
2383 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2384 new Pair<String, String>(alphaTag, number), new Integer(subId));
2385 return success;
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002389 }
2390
Ta-wei Yen87c49842016-05-13 21:19:52 -07002391 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002392 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2394 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2395 if (!TextUtils.equals(callingPackage, systemDialer)) {
2396 throw new SecurityException("caller must be system dialer");
2397 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002398
2399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2402 if (phoneAccountHandle == null) {
2403 return null;
2404 }
2405 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2406 } finally {
2407 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002408 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002409 }
2410
2411 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002412 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002413 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002415 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002416 return null;
2417 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002418
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002419 final long identity = Binder.clearCallingIdentity();
2420 try {
2421 return RemoteVvmTaskManager
2422 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
2425 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002426 }
2427
2428 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002429 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2430 VisualVoicemailSmsFilterSettings settings) {
2431 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002432
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2436 mPhone.getContext(), callingPackage, subId, settings);
2437 } finally {
2438 Binder.restoreCallingIdentity(identity);
2439 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002440 }
2441
2442 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002443 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002445
2446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2449 mPhone.getContext(), callingPackage, subId);
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
2452 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002453 }
2454
2455 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002456 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2457 String callingPackage, int subId) {
2458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002459
2460 final long identity = Binder.clearCallingIdentity();
2461 try {
2462 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2463 mPhone.getContext(), callingPackage, subId);
2464 } finally {
2465 Binder.restoreCallingIdentity(identity);
2466 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002467 }
2468
2469 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002470 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002471 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002472
2473 final long identity = Binder.clearCallingIdentity();
2474 try {
2475 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2476 mPhone.getContext(), subId);
2477 } finally {
2478 Binder.restoreCallingIdentity(identity);
2479 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002480 }
2481
2482 @Override
2483 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2484 String number, int port, String text, PendingIntent sentIntent) {
2485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002486 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002487 enforceSendSmsPermission();
2488 // Make the calls as the phone process.
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2492 if (port == 0) {
2493 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2494 sentIntent, null, false);
2495 } else {
2496 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2497 smsManager.sendDataMessageWithSelfPermissions(number, null,
2498 (short) port, data, sentIntent, null);
2499 }
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
2502 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002503 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002504 /**
fionaxu0152e512016-11-14 13:36:14 -08002505 * Sets the voice activation state of a given subId.
2506 */
2507 @Override
2508 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2510 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 final Phone phone = getPhone(subId);
2515 if (phone != null) {
2516 phone.setVoiceActivationState(activationState);
2517 } else {
2518 loge("setVoiceActivationState fails with invalid subId: " + subId);
2519 }
2520 } finally {
2521 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002522 }
2523 }
2524
2525 /**
2526 * Sets the data activation state of a given subId.
2527 */
2528 @Override
2529 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2531 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002532
2533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 final Phone phone = getPhone(subId);
2536 if (phone != null) {
2537 phone.setDataActivationState(activationState);
2538 } else {
2539 loge("setVoiceActivationState fails with invalid subId: " + subId);
2540 }
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002543 }
2544 }
2545
2546 /**
2547 * Returns the voice activation state of a given subId.
2548 */
2549 @Override
2550 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002551 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002552
fionaxu0152e512016-11-14 13:36:14 -08002553 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 if (phone != null) {
2557 return phone.getVoiceActivationState();
2558 } else {
2559 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002563 }
2564 }
2565
2566 /**
2567 * Returns the data activation state of a given subId.
2568 */
2569 @Override
2570 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002571 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002572
fionaxu0152e512016-11-14 13:36:14 -08002573 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 if (phone != null) {
2577 return phone.getDataActivationState();
2578 } else {
2579 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2580 }
2581 } finally {
2582 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002583 }
2584 }
2585
2586 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 * Returns the unread count of voicemails
2588 */
2589 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002590 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002591 }
2592
2593 /**
2594 * Returns the unread count of voicemails for a subId
2595 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002596 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002597 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 final Phone phone = getPhone(subId);
2601 if (phone != null) {
2602 return phone.getVoiceMessageCount();
2603 } else {
2604 return 0;
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 }
2610
2611 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002612 * returns true, if the device is in a state where both voice and data
2613 * are supported simultaneously. This can change based on location or network condition.
2614 */
2615 @Override
2616 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002617 final long identity = Binder.clearCallingIdentity();
2618 try {
2619 final Phone phone = getPhone(subId);
2620 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
2623 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002624 }
2625
2626 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002627 * Send the dialer code if called from the current default dialer or the caller has
2628 * carrier privilege.
2629 * @param inputCode The dialer code to send
2630 */
2631 @Override
2632 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2633 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2634 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2635 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002636 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2637 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002638 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002639
2640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 mPhone.sendDialerSpecialCode(inputCode);
2643 } finally {
2644 Binder.restoreCallingIdentity(identity);
2645 }
fionaxu235cc5e2017-03-06 22:25:57 -08002646 }
2647
2648 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002649 * Returns the data network type.
2650 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 *
2652 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2653 */
2654 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002655 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 final Phone phone = getPhone(getDefaultSubscription());
2659 if (phone != null) {
2660 return phone.getServiceState().getDataNetworkType();
2661 } else {
2662 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2663 }
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002666 }
Wink Saville36469e72014-06-11 15:17:00 -07002667 }
2668
Pengquan Meng0c05b502018-09-06 09:59:22 -07002669 @Override
2670 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002671 if (!isActiveSubscription(subId)) {
2672 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2673 }
2674
Pengquan Meng0c05b502018-09-06 09:59:22 -07002675 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2676 }
2677
Brad Ebinger4c460712018-10-01 10:40:55 -07002678 @Override
2679 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2680 String callingPackage) throws RemoteException {
2681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2682 "addImsRegistrationCallback")) {
2683 return;
2684 }
2685 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2686 final long token = Binder.clearCallingIdentity();
2687 try {
2688 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2689 .addRegistrationCallbackForSubscription(c, subId);
2690 } finally {
2691 Binder.restoreCallingIdentity(token);
2692 }
2693 }
2694
2695 @Override
2696 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2697 String callingPackage) {
2698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2699 "removeImsRegistrationCallback")) {
2700 return;
2701 }
2702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2703 Binder.withCleanCallingIdentity(() ->
2704 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2705 .removeRegistrationCallbackForSubscription(c, subId));
2706 }
2707
2708 @Override
2709 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2710 String callingPackage) throws RemoteException {
2711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2712 "addMmTelCapabilityCallback")) {
2713 return;
2714 }
2715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2716 final long token = Binder.clearCallingIdentity();
2717 try {
2718 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2719 .addCapabilitiesCallbackForSubscription(c, subId);
2720 } finally {
2721 Binder.restoreCallingIdentity(token);
2722 }
2723 }
2724
2725 @Override
2726 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2727 String callingPackage) {
2728 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2729 "removeMmTelCapabilityCallback")) {
2730 return;
2731 }
2732 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2733 Binder.withCleanCallingIdentity(() ->
2734 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2735 .removeCapabilitiesCallbackForSubscription(c, subId));
2736 }
2737
2738 @Override
2739 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2740 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2741 "isCapable")) {
2742 return false;
2743 }
2744 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2745 final long token = Binder.clearCallingIdentity();
2746 try {
2747 return ImsManager.getInstance(mPhone.getContext(),
2748 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2749 } catch (ImsException e) {
2750 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2751 return false;
2752 } finally {
2753 Binder.restoreCallingIdentity(token);
2754 }
2755 }
2756
2757 @Override
2758 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2759 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2760 "isAvailable")) {
2761 return false;
2762 }
2763 final long token = Binder.clearCallingIdentity();
2764 try {
2765 Phone phone = getPhone(subId);
2766 if (phone == null) return false;
2767 return phone.isImsCapabilityAvailable(capability, regTech);
2768 } finally {
2769 Binder.restoreCallingIdentity(token);
2770 }
2771 }
2772
2773 @Override
2774 public boolean isAdvancedCallingSettingEnabled(int subId) {
2775 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2777 final long token = Binder.clearCallingIdentity();
2778 try {
2779 return ImsManager.getInstance(mPhone.getContext(),
2780 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2781 } finally {
2782 Binder.restoreCallingIdentity(token);
2783 }
2784 }
2785
2786 @Override
2787 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2789 "setAdvancedCallingSetting");
2790 final long identity = Binder.clearCallingIdentity();
2791 try {
2792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2793 ImsManager.getInstance(mPhone.getContext(),
2794 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2795 } finally {
2796 Binder.restoreCallingIdentity(identity);
2797 }
2798 }
2799
2800 @Override
2801 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2803 "isVtSettingEnabled")) {
2804 return false;
2805 }
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2809 return ImsManager.getInstance(mPhone.getContext(),
2810 getSlotIndexOrException(subId)).isVtEnabledByUser();
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
2813 }
2814 }
2815
2816 @Override
2817 public void setVtSetting(int subId, boolean isEnabled) {
2818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2819 "setVtSetting");
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2823 ImsManager.getInstance(mPhone.getContext(),
2824 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
2827 }
2828 }
2829
2830 @Override
2831 public boolean isVoWiFiSettingEnabled(int subId) {
2832 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2836 return ImsManager.getInstance(mPhone.getContext(),
2837 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
2840 }
2841 }
2842
2843 @Override
2844 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2846 "setVoWiFiSetting");
2847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2850 ImsManager.getInstance(mPhone.getContext(),
2851 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
2854 }
2855 }
2856
2857 @Override
2858 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2859 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2863 return ImsManager.getInstance(mPhone.getContext(),
2864 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
2867 }
2868 }
2869
2870 @Override
2871 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2873 "setVoWiFiRoamingSetting");
2874 final long identity = Binder.clearCallingIdentity();
2875 try {
2876 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2877 ImsManager.getInstance(mPhone.getContext(),
2878 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2879 } finally {
2880 Binder.restoreCallingIdentity(identity);
2881 }
2882 }
2883
2884 @Override
2885 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2887 "setVoWiFiNonPersistent");
2888 final long identity = Binder.clearCallingIdentity();
2889 try {
2890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2891 ImsManager.getInstance(mPhone.getContext(),
2892 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2893 } finally {
2894 Binder.restoreCallingIdentity(identity);
2895 }
2896 }
2897
2898 @Override
2899 public int getVoWiFiModeSetting(int subId) {
2900 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2904 return ImsManager.getInstance(mPhone.getContext(),
2905 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
2908 }
2909 }
2910
2911 @Override
2912 public void setVoWiFiModeSetting(int subId, int mode) {
2913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2914 "setVoWiFiModeSetting");
2915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2918 ImsManager.getInstance(mPhone.getContext(),
2919 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2920 } finally {
2921 Binder.restoreCallingIdentity(identity);
2922 }
2923 }
2924
2925 @Override
2926 public int getVoWiFiRoamingModeSetting(int subId) {
2927 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2931 return ImsManager.getInstance(mPhone.getContext(),
2932 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
2935 }
2936 }
2937
2938 @Override
2939 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2941 "setVoWiFiRoamingModeSetting");
2942 final long identity = Binder.clearCallingIdentity();
2943 try {
2944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2945 ImsManager.getInstance(mPhone.getContext(),
2946 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
2949 }
2950 }
2951
2952 @Override
2953 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2955 "setRttCapabilityEnabled");
2956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2959 ImsManager.getInstance(mPhone.getContext(),
2960 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
2963 }
2964 }
2965
2966 @Override
2967 public boolean isTtyOverVolteEnabled(int subId) {
2968 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2972 return ImsManager.getInstance(mPhone.getContext(),
2973 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2974 } finally {
2975 Binder.restoreCallingIdentity(identity);
2976 }
2977 }
2978
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002979 @Override
2980 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2981 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2985 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2986 .getConfigInterface().addConfigCallback(callback);
2987 } catch (ImsException e) {
2988 throw new IllegalArgumentException(e.getMessage());
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
2991 }
2992 }
2993
2994 @Override
2995 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2996 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3000 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3001 .getConfigInterface().removeConfigCallback(callback);
3002 } catch (ImsException e) {
3003 throw new IllegalArgumentException(e.getMessage());
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
3007 }
3008
3009 @Override
3010 public int getImsProvisioningInt(int subId, int key) {
3011 enforceReadPrivilegedPermission("getImsProvisioningInt");
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3015 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3016 .getConfigInterface().getConfigInt(key);
3017 } catch (ImsException e) {
3018 throw new IllegalArgumentException(e.getMessage());
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public String getImsProvisioningString(int subId, int key) {
3026 enforceReadPrivilegedPermission("getImsProvisioningString");
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3030 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3031 .getConfigInterface().getConfigString(key);
3032 } catch (ImsException e) {
3033 throw new IllegalArgumentException(e.getMessage());
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 @Override
3040 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3042 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3046 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3047 .getConfigInterface().setConfig(key, value);
3048 } catch (ImsException e) {
3049 throw new IllegalArgumentException(e.getMessage());
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
3053 }
3054
3055 @Override
3056 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3058 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3062 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3063 .getConfigInterface().setConfig(key, value);
3064 } catch (ImsException e) {
3065 throw new IllegalArgumentException(e.getMessage());
3066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
3069 }
3070
Brad Ebinger4c460712018-10-01 10:40:55 -07003071 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3072 int slotId = SubscriptionManager.getSlotIndex(subId);
3073 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3074 throw new IllegalArgumentException("Invalid Subscription Id.");
3075 }
3076 return slotId;
3077 }
3078
Wink Saville36469e72014-06-11 15:17:00 -07003079 /**
3080 * Returns the network type for a subId
3081 */
3082 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003083 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003085 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003086 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3087 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003088
Malcolm Chend965c8b2018-02-28 15:00:40 -08003089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 final Phone phone = getPhone(subId);
3092 if (phone != null) {
3093 return phone.getServiceState().getDataNetworkType();
3094 } else {
3095 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3096 }
3097 } finally {
3098 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 }
3101
3102 /**
3103 * Returns the data network type
3104 */
3105 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003106 public int getDataNetworkType(String callingPackage) {
3107 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003108 }
3109
3110 /**
3111 * Returns the data network type for a subId
3112 */
3113 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003114 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003116 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003117 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3118 }
3119
Malcolm Chend965c8b2018-02-28 15:00:40 -08003120 final long identity = Binder.clearCallingIdentity();
3121 try {
3122 final Phone phone = getPhone(subId);
3123 if (phone != null) {
3124 return phone.getServiceState().getDataNetworkType();
3125 } else {
3126 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3127 }
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003130 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003131 }
3132
3133 /**
Wink Saville36469e72014-06-11 15:17:00 -07003134 * Returns the Voice network type for a subId
3135 */
3136 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003137 public int getVoiceNetworkTypeForSubscriber(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 Greenwalta5dcfcb2015-07-10 09:06:29 -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().getVoiceNetworkType();
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 /**
3157 * @return true if a ICC card is present
3158 */
3159 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003160 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003161 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3162 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003163 }
3164
3165 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003166 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003167 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003168 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003169 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003170 final long identity = Binder.clearCallingIdentity();
3171 try {
3172 final Phone phone = PhoneFactory.getPhone(slotIndex);
3173 if (phone != null) {
3174 return phone.getIccCard().hasIccCard();
3175 } else {
3176 return false;
3177 }
3178 } finally {
3179 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 }
3182
3183 /**
3184 * Return if the current radio is LTE on CDMA. This
3185 * is a tri-state return value as for a period of time
3186 * the mode may be unknown.
3187 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003188 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003190 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003192 @Override
3193 public int getLteOnCdmaMode(String callingPackage) {
3194 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003195 }
3196
Sanket Padawe356d7632015-06-22 14:03:32 -07003197 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003198 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003199 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003200 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003201 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3202 }
3203
Malcolm Chend965c8b2018-02-28 15:00:40 -08003204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 final Phone phone = getPhone(subId);
3207 if (phone == null) {
3208 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3209 } else {
3210 return phone.getLteOnCdmaMode();
3211 }
3212 } finally {
3213 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 }
Wink Saville36469e72014-06-11 15:17:00 -07003215 }
3216
3217 public void setPhone(Phone phone) {
3218 mPhone = phone;
3219 }
3220
3221 /**
3222 * {@hide}
3223 * Returns Default subId, 0 in the case of single standby.
3224 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003225 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003226 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003227 }
3228
Shishir Agrawala9f32182016-04-12 12:00:16 -07003229 private int getSlotForDefaultSubscription() {
3230 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3231 }
3232
Wink Savilleb564aae2014-10-23 10:18:09 -07003233 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003234 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003236
Pengquan Meng466e2482018-09-21 15:54:48 -07003237 private boolean isActiveSubscription(int subId) {
3238 return mSubscriptionController.isActiveSubId(subId);
3239 }
3240
Ihab Awadf2177b72013-11-25 13:33:23 -08003241 /**
3242 * @see android.telephony.TelephonyManager.WifiCallingChoices
3243 */
3244 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003245 final long identity = Binder.clearCallingIdentity();
3246 try {
3247 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3248 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3249 getWhenToMakeWifiCallsDefaultPreference());
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
3252 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003253 }
3254
3255 /**
3256 * @see android.telephony.TelephonyManager.WifiCallingChoices
3257 */
3258 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003259 final long identity = Binder.clearCallingIdentity();
3260 try {
3261 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3262 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3263 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3264 } finally {
3265 Binder.restoreCallingIdentity(identity);
3266 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003267 }
3268
Sailesh Nepald1e68152013-12-12 19:08:02 -08003269 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003270 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003271 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003272 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003273
Shishir Agrawal566b7612013-10-28 14:41:00 -07003274 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003275 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3276 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3278 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003279 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003280
Malcolm Chend965c8b2018-02-28 15:00:40 -08003281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 if (TextUtils.equals(ISDR_AID, aid)) {
3284 // Only allows LPA to open logical channel to ISD-R.
3285 ComponentInfo bestComponent =
3286 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3287 if (bestComponent == null
3288 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3289 loge("The calling package is not allowed to access ISD-R.");
3290 throw new SecurityException(
3291 "The calling package is not allowed to access ISD-R.");
3292 }
Derek Tan740e1672017-06-27 14:56:27 -07003293 }
Derek Tan740e1672017-06-27 14:56:27 -07003294
Malcolm Chend965c8b2018-02-28 15:00:40 -08003295 if (DBG) {
3296 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3297 }
3298 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3299 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3300 if (DBG) log("iccOpenLogicalChannel: " + response);
3301 return response;
3302 } finally {
3303 Binder.restoreCallingIdentity(identity);
3304 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003305 }
3306
3307 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003308 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3310 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003311
Malcolm Chend965c8b2018-02-28 15:00:40 -08003312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3315 if (channel < 0) {
3316 return false;
3317 }
3318 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3319 if (DBG) log("iccCloseLogicalChannel: " + success);
3320 return success;
3321 } finally {
3322 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003323 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003324 }
3325
3326 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003327 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003328 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3330 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003331
Malcolm Chend965c8b2018-02-28 15:00:40 -08003332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 if (DBG) {
3335 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3336 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3337 + p3 + " data=" + data);
3338 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003339
Malcolm Chend965c8b2018-02-28 15:00:40 -08003340 if (channel < 0) {
3341 return "";
3342 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003343
Malcolm Chend965c8b2018-02-28 15:00:40 -08003344 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3345 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3346 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003347
Malcolm Chend965c8b2018-02-28 15:00:40 -08003348 // Append the returned status code to the end of the response payload.
3349 String s = Integer.toHexString(
3350 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3351 if (response.payload != null) {
3352 s = IccUtils.bytesToHexString(response.payload) + s;
3353 }
3354 return s;
3355 } finally {
3356 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003357 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003358 }
Jake Hambye994d462014-02-03 13:10:13 -08003359
Evan Charltonc66da362014-05-16 14:06:40 -07003360 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003361 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3362 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3364 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003365 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003366
Malcolm Chend965c8b2018-02-28 15:00:40 -08003367 final long identity = Binder.clearCallingIdentity();
3368 try {
3369 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3370 && TextUtils.equals(ISDR_AID, data)) {
3371 // Only allows LPA to select ISD-R.
3372 ComponentInfo bestComponent =
3373 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3374 if (bestComponent == null
3375 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3376 loge("The calling package is not allowed to select ISD-R.");
3377 throw new SecurityException(
3378 "The calling package is not allowed to select ISD-R.");
3379 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003380 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003381
Malcolm Chend965c8b2018-02-28 15:00:40 -08003382 if (DBG) {
3383 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3384 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3385 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003386
Malcolm Chend965c8b2018-02-28 15:00:40 -08003387 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3388 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3389 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003390
Malcolm Chend965c8b2018-02-28 15:00:40 -08003391 // Append the returned status code to the end of the response payload.
3392 String s = Integer.toHexString(
3393 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3394 if (response.payload != null) {
3395 s = IccUtils.bytesToHexString(response.payload) + s;
3396 }
3397 return s;
3398 } finally {
3399 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003400 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003401 }
3402
3403 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003404 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003405 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3407 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003408
Malcolm Chend965c8b2018-02-28 15:00:40 -08003409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 if (DBG) {
3412 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3413 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3414 }
3415
3416 IccIoResult response =
3417 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3418 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3419 subId);
3420
3421 if (DBG) {
3422 log("Exchange SIM_IO [R]" + response);
3423 }
3424
3425 byte[] result = null;
3426 int length = 2;
3427 if (response.payload != null) {
3428 length = 2 + response.payload.length;
3429 result = new byte[length];
3430 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3431 } else {
3432 result = new byte[length];
3433 }
3434
3435 result[length - 1] = (byte) response.sw2;
3436 result[length - 2] = (byte) response.sw1;
3437 return result;
3438 } finally {
3439 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003440 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003441 }
3442
Nathan Haroldb3014052017-01-25 15:57:32 -08003443 /**
3444 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3445 * on a particular subscription
3446 */
sqianb6e41952018-03-12 14:54:01 -07003447 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3449 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3450 return null;
3451 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003452
3453 final long identity = Binder.clearCallingIdentity();
3454 try {
3455 if (appType != TelephonyManager.APPTYPE_USIM
3456 && appType != TelephonyManager.APPTYPE_SIM) {
3457 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3458 return null;
3459 }
3460 Object response = sendRequest(
3461 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3462 if (response instanceof String[]) {
3463 return (String[]) response;
3464 }
3465 // Response is an Exception of some kind,
3466 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003467 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003468 } finally {
3469 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003470 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003471 }
3472
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003473 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003474 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3476 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003477
Malcolm Chend965c8b2018-02-28 15:00:40 -08003478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3481 if (response.payload == null) {
3482 return "";
3483 }
Evan Charltonc66da362014-05-16 14:06:40 -07003484
Malcolm Chend965c8b2018-02-28 15:00:40 -08003485 // Append the returned status code to the end of the response payload.
3486 String s = Integer.toHexString(
3487 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3488 s = IccUtils.bytesToHexString(response.payload) + s;
3489 return s;
3490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
Evan Charltonc66da362014-05-16 14:06:40 -07003493 }
3494
Jake Hambye994d462014-02-03 13:10:13 -08003495 /**
3496 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3497 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3498 *
3499 * @param itemID the ID of the item to read
3500 * @return the NV item as a String, or null on error.
3501 */
3502 @Override
3503 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3506 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003507
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003511 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003512 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3513 return value;
3514 } finally {
3515 Binder.restoreCallingIdentity(identity);
3516 }
Jake Hambye994d462014-02-03 13:10:13 -08003517 }
3518
3519 /**
3520 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3521 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3522 *
3523 * @param itemID the ID of the item to read
3524 * @param itemValue the value to write, as a String
3525 * @return true on success; false on any failure
3526 */
3527 @Override
3528 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003529 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3531 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003532
3533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3536 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003537 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003538 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3539 return success;
3540 } finally {
3541 Binder.restoreCallingIdentity(identity);
3542 }
Jake Hambye994d462014-02-03 13:10:13 -08003543 }
3544
3545 /**
3546 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3547 * Used for device configuration by some CDMA operators.
3548 *
3549 * @param preferredRoamingList byte array containing the new PRL
3550 * @return true on success; false on any failure
3551 */
3552 @Override
3553 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3555 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003556
3557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3560 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3561 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3562 return success;
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
3565 }
Jake Hambye994d462014-02-03 13:10:13 -08003566 }
3567
3568 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003569 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003570 * Used for device configuration by some CDMA operators.
3571 *
chen xu1cc0abe2018-10-26 17:39:23 -07003572 * @param slotIndex - device slot.
3573 *
Jake Hambye994d462014-02-03 13:10:13 -08003574 * @return true on success; false on any failure
3575 */
3576 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003577 public boolean resetModemConfig(int slotIndex) {
3578 Phone phone = PhoneFactory.getPhone(slotIndex);
3579 if (phone != null) {
3580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3581 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003582
chen xu1cc0abe2018-10-26 17:39:23 -07003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3586 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3587 return success;
3588 } finally {
3589 Binder.restoreCallingIdentity(identity);
3590 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003591 }
chen xu1cc0abe2018-10-26 17:39:23 -07003592 return false;
3593 }
3594
3595 /**
3596 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3597 *
3598 * @param slotIndex - device slot.
3599 *
3600 * @return true on success; false on any failure
3601 */
3602 @Override
3603 public boolean rebootModem(int slotIndex) {
3604 Phone phone = PhoneFactory.getPhone(slotIndex);
3605 if (phone != null) {
3606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3607 mApp, phone.getSubId(), "rebootModem");
3608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3612 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3613 return success;
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 }
3618 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003619 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003620
Svet Ganovb320e182015-04-16 12:30:10 -07003621 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003623 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003624 return new String[0];
3625 }
3626
Malcolm Chend965c8b2018-02-28 15:00:40 -08003627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 return mPhone.getPcscfAddress(apnType);
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
Wink Saville36469e72014-06-11 15:17:00 -07003633 }
3634
Brad Ebinger51f743a2017-01-23 13:50:20 -08003635 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003636 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3637 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003638 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003639 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003640 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003641
3642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 PhoneFactory.getImsResolver().enableIms(slotId);
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003648 }
3649
3650 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003651 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3652 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003653 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003654 public void disableIms(int slotId) {
3655 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003656
3657 final long identity = Binder.clearCallingIdentity();
3658 try {
3659 PhoneFactory.getImsResolver().disableIms(slotId);
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003663 }
3664
3665 /**
3666 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3667 * feature or {@link null} if the service is not available. If the feature is available, the
3668 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3669 */
3670 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003671 IImsServiceFeatureCallback callback) {
3672 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003673
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003680 }
3681
3682 /**
3683 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3684 * feature during emergency calling or {@link null} if the service is not available. If the
3685 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3686 * listener for feature updates.
3687 */
3688 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3689 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003690
3691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003697 }
3698
Brad Ebinger5f64b052017-12-14 14:26:15 -08003699 /**
3700 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3701 * specified.
3702 */
3703 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3704 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003705
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003712 }
3713
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003714 /**
3715 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3716 * specified.
3717 */
3718 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3719 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003720
3721 final long identity = Binder.clearCallingIdentity();
3722 try {
3723 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003727 }
3728
Brad Ebinger884c07b2018-02-15 16:17:40 -08003729 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003730 * Sets the ImsService Package Name that Telephony will bind to.
3731 *
3732 * @param slotId the slot ID that the ImsService should bind for.
3733 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3734 * ImsService is the device default ImsService.
3735 * @param packageName The package name of the application that contains the ImsService to bind
3736 * to.
3737 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3738 * @hide
3739 */
3740 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003741 int[] subIds = SubscriptionManager.getSubId(slotId);
3742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3743 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3744 "setImsService");
3745
Malcolm Chend965c8b2018-02-28 15:00:40 -08003746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3749 isCarrierImsService, packageName);
3750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003753 }
3754
3755 /**
3756 * Return the ImsService configuration.
3757 *
3758 * @param slotId The slot that the ImsService is associated with.
3759 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3760 * the device default.
3761 * @return the package name of the ImsService configuration.
3762 */
3763 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003764 int[] subIds = SubscriptionManager.getSubId(slotId);
3765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3766 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3767 "getImsService");
3768
Malcolm Chend965c8b2018-02-28 15:00:40 -08003769 final long identity = Binder.clearCallingIdentity();
3770 try {
3771 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3772 isCarrierImsService);
3773 } finally {
3774 Binder.restoreCallingIdentity(identity);
3775 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003776 }
3777
Wink Saville36469e72014-06-11 15:17:00 -07003778 public void setImsRegistrationState(boolean registered) {
3779 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003780
3781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 mPhone.setImsRegistrationState(registered);
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
3786 }
Wink Saville36469e72014-06-11 15:17:00 -07003787 }
3788
3789 /**
Stuart Scott54788802015-03-30 13:18:01 -07003790 * Set the network selection mode to automatic.
3791 *
3792 */
3793 @Override
3794 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3796 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003797
Pengquan Meng466e2482018-09-21 15:54:48 -07003798 if (!isActiveSubscription(subId)) {
3799 return;
3800 }
3801
Malcolm Chend965c8b2018-02-28 15:00:40 -08003802 final long identity = Binder.clearCallingIdentity();
3803 try {
3804 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3805 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3806 } finally {
3807 Binder.restoreCallingIdentity(identity);
3808 }
Stuart Scott54788802015-03-30 13:18:01 -07003809 }
3810
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003811 /**
3812 * Ask the radio to connect to the input network and change selection mode to manual.
3813 *
3814 * @param subId the id of the subscription.
3815 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3816 * the operator to attach to.
3817 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3818 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3819 * normal network selection next time.
3820 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003821 */
3822 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003823 public boolean setNetworkSelectionModeManual(
3824 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3826 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003827
3828 if (!isActiveSubscription(subId)) {
3829 return false;
3830 }
3831
Malcolm Chend965c8b2018-02-28 15:00:40 -08003832 final long identity = Binder.clearCallingIdentity();
3833 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003834 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003835 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003836 if (DBG) {
3837 log("setNetworkSelectionModeManual: subId: " + subId
3838 + " operator: " + operatorInfo);
3839 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003840 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
3843 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003844 }
3845
3846 /**
3847 * Scans for available networks.
3848 */
3849 @Override
3850 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3852 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003853
Pengquan Meng0c05b502018-09-06 09:59:22 -07003854 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003855 try {
3856 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003857 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003858 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003862 }
3863
3864 /**
yinxub1bed742017-04-17 11:45:04 -07003865 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003866 *
yinxub1bed742017-04-17 11:45:04 -07003867 * @param subId id of the subscription
3868 * @param request contains the radio access networks with bands/channels to scan
3869 * @param messenger callback messenger for scan results or errors
3870 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003871 * @return the id of the requested scan which can be used to stop the scan.
3872 */
3873 @Override
3874 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3875 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3877 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003878
3879 final long identity = Binder.clearCallingIdentity();
3880 try {
3881 return mNetworkScanRequestTracker.startNetworkScan(
3882 request, messenger, binder, getPhone(subId));
3883 } finally {
3884 Binder.restoreCallingIdentity(identity);
3885 }
yinxu504e1392017-04-12 16:03:22 -07003886 }
3887
3888 /**
3889 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003890 *
3891 * @param subId id of the subscription
3892 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003893 */
3894 @Override
3895 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003896 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3897 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003898
3899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
3904 }
yinxu504e1392017-04-12 16:03:22 -07003905 }
3906
3907 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003908 * Get the calculated preferred network type.
3909 * Used for debugging incorrect network type.
3910 *
3911 * @return the preferred network type, defined in RILConstants.java.
3912 */
3913 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003914 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003916 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003917 return RILConstants.PREFERRED_NETWORK_MODE;
3918 }
3919
Malcolm Chend965c8b2018-02-28 15:00:40 -08003920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 // FIXME: need to get SubId from somewhere.
3923 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
3926 }
Junda Liu84d15a22014-07-02 11:21:04 -07003927 }
3928
3929 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003930 * Get the preferred network type.
3931 * Used for device configuration by some CDMA operators.
3932 *
3933 * @return the preferred network type, defined in RILConstants.java.
3934 */
3935 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003936 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3938 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003939
3940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 if (DBG) log("getPreferredNetworkType");
3943 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3944 int networkType = (result != null ? result[0] : -1);
3945 if (DBG) log("getPreferredNetworkType: " + networkType);
3946 return networkType;
3947 } finally {
3948 Binder.restoreCallingIdentity(identity);
3949 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003950 }
3951
3952 /**
3953 * Set the preferred network type.
3954 * Used for device configuration by some CDMA operators.
3955 *
3956 * @param networkType the preferred network type, defined in RILConstants.java.
3957 * @return true on success; false on any failure.
3958 */
3959 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003960 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3962 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003963
3964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3967 Boolean success = (Boolean) sendRequest(
3968 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3969 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3970 if (success) {
3971 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3972 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3973 }
3974 return success;
3975 } finally {
3976 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003977 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003978 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003979
3980 /**
Junda Liu475951f2014-11-07 16:45:03 -08003981 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003982 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003983 * tethering.
3984 *
3985 * @return 0: Not required. 1: required. 2: Not set.
3986 * @hide
3987 */
3988 @Override
3989 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003990 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003991
3992 final long identity = Binder.clearCallingIdentity();
3993 try {
3994 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3995 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07003996 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08003997 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3998 dunRequired = 1;
3999 }
4000 return dunRequired;
4001 } finally {
4002 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004003 }
Junda Liu475951f2014-11-07 16:45:03 -08004004 }
4005
4006 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004007 * Set mobile data enabled
4008 * Used by the user through settings etc to turn on/off mobile data
4009 *
4010 * @param enable {@code true} turn turn data on, else {@code false}
4011 */
4012 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004013 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4015 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004016
4017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 int phoneId = mSubscriptionController.getPhoneId(subId);
4020 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4021 Phone phone = PhoneFactory.getPhone(phoneId);
4022 if (phone != null) {
4023 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4024 phone.setUserDataEnabled(enable);
4025 } else {
4026 loge("setUserDataEnabled: no phone for subId=" + subId);
4027 }
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004030 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004031 }
4032
4033 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004034 * Get the user enabled state of Mobile Data.
4035 *
4036 * TODO: remove and use isUserDataEnabled.
4037 * This can't be removed now because some vendor codes
4038 * calls through ITelephony directly while they should
4039 * use TelephonyManager.
4040 *
4041 * @return true on enabled
4042 */
4043 @Override
4044 public boolean getDataEnabled(int subId) {
4045 return isUserDataEnabled(subId);
4046 }
4047
4048 /**
4049 * Get whether mobile data is enabled per user setting.
4050 *
4051 * There are other factors deciding whether mobile data is actually enabled, but they are
4052 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004053 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004054 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004055 *
4056 * @return {@code true} if data is enabled else {@code false}
4057 */
4058 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004059 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004060 try {
4061 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4062 null);
4063 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4065 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004066 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004067
4068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 int phoneId = mSubscriptionController.getPhoneId(subId);
4071 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4072 Phone phone = PhoneFactory.getPhone(phoneId);
4073 if (phone != null) {
4074 boolean retVal = phone.isUserDataEnabled();
4075 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4076 return retVal;
4077 } else {
4078 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4079 return false;
4080 }
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004083 }
4084 }
4085
4086 /**
4087 * Get whether mobile data is enabled.
4088 *
4089 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4090 * whether mobile data is actually enabled.
4091 *
4092 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4093 *
4094 * @return {@code true} if data is enabled else {@code false}
4095 */
4096 @Override
4097 public boolean isDataEnabled(int subId) {
4098 try {
4099 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4100 null);
4101 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4103 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004104 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004105
4106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 int phoneId = mSubscriptionController.getPhoneId(subId);
4109 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4110 Phone phone = PhoneFactory.getPhone(phoneId);
4111 if (phone != null) {
4112 boolean retVal = phone.isDataEnabled();
4113 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4114 return retVal;
4115 } else {
4116 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4117 return false;
4118 }
4119 } finally {
4120 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004121 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004122 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004123
4124 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004125 public int getCarrierPrivilegeStatus(int subId) {
4126 final Phone phone = getPhone(subId);
4127 if (phone == null) {
4128 loge("getCarrierPrivilegeStatus: Invalid subId");
4129 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4130 }
4131 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004132 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004133 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004134 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4135 }
4136 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004137 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004138 }
Junda Liu29340342014-07-10 15:23:27 -07004139
4140 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004141 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4142 final Phone phone = getPhone(subId);
4143 if (phone == null) {
4144 loge("getCarrierPrivilegeStatus: Invalid subId");
4145 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4146 }
4147 UiccProfile profile =
4148 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4149 if (profile == null) {
4150 loge("getCarrierPrivilegeStatus: No UICC");
4151 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4152 }
4153 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4154 }
4155
4156 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004157 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004158 if (TextUtils.isEmpty(pkgName))
4159 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004160 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004161 if (card == null) {
4162 loge("checkCarrierPrivilegesForPackage: No UICC");
4163 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4164 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004165 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4166 }
4167
4168 @Override
4169 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004170 if (TextUtils.isEmpty(pkgName))
4171 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004172 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4173 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4174 UiccCard card = UiccController.getInstance().getUiccCard(i);
4175 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004176 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004177 continue;
4178 }
4179
4180 result = card.getCarrierPrivilegeStatus(
4181 mPhone.getContext().getPackageManager(), pkgName);
4182 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4183 break;
4184 }
4185 }
4186
4187 return result;
Junda Liu29340342014-07-10 15:23:27 -07004188 }
Derek Tan89e89d42014-07-08 17:00:10 -07004189
4190 @Override
Junda Liue64de782015-04-16 17:19:16 -07004191 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4192 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4193 loge("phoneId " + phoneId + " is not valid.");
4194 return null;
4195 }
4196 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004197 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004198 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004199 return null ;
4200 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004201 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004202 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004203 }
4204
Amith Yamasani6e118872016-02-19 12:53:51 -08004205 @Override
4206 public List<String> getPackagesWithCarrierPrivileges() {
4207 PackageManager pm = mPhone.getContext().getPackageManager();
4208 List<String> privilegedPackages = new ArrayList<>();
4209 List<PackageInfo> packages = null;
4210 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4211 UiccCard card = UiccController.getInstance().getUiccCard(i);
4212 if (card == null) {
4213 // No UICC in that slot.
4214 continue;
4215 }
4216 if (card.hasCarrierPrivilegeRules()) {
4217 if (packages == null) {
4218 // Only check packages in user 0 for now
4219 packages = pm.getInstalledPackagesAsUser(
4220 PackageManager.MATCH_DISABLED_COMPONENTS
4221 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4222 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4223 }
4224 for (int p = packages.size() - 1; p >= 0; p--) {
4225 PackageInfo pkgInfo = packages.get(p);
4226 if (pkgInfo != null && pkgInfo.packageName != null
4227 && card.getCarrierPrivilegeStatus(pkgInfo)
4228 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4229 privilegedPackages.add(pkgInfo.packageName);
4230 }
4231 }
4232 }
4233 }
4234 return privilegedPackages;
4235 }
4236
Wink Savilleb564aae2014-10-23 10:18:09 -07004237 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004238 final Phone phone = getPhone(subId);
4239 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004240 if (card == null) {
4241 loge("getIccId: No UICC");
4242 return null;
4243 }
4244 String iccId = card.getIccId();
4245 if (TextUtils.isEmpty(iccId)) {
4246 loge("getIccId: ICC ID is null or empty.");
4247 return null;
4248 }
4249 return iccId;
4250 }
4251
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004252 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004253 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4254 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004255 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4256 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004257
Malcolm Chend965c8b2018-02-28 15:00:40 -08004258 final long identity = Binder.clearCallingIdentity();
4259 try {
4260 final String iccId = getIccId(subId);
4261 final Phone phone = getPhone(subId);
4262 if (phone == null) {
4263 return false;
4264 }
4265 final String subscriberId = phone.getSubscriberId();
4266
4267 if (DBG_MERGE) {
4268 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4269 + subscriberId + " to " + number);
4270 }
4271
4272 if (TextUtils.isEmpty(iccId)) {
4273 return false;
4274 }
4275
4276 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4277
4278 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4279 if (alphaTag == null) {
4280 editor.remove(alphaTagPrefKey);
4281 } else {
4282 editor.putString(alphaTagPrefKey, alphaTag);
4283 }
4284
4285 // Record both the line number and IMSI for this ICCID, since we need to
4286 // track all merged IMSIs based on line number
4287 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4288 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4289 if (number == null) {
4290 editor.remove(numberPrefKey);
4291 editor.remove(subscriberPrefKey);
4292 } else {
4293 editor.putString(numberPrefKey, number);
4294 editor.putString(subscriberPrefKey, subscriberId);
4295 }
4296
4297 editor.commit();
4298 return true;
4299 } finally {
4300 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004301 }
Derek Tan7226c842014-07-02 17:42:23 -07004302 }
4303
4304 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004305 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004306 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004308 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004309 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004310 return null;
4311 }
Derek Tan97ebb422014-09-05 16:55:38 -07004312
Malcolm Chend965c8b2018-02-28 15:00:40 -08004313 final long identity = Binder.clearCallingIdentity();
4314 try {
4315 String iccId = getIccId(subId);
4316 if (iccId != null) {
4317 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4318 if (DBG_MERGE) {
4319 log("getLine1NumberForDisplay returning "
4320 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4321 }
4322 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004323 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004324 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4325 return null;
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004328 }
Derek Tan7226c842014-07-02 17:42:23 -07004329 }
4330
4331 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004332 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004333 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004334 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004335 return null;
4336 }
Derek Tan97ebb422014-09-05 16:55:38 -07004337
Malcolm Chend965c8b2018-02-28 15:00:40 -08004338 final long identity = Binder.clearCallingIdentity();
4339 try {
4340 String iccId = getIccId(subId);
4341 if (iccId != null) {
4342 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4343 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4344 }
4345 return null;
4346 } finally {
4347 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004348 }
Derek Tan7226c842014-07-02 17:42:23 -07004349 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004350
4351 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004352 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004353 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4354 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004356 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4357 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004358 return null;
4359 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004360
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004361 final long identity = Binder.clearCallingIdentity();
4362 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004363 final Context context = mPhone.getContext();
4364 final TelephonyManager tele = TelephonyManager.from(context);
4365 final SubscriptionManager sub = SubscriptionManager.from(context);
4366
4367 // Figure out what subscribers are currently active
4368 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4369 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4370 // the process, where TelephonyManager was instantiated.
4371 // Otherwise AppOps check will fail.
4372
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004373 final int[] subIds = sub.getActiveSubscriptionIdList();
4374 for (int subId : subIds) {
4375 activeSubscriberIds.add(tele.getSubscriberId(subId));
4376 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004377
4378 // First pass, find a number override for an active subscriber
4379 String mergeNumber = null;
4380 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4381 for (String key : prefs.keySet()) {
4382 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4383 final String subscriberId = (String) prefs.get(key);
4384 if (activeSubscriberIds.contains(subscriberId)) {
4385 final String iccId = key.substring(
4386 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4387 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4388 mergeNumber = (String) prefs.get(numberKey);
4389 if (DBG_MERGE) {
4390 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4391 + " for active subscriber " + subscriberId);
4392 }
4393 if (!TextUtils.isEmpty(mergeNumber)) {
4394 break;
4395 }
4396 }
4397 }
4398 }
4399
4400 // Shortcut when no active merged subscribers
4401 if (TextUtils.isEmpty(mergeNumber)) {
4402 return null;
4403 }
4404
4405 // Second pass, find all subscribers under that line override
4406 final ArraySet<String> result = new ArraySet<>();
4407 for (String key : prefs.keySet()) {
4408 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4409 final String number = (String) prefs.get(key);
4410 if (mergeNumber.equals(number)) {
4411 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4412 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4413 final String subscriberId = (String) prefs.get(subscriberKey);
4414 if (!TextUtils.isEmpty(subscriberId)) {
4415 result.add(subscriberId);
4416 }
4417 }
4418 }
4419 }
4420
4421 final String[] resultArray = result.toArray(new String[result.size()]);
4422 Arrays.sort(resultArray);
4423 if (DBG_MERGE) {
4424 Slog.d(LOG_TAG,
4425 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4426 }
4427 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004428 } finally {
4429 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004430 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004431 }
4432
4433 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004434 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004435 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4436 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004437
4438 final long identity = Binder.clearCallingIdentity();
4439 try {
4440 final Phone phone = getPhone(subId);
4441 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4442 } finally {
4443 Binder.restoreCallingIdentity(identity);
4444 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004445 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004446
4447 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004448 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004449 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4450 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004451 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004452
4453 final long identity = Binder.clearCallingIdentity();
4454 try {
4455 final Phone phone = getPhone(subId);
4456 if (phone == null) {
4457 return false;
4458 }
4459 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4460 cdmaNonRoamingList);
4461 } finally {
4462 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004463 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004464 }
4465
4466 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004467 @Deprecated
4468 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4469 enforceModifyPermission();
4470
4471 int returnValue = 0;
4472 try {
vagdevie435a3e2018-08-15 16:01:53 -07004473 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004474 if(result.exception == null) {
4475 if (result.result != null) {
4476 byte[] responseData = (byte[])(result.result);
4477 if(responseData.length > oemResp.length) {
4478 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4479 responseData.length + "bytes. Buffer Size is " +
4480 oemResp.length + "bytes.");
4481 }
4482 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4483 returnValue = responseData.length;
4484 }
4485 } else {
4486 CommandException ex = (CommandException) result.exception;
4487 returnValue = ex.getCommandError().ordinal();
4488 if(returnValue > 0) returnValue *= -1;
4489 }
4490 } catch (RuntimeException e) {
4491 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4492 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4493 if(returnValue > 0) returnValue *= -1;
4494 }
4495
4496 return returnValue;
4497 }
4498
4499 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004500 public void setRadioCapability(RadioAccessFamily[] rafs) {
4501 try {
4502 ProxyController.getInstance().setRadioCapability(rafs);
4503 } catch (RuntimeException e) {
4504 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4505 }
4506 }
4507
4508 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004509 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004510 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004511 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004512 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004513 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004514 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004515 final long identity = Binder.clearCallingIdentity();
4516 try {
chen xufeeed752018-10-26 14:17:57 -07004517 TelephonyPermissions
4518 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4519 mApp, phone.getSubId(), "getRadioAccessFamily");
4520 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
chen xufeeed752018-10-26 14:17:57 -07004524 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004525 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004526
4527 @Override
4528 public void enableVideoCalling(boolean enable) {
4529 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004530
4531 final long identity = Binder.clearCallingIdentity();
4532 try {
4533 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4534 } finally {
4535 Binder.restoreCallingIdentity(identity);
4536 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004537 }
4538
4539 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004540 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4542 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4543 return false;
4544 }
Svet Ganovb320e182015-04-16 12:30:10 -07004545
Malcolm Chend965c8b2018-02-28 15:00:40 -08004546 final long identity = Binder.clearCallingIdentity();
4547 try {
4548 // Check the user preference and the system-level IMS setting. Even if the user has
4549 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4550 // In the long run, we may instead need to check if there exists a connection service
4551 // which can support video calling.
4552 ImsManager imsManager =
4553 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4554 return imsManager.isVtEnabledByPlatform()
4555 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4556 && imsManager.isVtEnabledByUser();
4557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004560 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004561
Andrew Leea1239f22015-03-02 17:44:07 -08004562 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004563 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4565 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4566 return false;
4567 }
4568
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 CarrierConfigManager configManager =
4572 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4573 return configManager.getConfigForSubId(mPhone.getSubId())
4574 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Andrew Leea1239f22015-03-02 17:44:07 -08004578 }
4579
4580 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004581 public boolean isWorldPhone(int subId, String callingPackage) {
4582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4583 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4584 return false;
4585 }
4586
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
4589 CarrierConfigManager configManager =
4590 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4591 return configManager.getConfigForSubId(mPhone.getSubId())
4592 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4593 } finally {
4594 Binder.restoreCallingIdentity(identity);
4595 }
Andrew Leea1239f22015-03-02 17:44:07 -08004596 }
4597
Andrew Lee9431b832015-03-09 18:46:45 -07004598 @Override
4599 public boolean isTtyModeSupported() {
4600 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004601 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004602 }
4603
4604 @Override
4605 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4609 } finally {
4610 Binder.restoreCallingIdentity(identity);
4611 }
Andrew Lee9431b832015-03-09 18:46:45 -07004612 }
4613
Hall Liuf6668912018-10-31 17:05:23 -07004614 /**
4615 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4616 * support for the feature and device firmware support.
4617 *
4618 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4619 */
4620 @Override
4621 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4625 mPhone.getSubId()).getBoolean(
4626 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4627 boolean isDeviceSupported =
4628 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4629 return isCarrierSupported && isDeviceSupported;
4630 } finally {
4631 Binder.restoreCallingIdentity(identity);
4632 }
Hall Liu98187582018-01-22 19:15:32 -08004633 }
4634
Hall Liuf6668912018-10-31 17:05:23 -07004635 /**
4636 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4637 * both also support RTT.
4638 */
4639 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004640 final long identity = Binder.clearCallingIdentity();
4641 try {
Hall Liuf6668912018-10-31 17:05:23 -07004642 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004643 mPhone.getContext().getContentResolver(),
4644 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4645 } finally {
4646 Binder.restoreCallingIdentity(identity);
4647 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004648 }
4649
Sanket Padawe7310cc72015-01-14 09:53:20 -08004650 /**
4651 * Returns the unique device ID of phone, for example, the IMEI for
4652 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4653 *
4654 * <p>Requires Permission:
4655 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4656 */
4657 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004658 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004659 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004660 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004661 return null;
4662 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004663 int subId = phone.getSubId();
4664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4665 mApp, subId, callingPackage, "getDeviceId")) {
4666 return null;
4667 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004668
4669 final long identity = Binder.clearCallingIdentity();
4670 try {
4671 return phone.getDeviceId();
4672 } finally {
4673 Binder.restoreCallingIdentity(identity);
4674 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004675 }
4676
Ping Sunc67b7c22016-03-02 19:16:45 +08004677 /**
4678 * {@hide}
4679 * Returns the IMS Registration Status on a particular subid
4680 *
4681 * @param subId
4682 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004683 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004684 Phone phone = getPhone(subId);
4685 if (phone != null) {
4686 return phone.isImsRegistered();
4687 } else {
4688 return false;
4689 }
4690 }
4691
Santos Cordon7a1885b2015-02-03 11:15:19 -08004692 @Override
4693 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004694 final long identity = Binder.clearCallingIdentity();
4695 try {
4696 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004700 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004701
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004702 /**
4703 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004704 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004705 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004706 final long identity = Binder.clearCallingIdentity();
4707 try {
4708 Phone phone = getPhone(subId);
4709 if (phone != null) {
4710 return phone.isWifiCallingEnabled();
4711 } else {
4712 return false;
4713 }
4714 } finally {
4715 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004716 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004717 }
4718
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004719 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004720 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004721 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004722 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004723 final long identity = Binder.clearCallingIdentity();
4724 try {
4725 Phone phone = getPhone(subId);
4726 if (phone != null) {
4727 return phone.isVideoEnabled();
4728 } else {
4729 return false;
4730 }
4731 } finally {
4732 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004733 }
4734 }
4735
4736 /**
4737 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4738 * defined in {@link ImsRegistrationImplBase}.
4739 */
4740 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004741 final long identity = Binder.clearCallingIdentity();
4742 try {
4743 Phone phone = getPhone(subId);
4744 if (phone != null) {
4745 return phone.getImsRegistrationTech();
4746 } else {
4747 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4748 }
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004751 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004752 }
4753
Stuart Scott8eef64f2015-04-08 15:13:54 -07004754 @Override
4755 public void factoryReset(int subId) {
4756 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004757 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4758 return;
4759 }
4760
Svet Ganovcc087f82015-05-12 20:35:54 -07004761 final long identity = Binder.clearCallingIdentity();
4762 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004763 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4764 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004765 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004766 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004767 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4768 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004769 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004770 }
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004773 }
4774 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004775
4776 @Override
4777 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004778 final long identity = Binder.clearCallingIdentity();
4779 try {
4780 // We query all subscriptions instead of just the active ones, because
4781 // this might be called early on in the provisioning flow when the
4782 // subscriptions potentially aren't active yet.
4783 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4784 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004785 return null;
4786 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004787
Malcolm Chend965c8b2018-02-28 15:00:40 -08004788 // This function may be called very early, say, from the setup wizard, at
4789 // which point we won't have a default subscription set. If that's the case
4790 // we just choose the first, which will be valid in "most cases".
4791 final int defaultSubId = getDefaultSubscription();
4792 SubscriptionInfo info = null;
4793 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4794 info = slist.get(0);
4795 } else {
4796 for (SubscriptionInfo item : slist) {
4797 if (item.getSubscriptionId() == defaultSubId) {
4798 info = item;
4799 break;
4800 }
4801 }
4802
4803 if (info == null) {
4804 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004805 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004806 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004807
Malcolm Chend965c8b2018-02-28 15:00:40 -08004808 // Try and fetch the locale from the carrier properties or from the SIM language
4809 // preferences (EF-PL and EF-LI)...
4810 final int mcc = info.getMcc();
4811 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4812 String simLanguage = null;
4813 if (defaultPhone != null) {
4814 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4815 if (localeFromDefaultSim != null) {
4816 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4817 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4818 return localeFromDefaultSim.toLanguageTag();
4819 } else {
4820 simLanguage = localeFromDefaultSim.getLanguage();
4821 }
4822 }
4823 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004824
Malcolm Chend965c8b2018-02-28 15:00:40 -08004825 // The SIM language preferences only store a language (e.g. fr = French), not an
4826 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4827 // the SIM and carrier preferences does not include a country we add the country
4828 // determined from the SIM MCC to provide an exact locale.
4829 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4830 simLanguage);
4831 if (mccLocale != null) {
4832 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4833 return mccLocale.toLanguageTag();
4834 }
4835
4836 if (DBG) log("No locale found - returning null");
4837 return null;
4838 } finally {
4839 Binder.restoreCallingIdentity(identity);
4840 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004841 }
4842
4843 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004844 return mSubscriptionController.getAllSubInfoList(
4845 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004846 }
4847
Malcolm Chend965c8b2018-02-28 15:00:40 -08004848 /**
4849 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4850 */
4851 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4852 return mSubscriptionController.getActiveSubscriptionInfoList(
4853 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004854 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004855
Chenjie Yu1ba97252018-01-11 18:16:20 -08004856 private final ModemActivityInfo mLastModemActivityInfo =
4857 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4858
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004859 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004860 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4861 * representing the state of the modem.
4862 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004863 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4864 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004865 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004866 */
4867 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004868 public void requestModemActivityInfo(ResultReceiver result) {
4869 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004870 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004871
4872 final long identity = Binder.clearCallingIdentity();
4873 try {
4874 ModemActivityInfo ret = null;
4875 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004876 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4877 CMD_GET_MODEM_ACTIVITY_INFO,
4878 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004879 if (isModemActivityInfoValid(info)) {
4880 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4881 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4882 mergedTxTimeMs[i] =
4883 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4884 }
4885 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4886 mLastModemActivityInfo.setSleepTimeMillis(
4887 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4888 mLastModemActivityInfo.setIdleTimeMillis(
4889 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4890 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4891 mLastModemActivityInfo.setRxTimeMillis(
4892 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4893 mLastModemActivityInfo.setEnergyUsed(
4894 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004895 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004896 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4897 mLastModemActivityInfo.getSleepTimeMillis(),
4898 mLastModemActivityInfo.getIdleTimeMillis(),
4899 mLastModemActivityInfo.getTxTimeMillis(),
4900 mLastModemActivityInfo.getRxTimeMillis(),
4901 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004902 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004903 Bundle bundle = new Bundle();
4904 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4905 result.send(0, bundle);
4906 } finally {
4907 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004908 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004909 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004910
Siddharth Rayf5d29552018-06-17 15:02:38 -07004911 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4912 // less than total activity duration.
4913 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4914 if (info == null) {
4915 return false;
4916 }
4917 int activityDurationMs =
4918 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4919 int totalTxTimeMs = 0;
4920 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4921 totalTxTimeMs += info.getTxTimeMillis()[i];
4922 }
4923 return (info.isValid()
4924 && (info.getSleepTimeMillis() <= activityDurationMs)
4925 && (info.getIdleTimeMillis() <= activityDurationMs)
4926 && (info.getRxTimeMillis() <= activityDurationMs)
4927 && (totalTxTimeMs <= activityDurationMs));
4928 }
4929
Jack Yu85bd38a2015-11-09 11:34:32 -08004930 /**
4931 * {@hide}
4932 * Returns the service state information on specified subscription.
4933 */
4934 @Override
4935 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004937 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004938 return null;
4939 }
4940
Malcolm Chend965c8b2018-02-28 15:00:40 -08004941 final long identity = Binder.clearCallingIdentity();
4942 try {
4943 final Phone phone = getPhone(subId);
4944 if (phone == null) {
4945 return null;
4946 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004947
Malcolm Chend965c8b2018-02-28 15:00:40 -08004948 return phone.getServiceState();
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004952 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004953
4954 /**
4955 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4956 *
4957 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4958 * voicemail ringtone.
4959 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4960 * PhoneAccount.
4961 */
4962 @Override
4963 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004964 final long identity = Binder.clearCallingIdentity();
4965 try {
4966 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4967 if (phone == null) {
4968 phone = mPhone;
4969 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004970
Malcolm Chend965c8b2018-02-28 15:00:40 -08004971 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004975 }
4976
4977 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004978 * Sets the per-account voicemail ringtone.
4979 *
4980 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4981 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4982 *
4983 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4984 * voicemail ringtone.
4985 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4986 * PhoneAccount.
4987 */
4988 @Override
4989 public void setVoicemailRingtoneUri(String callingPackage,
4990 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4992 if (!TextUtils.equals(callingPackage,
4993 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4995 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4996 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004997 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004998
4999 final long identity = Binder.clearCallingIdentity();
5000 try {
5001 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5002 if (phone == null) {
5003 phone = mPhone;
5004 }
5005 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5006 } finally {
5007 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005008 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005009 }
5010
5011 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005012 * Returns whether vibration is set for voicemail notification in Phone settings.
5013 *
5014 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5015 * voicemail vibration setting.
5016 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5017 */
5018 @Override
5019 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005020 final long identity = Binder.clearCallingIdentity();
5021 try {
5022 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5023 if (phone == null) {
5024 phone = mPhone;
5025 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005026
Malcolm Chend965c8b2018-02-28 15:00:40 -08005027 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005031 }
5032
Youhan Wange64578a2016-05-02 15:32:42 -07005033 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005034 * Sets the per-account voicemail vibration.
5035 *
5036 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5037 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5038 *
5039 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5040 * voicemail vibration setting.
5041 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5042 * specific PhoneAccount.
5043 */
5044 @Override
5045 public void setVoicemailVibrationEnabled(String callingPackage,
5046 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5047 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5048 if (!TextUtils.equals(callingPackage,
5049 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5051 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5052 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005053 }
5054
Malcolm Chend965c8b2018-02-28 15:00:40 -08005055 final long identity = Binder.clearCallingIdentity();
5056 try {
5057 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5058 if (phone == null) {
5059 phone = mPhone;
5060 }
5061 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5062 } finally {
5063 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005064 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005065 }
5066
5067 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005068 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5069 *
5070 * @throws SecurityException if the caller does not have the required permission
5071 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005072 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005073 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005074 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005075 }
5076
5077 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005078 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5079 * permission.
5080 *
5081 * @throws SecurityException if the caller does not have the required permission
5082 */
5083 private void enforceSendSmsPermission() {
5084 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5085 }
5086
5087 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005088 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005089 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005090 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005091 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005092 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005093 final long identity = Binder.clearCallingIdentity();
5094 try {
5095 ComponentName componentName =
5096 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5097 if (componentName == null) {
5098 throw new SecurityException(
5099 "Caller not current active visual voicemail package[null]");
5100 }
5101 String vvmPackage = componentName.getPackageName();
5102 if (!callingPackage.equals(vvmPackage)) {
5103 throw new SecurityException("Caller not current active visual voicemail package["
5104 + vvmPackage + "]");
5105 }
5106 } finally {
5107 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005108 }
5109 }
5110
5111 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005112 * Return the application ID for the app type.
5113 *
5114 * @param subId the subscription ID that this request applies to.
5115 * @param appType the uicc app type.
5116 * @return Application ID for specificied app type, or null if no uicc.
5117 */
5118 @Override
5119 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005120 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005121 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005122
5123 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005124 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005125 if (phone == null) {
5126 return null;
5127 }
5128 String aid = null;
5129 try {
5130 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5131 .getApplicationByType(appType).getAid();
5132 } catch (Exception e) {
5133 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5134 }
5135 return aid;
5136 } finally {
5137 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005138 }
Youhan Wange64578a2016-05-02 15:32:42 -07005139 }
5140
Youhan Wang4001d252016-05-11 10:29:41 -07005141 /**
5142 * Return the Electronic Serial Number.
5143 *
5144 * @param subId the subscription ID that this request applies to.
5145 * @return ESN or null if error.
5146 */
5147 @Override
5148 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005149 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005150 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005151
5152 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005153 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005154 if (phone == null) {
5155 return null;
5156 }
5157 String esn = null;
5158 try {
5159 esn = phone.getEsn();
5160 } catch (Exception e) {
5161 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5162 }
5163 return esn;
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005166 }
Youhan Wang4001d252016-05-11 10:29:41 -07005167 }
5168
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005169 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005170 * Return the Preferred Roaming List Version.
5171 *
5172 * @param subId the subscription ID that this request applies to.
5173 * @return PRLVersion or null if error.
5174 */
5175 @Override
5176 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005177 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005178 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005179
5180 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005181 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005182 if (phone == null) {
5183 return null;
5184 }
5185 String cdmaPrlVersion = null;
5186 try {
5187 cdmaPrlVersion = phone.getCdmaPrlVersion();
5188 } catch (Exception e) {
5189 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5190 }
5191 return cdmaPrlVersion;
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005194 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005195 }
5196
5197 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005198 * Get snapshot of Telephony histograms
5199 * @return List of Telephony histograms
5200 * @hide
5201 */
5202 @Override
5203 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5205 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005206
5207 final long identity = Binder.clearCallingIdentity();
5208 try {
5209 return RIL.getTelephonyRILTimingHistograms();
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005213 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005214
5215 /**
5216 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005217 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005218 * Require system privileges. In the future we may add this to carrier APIs.
5219 *
5220 * @return The number of carriers set successfully, should match length of carriers
5221 */
5222 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005223 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005224 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005225 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005226
Meng Wang9b7c4e92017-02-17 11:41:27 -08005227 if (carriers == null) {
5228 throw new NullPointerException("carriers cannot be null");
5229 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005230
Malcolm Chend965c8b2018-02-28 15:00:40 -08005231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005234 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5235 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005236 return retVal[0];
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005240 }
5241
5242 /**
5243 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005244 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005245 * Require system privileges. In the future we may add this to carrier APIs.
5246 *
5247 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5248 * means all carriers are allowed.
5249 */
5250 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005251 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005252 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005253 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005254
5255 final long identity = Binder.clearCallingIdentity();
5256 try {
5257 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005258 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5259 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005263 }
5264
fionaxu59545b42016-05-25 15:53:37 -07005265 /**
5266 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5267 * @param subId the subscription ID that this action applies to.
5268 * @param enabled control enable or disable metered apns.
5269 * {@hide}
5270 */
5271 @Override
5272 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5273 enforceModifyPermission();
5274 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005275
5276 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005277 if (phone == null) {
5278 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5279 return;
5280 }
5281 try {
5282 phone.carrierActionSetMeteredApnsEnabled(enabled);
5283 } catch (Exception e) {
5284 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005285 } finally {
5286 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005287 }
5288 }
5289
5290 /**
5291 * Action set from carrier signalling broadcast receivers to enable/disable radio
5292 * @param subId the subscription ID that this action applies to.
5293 * @param enabled control enable or disable radio.
5294 * {@hide}
5295 */
5296 @Override
5297 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5298 enforceModifyPermission();
5299 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005300
5301 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005302 if (phone == null) {
5303 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5304 return;
5305 }
5306 try {
5307 phone.carrierActionSetRadioEnabled(enabled);
5308 } catch (Exception e) {
5309 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005310 } finally {
5311 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005312 }
5313 }
5314
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005315 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005316 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5317 * network status based on which carrier apps could apply actions accordingly,
5318 * enable/disable default url handler for example.
5319 *
5320 * @param subId the subscription ID that this action applies to.
5321 * @param report control start/stop reporting the default network status.
5322 * {@hide}
5323 */
5324 @Override
5325 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5326 enforceModifyPermission();
5327 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005328
5329 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005330 if (phone == null) {
5331 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5332 return;
5333 }
5334 try {
5335 phone.carrierActionReportDefaultNetworkStatus(report);
5336 } catch (Exception e) {
5337 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005338 } finally {
5339 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005340 }
5341 }
5342
5343 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005344 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5345 * bug report is being generated.
5346 */
5347 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005348 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005349 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5350 != PackageManager.PERMISSION_GRANTED) {
5351 writer.println("Permission Denial: can't dump Phone from pid="
5352 + Binder.getCallingPid()
5353 + ", uid=" + Binder.getCallingUid()
5354 + "without permission "
5355 + android.Manifest.permission.DUMP);
5356 return;
5357 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005358 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005359 }
Jack Yueb89b242016-06-22 13:27:47 -07005360
Brad Ebingerdac2f002018-04-03 15:17:52 -07005361 @Override
5362 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5363 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5364 throws RemoteException {
5365 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5366 }
5367
Jack Yueb89b242016-06-22 13:27:47 -07005368 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005369 * Get aggregated video call data usage since boot.
5370 *
5371 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5372 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005373 * {@hide}
5374 */
5375 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005376 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005377 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5378 null);
5379
Malcolm Chend965c8b2018-02-28 15:00:40 -08005380 final long identity = Binder.clearCallingIdentity();
5381 try {
5382 // NetworkStatsService keeps tracking the active network interface and identity. It
5383 // records the delta with the corresponding network identity.
5384 // We just return the total video call data usage snapshot since boot.
5385 Phone phone = getPhone(subId);
5386 if (phone != null) {
5387 return phone.getVtDataUsage(perUidStats);
5388 }
5389 return null;
5390 } finally {
5391 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005392 }
Jack Yueb89b242016-06-22 13:27:47 -07005393 }
Jack Yu75ab2952016-07-08 14:29:33 -07005394
5395 /**
5396 * Policy control of data connection. Usually used when data limit is passed.
5397 * @param enabled True if enabling the data, otherwise disabling.
5398 * @param subId Subscription index
5399 * {@hide}
5400 */
5401 @Override
5402 public void setPolicyDataEnabled(boolean enabled, int subId) {
5403 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005404
5405 final long identity = Binder.clearCallingIdentity();
5406 try {
5407 Phone phone = getPhone(subId);
5408 if (phone != null) {
5409 phone.setPolicyDataEnabled(enabled);
5410 }
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005413 }
5414 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005415
5416 /**
5417 * Get Client request stats
5418 * @return List of Client Request Stats
5419 * @hide
5420 */
5421 @Override
5422 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005423 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005424 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005425 return null;
5426 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005427 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005428
Malcolm Chend965c8b2018-02-28 15:00:40 -08005429 final long identity = Binder.clearCallingIdentity();
5430 try {
5431 if (phone != null) {
5432 return phone.getClientRequestStats();
5433 }
5434
5435 return null;
5436 } finally {
5437 Binder.restoreCallingIdentity(identity);
5438 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005439 }
5440
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005441 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005442 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005443 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005444 }
Jack Yueb4124c2017-02-16 15:32:43 -08005445
5446 /**
Grace Chen70990072017-03-24 17:21:30 -07005447 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005448 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005449 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005450 * @param state State of SIM (power down, power up, pass through)
5451 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5452 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5453 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005454 *
5455 **/
5456 @Override
Grace Chen70990072017-03-24 17:21:30 -07005457 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005458 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005459 Phone phone = PhoneFactory.getPhone(slotIndex);
5460
vagdevie435a3e2018-08-15 16:01:53 -07005461 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5462
Malcolm Chend965c8b2018-02-28 15:00:40 -08005463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005466 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005467 }
5468 } finally {
5469 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005470 }
5471 }
Shuo Qiandd210312017-04-12 22:11:33 +00005472
Tyler Gunn65d45c22017-06-05 11:22:26 -07005473 private boolean isUssdApiAllowed(int subId) {
5474 CarrierConfigManager configManager =
5475 (CarrierConfigManager) mPhone.getContext().getSystemService(
5476 Context.CARRIER_CONFIG_SERVICE);
5477 if (configManager == null) {
5478 return false;
5479 }
5480 PersistableBundle pb = configManager.getConfigForSubId(subId);
5481 if (pb == null) {
5482 return false;
5483 }
5484 return pb.getBoolean(
5485 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5486 }
5487
Shuo Qiandd210312017-04-12 22:11:33 +00005488 /**
5489 * Check if phone is in emergency callback mode
5490 * @return true if phone is in emergency callback mode
5491 * @param subId sub id
5492 */
goneil9c5f4872017-12-05 14:07:56 -08005493 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005494 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005495 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005496 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005497
5498 final long identity = Binder.clearCallingIdentity();
5499 try {
5500 if (phone != null) {
5501 return phone.isInEcm();
5502 } else {
5503 return false;
5504 }
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005507 }
5508 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005509
5510 /**
5511 * Get the current signal strength information for the given subscription.
5512 * Because this information is not updated when the device is in a low power state
5513 * it should not be relied-upon to be current.
5514 * @param subId Subscription index
5515 * @return the most recent cached signal strength info from the modem
5516 */
5517 @Override
5518 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005519 final long identity = Binder.clearCallingIdentity();
5520 try {
5521 Phone p = getPhone(subId);
5522 if (p == null) {
5523 return null;
5524 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005525
Malcolm Chend965c8b2018-02-28 15:00:40 -08005526 return p.getSignalStrength();
5527 } finally {
5528 Binder.restoreCallingIdentity(identity);
5529 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005530 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005531
Pengquan Meng9140aec2018-08-22 14:49:57 -07005532 /**
chen xu907e5a22018-10-11 13:21:04 -07005533 * Get the current modem radio state for the given slot.
5534 * @param slotIndex slot index.
5535 * @param callingPackage the name of the package making the call.
5536 * @return the current radio power state from the modem
5537 */
5538 @Override
5539 public int getRadioPowerState(int slotIndex, String callingPackage) {
5540 Phone phone = PhoneFactory.getPhone(slotIndex);
5541 if (phone != null) {
5542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5543 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5544 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5545 }
5546
5547 final long identity = Binder.clearCallingIdentity();
5548 try {
5549 return phone.getRadioPowerState();
5550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
5553 }
5554 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5555 }
5556
5557 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005558 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5559 *
5560 * <p>Requires one of the following permissions:
5561 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5562 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5563 * privileges.
5564 *
5565 * @param subId subscription id
5566 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5567 * {@code false}.
5568 */
5569 @Override
5570 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005571 boolean isEnabled = false;
5572 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005573 try {
5574 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005575 null /* message */);
5576 Phone phone = getPhone(subId);
5577 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005578 } catch (Exception e) {
5579 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5580 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005581 } finally {
5582 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005583 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005584 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005585 }
5586
5587
5588 /**
5589 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5590 *
5591 * <p> Requires permission:
5592 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5593 * privileges.
5594 *
5595 * @param subId subscription id
5596 * @param isEnabled {@code true} means enable, {@code false} means disable.
5597 */
5598 @Override
5599 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005600 final long identity = Binder.clearCallingIdentity();
5601 try {
5602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5603 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005604
Pengquan Meng0c05b502018-09-06 09:59:22 -07005605 Phone phone = getPhone(subId);
5606 if (phone != null) {
5607 phone.setDataRoamingEnabled(isEnabled);
5608 }
5609 } finally {
5610 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005611 }
5612 }
5613
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005614 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005615 public boolean isManualNetworkSelectionAllowed(int subId) {
5616 boolean isAllowed = true;
5617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5620 mApp, subId, "isManualNetworkSelectionAllowed");
5621 Phone phone = getPhone(subId);
5622 if (phone != null) {
5623 isAllowed = phone.isCspPlmnEnabled();
5624 }
5625 } finally {
5626 Binder.restoreCallingIdentity(identity);
5627 }
5628 return isAllowed;
5629 }
5630
5631 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005632 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005633 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005634
Malcolm Chend965c8b2018-02-28 15:00:40 -08005635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5638 if (slots == null) {
5639 Rlog.i(LOG_TAG, "slots is null.");
5640 return null;
5641 }
5642
5643 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5644 for (int i = 0; i < slots.length; i++) {
5645 UiccSlot slot = slots[i];
5646 if (slot == null) {
5647 continue;
5648 }
5649
5650 String cardId;
5651 UiccCard card = slot.getUiccCard();
5652 if (card != null) {
5653 cardId = card.getCardId();
5654 } else {
5655 cardId = slot.getIccId();
5656 }
5657
5658 int cardState = 0;
5659 switch (slot.getCardState()) {
5660 case CARDSTATE_ABSENT:
5661 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5662 break;
5663 case CARDSTATE_PRESENT:
5664 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5665 break;
5666 case CARDSTATE_ERROR:
5667 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5668 break;
5669 case CARDSTATE_RESTRICTED:
5670 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5671 break;
5672 default:
5673 break;
5674
5675 }
5676
5677 infos[i] = new UiccSlotInfo(
5678 slot.isActive(),
5679 slot.isEuicc(),
5680 cardId,
5681 cardState,
5682 slot.getPhoneId(),
5683 slot.isExtendedApduSupported());
5684 }
5685 return infos;
5686 } finally {
5687 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005688 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005689 }
5690
5691 @Override
5692 public boolean switchSlots(int[] physicalSlots) {
5693 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005701 }
Jack Yu4c988042018-02-27 15:30:01 -08005702
5703 @Override
5704 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5705 enforceModifyPermission();
5706 final Phone phone = getPhone(subId);
5707 if (phone == null) {
5708 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5709 return;
5710 }
5711
Malcolm Chend965c8b2018-02-28 15:00:40 -08005712 final long identity = Binder.clearCallingIdentity();
5713 try {
5714 phone.setRadioIndicationUpdateMode(filters, mode);
5715 } finally {
5716 Binder.restoreCallingIdentity(identity);
5717 }
Jack Yu4c988042018-02-27 15:30:01 -08005718 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005719
5720 /**
goneil47ffb6e2018-04-06 15:40:58 -07005721 * A test API to reload the UICC profile.
5722 *
5723 * <p>Requires that the calling app has permission
5724 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5725 * @hide
5726 */
5727 @Override
5728 public void refreshUiccProfile(int subId) {
5729 enforceModifyPermission();
5730
5731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 Phone phone = getPhone(subId);
5734 if (phone == null) {
5735 return;
5736 }
5737 UiccCard uiccCard = phone.getUiccCard();
5738 if (uiccCard == null) {
5739 return;
5740 }
5741 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5742 if (uiccProfile == null) {
5743 return;
5744 }
5745 uiccProfile.refresh();
5746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
5749 }
5750
5751 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005752 * Returns false if the mobile data is disabled by default, otherwise return true.
5753 */
5754 private boolean getDefaultDataEnabled() {
5755 return "true".equalsIgnoreCase(
5756 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5757 }
5758
5759 /**
5760 * Returns true if the data roaming is enabled by default, i.e the system property
5761 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5762 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5763 */
5764 private boolean getDefaultDataRoamingEnabled(int subId) {
5765 final CarrierConfigManager configMgr = (CarrierConfigManager)
5766 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5767 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5768 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5769 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5770 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5771 return isDataRoamingEnabled;
5772 }
5773
5774 /**
5775 * Returns the default network type for the given {@code subId}, if the default network type is
5776 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5777 */
5778 private int getDefaultNetworkType(int subId) {
5779 return Integer.parseInt(
5780 TelephonyManager.getTelephonyProperty(
5781 mSubscriptionController.getPhoneId(subId),
5782 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5783 String.valueOf(Phone.PREFERRED_NT_MODE)));
5784 }
fionaxua13278b2018-03-21 00:08:13 -07005785
5786 @Override
5787 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5788 gid1, String gid2, String plmn, String spn) {
5789 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005790
5791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 final Phone phone = getPhone(subId);
5794 if (phone == null) {
5795 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5796 return;
5797 }
5798 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005801 }
fionaxua13278b2018-03-21 00:08:13 -07005802 }
5803
5804 @Override
5805 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005806 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 final Phone phone = getPhone(subId);
5811 if (phone == null) {
5812 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5813 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5814 }
5815 return phone.getCarrierIdListVersion();
5816 } finally {
5817 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005818 }
fionaxua13278b2018-03-21 00:08:13 -07005819 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005820
5821 @Override
5822 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5824 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5825 return -1;
5826 }
5827
5828 final long identity = Binder.clearCallingIdentity();
5829 try {
5830 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5831 } finally {
5832 Binder.restoreCallingIdentity(identity);
5833 }
5834 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005835
5836 @Override
5837 public int getCdmaRoamingMode(int subId) {
5838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5839 mApp, subId, "getCdmaRoamingMode");
5840
5841 final long identity = Binder.clearCallingIdentity();
5842 try {
5843 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
5847 }
5848
5849 @Override
5850 public boolean setCdmaRoamingMode(int subId, int mode) {
5851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5852 mApp, subId, "setCdmaRoamingMode");
5853
5854 final long identity = Binder.clearCallingIdentity();
5855 try {
5856 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
5860 }
5861
5862 @Override
5863 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5865 mApp, subId, "setCdmaSubscriptionMode");
5866
5867 final long identity = Binder.clearCallingIdentity();
5868 try {
5869 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5870 } finally {
5871 Binder.restoreCallingIdentity(identity);
5872 }
5873 }
chen xu7ee67862018-10-30 22:27:10 -07005874
sqian2fff4a32018-11-05 14:18:37 -08005875 private void ensureUserRunning(int userId) {
5876 if (!mUserManager.isUserRunning(userId)) {
5877 throw new IllegalStateException("User " + userId + " does not exist or not running");
5878 }
5879 }
5880
5881 /**
5882 * Returns a list of SMS apps on a given user.
5883 *
5884 * Only the shell user (UID 2000 or 0) can call it.
5885 * Target user must be running.
5886 */
5887 @Override
5888 public String[] getSmsApps(int userId) {
5889 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5890 ensureUserRunning(userId);
5891
5892 final Collection<SmsApplicationData> apps =
5893 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5894
5895 String[] ret = new String[apps.size()];
5896 int i = 0;
5897 for (SmsApplicationData app : apps) {
5898 ret[i++] = app.mPackageName;
5899 }
5900 return ret;
5901 }
5902
5903 /**
5904 * Returns the default SMS app package name on a given user.
5905 *
5906 * Only the shell user (UID 2000 or 0) can call it.
5907 * Target user must be running.
5908 */
5909 @Override
5910 public String getDefaultSmsApp(int userId) {
5911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5912 ensureUserRunning(userId);
5913
5914 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5915 /* updateIfNeeded= */ true, userId);
5916 return cn == null ? null : cn.getPackageName();
5917 }
5918
5919 /**
5920 * Set a package as the default SMS app on a given user.
5921 *
5922 * Only the shell user (UID 2000 or 0) can call it.
5923 * Target user must be running.
5924 */
5925 @Override
5926 public void setDefaultSmsApp(int userId, String packageName) {
5927 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5928 ensureUserRunning(userId);
5929
5930 boolean found = false;
5931 for (String pkg : getSmsApps(userId)) {
5932 if (TextUtils.equals(packageName, pkg)) {
5933 found = true;
5934 break;
5935 }
5936 }
5937 if (!found) {
5938 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5939 }
5940
5941 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5942 }
5943
chen xu7ee67862018-10-30 22:27:10 -07005944 @Override
sqian04b86072018-11-07 14:02:21 -08005945 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5946 String callingPackage) {
5947 // TODO connect with internal content
5948 return null;
5949 }
5950
5951 @Override
5952 public boolean isCurrentEmergencyNumber(String number) {
5953 // TODO connect with internal content
5954 return false;
5955 }
5956
5957 @Override
chen xu7ee67862018-10-30 22:27:10 -07005958 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5959 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5960 Phone phone = getPhone(subId);
5961 if (phone == null) {
5962 return null;
5963 }
5964 final long identity = Binder.clearCallingIdentity();
5965 try {
5966 UiccProfile profile = UiccController.getInstance()
5967 .getUiccProfileForPhone(phone.getPhoneId());
5968 if (profile != null) {
5969 return profile.getCertsFromCarrierPrivilegeAccessRules();
5970 }
5971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
5974 return null;
5975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005976}