blob: b36b87e1cb865e527f746068eecba3df8926777f [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
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002679 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2680 throws RemoteException {
2681 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002682 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2683 final long token = Binder.clearCallingIdentity();
2684 try {
2685 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2686 .addRegistrationCallbackForSubscription(c, subId);
2687 } finally {
2688 Binder.restoreCallingIdentity(token);
2689 }
2690 }
2691
2692 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002693 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2694 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002695 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2696 Binder.withCleanCallingIdentity(() ->
2697 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2698 .removeRegistrationCallbackForSubscription(c, subId));
2699 }
2700
2701 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002702 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2703 throws RemoteException {
2704 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002705 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2706 final long token = Binder.clearCallingIdentity();
2707 try {
2708 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2709 .addCapabilitiesCallbackForSubscription(c, subId);
2710 } finally {
2711 Binder.restoreCallingIdentity(token);
2712 }
2713 }
2714
2715 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002716 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2717 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2719 Binder.withCleanCallingIdentity(() ->
2720 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2721 .removeCapabilitiesCallbackForSubscription(c, subId));
2722 }
2723
2724 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002725 public boolean isCapable(int subId, int capability, int regTech) {
2726 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002727 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2728 final long token = Binder.clearCallingIdentity();
2729 try {
2730 return ImsManager.getInstance(mPhone.getContext(),
2731 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2732 } catch (ImsException e) {
2733 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2734 return false;
2735 } finally {
2736 Binder.restoreCallingIdentity(token);
2737 }
2738 }
2739
2740 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002741 public boolean isAvailable(int subId, int capability, int regTech) {
2742 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002743 final long token = Binder.clearCallingIdentity();
2744 try {
2745 Phone phone = getPhone(subId);
2746 if (phone == null) return false;
2747 return phone.isImsCapabilityAvailable(capability, regTech);
2748 } finally {
2749 Binder.restoreCallingIdentity(token);
2750 }
2751 }
2752
2753 @Override
2754 public boolean isAdvancedCallingSettingEnabled(int subId) {
2755 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2756 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2757 final long token = Binder.clearCallingIdentity();
2758 try {
2759 return ImsManager.getInstance(mPhone.getContext(),
2760 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2761 } finally {
2762 Binder.restoreCallingIdentity(token);
2763 }
2764 }
2765
2766 @Override
2767 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2769 "setAdvancedCallingSetting");
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2773 ImsManager.getInstance(mPhone.getContext(),
2774 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
2777 }
2778 }
2779
2780 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002781 public boolean isVtSettingEnabled(int subId) {
2782 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2786 return ImsManager.getInstance(mPhone.getContext(),
2787 getSlotIndexOrException(subId)).isVtEnabledByUser();
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
2790 }
2791 }
2792
2793 @Override
2794 public void setVtSetting(int subId, boolean isEnabled) {
2795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2796 "setVtSetting");
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2800 ImsManager.getInstance(mPhone.getContext(),
2801 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2802 } finally {
2803 Binder.restoreCallingIdentity(identity);
2804 }
2805 }
2806
2807 @Override
2808 public boolean isVoWiFiSettingEnabled(int subId) {
2809 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2813 return ImsManager.getInstance(mPhone.getContext(),
2814 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
2818 }
2819
2820 @Override
2821 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2823 "setVoWiFiSetting");
2824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2827 ImsManager.getInstance(mPhone.getContext(),
2828 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
2831 }
2832 }
2833
2834 @Override
2835 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2836 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2840 return ImsManager.getInstance(mPhone.getContext(),
2841 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
2844 }
2845 }
2846
2847 @Override
2848 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2850 "setVoWiFiRoamingSetting");
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2854 ImsManager.getInstance(mPhone.getContext(),
2855 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
2859 }
2860
2861 @Override
2862 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2864 "setVoWiFiNonPersistent");
2865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2868 ImsManager.getInstance(mPhone.getContext(),
2869 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2870 } finally {
2871 Binder.restoreCallingIdentity(identity);
2872 }
2873 }
2874
2875 @Override
2876 public int getVoWiFiModeSetting(int subId) {
2877 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2881 return ImsManager.getInstance(mPhone.getContext(),
2882 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2883 } finally {
2884 Binder.restoreCallingIdentity(identity);
2885 }
2886 }
2887
2888 @Override
2889 public void setVoWiFiModeSetting(int subId, int mode) {
2890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2891 "setVoWiFiModeSetting");
2892 final long identity = Binder.clearCallingIdentity();
2893 try {
2894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2895 ImsManager.getInstance(mPhone.getContext(),
2896 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
2899 }
2900 }
2901
2902 @Override
2903 public int getVoWiFiRoamingModeSetting(int subId) {
2904 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2908 return ImsManager.getInstance(mPhone.getContext(),
2909 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
2912 }
2913 }
2914
2915 @Override
2916 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2918 "setVoWiFiRoamingModeSetting");
2919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2922 ImsManager.getInstance(mPhone.getContext(),
2923 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
2927 }
2928
2929 @Override
2930 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2932 "setRttCapabilityEnabled");
2933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2936 ImsManager.getInstance(mPhone.getContext(),
2937 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
2941 }
2942
2943 @Override
2944 public boolean isTtyOverVolteEnabled(int subId) {
2945 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2949 return ImsManager.getInstance(mPhone.getContext(),
2950 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
2954 }
2955
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07002956 @Override
2957 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2958 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2962 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2963 .getConfigInterface().addConfigCallback(callback);
2964 } catch (ImsException e) {
2965 throw new IllegalArgumentException(e.getMessage());
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
2972 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
2973 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2977 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2978 .getConfigInterface().removeConfigCallback(callback);
2979 } catch (ImsException e) {
2980 throw new IllegalArgumentException(e.getMessage());
2981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
2984 }
2985
2986 @Override
2987 public int getImsProvisioningInt(int subId, int key) {
2988 enforceReadPrivilegedPermission("getImsProvisioningInt");
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
2991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2992 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2993 .getConfigInterface().getConfigInt(key);
2994 } catch (ImsException e) {
2995 throw new IllegalArgumentException(e.getMessage());
2996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
2999 }
3000
3001 @Override
3002 public String getImsProvisioningString(int subId, int key) {
3003 enforceReadPrivilegedPermission("getImsProvisioningString");
3004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3007 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3008 .getConfigInterface().getConfigString(key);
3009 } catch (ImsException e) {
3010 throw new IllegalArgumentException(e.getMessage());
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
3014 }
3015
3016 @Override
3017 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3019 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3023 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3024 .getConfigInterface().setConfig(key, value);
3025 } catch (ImsException e) {
3026 throw new IllegalArgumentException(e.getMessage());
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
3029 }
3030 }
3031
3032 @Override
3033 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3035 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3039 return ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
3040 .getConfigInterface().setConfig(key, value);
3041 } catch (ImsException e) {
3042 throw new IllegalArgumentException(e.getMessage());
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
3046 }
3047
Brad Ebinger4c460712018-10-01 10:40:55 -07003048 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3049 int slotId = SubscriptionManager.getSlotIndex(subId);
3050 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3051 throw new IllegalArgumentException("Invalid Subscription Id.");
3052 }
3053 return slotId;
3054 }
3055
Wink Saville36469e72014-06-11 15:17:00 -07003056 /**
3057 * Returns the network type for a subId
3058 */
3059 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003060 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003062 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003063 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3064 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003065
Malcolm Chend965c8b2018-02-28 15:00:40 -08003066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 final Phone phone = getPhone(subId);
3069 if (phone != null) {
3070 return phone.getServiceState().getDataNetworkType();
3071 } else {
3072 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3073 }
3074 } finally {
3075 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003076 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003077 }
3078
3079 /**
3080 * Returns the data network type
3081 */
3082 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003083 public int getDataNetworkType(String callingPackage) {
3084 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003085 }
3086
3087 /**
3088 * Returns the data network type for a subId
3089 */
3090 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003091 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003093 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003094 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3095 }
3096
Malcolm Chend965c8b2018-02-28 15:00:40 -08003097 final long identity = Binder.clearCallingIdentity();
3098 try {
3099 final Phone phone = getPhone(subId);
3100 if (phone != null) {
3101 return phone.getServiceState().getDataNetworkType();
3102 } else {
3103 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3104 }
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
3110 /**
Wink Saville36469e72014-06-11 15:17:00 -07003111 * Returns the Voice network type for a subId
3112 */
3113 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003114 public int getVoiceNetworkTypeForSubscriber(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 Greenwalta5dcfcb2015-07-10 09:06:29 -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().getVoiceNetworkType();
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 /**
3134 * @return true if a ICC card is present
3135 */
3136 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003137 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003138 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3139 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003140 }
3141
3142 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003143 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003144 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003145 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003146 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 final Phone phone = PhoneFactory.getPhone(slotIndex);
3150 if (phone != null) {
3151 return phone.getIccCard().hasIccCard();
3152 } else {
3153 return false;
3154 }
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
3159
3160 /**
3161 * Return if the current radio is LTE on CDMA. This
3162 * is a tri-state return value as for a period of time
3163 * the mode may be unknown.
3164 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003165 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003167 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003169 @Override
3170 public int getLteOnCdmaMode(String callingPackage) {
3171 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003172 }
3173
Sanket Padawe356d7632015-06-22 14:03:32 -07003174 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003175 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003177 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003178 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3179 }
3180
Malcolm Chend965c8b2018-02-28 15:00:40 -08003181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 final Phone phone = getPhone(subId);
3184 if (phone == null) {
3185 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3186 } else {
3187 return phone.getLteOnCdmaMode();
3188 }
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003191 }
Wink Saville36469e72014-06-11 15:17:00 -07003192 }
3193
3194 public void setPhone(Phone phone) {
3195 mPhone = phone;
3196 }
3197
3198 /**
3199 * {@hide}
3200 * Returns Default subId, 0 in the case of single standby.
3201 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003202 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003203 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003204 }
3205
Shishir Agrawala9f32182016-04-12 12:00:16 -07003206 private int getSlotForDefaultSubscription() {
3207 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3208 }
3209
Wink Savilleb564aae2014-10-23 10:18:09 -07003210 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003211 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003213
Pengquan Meng466e2482018-09-21 15:54:48 -07003214 private boolean isActiveSubscription(int subId) {
3215 return mSubscriptionController.isActiveSubId(subId);
3216 }
3217
Ihab Awadf2177b72013-11-25 13:33:23 -08003218 /**
3219 * @see android.telephony.TelephonyManager.WifiCallingChoices
3220 */
3221 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3225 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3226 getWhenToMakeWifiCallsDefaultPreference());
3227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003230 }
3231
3232 /**
3233 * @see android.telephony.TelephonyManager.WifiCallingChoices
3234 */
3235 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3239 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3240 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003244 }
3245
Sailesh Nepald1e68152013-12-12 19:08:02 -08003246 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003247 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003248 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003249 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003250
Shishir Agrawal566b7612013-10-28 14:41:00 -07003251 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003252 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3253 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3255 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003256 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003257
Malcolm Chend965c8b2018-02-28 15:00:40 -08003258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 if (TextUtils.equals(ISDR_AID, aid)) {
3261 // Only allows LPA to open logical channel to ISD-R.
3262 ComponentInfo bestComponent =
3263 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3264 if (bestComponent == null
3265 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3266 loge("The calling package is not allowed to access ISD-R.");
3267 throw new SecurityException(
3268 "The calling package is not allowed to access ISD-R.");
3269 }
Derek Tan740e1672017-06-27 14:56:27 -07003270 }
Derek Tan740e1672017-06-27 14:56:27 -07003271
Malcolm Chend965c8b2018-02-28 15:00:40 -08003272 if (DBG) {
3273 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3274 }
3275 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3276 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3277 if (DBG) log("iccOpenLogicalChannel: " + response);
3278 return response;
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003282 }
3283
3284 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003285 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3287 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003288
Malcolm Chend965c8b2018-02-28 15:00:40 -08003289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3292 if (channel < 0) {
3293 return false;
3294 }
3295 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3296 if (DBG) log("iccCloseLogicalChannel: " + success);
3297 return success;
3298 } finally {
3299 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003300 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003301 }
3302
3303 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003304 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003305 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3307 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003308
Malcolm Chend965c8b2018-02-28 15:00:40 -08003309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 if (DBG) {
3312 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3313 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3314 + p3 + " data=" + data);
3315 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003316
Malcolm Chend965c8b2018-02-28 15:00:40 -08003317 if (channel < 0) {
3318 return "";
3319 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003320
Malcolm Chend965c8b2018-02-28 15:00:40 -08003321 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3322 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3323 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003324
Malcolm Chend965c8b2018-02-28 15:00:40 -08003325 // Append the returned status code to the end of the response payload.
3326 String s = Integer.toHexString(
3327 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3328 if (response.payload != null) {
3329 s = IccUtils.bytesToHexString(response.payload) + s;
3330 }
3331 return s;
3332 } finally {
3333 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003334 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003335 }
Jake Hambye994d462014-02-03 13:10:13 -08003336
Evan Charltonc66da362014-05-16 14:06:40 -07003337 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003338 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3339 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3341 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003342 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003343
Malcolm Chend965c8b2018-02-28 15:00:40 -08003344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3347 && TextUtils.equals(ISDR_AID, data)) {
3348 // Only allows LPA to select ISD-R.
3349 ComponentInfo bestComponent =
3350 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3351 if (bestComponent == null
3352 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3353 loge("The calling package is not allowed to select ISD-R.");
3354 throw new SecurityException(
3355 "The calling package is not allowed to select ISD-R.");
3356 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003357 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003358
Malcolm Chend965c8b2018-02-28 15:00:40 -08003359 if (DBG) {
3360 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3361 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3362 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003363
Malcolm Chend965c8b2018-02-28 15:00:40 -08003364 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3365 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3366 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003367
Malcolm Chend965c8b2018-02-28 15:00:40 -08003368 // Append the returned status code to the end of the response payload.
3369 String s = Integer.toHexString(
3370 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3371 if (response.payload != null) {
3372 s = IccUtils.bytesToHexString(response.payload) + s;
3373 }
3374 return s;
3375 } finally {
3376 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003377 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003378 }
3379
3380 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003381 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003382 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3384 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003385
Malcolm Chend965c8b2018-02-28 15:00:40 -08003386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 if (DBG) {
3389 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3390 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3391 }
3392
3393 IccIoResult response =
3394 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3395 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3396 subId);
3397
3398 if (DBG) {
3399 log("Exchange SIM_IO [R]" + response);
3400 }
3401
3402 byte[] result = null;
3403 int length = 2;
3404 if (response.payload != null) {
3405 length = 2 + response.payload.length;
3406 result = new byte[length];
3407 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3408 } else {
3409 result = new byte[length];
3410 }
3411
3412 result[length - 1] = (byte) response.sw2;
3413 result[length - 2] = (byte) response.sw1;
3414 return result;
3415 } finally {
3416 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003417 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003418 }
3419
Nathan Haroldb3014052017-01-25 15:57:32 -08003420 /**
3421 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3422 * on a particular subscription
3423 */
sqianb6e41952018-03-12 14:54:01 -07003424 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3426 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3427 return null;
3428 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003429
3430 final long identity = Binder.clearCallingIdentity();
3431 try {
3432 if (appType != TelephonyManager.APPTYPE_USIM
3433 && appType != TelephonyManager.APPTYPE_SIM) {
3434 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3435 return null;
3436 }
3437 Object response = sendRequest(
3438 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3439 if (response instanceof String[]) {
3440 return (String[]) response;
3441 }
3442 // Response is an Exception of some kind,
3443 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003444 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003445 } finally {
3446 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003447 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003448 }
3449
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003450 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003451 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3453 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003454
Malcolm Chend965c8b2018-02-28 15:00:40 -08003455 final long identity = Binder.clearCallingIdentity();
3456 try {
3457 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3458 if (response.payload == null) {
3459 return "";
3460 }
Evan Charltonc66da362014-05-16 14:06:40 -07003461
Malcolm Chend965c8b2018-02-28 15:00:40 -08003462 // Append the returned status code to the end of the response payload.
3463 String s = Integer.toHexString(
3464 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3465 s = IccUtils.bytesToHexString(response.payload) + s;
3466 return s;
3467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
Evan Charltonc66da362014-05-16 14:06:40 -07003470 }
3471
Jake Hambye994d462014-02-03 13:10:13 -08003472 /**
3473 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3474 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3475 *
3476 * @param itemID the ID of the item to read
3477 * @return the NV item as a String, or null on error.
3478 */
3479 @Override
3480 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003481 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3483 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003484
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003488 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003489 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3490 return value;
3491 } finally {
3492 Binder.restoreCallingIdentity(identity);
3493 }
Jake Hambye994d462014-02-03 13:10:13 -08003494 }
3495
3496 /**
3497 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3498 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3499 *
3500 * @param itemID the ID of the item to read
3501 * @param itemValue the value to write, as a String
3502 * @return true on success; false on any failure
3503 */
3504 @Override
3505 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3508 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003509
3510 final long identity = Binder.clearCallingIdentity();
3511 try {
3512 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3513 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003514 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003515 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3516 return success;
3517 } finally {
3518 Binder.restoreCallingIdentity(identity);
3519 }
Jake Hambye994d462014-02-03 13:10:13 -08003520 }
3521
3522 /**
3523 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3524 * Used for device configuration by some CDMA operators.
3525 *
3526 * @param preferredRoamingList byte array containing the new PRL
3527 * @return true on success; false on any failure
3528 */
3529 @Override
3530 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3532 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003533
3534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3537 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3538 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3539 return success;
3540 } finally {
3541 Binder.restoreCallingIdentity(identity);
3542 }
Jake Hambye994d462014-02-03 13:10:13 -08003543 }
3544
3545 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003546 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003547 * Used for device configuration by some CDMA operators.
3548 *
chen xu1cc0abe2018-10-26 17:39:23 -07003549 * @param slotIndex - device slot.
3550 *
Jake Hambye994d462014-02-03 13:10:13 -08003551 * @return true on success; false on any failure
3552 */
3553 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003554 public boolean resetModemConfig(int slotIndex) {
3555 Phone phone = PhoneFactory.getPhone(slotIndex);
3556 if (phone != null) {
3557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3558 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003559
chen xu1cc0abe2018-10-26 17:39:23 -07003560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3563 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3564 return success;
3565 } finally {
3566 Binder.restoreCallingIdentity(identity);
3567 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003568 }
chen xu1cc0abe2018-10-26 17:39:23 -07003569 return false;
3570 }
3571
3572 /**
3573 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3574 *
3575 * @param slotIndex - device slot.
3576 *
3577 * @return true on success; false on any failure
3578 */
3579 @Override
3580 public boolean rebootModem(int slotIndex) {
3581 Phone phone = PhoneFactory.getPhone(slotIndex);
3582 if (phone != null) {
3583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3584 mApp, phone.getSubId(), "rebootModem");
3585
3586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3589 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3590 return success;
3591 } finally {
3592 Binder.restoreCallingIdentity(identity);
3593 }
3594 }
3595 return false;
Jake Hambye994d462014-02-03 13:10:13 -08003596 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003597
Svet Ganovb320e182015-04-16 12:30:10 -07003598 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003600 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003601 return new String[0];
3602 }
3603
Malcolm Chend965c8b2018-02-28 15:00:40 -08003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 return mPhone.getPcscfAddress(apnType);
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
3609 }
Wink Saville36469e72014-06-11 15:17:00 -07003610 }
3611
Brad Ebinger51f743a2017-01-23 13:50:20 -08003612 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003613 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3614 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003615 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003616 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003617 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003618
3619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 PhoneFactory.getImsResolver().enableIms(slotId);
3622 } finally {
3623 Binder.restoreCallingIdentity(identity);
3624 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003625 }
3626
3627 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003628 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3629 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003630 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003631 public void disableIms(int slotId) {
3632 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003633
3634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 PhoneFactory.getImsResolver().disableIms(slotId);
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003640 }
3641
3642 /**
3643 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3644 * feature or {@link null} if the service is not available. If the feature is available, the
3645 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3646 */
3647 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003648 IImsServiceFeatureCallback callback) {
3649 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003650
3651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003657 }
3658
3659 /**
3660 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3661 * feature during emergency calling or {@link null} if the service is not available. If the
3662 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3663 * listener for feature updates.
3664 */
3665 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3666 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003667
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
3673 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003674 }
3675
Brad Ebinger5f64b052017-12-14 14:26:15 -08003676 /**
3677 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3678 * specified.
3679 */
3680 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3681 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003682
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003689 }
3690
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003691 /**
3692 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3693 * specified.
3694 */
3695 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3696 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003697
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003704 }
3705
Brad Ebinger884c07b2018-02-15 16:17:40 -08003706 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003707 * Sets the ImsService Package Name that Telephony will bind to.
3708 *
3709 * @param slotId the slot ID that the ImsService should bind for.
3710 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3711 * ImsService is the device default ImsService.
3712 * @param packageName The package name of the application that contains the ImsService to bind
3713 * to.
3714 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3715 * @hide
3716 */
3717 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003718 int[] subIds = SubscriptionManager.getSubId(slotId);
3719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3720 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3721 "setImsService");
3722
Malcolm Chend965c8b2018-02-28 15:00:40 -08003723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3726 isCarrierImsService, packageName);
3727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003730 }
3731
3732 /**
3733 * Return the ImsService configuration.
3734 *
3735 * @param slotId The slot that the ImsService is associated with.
3736 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3737 * the device default.
3738 * @return the package name of the ImsService configuration.
3739 */
3740 public String getImsService(int slotId, boolean isCarrierImsService) {
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 "getImsService");
3745
Malcolm Chend965c8b2018-02-28 15:00:40 -08003746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3749 isCarrierImsService);
3750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003753 }
3754
Wink Saville36469e72014-06-11 15:17:00 -07003755 public void setImsRegistrationState(boolean registered) {
3756 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003757
3758 final long identity = Binder.clearCallingIdentity();
3759 try {
3760 mPhone.setImsRegistrationState(registered);
3761 } finally {
3762 Binder.restoreCallingIdentity(identity);
3763 }
Wink Saville36469e72014-06-11 15:17:00 -07003764 }
3765
3766 /**
Stuart Scott54788802015-03-30 13:18:01 -07003767 * Set the network selection mode to automatic.
3768 *
3769 */
3770 @Override
3771 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3773 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003774
Pengquan Meng466e2482018-09-21 15:54:48 -07003775 if (!isActiveSubscription(subId)) {
3776 return;
3777 }
3778
Malcolm Chend965c8b2018-02-28 15:00:40 -08003779 final long identity = Binder.clearCallingIdentity();
3780 try {
3781 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3782 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
3785 }
Stuart Scott54788802015-03-30 13:18:01 -07003786 }
3787
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003788 /**
3789 * Ask the radio to connect to the input network and change selection mode to manual.
3790 *
3791 * @param subId the id of the subscription.
3792 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3793 * the operator to attach to.
3794 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3795 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3796 * normal network selection next time.
3797 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003798 */
3799 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003800 public boolean setNetworkSelectionModeManual(
3801 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3803 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07003804
3805 if (!isActiveSubscription(subId)) {
3806 return false;
3807 }
3808
Malcolm Chend965c8b2018-02-28 15:00:40 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003811 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08003812 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07003813 if (DBG) {
3814 log("setNetworkSelectionModeManual: subId: " + subId
3815 + " operator: " + operatorInfo);
3816 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003817 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003821 }
3822
3823 /**
3824 * Scans for available networks.
3825 */
3826 @Override
3827 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3829 mApp, subId, "getCellNetworkScanResults");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003830
Pengquan Meng0c05b502018-09-06 09:59:22 -07003831 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003832 try {
3833 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07003834 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08003835 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003836 } finally {
3837 Binder.restoreCallingIdentity(identity);
3838 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003839 }
3840
3841 /**
yinxub1bed742017-04-17 11:45:04 -07003842 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003843 *
yinxub1bed742017-04-17 11:45:04 -07003844 * @param subId id of the subscription
3845 * @param request contains the radio access networks with bands/channels to scan
3846 * @param messenger callback messenger for scan results or errors
3847 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003848 * @return the id of the requested scan which can be used to stop the scan.
3849 */
3850 @Override
3851 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3852 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3854 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003855
3856 final long identity = Binder.clearCallingIdentity();
3857 try {
3858 return mNetworkScanRequestTracker.startNetworkScan(
3859 request, messenger, binder, getPhone(subId));
3860 } finally {
3861 Binder.restoreCallingIdentity(identity);
3862 }
yinxu504e1392017-04-12 16:03:22 -07003863 }
3864
3865 /**
3866 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003867 *
3868 * @param subId id of the subscription
3869 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003870 */
3871 @Override
3872 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3874 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003875
3876 final long identity = Binder.clearCallingIdentity();
3877 try {
3878 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
3881 }
yinxu504e1392017-04-12 16:03:22 -07003882 }
3883
3884 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003885 * Get the calculated preferred network type.
3886 * Used for debugging incorrect network type.
3887 *
3888 * @return the preferred network type, defined in RILConstants.java.
3889 */
3890 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003891 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003893 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003894 return RILConstants.PREFERRED_NETWORK_MODE;
3895 }
3896
Malcolm Chend965c8b2018-02-28 15:00:40 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 // FIXME: need to get SubId from somewhere.
3900 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
3903 }
Junda Liu84d15a22014-07-02 11:21:04 -07003904 }
3905
3906 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003907 * Get the preferred network type.
3908 * Used for device configuration by some CDMA operators.
3909 *
3910 * @return the preferred network type, defined in RILConstants.java.
3911 */
3912 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003913 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3915 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003916
3917 final long identity = Binder.clearCallingIdentity();
3918 try {
3919 if (DBG) log("getPreferredNetworkType");
3920 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3921 int networkType = (result != null ? result[0] : -1);
3922 if (DBG) log("getPreferredNetworkType: " + networkType);
3923 return networkType;
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
3926 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003927 }
3928
3929 /**
3930 * Set the preferred network type.
3931 * Used for device configuration by some CDMA operators.
3932 *
3933 * @param networkType the preferred network type, defined in RILConstants.java.
3934 * @return true on success; false on any failure.
3935 */
3936 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003937 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3939 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003940
3941 final long identity = Binder.clearCallingIdentity();
3942 try {
3943 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3944 Boolean success = (Boolean) sendRequest(
3945 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3946 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3947 if (success) {
3948 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3949 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3950 }
3951 return success;
3952 } finally {
3953 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003954 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003955 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003956
3957 /**
Junda Liu475951f2014-11-07 16:45:03 -08003958 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07003959 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08003960 * tethering.
3961 *
3962 * @return 0: Not required. 1: required. 2: Not set.
3963 * @hide
3964 */
3965 @Override
3966 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003967 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08003968
3969 final long identity = Binder.clearCallingIdentity();
3970 try {
3971 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3972 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07003973 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Malcolm Chend965c8b2018-02-28 15:00:40 -08003974 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3975 dunRequired = 1;
3976 }
3977 return dunRequired;
3978 } finally {
3979 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003980 }
Junda Liu475951f2014-11-07 16:45:03 -08003981 }
3982
3983 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003984 * Set mobile data enabled
3985 * Used by the user through settings etc to turn on/off mobile data
3986 *
3987 * @param enable {@code true} turn turn data on, else {@code false}
3988 */
3989 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003990 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3992 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003993
3994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 int phoneId = mSubscriptionController.getPhoneId(subId);
3997 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3998 Phone phone = PhoneFactory.getPhone(phoneId);
3999 if (phone != null) {
4000 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
4001 phone.setUserDataEnabled(enable);
4002 } else {
4003 loge("setUserDataEnabled: no phone for subId=" + subId);
4004 }
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004007 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004008 }
4009
4010 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004011 * Get the user enabled state of Mobile Data.
4012 *
4013 * TODO: remove and use isUserDataEnabled.
4014 * This can't be removed now because some vendor codes
4015 * calls through ITelephony directly while they should
4016 * use TelephonyManager.
4017 *
4018 * @return true on enabled
4019 */
4020 @Override
4021 public boolean getDataEnabled(int subId) {
4022 return isUserDataEnabled(subId);
4023 }
4024
4025 /**
4026 * Get whether mobile data is enabled per user setting.
4027 *
4028 * There are other factors deciding whether mobile data is actually enabled, but they are
4029 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004030 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004031 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004032 *
4033 * @return {@code true} if data is enabled else {@code false}
4034 */
4035 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004036 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004037 try {
4038 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4039 null);
4040 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4042 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004043 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004044
4045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 int phoneId = mSubscriptionController.getPhoneId(subId);
4048 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4049 Phone phone = PhoneFactory.getPhone(phoneId);
4050 if (phone != null) {
4051 boolean retVal = phone.isUserDataEnabled();
4052 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4053 return retVal;
4054 } else {
4055 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4056 return false;
4057 }
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004060 }
4061 }
4062
4063 /**
4064 * Get whether mobile data is enabled.
4065 *
4066 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4067 * whether mobile data is actually enabled.
4068 *
4069 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4070 *
4071 * @return {@code true} if data is enabled else {@code false}
4072 */
4073 @Override
4074 public boolean isDataEnabled(int subId) {
4075 try {
4076 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4077 null);
4078 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004081 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004082
4083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 int phoneId = mSubscriptionController.getPhoneId(subId);
4086 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4087 Phone phone = PhoneFactory.getPhone(phoneId);
4088 if (phone != null) {
4089 boolean retVal = phone.isDataEnabled();
4090 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4091 return retVal;
4092 } else {
4093 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4094 return false;
4095 }
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004098 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004099 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004100
4101 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004102 public int getCarrierPrivilegeStatus(int subId) {
4103 final Phone phone = getPhone(subId);
4104 if (phone == null) {
4105 loge("getCarrierPrivilegeStatus: Invalid subId");
4106 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4107 }
4108 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004109 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004110 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004111 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4112 }
4113 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004114 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004115 }
Junda Liu29340342014-07-10 15:23:27 -07004116
4117 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004118 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4119 final Phone phone = getPhone(subId);
4120 if (phone == null) {
4121 loge("getCarrierPrivilegeStatus: Invalid subId");
4122 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4123 }
4124 UiccProfile profile =
4125 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4126 if (profile == null) {
4127 loge("getCarrierPrivilegeStatus: No UICC");
4128 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4129 }
4130 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4131 }
4132
4133 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004134 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004135 if (TextUtils.isEmpty(pkgName))
4136 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08004137 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004138 if (card == null) {
4139 loge("checkCarrierPrivilegesForPackage: No UICC");
4140 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4141 }
Zach Johnson50ecba32015-05-19 00:24:21 -07004142 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
4143 }
4144
4145 @Override
4146 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004147 if (TextUtils.isEmpty(pkgName))
4148 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004149 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4150 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4151 UiccCard card = UiccController.getInstance().getUiccCard(i);
4152 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004153 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004154 continue;
4155 }
4156
4157 result = card.getCarrierPrivilegeStatus(
4158 mPhone.getContext().getPackageManager(), pkgName);
4159 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4160 break;
4161 }
4162 }
4163
4164 return result;
Junda Liu29340342014-07-10 15:23:27 -07004165 }
Derek Tan89e89d42014-07-08 17:00:10 -07004166
4167 @Override
Junda Liue64de782015-04-16 17:19:16 -07004168 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4169 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4170 loge("phoneId " + phoneId + " is not valid.");
4171 return null;
4172 }
4173 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004174 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004175 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004176 return null ;
4177 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004178 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07004179 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004180 }
4181
Amith Yamasani6e118872016-02-19 12:53:51 -08004182 @Override
4183 public List<String> getPackagesWithCarrierPrivileges() {
4184 PackageManager pm = mPhone.getContext().getPackageManager();
4185 List<String> privilegedPackages = new ArrayList<>();
4186 List<PackageInfo> packages = null;
4187 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4188 UiccCard card = UiccController.getInstance().getUiccCard(i);
4189 if (card == null) {
4190 // No UICC in that slot.
4191 continue;
4192 }
4193 if (card.hasCarrierPrivilegeRules()) {
4194 if (packages == null) {
4195 // Only check packages in user 0 for now
4196 packages = pm.getInstalledPackagesAsUser(
4197 PackageManager.MATCH_DISABLED_COMPONENTS
4198 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4199 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4200 }
4201 for (int p = packages.size() - 1; p >= 0; p--) {
4202 PackageInfo pkgInfo = packages.get(p);
4203 if (pkgInfo != null && pkgInfo.packageName != null
4204 && card.getCarrierPrivilegeStatus(pkgInfo)
4205 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4206 privilegedPackages.add(pkgInfo.packageName);
4207 }
4208 }
4209 }
4210 }
4211 return privilegedPackages;
4212 }
4213
Wink Savilleb564aae2014-10-23 10:18:09 -07004214 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004215 final Phone phone = getPhone(subId);
4216 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004217 if (card == null) {
4218 loge("getIccId: No UICC");
4219 return null;
4220 }
4221 String iccId = card.getIccId();
4222 if (TextUtils.isEmpty(iccId)) {
4223 loge("getIccId: ICC ID is null or empty.");
4224 return null;
4225 }
4226 return iccId;
4227 }
4228
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004229 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004230 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4231 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004232 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4233 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004234
Malcolm Chend965c8b2018-02-28 15:00:40 -08004235 final long identity = Binder.clearCallingIdentity();
4236 try {
4237 final String iccId = getIccId(subId);
4238 final Phone phone = getPhone(subId);
4239 if (phone == null) {
4240 return false;
4241 }
4242 final String subscriberId = phone.getSubscriberId();
4243
4244 if (DBG_MERGE) {
4245 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4246 + subscriberId + " to " + number);
4247 }
4248
4249 if (TextUtils.isEmpty(iccId)) {
4250 return false;
4251 }
4252
4253 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4254
4255 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4256 if (alphaTag == null) {
4257 editor.remove(alphaTagPrefKey);
4258 } else {
4259 editor.putString(alphaTagPrefKey, alphaTag);
4260 }
4261
4262 // Record both the line number and IMSI for this ICCID, since we need to
4263 // track all merged IMSIs based on line number
4264 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4265 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4266 if (number == null) {
4267 editor.remove(numberPrefKey);
4268 editor.remove(subscriberPrefKey);
4269 } else {
4270 editor.putString(numberPrefKey, number);
4271 editor.putString(subscriberPrefKey, subscriberId);
4272 }
4273
4274 editor.commit();
4275 return true;
4276 } finally {
4277 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004278 }
Derek Tan7226c842014-07-02 17:42:23 -07004279 }
4280
4281 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004282 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004283 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004285 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004286 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004287 return null;
4288 }
Derek Tan97ebb422014-09-05 16:55:38 -07004289
Malcolm Chend965c8b2018-02-28 15:00:40 -08004290 final long identity = Binder.clearCallingIdentity();
4291 try {
4292 String iccId = getIccId(subId);
4293 if (iccId != null) {
4294 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4295 if (DBG_MERGE) {
4296 log("getLine1NumberForDisplay returning "
4297 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4298 }
4299 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004300 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004301 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4302 return null;
4303 } finally {
4304 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004305 }
Derek Tan7226c842014-07-02 17:42:23 -07004306 }
4307
4308 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004309 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004311 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004312 return null;
4313 }
Derek Tan97ebb422014-09-05 16:55:38 -07004314
Malcolm Chend965c8b2018-02-28 15:00:40 -08004315 final long identity = Binder.clearCallingIdentity();
4316 try {
4317 String iccId = getIccId(subId);
4318 if (iccId != null) {
4319 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4320 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4321 }
4322 return null;
4323 } finally {
4324 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004325 }
Derek Tan7226c842014-07-02 17:42:23 -07004326 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004327
4328 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004329 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004330 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4331 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004333 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4334 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004335 return null;
4336 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004337
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004338 final long identity = Binder.clearCallingIdentity();
4339 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004340 final Context context = mPhone.getContext();
4341 final TelephonyManager tele = TelephonyManager.from(context);
4342 final SubscriptionManager sub = SubscriptionManager.from(context);
4343
4344 // Figure out what subscribers are currently active
4345 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4346 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4347 // the process, where TelephonyManager was instantiated.
4348 // Otherwise AppOps check will fail.
4349
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004350 final int[] subIds = sub.getActiveSubscriptionIdList();
4351 for (int subId : subIds) {
4352 activeSubscriberIds.add(tele.getSubscriberId(subId));
4353 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004354
4355 // First pass, find a number override for an active subscriber
4356 String mergeNumber = null;
4357 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4358 for (String key : prefs.keySet()) {
4359 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4360 final String subscriberId = (String) prefs.get(key);
4361 if (activeSubscriberIds.contains(subscriberId)) {
4362 final String iccId = key.substring(
4363 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4364 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4365 mergeNumber = (String) prefs.get(numberKey);
4366 if (DBG_MERGE) {
4367 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4368 + " for active subscriber " + subscriberId);
4369 }
4370 if (!TextUtils.isEmpty(mergeNumber)) {
4371 break;
4372 }
4373 }
4374 }
4375 }
4376
4377 // Shortcut when no active merged subscribers
4378 if (TextUtils.isEmpty(mergeNumber)) {
4379 return null;
4380 }
4381
4382 // Second pass, find all subscribers under that line override
4383 final ArraySet<String> result = new ArraySet<>();
4384 for (String key : prefs.keySet()) {
4385 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4386 final String number = (String) prefs.get(key);
4387 if (mergeNumber.equals(number)) {
4388 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4389 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4390 final String subscriberId = (String) prefs.get(subscriberKey);
4391 if (!TextUtils.isEmpty(subscriberId)) {
4392 result.add(subscriberId);
4393 }
4394 }
4395 }
4396 }
4397
4398 final String[] resultArray = result.toArray(new String[result.size()]);
4399 Arrays.sort(resultArray);
4400 if (DBG_MERGE) {
4401 Slog.d(LOG_TAG,
4402 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4403 }
4404 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004405 } finally {
4406 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004407 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004408 }
4409
4410 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004411 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004412 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4413 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004414
4415 final long identity = Binder.clearCallingIdentity();
4416 try {
4417 final Phone phone = getPhone(subId);
4418 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004422 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004423
4424 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004425 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004426 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4427 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004428 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004429
4430 final long identity = Binder.clearCallingIdentity();
4431 try {
4432 final Phone phone = getPhone(subId);
4433 if (phone == null) {
4434 return false;
4435 }
4436 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4437 cdmaNonRoamingList);
4438 } finally {
4439 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004440 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004441 }
4442
4443 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004444 @Deprecated
4445 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4446 enforceModifyPermission();
4447
4448 int returnValue = 0;
4449 try {
vagdevie435a3e2018-08-15 16:01:53 -07004450 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004451 if(result.exception == null) {
4452 if (result.result != null) {
4453 byte[] responseData = (byte[])(result.result);
4454 if(responseData.length > oemResp.length) {
4455 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4456 responseData.length + "bytes. Buffer Size is " +
4457 oemResp.length + "bytes.");
4458 }
4459 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4460 returnValue = responseData.length;
4461 }
4462 } else {
4463 CommandException ex = (CommandException) result.exception;
4464 returnValue = ex.getCommandError().ordinal();
4465 if(returnValue > 0) returnValue *= -1;
4466 }
4467 } catch (RuntimeException e) {
4468 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4469 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4470 if(returnValue > 0) returnValue *= -1;
4471 }
4472
4473 return returnValue;
4474 }
4475
4476 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004477 public void setRadioCapability(RadioAccessFamily[] rafs) {
4478 try {
4479 ProxyController.getInstance().setRadioCapability(rafs);
4480 } catch (RuntimeException e) {
4481 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4482 }
4483 }
4484
4485 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004486 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004487 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004488 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004489 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004490 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004491 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004492 final long identity = Binder.clearCallingIdentity();
4493 try {
chen xufeeed752018-10-26 14:17:57 -07004494 TelephonyPermissions
4495 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4496 mApp, phone.getSubId(), "getRadioAccessFamily");
4497 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
chen xufeeed752018-10-26 14:17:57 -07004501 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004502 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004503
4504 @Override
4505 public void enableVideoCalling(boolean enable) {
4506 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004507
4508 final long identity = Binder.clearCallingIdentity();
4509 try {
4510 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004514 }
4515
4516 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004517 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4519 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4520 return false;
4521 }
Svet Ganovb320e182015-04-16 12:30:10 -07004522
Malcolm Chend965c8b2018-02-28 15:00:40 -08004523 final long identity = Binder.clearCallingIdentity();
4524 try {
4525 // Check the user preference and the system-level IMS setting. Even if the user has
4526 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4527 // In the long run, we may instead need to check if there exists a connection service
4528 // which can support video calling.
4529 ImsManager imsManager =
4530 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4531 return imsManager.isVtEnabledByPlatform()
4532 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4533 && imsManager.isVtEnabledByUser();
4534 } finally {
4535 Binder.restoreCallingIdentity(identity);
4536 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004537 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004538
Andrew Leea1239f22015-03-02 17:44:07 -08004539 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004540 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4542 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4543 return false;
4544 }
4545
4546 final long identity = Binder.clearCallingIdentity();
4547 try {
4548 CarrierConfigManager configManager =
4549 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4550 return configManager.getConfigForSubId(mPhone.getSubId())
4551 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4552 } finally {
4553 Binder.restoreCallingIdentity(identity);
4554 }
Andrew Leea1239f22015-03-02 17:44:07 -08004555 }
4556
4557 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004558 public boolean isWorldPhone(int subId, String callingPackage) {
4559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4560 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4561 return false;
4562 }
4563
4564 final long identity = Binder.clearCallingIdentity();
4565 try {
4566 CarrierConfigManager configManager =
4567 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4568 return configManager.getConfigForSubId(mPhone.getSubId())
4569 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4570 } finally {
4571 Binder.restoreCallingIdentity(identity);
4572 }
Andrew Leea1239f22015-03-02 17:44:07 -08004573 }
4574
Andrew Lee9431b832015-03-09 18:46:45 -07004575 @Override
4576 public boolean isTtyModeSupported() {
4577 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004578 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004579 }
4580
4581 @Override
4582 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004583 final long identity = Binder.clearCallingIdentity();
4584 try {
4585 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4586 } finally {
4587 Binder.restoreCallingIdentity(identity);
4588 }
Andrew Lee9431b832015-03-09 18:46:45 -07004589 }
4590
Hall Liuf6668912018-10-31 17:05:23 -07004591 /**
4592 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
4593 * support for the feature and device firmware support.
4594 *
4595 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
4596 */
4597 @Override
4598 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004599 final long identity = Binder.clearCallingIdentity();
4600 try {
4601 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4602 mPhone.getSubId()).getBoolean(
4603 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4604 boolean isDeviceSupported =
4605 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4606 return isCarrierSupported && isDeviceSupported;
4607 } finally {
4608 Binder.restoreCallingIdentity(identity);
4609 }
Hall Liu98187582018-01-22 19:15:32 -08004610 }
4611
Hall Liuf6668912018-10-31 17:05:23 -07004612 /**
4613 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
4614 * both also support RTT.
4615 */
4616 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004617 final long identity = Binder.clearCallingIdentity();
4618 try {
Hall Liuf6668912018-10-31 17:05:23 -07004619 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004620 mPhone.getContext().getContentResolver(),
4621 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4622 } finally {
4623 Binder.restoreCallingIdentity(identity);
4624 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004625 }
4626
Sanket Padawe7310cc72015-01-14 09:53:20 -08004627 /**
4628 * Returns the unique device ID of phone, for example, the IMEI for
4629 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4630 *
4631 * <p>Requires Permission:
4632 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4633 */
4634 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004635 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004636 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004637 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004638 return null;
4639 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004640 int subId = phone.getSubId();
4641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4642 mApp, subId, callingPackage, "getDeviceId")) {
4643 return null;
4644 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004645
4646 final long identity = Binder.clearCallingIdentity();
4647 try {
4648 return phone.getDeviceId();
4649 } finally {
4650 Binder.restoreCallingIdentity(identity);
4651 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004652 }
4653
Ping Sunc67b7c22016-03-02 19:16:45 +08004654 /**
4655 * {@hide}
4656 * Returns the IMS Registration Status on a particular subid
4657 *
4658 * @param subId
4659 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004660 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004661 Phone phone = getPhone(subId);
4662 if (phone != null) {
4663 return phone.isImsRegistered();
4664 } else {
4665 return false;
4666 }
4667 }
4668
Santos Cordon7a1885b2015-02-03 11:15:19 -08004669 @Override
4670 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004671 final long identity = Binder.clearCallingIdentity();
4672 try {
4673 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4674 } finally {
4675 Binder.restoreCallingIdentity(identity);
4676 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004677 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004678
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004679 /**
4680 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004681 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004682 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004683 final long identity = Binder.clearCallingIdentity();
4684 try {
4685 Phone phone = getPhone(subId);
4686 if (phone != null) {
4687 return phone.isWifiCallingEnabled();
4688 } else {
4689 return false;
4690 }
4691 } finally {
4692 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004693 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004694 }
4695
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004696 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004697 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004698 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004699 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004700 final long identity = Binder.clearCallingIdentity();
4701 try {
4702 Phone phone = getPhone(subId);
4703 if (phone != null) {
4704 return phone.isVideoEnabled();
4705 } else {
4706 return false;
4707 }
4708 } finally {
4709 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004710 }
4711 }
4712
4713 /**
4714 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4715 * defined in {@link ImsRegistrationImplBase}.
4716 */
4717 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004718 final long identity = Binder.clearCallingIdentity();
4719 try {
4720 Phone phone = getPhone(subId);
4721 if (phone != null) {
4722 return phone.getImsRegistrationTech();
4723 } else {
4724 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4725 }
4726 } finally {
4727 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004728 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004729 }
4730
Stuart Scott8eef64f2015-04-08 15:13:54 -07004731 @Override
4732 public void factoryReset(int subId) {
4733 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004734 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4735 return;
4736 }
4737
Svet Ganovcc087f82015-05-12 20:35:54 -07004738 final long identity = Binder.clearCallingIdentity();
4739 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004740 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4741 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004742 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004743 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004744 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4745 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004746 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004747 }
4748 } finally {
4749 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004750 }
4751 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004752
4753 @Override
4754 public String getLocaleFromDefaultSim() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004755 final long identity = Binder.clearCallingIdentity();
4756 try {
4757 // We query all subscriptions instead of just the active ones, because
4758 // this might be called early on in the provisioning flow when the
4759 // subscriptions potentially aren't active yet.
4760 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4761 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004762 return null;
4763 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004764
Malcolm Chend965c8b2018-02-28 15:00:40 -08004765 // This function may be called very early, say, from the setup wizard, at
4766 // which point we won't have a default subscription set. If that's the case
4767 // we just choose the first, which will be valid in "most cases".
4768 final int defaultSubId = getDefaultSubscription();
4769 SubscriptionInfo info = null;
4770 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4771 info = slist.get(0);
4772 } else {
4773 for (SubscriptionInfo item : slist) {
4774 if (item.getSubscriptionId() == defaultSubId) {
4775 info = item;
4776 break;
4777 }
4778 }
4779
4780 if (info == null) {
4781 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004782 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004783 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004784
Malcolm Chend965c8b2018-02-28 15:00:40 -08004785 // Try and fetch the locale from the carrier properties or from the SIM language
4786 // preferences (EF-PL and EF-LI)...
4787 final int mcc = info.getMcc();
4788 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4789 String simLanguage = null;
4790 if (defaultPhone != null) {
4791 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4792 if (localeFromDefaultSim != null) {
4793 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4794 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4795 return localeFromDefaultSim.toLanguageTag();
4796 } else {
4797 simLanguage = localeFromDefaultSim.getLanguage();
4798 }
4799 }
4800 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004801
Malcolm Chend965c8b2018-02-28 15:00:40 -08004802 // The SIM language preferences only store a language (e.g. fr = French), not an
4803 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4804 // the SIM and carrier preferences does not include a country we add the country
4805 // determined from the SIM MCC to provide an exact locale.
4806 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4807 simLanguage);
4808 if (mccLocale != null) {
4809 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4810 return mccLocale.toLanguageTag();
4811 }
4812
4813 if (DBG) log("No locale found - returning null");
4814 return null;
4815 } finally {
4816 Binder.restoreCallingIdentity(identity);
4817 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004818 }
4819
4820 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004821 return mSubscriptionController.getAllSubInfoList(
4822 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004823 }
4824
Malcolm Chend965c8b2018-02-28 15:00:40 -08004825 /**
4826 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4827 */
4828 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4829 return mSubscriptionController.getActiveSubscriptionInfoList(
4830 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004831 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004832
Chenjie Yu1ba97252018-01-11 18:16:20 -08004833 private final ModemActivityInfo mLastModemActivityInfo =
4834 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4835
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004836 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004837 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4838 * representing the state of the modem.
4839 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004840 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4841 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004842 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004843 */
4844 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004845 public void requestModemActivityInfo(ResultReceiver result) {
4846 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07004847 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004848
4849 final long identity = Binder.clearCallingIdentity();
4850 try {
4851 ModemActivityInfo ret = null;
4852 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07004853 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4854 CMD_GET_MODEM_ACTIVITY_INFO,
4855 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004856 if (isModemActivityInfoValid(info)) {
4857 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4858 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4859 mergedTxTimeMs[i] =
4860 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4861 }
4862 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4863 mLastModemActivityInfo.setSleepTimeMillis(
4864 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4865 mLastModemActivityInfo.setIdleTimeMillis(
4866 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4867 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4868 mLastModemActivityInfo.setRxTimeMillis(
4869 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4870 mLastModemActivityInfo.setEnergyUsed(
4871 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004872 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004873 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4874 mLastModemActivityInfo.getSleepTimeMillis(),
4875 mLastModemActivityInfo.getIdleTimeMillis(),
4876 mLastModemActivityInfo.getTxTimeMillis(),
4877 mLastModemActivityInfo.getRxTimeMillis(),
4878 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004879 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004880 Bundle bundle = new Bundle();
4881 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4882 result.send(0, bundle);
4883 } finally {
4884 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004885 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004886 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004887
Siddharth Rayf5d29552018-06-17 15:02:38 -07004888 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4889 // less than total activity duration.
4890 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4891 if (info == null) {
4892 return false;
4893 }
4894 int activityDurationMs =
4895 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4896 int totalTxTimeMs = 0;
4897 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4898 totalTxTimeMs += info.getTxTimeMillis()[i];
4899 }
4900 return (info.isValid()
4901 && (info.getSleepTimeMillis() <= activityDurationMs)
4902 && (info.getIdleTimeMillis() <= activityDurationMs)
4903 && (info.getRxTimeMillis() <= activityDurationMs)
4904 && (totalTxTimeMs <= activityDurationMs));
4905 }
4906
Jack Yu85bd38a2015-11-09 11:34:32 -08004907 /**
4908 * {@hide}
4909 * Returns the service state information on specified subscription.
4910 */
4911 @Override
4912 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004913 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004914 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004915 return null;
4916 }
4917
Malcolm Chend965c8b2018-02-28 15:00:40 -08004918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 final Phone phone = getPhone(subId);
4921 if (phone == null) {
4922 return null;
4923 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004924
Malcolm Chend965c8b2018-02-28 15:00:40 -08004925 return phone.getServiceState();
4926 } finally {
4927 Binder.restoreCallingIdentity(identity);
4928 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004929 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004930
4931 /**
4932 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4933 *
4934 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4935 * voicemail ringtone.
4936 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4937 * PhoneAccount.
4938 */
4939 @Override
4940 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004941 final long identity = Binder.clearCallingIdentity();
4942 try {
4943 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4944 if (phone == null) {
4945 phone = mPhone;
4946 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004947
Malcolm Chend965c8b2018-02-28 15:00:40 -08004948 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004952 }
4953
4954 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004955 * Sets the per-account voicemail ringtone.
4956 *
4957 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4958 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4959 *
4960 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4961 * voicemail ringtone.
4962 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4963 * PhoneAccount.
4964 */
4965 @Override
4966 public void setVoicemailRingtoneUri(String callingPackage,
4967 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4968 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4969 if (!TextUtils.equals(callingPackage,
4970 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4972 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4973 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004974 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004975
4976 final long identity = Binder.clearCallingIdentity();
4977 try {
4978 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4979 if (phone == null) {
4980 phone = mPhone;
4981 }
4982 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4983 } finally {
4984 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004985 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004986 }
4987
4988 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004989 * Returns whether vibration is set for voicemail notification in Phone settings.
4990 *
4991 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4992 * voicemail vibration setting.
4993 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4994 */
4995 @Override
4996 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004997 final long identity = Binder.clearCallingIdentity();
4998 try {
4999 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5000 if (phone == null) {
5001 phone = mPhone;
5002 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005003
Malcolm Chend965c8b2018-02-28 15:00:40 -08005004 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5005 } finally {
5006 Binder.restoreCallingIdentity(identity);
5007 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005008 }
5009
Youhan Wange64578a2016-05-02 15:32:42 -07005010 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005011 * Sets the per-account voicemail vibration.
5012 *
5013 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5014 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5015 *
5016 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5017 * voicemail vibration setting.
5018 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5019 * specific PhoneAccount.
5020 */
5021 @Override
5022 public void setVoicemailVibrationEnabled(String callingPackage,
5023 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
5024 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5025 if (!TextUtils.equals(callingPackage,
5026 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5028 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5029 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005030 }
5031
Malcolm Chend965c8b2018-02-28 15:00:40 -08005032 final long identity = Binder.clearCallingIdentity();
5033 try {
5034 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5035 if (phone == null) {
5036 phone = mPhone;
5037 }
5038 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5039 } finally {
5040 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005041 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005042 }
5043
5044 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005045 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5046 *
5047 * @throws SecurityException if the caller does not have the required permission
5048 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005049 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005050 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005051 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005052 }
5053
5054 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005055 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5056 * permission.
5057 *
5058 * @throws SecurityException if the caller does not have the required permission
5059 */
5060 private void enforceSendSmsPermission() {
5061 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5062 }
5063
5064 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005065 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005066 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005067 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005068 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005069 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 ComponentName componentName =
5073 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
5074 if (componentName == null) {
5075 throw new SecurityException(
5076 "Caller not current active visual voicemail package[null]");
5077 }
5078 String vvmPackage = componentName.getPackageName();
5079 if (!callingPackage.equals(vvmPackage)) {
5080 throw new SecurityException("Caller not current active visual voicemail package["
5081 + vvmPackage + "]");
5082 }
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005085 }
5086 }
5087
5088 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005089 * Return the application ID for the app type.
5090 *
5091 * @param subId the subscription ID that this request applies to.
5092 * @param appType the uicc app type.
5093 * @return Application ID for specificied app type, or null if no uicc.
5094 */
5095 @Override
5096 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005097 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005098 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005099
5100 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005101 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005102 if (phone == null) {
5103 return null;
5104 }
5105 String aid = null;
5106 try {
5107 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5108 .getApplicationByType(appType).getAid();
5109 } catch (Exception e) {
5110 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5111 }
5112 return aid;
5113 } finally {
5114 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005115 }
Youhan Wange64578a2016-05-02 15:32:42 -07005116 }
5117
Youhan Wang4001d252016-05-11 10:29:41 -07005118 /**
5119 * Return the Electronic Serial Number.
5120 *
5121 * @param subId the subscription ID that this request applies to.
5122 * @return ESN or null if error.
5123 */
5124 @Override
5125 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005126 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005127 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005128
5129 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005130 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005131 if (phone == null) {
5132 return null;
5133 }
5134 String esn = null;
5135 try {
5136 esn = phone.getEsn();
5137 } catch (Exception e) {
5138 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5139 }
5140 return esn;
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005143 }
Youhan Wang4001d252016-05-11 10:29:41 -07005144 }
5145
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005146 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005147 * Return the Preferred Roaming List Version.
5148 *
5149 * @param subId the subscription ID that this request applies to.
5150 * @return PRLVersion or null if error.
5151 */
5152 @Override
5153 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005154 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005155 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005156
5157 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005158 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005159 if (phone == null) {
5160 return null;
5161 }
5162 String cdmaPrlVersion = null;
5163 try {
5164 cdmaPrlVersion = phone.getCdmaPrlVersion();
5165 } catch (Exception e) {
5166 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5167 }
5168 return cdmaPrlVersion;
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005171 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005172 }
5173
5174 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005175 * Get snapshot of Telephony histograms
5176 * @return List of Telephony histograms
5177 * @hide
5178 */
5179 @Override
5180 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5182 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005183
5184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 return RIL.getTelephonyRILTimingHistograms();
5187 } finally {
5188 Binder.restoreCallingIdentity(identity);
5189 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005190 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005191
5192 /**
5193 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005194 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07005195 * Require system privileges. In the future we may add this to carrier APIs.
5196 *
5197 * @return The number of carriers set successfully, should match length of carriers
5198 */
5199 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005200 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005201 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005202 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005203
Meng Wang9b7c4e92017-02-17 11:41:27 -08005204 if (carriers == null) {
5205 throw new NullPointerException("carriers cannot be null");
5206 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005207
Malcolm Chend965c8b2018-02-28 15:00:40 -08005208 final long identity = Binder.clearCallingIdentity();
5209 try {
5210 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005211 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
5212 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005213 return retVal[0];
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005217 }
5218
5219 /**
5220 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005221 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005222 * Require system privileges. In the future we may add this to carrier APIs.
5223 *
5224 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5225 * means all carriers are allowed.
5226 */
5227 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005228 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005229 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005230 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005231
5232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdevie435a3e2018-08-15 16:01:53 -07005235 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5236 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005240 }
5241
fionaxu59545b42016-05-25 15:53:37 -07005242 /**
5243 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5244 * @param subId the subscription ID that this action applies to.
5245 * @param enabled control enable or disable metered apns.
5246 * {@hide}
5247 */
5248 @Override
5249 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5250 enforceModifyPermission();
5251 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005252
5253 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005254 if (phone == null) {
5255 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5256 return;
5257 }
5258 try {
5259 phone.carrierActionSetMeteredApnsEnabled(enabled);
5260 } catch (Exception e) {
5261 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005262 } finally {
5263 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005264 }
5265 }
5266
5267 /**
5268 * Action set from carrier signalling broadcast receivers to enable/disable radio
5269 * @param subId the subscription ID that this action applies to.
5270 * @param enabled control enable or disable radio.
5271 * {@hide}
5272 */
5273 @Override
5274 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5275 enforceModifyPermission();
5276 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005277
5278 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005279 if (phone == null) {
5280 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5281 return;
5282 }
5283 try {
5284 phone.carrierActionSetRadioEnabled(enabled);
5285 } catch (Exception e) {
5286 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005287 } finally {
5288 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005289 }
5290 }
5291
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005292 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005293 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5294 * network status based on which carrier apps could apply actions accordingly,
5295 * enable/disable default url handler for example.
5296 *
5297 * @param subId the subscription ID that this action applies to.
5298 * @param report control start/stop reporting the default network status.
5299 * {@hide}
5300 */
5301 @Override
5302 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5303 enforceModifyPermission();
5304 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005305
5306 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005307 if (phone == null) {
5308 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5309 return;
5310 }
5311 try {
5312 phone.carrierActionReportDefaultNetworkStatus(report);
5313 } catch (Exception e) {
5314 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005315 } finally {
5316 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005317 }
5318 }
5319
5320 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005321 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5322 * bug report is being generated.
5323 */
5324 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005325 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005326 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5327 != PackageManager.PERMISSION_GRANTED) {
5328 writer.println("Permission Denial: can't dump Phone from pid="
5329 + Binder.getCallingPid()
5330 + ", uid=" + Binder.getCallingUid()
5331 + "without permission "
5332 + android.Manifest.permission.DUMP);
5333 return;
5334 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005335 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005336 }
Jack Yueb89b242016-06-22 13:27:47 -07005337
Brad Ebingerdac2f002018-04-03 15:17:52 -07005338 @Override
5339 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5340 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5341 throws RemoteException {
5342 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5343 }
5344
Jack Yueb89b242016-06-22 13:27:47 -07005345 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005346 * Get aggregated video call data usage since boot.
5347 *
5348 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5349 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005350 * {@hide}
5351 */
5352 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005353 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005354 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5355 null);
5356
Malcolm Chend965c8b2018-02-28 15:00:40 -08005357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 // NetworkStatsService keeps tracking the active network interface and identity. It
5360 // records the delta with the corresponding network identity.
5361 // We just return the total video call data usage snapshot since boot.
5362 Phone phone = getPhone(subId);
5363 if (phone != null) {
5364 return phone.getVtDataUsage(perUidStats);
5365 }
5366 return null;
5367 } finally {
5368 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005369 }
Jack Yueb89b242016-06-22 13:27:47 -07005370 }
Jack Yu75ab2952016-07-08 14:29:33 -07005371
5372 /**
5373 * Policy control of data connection. Usually used when data limit is passed.
5374 * @param enabled True if enabling the data, otherwise disabling.
5375 * @param subId Subscription index
5376 * {@hide}
5377 */
5378 @Override
5379 public void setPolicyDataEnabled(boolean enabled, int subId) {
5380 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005381
5382 final long identity = Binder.clearCallingIdentity();
5383 try {
5384 Phone phone = getPhone(subId);
5385 if (phone != null) {
5386 phone.setPolicyDataEnabled(enabled);
5387 }
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005390 }
5391 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005392
5393 /**
5394 * Get Client request stats
5395 * @return List of Client Request Stats
5396 * @hide
5397 */
5398 @Override
5399 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005401 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005402 return null;
5403 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005404 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005405
Malcolm Chend965c8b2018-02-28 15:00:40 -08005406 final long identity = Binder.clearCallingIdentity();
5407 try {
5408 if (phone != null) {
5409 return phone.getClientRequestStats();
5410 }
5411
5412 return null;
5413 } finally {
5414 Binder.restoreCallingIdentity(identity);
5415 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005416 }
5417
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005418 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005419 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005420 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005421 }
Jack Yueb4124c2017-02-16 15:32:43 -08005422
5423 /**
Grace Chen70990072017-03-24 17:21:30 -07005424 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005425 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005426 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005427 * @param state State of SIM (power down, power up, pass through)
5428 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5429 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5430 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005431 *
5432 **/
5433 @Override
Grace Chen70990072017-03-24 17:21:30 -07005434 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005435 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005436 Phone phone = PhoneFactory.getPhone(slotIndex);
5437
vagdevie435a3e2018-08-15 16:01:53 -07005438 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5439
Malcolm Chend965c8b2018-02-28 15:00:40 -08005440 final long identity = Binder.clearCallingIdentity();
5441 try {
5442 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005443 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005444 }
5445 } finally {
5446 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005447 }
5448 }
Shuo Qiandd210312017-04-12 22:11:33 +00005449
Tyler Gunn65d45c22017-06-05 11:22:26 -07005450 private boolean isUssdApiAllowed(int subId) {
5451 CarrierConfigManager configManager =
5452 (CarrierConfigManager) mPhone.getContext().getSystemService(
5453 Context.CARRIER_CONFIG_SERVICE);
5454 if (configManager == null) {
5455 return false;
5456 }
5457 PersistableBundle pb = configManager.getConfigForSubId(subId);
5458 if (pb == null) {
5459 return false;
5460 }
5461 return pb.getBoolean(
5462 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5463 }
5464
Shuo Qiandd210312017-04-12 22:11:33 +00005465 /**
5466 * Check if phone is in emergency callback mode
5467 * @return true if phone is in emergency callback mode
5468 * @param subId sub id
5469 */
goneil9c5f4872017-12-05 14:07:56 -08005470 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005471 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005472 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005473 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005474
5475 final long identity = Binder.clearCallingIdentity();
5476 try {
5477 if (phone != null) {
5478 return phone.isInEcm();
5479 } else {
5480 return false;
5481 }
5482 } finally {
5483 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005484 }
5485 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005486
5487 /**
5488 * Get the current signal strength information for the given subscription.
5489 * Because this information is not updated when the device is in a low power state
5490 * it should not be relied-upon to be current.
5491 * @param subId Subscription index
5492 * @return the most recent cached signal strength info from the modem
5493 */
5494 @Override
5495 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005496 final long identity = Binder.clearCallingIdentity();
5497 try {
5498 Phone p = getPhone(subId);
5499 if (p == null) {
5500 return null;
5501 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005502
Malcolm Chend965c8b2018-02-28 15:00:40 -08005503 return p.getSignalStrength();
5504 } finally {
5505 Binder.restoreCallingIdentity(identity);
5506 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005507 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005508
Pengquan Meng9140aec2018-08-22 14:49:57 -07005509 /**
chen xu907e5a22018-10-11 13:21:04 -07005510 * Get the current modem radio state for the given slot.
5511 * @param slotIndex slot index.
5512 * @param callingPackage the name of the package making the call.
5513 * @return the current radio power state from the modem
5514 */
5515 @Override
5516 public int getRadioPowerState(int slotIndex, String callingPackage) {
5517 Phone phone = PhoneFactory.getPhone(slotIndex);
5518 if (phone != null) {
5519 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5520 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5521 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5522 }
5523
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 return phone.getRadioPowerState();
5527 } finally {
5528 Binder.restoreCallingIdentity(identity);
5529 }
5530 }
5531 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5532 }
5533
5534 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005535 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5536 *
5537 * <p>Requires one of the following permissions:
5538 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5539 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5540 * privileges.
5541 *
5542 * @param subId subscription id
5543 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5544 * {@code false}.
5545 */
5546 @Override
5547 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005548 boolean isEnabled = false;
5549 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07005550 try {
5551 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07005552 null /* message */);
5553 Phone phone = getPhone(subId);
5554 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005555 } catch (Exception e) {
5556 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5557 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07005558 } finally {
5559 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005560 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005561 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07005562 }
5563
5564
5565 /**
5566 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5567 *
5568 * <p> Requires permission:
5569 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5570 * privileges.
5571 *
5572 * @param subId subscription id
5573 * @param isEnabled {@code true} means enable, {@code false} means disable.
5574 */
5575 @Override
5576 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07005577 final long identity = Binder.clearCallingIdentity();
5578 try {
5579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5580 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07005581
Pengquan Meng0c05b502018-09-06 09:59:22 -07005582 Phone phone = getPhone(subId);
5583 if (phone != null) {
5584 phone.setDataRoamingEnabled(isEnabled);
5585 }
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07005588 }
5589 }
5590
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005591 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07005592 public boolean isManualNetworkSelectionAllowed(int subId) {
5593 boolean isAllowed = true;
5594 final long identity = Binder.clearCallingIdentity();
5595 try {
5596 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5597 mApp, subId, "isManualNetworkSelectionAllowed");
5598 Phone phone = getPhone(subId);
5599 if (phone != null) {
5600 isAllowed = phone.isCspPlmnEnabled();
5601 }
5602 } finally {
5603 Binder.restoreCallingIdentity(identity);
5604 }
5605 return isAllowed;
5606 }
5607
5608 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005609 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005610 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005611
Malcolm Chend965c8b2018-02-28 15:00:40 -08005612 final long identity = Binder.clearCallingIdentity();
5613 try {
5614 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5615 if (slots == null) {
5616 Rlog.i(LOG_TAG, "slots is null.");
5617 return null;
5618 }
5619
5620 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5621 for (int i = 0; i < slots.length; i++) {
5622 UiccSlot slot = slots[i];
5623 if (slot == null) {
5624 continue;
5625 }
5626
5627 String cardId;
5628 UiccCard card = slot.getUiccCard();
5629 if (card != null) {
5630 cardId = card.getCardId();
5631 } else {
5632 cardId = slot.getIccId();
5633 }
5634
5635 int cardState = 0;
5636 switch (slot.getCardState()) {
5637 case CARDSTATE_ABSENT:
5638 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5639 break;
5640 case CARDSTATE_PRESENT:
5641 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5642 break;
5643 case CARDSTATE_ERROR:
5644 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5645 break;
5646 case CARDSTATE_RESTRICTED:
5647 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5648 break;
5649 default:
5650 break;
5651
5652 }
5653
5654 infos[i] = new UiccSlotInfo(
5655 slot.isActive(),
5656 slot.isEuicc(),
5657 cardId,
5658 cardState,
5659 slot.getPhoneId(),
5660 slot.isExtendedApduSupported());
5661 }
5662 return infos;
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005665 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005666 }
5667
5668 @Override
5669 public boolean switchSlots(int[] physicalSlots) {
5670 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005671
5672 final long identity = Binder.clearCallingIdentity();
5673 try {
5674 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005678 }
Jack Yu4c988042018-02-27 15:30:01 -08005679
5680 @Override
5681 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5682 enforceModifyPermission();
5683 final Phone phone = getPhone(subId);
5684 if (phone == null) {
5685 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5686 return;
5687 }
5688
Malcolm Chend965c8b2018-02-28 15:00:40 -08005689 final long identity = Binder.clearCallingIdentity();
5690 try {
5691 phone.setRadioIndicationUpdateMode(filters, mode);
5692 } finally {
5693 Binder.restoreCallingIdentity(identity);
5694 }
Jack Yu4c988042018-02-27 15:30:01 -08005695 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005696
5697 /**
goneil47ffb6e2018-04-06 15:40:58 -07005698 * A test API to reload the UICC profile.
5699 *
5700 * <p>Requires that the calling app has permission
5701 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5702 * @hide
5703 */
5704 @Override
5705 public void refreshUiccProfile(int subId) {
5706 enforceModifyPermission();
5707
5708 final long identity = Binder.clearCallingIdentity();
5709 try {
5710 Phone phone = getPhone(subId);
5711 if (phone == null) {
5712 return;
5713 }
5714 UiccCard uiccCard = phone.getUiccCard();
5715 if (uiccCard == null) {
5716 return;
5717 }
5718 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5719 if (uiccProfile == null) {
5720 return;
5721 }
5722 uiccProfile.refresh();
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
5726 }
5727
5728 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005729 * Returns false if the mobile data is disabled by default, otherwise return true.
5730 */
5731 private boolean getDefaultDataEnabled() {
5732 return "true".equalsIgnoreCase(
5733 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5734 }
5735
5736 /**
5737 * Returns true if the data roaming is enabled by default, i.e the system property
5738 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5739 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5740 */
5741 private boolean getDefaultDataRoamingEnabled(int subId) {
5742 final CarrierConfigManager configMgr = (CarrierConfigManager)
5743 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5744 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5745 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5746 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5747 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5748 return isDataRoamingEnabled;
5749 }
5750
5751 /**
5752 * Returns the default network type for the given {@code subId}, if the default network type is
5753 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5754 */
5755 private int getDefaultNetworkType(int subId) {
5756 return Integer.parseInt(
5757 TelephonyManager.getTelephonyProperty(
5758 mSubscriptionController.getPhoneId(subId),
5759 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5760 String.valueOf(Phone.PREFERRED_NT_MODE)));
5761 }
fionaxua13278b2018-03-21 00:08:13 -07005762
5763 @Override
5764 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5765 gid1, String gid2, String plmn, String spn) {
5766 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005767
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
5770 final Phone phone = getPhone(subId);
5771 if (phone == null) {
5772 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5773 return;
5774 }
5775 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005778 }
fionaxua13278b2018-03-21 00:08:13 -07005779 }
5780
5781 @Override
5782 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005783 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005784
5785 final long identity = Binder.clearCallingIdentity();
5786 try {
5787 final Phone phone = getPhone(subId);
5788 if (phone == null) {
5789 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5790 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5791 }
5792 return phone.getCarrierIdListVersion();
5793 } finally {
5794 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005795 }
fionaxua13278b2018-03-21 00:08:13 -07005796 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005797
5798 @Override
5799 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5801 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5802 return -1;
5803 }
5804
5805 final long identity = Binder.clearCallingIdentity();
5806 try {
5807 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
5811 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07005812
5813 @Override
5814 public int getCdmaRoamingMode(int subId) {
5815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5816 mApp, subId, "getCdmaRoamingMode");
5817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5821 } finally {
5822 Binder.restoreCallingIdentity(identity);
5823 }
5824 }
5825
5826 @Override
5827 public boolean setCdmaRoamingMode(int subId, int mode) {
5828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5829 mApp, subId, "setCdmaRoamingMode");
5830
5831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
5836 }
5837 }
5838
5839 @Override
5840 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5842 mApp, subId, "setCdmaSubscriptionMode");
5843
5844 final long identity = Binder.clearCallingIdentity();
5845 try {
5846 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
5850 }
chen xu7ee67862018-10-30 22:27:10 -07005851
sqian2fff4a32018-11-05 14:18:37 -08005852 private void ensureUserRunning(int userId) {
5853 if (!mUserManager.isUserRunning(userId)) {
5854 throw new IllegalStateException("User " + userId + " does not exist or not running");
5855 }
5856 }
5857
5858 /**
5859 * Returns a list of SMS apps on a given user.
5860 *
5861 * Only the shell user (UID 2000 or 0) can call it.
5862 * Target user must be running.
5863 */
5864 @Override
5865 public String[] getSmsApps(int userId) {
5866 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5867 ensureUserRunning(userId);
5868
5869 final Collection<SmsApplicationData> apps =
5870 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5871
5872 String[] ret = new String[apps.size()];
5873 int i = 0;
5874 for (SmsApplicationData app : apps) {
5875 ret[i++] = app.mPackageName;
5876 }
5877 return ret;
5878 }
5879
5880 /**
5881 * Returns the default SMS app package name on a given user.
5882 *
5883 * Only the shell user (UID 2000 or 0) can call it.
5884 * Target user must be running.
5885 */
5886 @Override
5887 public String getDefaultSmsApp(int userId) {
5888 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5889 ensureUserRunning(userId);
5890
5891 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5892 /* updateIfNeeded= */ true, userId);
5893 return cn == null ? null : cn.getPackageName();
5894 }
5895
5896 /**
5897 * Set a package as the default SMS app on a given user.
5898 *
5899 * Only the shell user (UID 2000 or 0) can call it.
5900 * Target user must be running.
5901 */
5902 @Override
5903 public void setDefaultSmsApp(int userId, String packageName) {
5904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5905 ensureUserRunning(userId);
5906
5907 boolean found = false;
5908 for (String pkg : getSmsApps(userId)) {
5909 if (TextUtils.equals(packageName, pkg)) {
5910 found = true;
5911 break;
5912 }
5913 }
5914 if (!found) {
5915 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5916 }
5917
5918 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5919 }
5920
chen xu7ee67862018-10-30 22:27:10 -07005921 @Override
sqian04b86072018-11-07 14:02:21 -08005922 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
5923 String callingPackage) {
5924 // TODO connect with internal content
5925 return null;
5926 }
5927
5928 @Override
5929 public boolean isCurrentEmergencyNumber(String number) {
5930 // TODO connect with internal content
5931 return false;
5932 }
5933
5934 @Override
chen xu7ee67862018-10-30 22:27:10 -07005935 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
5936 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
5937 Phone phone = getPhone(subId);
5938 if (phone == null) {
5939 return null;
5940 }
5941 final long identity = Binder.clearCallingIdentity();
5942 try {
5943 UiccProfile profile = UiccController.getInstance()
5944 .getUiccProfileForPhone(phone.getPhoneId());
5945 if (profile != null) {
5946 return profile.getCertsFromCarrierPrivilegeAccessRules();
5947 }
5948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
5951 return null;
5952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005953}