blob: cdee4ea94e1cb68c76b311147781e941b78c6f45 [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;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070045import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070046import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070048import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070049import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070050import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080051import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070052import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080053import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080054import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070055import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070056import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070058import android.telephony.CellInfoGsm;
59import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070060import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070061import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070062import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080063import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070064import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080065import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070066import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070067import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070068import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080070import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070071import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080072import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070074import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070075import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000076import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070077import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070078import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070079import android.telephony.cdma.CdmaCellLocation;
80import android.telephony.gsm.GsmCellLocation;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080081import android.telephony.ims.aidl.IImsConfig;
82import android.telephony.ims.aidl.IImsMmTelFeature;
83import android.telephony.ims.aidl.IImsRcsFeature;
84import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080085import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080087import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080091
Andrew Lee312e8172014-10-23 17:01:36 -070092import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080093import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070094import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070095import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070096import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070097import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070098import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800101import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700102import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100103import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700104import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700105import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700107import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800108import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700109import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700110import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700111import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700112import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700113import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700114import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700115import com.android.internal.telephony.SmsApplication;
116import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800117import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800118import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700119import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700120import com.android.internal.telephony.uicc.IccIoResult;
121import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800122import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700123import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800124import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800126import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000127import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700128import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800129import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700130import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800131import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700132import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700133import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800134
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700135import java.io.FileDescriptor;
136import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800137import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700140import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800141import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100142import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800143import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144
145/**
146 * Implementation of the ITelephony interface.
147 */
Santos Cordon117fee72014-05-16 17:56:12 -0700148public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149 private static final String LOG_TAG = "PhoneInterfaceManager";
150 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
151 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800152 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153
154 // Message codes used with mMainThreadHandler
155 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700156 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
157 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158 private static final int CMD_OPEN_CHANNEL = 9;
159 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
160 private static final int CMD_CLOSE_CHANNEL = 11;
161 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800162 private static final int CMD_NV_READ_ITEM = 13;
163 private static final int EVENT_NV_READ_ITEM_DONE = 14;
164 private static final int CMD_NV_WRITE_ITEM = 15;
165 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
166 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
167 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
168 private static final int CMD_NV_RESET_CONFIG = 19;
169 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800170 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
171 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
172 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
173 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800174 private static final int CMD_SEND_ENVELOPE = 25;
175 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000176 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
177 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700178 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
179 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
180 private static final int CMD_EXCHANGE_SIM_IO = 31;
181 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800182 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
183 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700184 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
185 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700186 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
187 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700188 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
189 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
190 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
191 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700192 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
193 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
194 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
195 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700196 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800197 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
198 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000199 private static final int CMD_SWITCH_SLOTS = 50;
200 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700201 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
202 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
203 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
204 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
205 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
206 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
207 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
208 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700209 private static final int CMD_GET_ALL_CELL_INFO = 60;
210 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
211 private static final int CMD_GET_CELL_LOCATION = 62;
212 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800214 // Parameters of select command.
215 private static final int SELECT_COMMAND = 0xA4;
216 private static final int SELECT_P1 = 0x04;
217 private static final int SELECT_P2 = 0;
218 private static final int SELECT_P3 = 0x10;
219
Pengquan Meng85728fb2018-03-12 16:31:21 -0700220 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
221 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
222 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
223
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 /** The singleton instance. */
225 private static PhoneInterfaceManager sInstance;
226
Wink Saville3ab207e2014-11-20 13:07:20 -0800227 private PhoneGlobals mApp;
228 private Phone mPhone;
229 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700230 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800231 private AppOpsManager mAppOps;
232 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800233 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800234 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700235 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236
Derek Tan97ebb422014-09-05 16:55:38 -0700237 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
238 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800239 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700240
Derek Tan740e1672017-06-27 14:56:27 -0700241 // The AID of ISD-R.
242 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
243
yinxub1bed742017-04-17 11:45:04 -0700244 private NetworkScanRequestTracker mNetworkScanRequestTracker;
245
David Kelly5e06a7f2018-03-12 14:10:59 +0000246 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
247 private static final int MANUFACTURER_CODE_LENGTH = 8;
248
Derek Tan89e89d42014-07-08 17:00:10 -0700249 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700250 * A request object to use for transmitting data to an ICC.
251 */
252 private static final class IccAPDUArgument {
253 public int channel, cla, command, p1, p2, p3;
254 public String data;
255
256 public IccAPDUArgument(int channel, int cla, int command,
257 int p1, int p2, int p3, String data) {
258 this.channel = channel;
259 this.cla = cla;
260 this.command = command;
261 this.p1 = p1;
262 this.p2 = p2;
263 this.p3 = p3;
264 this.data = data;
265 }
266 }
267
268 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700269 * A request object to use for transmitting data to an ICC.
270 */
271 private static final class ManualNetworkSelectionArgument {
272 public OperatorInfo operatorInfo;
273 public boolean persistSelection;
274
275 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
276 this.operatorInfo = operatorInfo;
277 this.persistSelection = persistSelection;
278 }
279 }
280
281 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
283 * request after sending. The main thread will notify the request when it is complete.
284 */
285 private static final class MainThreadRequest {
286 /** The argument to use for the request */
287 public Object argument;
288 /** The result of the request that is run on the main thread */
289 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800290 // The subscriber id that this request applies to. Defaults to
291 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
292 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293
vagdeviaf9a5b92018-08-15 16:01:53 -0700294 public WorkSource workSource;
295
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296 public MainThreadRequest(Object argument) {
297 this.argument = argument;
298 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800299
vagdeviaf9a5b92018-08-15 16:01:53 -0700300 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800301 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800302 if (subId != null) {
303 this.subId = subId;
304 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700305 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700307 }
308
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800309 private static final class IncomingThirdPartyCallArgs {
310 public final ComponentName component;
311 public final String callId;
312 public final String callerDisplayName;
313
314 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
315 String callerDisplayName) {
316 this.component = component;
317 this.callId = callId;
318 this.callerDisplayName = callerDisplayName;
319 }
320 }
321
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 /**
323 * A handler that processes messages on the main thread in the phone process. Since many
324 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
325 * inbound binder threads to the main thread in the phone process. The Binder thread
326 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
327 * on, which will be notified when the operation completes and will contain the result of the
328 * request.
329 *
330 * <p>If a MainThreadRequest object is provided in the msg.obj field,
331 * note that request.result must be set to something non-null for the calling thread to
332 * unblock.
333 */
334 private final class MainThreadHandler extends Handler {
335 @Override
336 public void handleMessage(Message msg) {
337 MainThreadRequest request;
338 Message onCompleted;
339 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800340 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700341 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
343 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700344 case CMD_HANDLE_USSD_REQUEST: {
345 request = (MainThreadRequest) msg.obj;
346 final Phone phone = getPhoneFromRequest(request);
347 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
348 String ussdRequest = ussdObject.first;
349 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700350
Pengquan Menga1bb6272018-09-06 09:59:22 -0700351 if (!isUssdApiAllowed(request.subId)) {
352 // Carrier does not support use of this API, return failure.
353 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
354 UssdResponse response = new UssdResponse(ussdRequest, null);
355 Bundle returnData = new Bundle();
356 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
357 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700358
Pengquan Menga1bb6272018-09-06 09:59:22 -0700359 request.result = true;
360 notifyRequester(request);
361 return;
362 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700363
Pengquan Menga1bb6272018-09-06 09:59:22 -0700364 try {
365 request.result = phone != null
366 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
367 } catch (CallStateException cse) {
368 request.result = false;
369 }
370 // Wake up the requesting thread
371 notifyRequester(request);
372 break;
pkanwar32d516d2016-10-14 19:37:38 -0700373 }
374
Yorke Lee716f67e2015-06-17 15:39:16 -0700375 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700377 final Phone phone = getPhoneFromRequest(request);
378 request.result = phone != null ?
379 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
380 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700382 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700386 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700387 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700388 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800389 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700390 if (uiccCard == null) {
391 loge("iccTransmitApduLogicalChannel: No UICC");
392 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700393 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700394 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700395 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
396 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700397 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700398 iccArgument.channel, iccArgument.cla, iccArgument.command,
399 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700400 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700401 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700402 break;
403
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 ar = (AsyncResult) msg.obj;
406 request = (MainThreadRequest) ar.userObj;
407 if (ar.exception == null && ar.result != null) {
408 request.result = ar.result;
409 } else {
410 request.result = new IccIoResult(0x6F, 0, (byte[])null);
411 if (ar.result == null) {
412 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800413 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800415 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 } else {
417 loge("iccTransmitApduLogicalChannel: Unknown exception");
418 }
419 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 break;
422
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
424 request = (MainThreadRequest) msg.obj;
425 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800426 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 if (uiccCard == null) {
428 loge("iccTransmitApduBasicChannel: No UICC");
429 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700430 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 } else {
432 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
433 request);
434 uiccCard.iccTransmitApduBasicChannel(
435 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
436 iccArgument.p3, iccArgument.data, onCompleted);
437 }
438 break;
439
440 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
441 ar = (AsyncResult) msg.obj;
442 request = (MainThreadRequest) ar.userObj;
443 if (ar.exception == null && ar.result != null) {
444 request.result = ar.result;
445 } else {
446 request.result = new IccIoResult(0x6F, 0, (byte[])null);
447 if (ar.result == null) {
448 loge("iccTransmitApduBasicChannel: Empty response");
449 } else if (ar.exception instanceof CommandException) {
450 loge("iccTransmitApduBasicChannel: CommandException: " +
451 ar.exception);
452 } else {
453 loge("iccTransmitApduBasicChannel: Unknown exception");
454 }
455 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 break;
458
459 case CMD_EXCHANGE_SIM_IO:
460 request = (MainThreadRequest) msg.obj;
461 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800462 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 if (uiccCard == null) {
464 loge("iccExchangeSimIO: No UICC");
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 } else {
468 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
469 request);
470 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
471 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
472 iccArgument.data, onCompleted);
473 }
474 break;
475
476 case EVENT_EXCHANGE_SIM_IO_DONE:
477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6f, 0, (byte[])null);
483 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 break;
486
Derek Tan4d5e5c12014-02-04 11:54:58 -0800487 case CMD_SEND_ENVELOPE:
488 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 if (uiccCard == null) {
491 loge("sendEnvelopeWithStatus: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700494 } else {
495 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
496 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
497 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800498 break;
499
500 case EVENT_SEND_ENVELOPE_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800505 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
507 if (ar.result == null) {
508 loge("sendEnvelopeWithStatus: Empty response");
509 } else if (ar.exception instanceof CommandException) {
510 loge("sendEnvelopeWithStatus: CommandException: " +
511 ar.exception);
512 } else {
513 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
514 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800517 break;
518
Shishir Agrawal566b7612013-10-28 14:41:00 -0700519 case CMD_OPEN_CHANNEL:
520 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800522 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700523 if (uiccCard == null) {
524 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800525 request.result = new IccOpenLogicalChannelResponse(-1,
526 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700528 } else {
529 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800530 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
531 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700532 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700533 break;
534
535 case EVENT_OPEN_CHANNEL_DONE:
536 ar = (AsyncResult) msg.obj;
537 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 int[] result = (int[]) ar.result;
541 int channelId = result[0];
542 byte[] selectResponse = null;
543 if (result.length > 1) {
544 selectResponse = new byte[result.length - 1];
545 for (int i = 1; i < result.length; ++i) {
546 selectResponse[i - 1] = (byte) result[i];
547 }
548 }
549 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700550 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 if (ar.result == null) {
553 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 if (ar.exception != null) {
556 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
557 }
558
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700559 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700560 if (ar.exception instanceof CommandException) {
561 CommandException.Error error =
562 ((CommandException) (ar.exception)).getCommandError();
563 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700564 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700565 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700566 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 }
568 }
569 openChannelResp = new IccOpenLogicalChannelResponse(
570 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700572 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 break;
575
576 case CMD_CLOSE_CHANNEL:
577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800578 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900581 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 } else {
584 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
585 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
586 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 break;
588
589 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800590 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
591 break;
592
593 case CMD_NV_READ_ITEM:
594 request = (MainThreadRequest) msg.obj;
595 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700596 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800597 break;
598
599 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 ar = (AsyncResult) msg.obj;
601 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800602 if (ar.exception == null && ar.result != null) {
603 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800605 request.result = "";
606 if (ar.result == null) {
607 loge("nvReadItem: Empty response");
608 } else if (ar.exception instanceof CommandException) {
609 loge("nvReadItem: CommandException: " +
610 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800612 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
614 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 break;
617
Jake Hambye994d462014-02-03 13:10:13 -0800618 case CMD_NV_WRITE_ITEM:
619 request = (MainThreadRequest) msg.obj;
620 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
621 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700622 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
623 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800624 break;
625
626 case EVENT_NV_WRITE_ITEM_DONE:
627 handleNullReturnEvent(msg, "nvWriteItem");
628 break;
629
630 case CMD_NV_WRITE_CDMA_PRL:
631 request = (MainThreadRequest) msg.obj;
632 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
633 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
634 break;
635
636 case EVENT_NV_WRITE_CDMA_PRL_DONE:
637 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
638 break;
639
640 case CMD_NV_RESET_CONFIG:
641 request = (MainThreadRequest) msg.obj;
642 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
643 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
644 break;
645
646 case EVENT_NV_RESET_CONFIG_DONE:
647 handleNullReturnEvent(msg, "nvResetConfig");
648 break;
649
Jake Hamby7c27be32014-03-03 13:25:59 -0800650 case CMD_GET_PREFERRED_NETWORK_TYPE:
651 request = (MainThreadRequest) msg.obj;
652 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700653 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800654 break;
655
656 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
657 ar = (AsyncResult) msg.obj;
658 request = (MainThreadRequest) ar.userObj;
659 if (ar.exception == null && ar.result != null) {
660 request.result = ar.result; // Integer
661 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800662 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800663 if (ar.result == null) {
664 loge("getPreferredNetworkType: Empty response");
665 } else if (ar.exception instanceof CommandException) {
666 loge("getPreferredNetworkType: CommandException: " +
667 ar.exception);
668 } else {
669 loge("getPreferredNetworkType: Unknown exception");
670 }
671 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800673 break;
674
675 case CMD_SET_PREFERRED_NETWORK_TYPE:
676 request = (MainThreadRequest) msg.obj;
677 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
678 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700679 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800680 break;
681
682 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
683 handleNullReturnEvent(msg, "setPreferredNetworkType");
684 break;
685
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000686 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
687 request = (MainThreadRequest)msg.obj;
688 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700689 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000690 break;
691
692 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
693 ar = (AsyncResult)msg.obj;
694 request = (MainThreadRequest)ar.userObj;
695 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000697 break;
698
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800699 case CMD_SET_VOICEMAIL_NUMBER:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
702 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800703 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
704 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800705 break;
706
707 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
708 handleNullReturnEvent(msg, "setVoicemailNumber");
709 break;
710
Stuart Scott54788802015-03-30 13:18:01 -0700711 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
714 request);
715 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
716 break;
717
718 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
719 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
720 break;
721
Shishir Agrawal302c8692015-06-19 13:49:39 -0700722 case CMD_PERFORM_NETWORK_SCAN:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
725 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
726 break;
727
728 case EVENT_PERFORM_NETWORK_SCAN_DONE:
729 ar = (AsyncResult) msg.obj;
730 request = (MainThreadRequest) ar.userObj;
731 CellNetworkScanResult cellScanResult;
732 if (ar.exception == null && ar.result != null) {
733 cellScanResult = new CellNetworkScanResult(
734 CellNetworkScanResult.STATUS_SUCCESS,
735 (List<OperatorInfo>) ar.result);
736 } else {
737 if (ar.result == null) {
738 loge("getCellNetworkScanResults: Empty response");
739 }
740 if (ar.exception != null) {
741 loge("getCellNetworkScanResults: Exception: " + ar.exception);
742 }
743 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
744 if (ar.exception instanceof CommandException) {
745 CommandException.Error error =
746 ((CommandException) (ar.exception)).getCommandError();
747 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
748 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
749 } else if (error == CommandException.Error.GENERIC_FAILURE) {
750 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
751 }
752 }
753 cellScanResult = new CellNetworkScanResult(errorCode, null);
754 }
755 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700756 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700757 break;
758
759 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
760 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700761 ManualNetworkSelectionArgument selArg =
762 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700763 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
764 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700765 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
766 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700767 break;
768
769 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
770 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
771 break;
772
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700773 case CMD_GET_MODEM_ACTIVITY_INFO:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700776 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700777 break;
778
779 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
780 ar = (AsyncResult) msg.obj;
781 request = (MainThreadRequest) ar.userObj;
782 if (ar.exception == null && ar.result != null) {
783 request.result = ar.result;
784 } else {
785 if (ar.result == null) {
786 loge("queryModemActivityInfo: Empty response");
787 } else if (ar.exception instanceof CommandException) {
788 loge("queryModemActivityInfo: CommandException: " +
789 ar.exception);
790 } else {
791 loge("queryModemActivityInfo: Unknown exception");
792 }
793 }
Amit Mahajand4766222016-01-28 15:28:28 -0800794 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
795 if (request.result == null) {
796 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
797 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700798 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700799 break;
800
Meng Wang1a7c35a2016-05-05 20:56:15 -0700801 case CMD_SET_ALLOWED_CARRIERS:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
804 mPhone.setAllowedCarriers(
805 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700806 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700807 break;
808
809 case EVENT_SET_ALLOWED_CARRIERS_DONE:
810 ar = (AsyncResult) msg.obj;
811 request = (MainThreadRequest) ar.userObj;
812 if (ar.exception == null && ar.result != null) {
813 request.result = ar.result;
814 } else {
815 if (ar.result == null) {
816 loge("setAllowedCarriers: Empty response");
817 } else if (ar.exception instanceof CommandException) {
818 loge("setAllowedCarriers: CommandException: " +
819 ar.exception);
820 } else {
821 loge("setAllowedCarriers: Unknown exception");
822 }
823 }
824 // Result cannot be null. Return -1 on error.
825 if (request.result == null) {
826 request.result = new int[]{-1};
827 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700828 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700829 break;
830
831 case CMD_GET_ALLOWED_CARRIERS:
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700834 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700835 break;
836
837 case EVENT_GET_ALLOWED_CARRIERS_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result;
842 } else {
843 if (ar.result == null) {
844 loge("getAllowedCarriers: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("getAllowedCarriers: CommandException: " +
847 ar.exception);
848 } else {
849 loge("getAllowedCarriers: Unknown exception");
850 }
851 }
852 // Result cannot be null. Return empty list of CarrierIdentifier.
853 if (request.result == null) {
854 request.result = new ArrayList<CarrierIdentifier>(0);
855 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700856 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700857 break;
858
Nathan Haroldb3014052017-01-25 15:57:32 -0800859 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
860 ar = (AsyncResult) msg.obj;
861 request = (MainThreadRequest) ar.userObj;
862 if (ar.exception == null && ar.result != null) {
863 request.result = ar.result;
864 } else {
865 request.result = new IllegalArgumentException(
866 "Failed to retrieve Forbidden Plmns");
867 if (ar.result == null) {
868 loge("getForbiddenPlmns: Empty response");
869 } else {
870 loge("getForbiddenPlmns: Unknown exception");
871 }
872 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700873 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800874 break;
875
876 case CMD_GET_FORBIDDEN_PLMNS:
877 request = (MainThreadRequest) msg.obj;
878 uiccCard = getUiccCardFromRequest(request);
879 if (uiccCard == null) {
880 loge("getForbiddenPlmns() UiccCard is null");
881 request.result = new IllegalArgumentException(
882 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800884 break;
885 }
886 Integer appType = (Integer) request.argument;
887 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
888 if (uiccApp == null) {
889 loge("getForbiddenPlmns() no app with specified type -- "
890 + appType);
891 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700892 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800893 break;
894 } else {
895 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
896 + " specified type -- " + appType);
897 }
898 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
899 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
900 onCompleted);
901 break;
902
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000903 case CMD_SWITCH_SLOTS:
904 request = (MainThreadRequest) msg.obj;
905 int[] physicalSlots = (int[]) request.argument;
906 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
907 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
908 break;
909
910 case EVENT_SWITCH_SLOTS_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
915 break;
916 case CMD_GET_NETWORK_SELECTION_MODE:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
919 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
920 break;
921
922 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
923 ar = (AsyncResult) msg.obj;
924 request = (MainThreadRequest) ar.userObj;
925 if (ar.exception != null) {
926 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
927 } else {
928 int mode = ((int[]) ar.result)[0];
929 if (mode == 0) {
930 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
931 } else {
932 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
933 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000934 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700935 notifyRequester(request);
936 break;
937 case CMD_GET_CDMA_ROAMING_MODE:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
940 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
941 break;
942 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception != null) {
946 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
947 } else {
948 request.result = ((int[]) ar.result)[0];
949 }
950 notifyRequester(request);
951 break;
952 case CMD_SET_CDMA_ROAMING_MODE:
953 request = (MainThreadRequest) msg.obj;
954 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
955 int mode = (int) request.argument;
956 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
957 break;
958 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
959 ar = (AsyncResult) msg.obj;
960 request = (MainThreadRequest) ar.userObj;
961 request.result = ar.exception == null;
962 notifyRequester(request);
963 break;
964 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
967 int subscriptionMode = (int) request.argument;
968 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
969 break;
970 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
973 request.result = ar.exception == null;
974 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000975 break;
976
Nathan Harold3ff88932018-08-14 10:19:49 -0700977 case CMD_GET_ALL_CELL_INFO:
978 request = (MainThreadRequest) msg.obj;
979 Pair<Phone, WorkSource> args = (Pair<Phone, WorkSource>) request.argument;
980 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
981 ((Phone) args.first).getAllCellInfo(args.second, onCompleted);
982 break;
983
984 case EVENT_GET_ALL_CELL_INFO_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 request.result = (ar.exception == null) ? ar.result : new ArrayList<CellInfo>();
988 synchronized (request) {
989 request.notifyAll();
990 }
991 break;
992
993 case CMD_GET_CELL_LOCATION: {
994 request = (MainThreadRequest) msg.obj;
995 WorkSource ws = (WorkSource) request.argument;
996 Phone phone = getPhoneFromRequest(request);
997 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
998 break;
999 }
1000
1001 case EVENT_GET_CELL_LOCATION_DONE: {
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 if (ar.exception == null) {
1005 request.result = ar.result;
1006 } else {
1007 Phone phone = getPhoneFromRequest(request);
1008 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1009 ? new CdmaCellLocation() : new GsmCellLocation();
1010 }
1011
1012 synchronized (request) {
1013 request.notifyAll();
1014 }
1015 break;
1016 }
1017
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001018 default:
1019 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1020 break;
1021 }
1022 }
Jake Hambye994d462014-02-03 13:10:13 -08001023
Pengquan Menga1bb6272018-09-06 09:59:22 -07001024 private void notifyRequester(MainThreadRequest request) {
1025 synchronized (request) {
1026 request.notifyAll();
1027 }
1028 }
1029
Jake Hambye994d462014-02-03 13:10:13 -08001030 private void handleNullReturnEvent(Message msg, String command) {
1031 AsyncResult ar = (AsyncResult) msg.obj;
1032 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1033 if (ar.exception == null) {
1034 request.result = true;
1035 } else {
1036 request.result = false;
1037 if (ar.exception instanceof CommandException) {
1038 loge(command + ": CommandException: " + ar.exception);
1039 } else {
1040 loge(command + ": Unknown exception");
1041 }
1042 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001043 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001044 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 }
1046
1047 /**
1048 * Posts the specified command to be executed on the main thread,
1049 * waits for the request to complete, and returns the result.
1050 * @see #sendRequestAsync
1051 */
1052 private Object sendRequest(int command, Object argument) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001053 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1054 }
1055
1056 /**
1057 * Posts the specified command to be executed on the main thread,
1058 * waits for the request to complete, and returns the result.
1059 * @see #sendRequestAsync
1060 */
1061 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1062 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1063 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001064 }
1065
1066 /**
1067 * Posts the specified command to be executed on the main thread,
1068 * waits for the request to complete, and returns the result.
1069 * @see #sendRequestAsync
1070 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001071 private Object sendRequest(int command, Object argument, Integer subId) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001072 return sendRequest(command, argument, subId, null);
1073 }
1074
1075 /**
1076 * Posts the specified command to be executed on the main thread,
1077 * waits for the request to complete, and returns the result.
1078 * @see #sendRequestAsync
1079 */
1080 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001081 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1082 throw new RuntimeException("This method will deadlock if called from the main thread.");
1083 }
1084
vagdeviaf9a5b92018-08-15 16:01:53 -07001085 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001086 Message msg = mMainThreadHandler.obtainMessage(command, request);
1087 msg.sendToTarget();
1088
1089 // Wait for the request to complete
1090 synchronized (request) {
1091 while (request.result == null) {
1092 try {
1093 request.wait();
1094 } catch (InterruptedException e) {
1095 // Do nothing, go back and wait until the request is complete
1096 }
1097 }
1098 }
1099 return request.result;
1100 }
1101
1102 /**
1103 * Asynchronous ("fire and forget") version of sendRequest():
1104 * Posts the specified command to be executed on the main thread, and
1105 * returns immediately.
1106 * @see #sendRequest
1107 */
1108 private void sendRequestAsync(int command) {
1109 mMainThreadHandler.sendEmptyMessage(command);
1110 }
1111
1112 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001113 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1114 * @see {@link #sendRequest(int,Object)}
1115 */
1116 private void sendRequestAsync(int command, Object argument) {
1117 MainThreadRequest request = new MainThreadRequest(argument);
1118 Message msg = mMainThreadHandler.obtainMessage(command, request);
1119 msg.sendToTarget();
1120 }
1121
1122 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 * Initialize the singleton PhoneInterfaceManager instance.
1124 * This is only done once, at startup, from PhoneApp.onCreate().
1125 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001126 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001127 synchronized (PhoneInterfaceManager.class) {
1128 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001129 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130 } else {
1131 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1132 }
1133 return sInstance;
1134 }
1135 }
1136
1137 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001138 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 mApp = app;
1140 mPhone = phone;
1141 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001142 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001143 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1144 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001145 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001146 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001147 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001148 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001149 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001150
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001151 publish();
1152 }
1153
1154 private void publish() {
1155 if (DBG) log("publish: " + this);
1156
1157 ServiceManager.addService("phone", this);
1158 }
1159
Stuart Scott584921c2015-01-15 17:10:34 -08001160 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001161 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1162 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001163 }
1164
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001165 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1166 Phone phone = getPhoneFromRequest(request);
1167 return phone == null ? null :
1168 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1169 }
1170
Wink Saville36469e72014-06-11 15:17:00 -07001171 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001172 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001173 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175
1176 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001177 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001178 }
1179
Wink Savilleb564aae2014-10-23 10:18:09 -07001180 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001181 if (DBG) log("dial: " + number);
1182 // No permission check needed here: This is just a wrapper around the
1183 // ACTION_DIAL intent, which is available to any app since it puts up
1184 // the UI before it does anything.
1185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001186 final long identity = Binder.clearCallingIdentity();
1187 try {
1188 String url = createTelUrl(number);
1189 if (url == null) {
1190 return;
1191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001193 // PENDING: should we just silently fail if phone is offhook or ringing?
1194 PhoneConstants.State state = mCM.getState(subId);
1195 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1196 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1197 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1198 mApp.startActivity(intent);
1199 }
1200 } finally {
1201 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 }
1203 }
1204
1205 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001206 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001207 }
1208
Wink Savilleb564aae2014-10-23 10:18:09 -07001209 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001210 if (DBG) log("call: " + number);
1211
1212 // This is just a wrapper around the ACTION_CALL intent, but we still
1213 // need to do a permission check since we're calling startActivity()
1214 // from the context of the phone app.
1215 enforceCallPermission();
1216
1217 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1218 != AppOpsManager.MODE_ALLOWED) {
1219 return;
1220 }
1221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001222 final long identity = Binder.clearCallingIdentity();
1223 try {
1224 String url = createTelUrl(number);
1225 if (url == null) {
1226 return;
1227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001229 boolean isValid = false;
1230 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1231 if (slist != null) {
1232 for (SubscriptionInfo subInfoRecord : slist) {
1233 if (subInfoRecord.getSubscriptionId() == subId) {
1234 isValid = true;
1235 break;
1236 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001237 }
Wink Saville08874612014-08-31 19:19:58 -07001238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001239 if (!isValid) {
1240 return;
1241 }
Wink Saville08874612014-08-31 19:19:58 -07001242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001243 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1244 intent.putExtra(SUBSCRIPTION_KEY, subId);
1245 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1246 mApp.startActivity(intent);
1247 } finally {
1248 Binder.restoreCallingIdentity(identity);
1249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 }
1251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 /**
1253 * End a call based on call state
1254 * @return true is a call was ended
1255 */
1256 public boolean endCall() {
Hall Liu91943182018-09-14 17:42:41 -07001257 return false;
Wink Saville36469e72014-06-11 15:17:00 -07001258 }
1259
1260 /**
1261 * End a call based on the call state of the subId
1262 * @return true is a call was ended
1263 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001264 public boolean endCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001265 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 }
1267
1268 public void answerRingingCall() {
Hall Liu91943182018-09-14 17:42:41 -07001269 // Deprecated.
Wink Saville36469e72014-06-11 15:17:00 -07001270 }
1271
Wink Savilleb564aae2014-10-23 10:18:09 -07001272 public void answerRingingCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001273 // Deprecated
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 }
1275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001277 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001279 public void silenceRinger() {
1280 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 }
1282
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001283 @Override
1284 public boolean isOffhook(String callingPackage) {
1285 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
1287
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 @Override
1289 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001291 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001292 return false;
1293 }
1294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001295 final long identity = Binder.clearCallingIdentity();
1296 try {
1297 final Phone phone = getPhone(subId);
1298 if (phone != null) {
1299 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1300 } else {
1301 return false;
1302 }
1303 } finally {
1304 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 }
1307
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001308 @Override
1309 public boolean isRinging(String callingPackage) {
1310 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001311 }
1312
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001313 @Override
1314 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001316 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001317 return false;
1318 }
1319
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001320 final long identity = Binder.clearCallingIdentity();
1321 try {
1322 final Phone phone = getPhone(subId);
1323 if (phone != null) {
1324 return (phone.getState() == PhoneConstants.State.RINGING);
1325 } else {
1326 return false;
1327 }
1328 } finally {
1329 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 }
1332
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001333 @Override
1334 public boolean isIdle(String callingPackage) {
1335 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001336 }
1337
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001338 @Override
1339 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001341 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001342 return false;
1343 }
1344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001345 final long identity = Binder.clearCallingIdentity();
1346 try {
1347 final Phone phone = getPhone(subId);
1348 if (phone != null) {
1349 return (phone.getState() == PhoneConstants.State.IDLE);
1350 } else {
1351 return false;
1352 }
1353 } finally {
1354 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 }
1357
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001359 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001360 }
1361
Wink Savilleb564aae2014-10-23 10:18:09 -07001362 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001363 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001364 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1365 }
1366
1367 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001368 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001369 }
1370
Wink Savilleb564aae2014-10-23 10:18:09 -07001371 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001372 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001373 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1374 }
1375
1376 /** {@hide} */
1377 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001378 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001379 }
1380
Wink Savilleb564aae2014-10-23 10:18:09 -07001381 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001383
1384 final long identity = Binder.clearCallingIdentity();
1385 try {
1386 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1387 checkSimPin.start();
1388 return checkSimPin.unlockSim(null, pin);
1389 } finally {
1390 Binder.restoreCallingIdentity(identity);
1391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 }
1393
Wink Saville9de0f752013-10-22 19:04:03 -07001394 /** {@hide} */
1395 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001396 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001397 }
1398
Wink Savilleb564aae2014-10-23 10:18:09 -07001399 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001401
1402 final long identity = Binder.clearCallingIdentity();
1403 try {
1404 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1405 checkSimPuk.start();
1406 return checkSimPuk.unlockSim(puk, pin);
1407 } finally {
1408 Binder.restoreCallingIdentity(identity);
1409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 }
1411
1412 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001413 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414 * a synchronous one.
1415 */
1416 private static class UnlockSim extends Thread {
1417
1418 private final IccCard mSimCard;
1419
1420 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001421 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1422 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423
1424 // For replies from SimCard interface
1425 private Handler mHandler;
1426
1427 // For async handler to identify request type
1428 private static final int SUPPLY_PIN_COMPLETE = 100;
1429
1430 public UnlockSim(IccCard simCard) {
1431 mSimCard = simCard;
1432 }
1433
1434 @Override
1435 public void run() {
1436 Looper.prepare();
1437 synchronized (UnlockSim.this) {
1438 mHandler = new Handler() {
1439 @Override
1440 public void handleMessage(Message msg) {
1441 AsyncResult ar = (AsyncResult) msg.obj;
1442 switch (msg.what) {
1443 case SUPPLY_PIN_COMPLETE:
1444 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1445 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001446 mRetryCount = msg.arg1;
1447 if (ar.exception != null) {
1448 if (ar.exception instanceof CommandException &&
1449 ((CommandException)(ar.exception)).getCommandError()
1450 == CommandException.Error.PASSWORD_INCORRECT) {
1451 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1452 } else {
1453 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1454 }
1455 } else {
1456 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 mDone = true;
1459 UnlockSim.this.notifyAll();
1460 }
1461 break;
1462 }
1463 }
1464 };
1465 UnlockSim.this.notifyAll();
1466 }
1467 Looper.loop();
1468 }
1469
1470 /*
1471 * Use PIN or PUK to unlock SIM card
1472 *
1473 * If PUK is null, unlock SIM card with PIN
1474 *
1475 * If PUK is not null, unlock SIM card with PUK and set PIN code
1476 */
Wink Saville9de0f752013-10-22 19:04:03 -07001477 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478
1479 while (mHandler == null) {
1480 try {
1481 wait();
1482 } catch (InterruptedException e) {
1483 Thread.currentThread().interrupt();
1484 }
1485 }
1486 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1487
1488 if (puk == null) {
1489 mSimCard.supplyPin(pin, callback);
1490 } else {
1491 mSimCard.supplyPuk(puk, pin, callback);
1492 }
1493
1494 while (!mDone) {
1495 try {
1496 Log.d(LOG_TAG, "wait for done");
1497 wait();
1498 } catch (InterruptedException e) {
1499 // Restore the interrupted status
1500 Thread.currentThread().interrupt();
1501 }
1502 }
1503 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001504 int[] resultArray = new int[2];
1505 resultArray[0] = mResult;
1506 resultArray[1] = mRetryCount;
1507 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 }
1509 }
1510
1511 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001513
1514 }
1515
Wink Savilleb564aae2014-10-23 10:18:09 -07001516 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001517 // No permission check needed here: this call is harmless, and it's
1518 // needed for the ServiceState.requestStateUpdate() call (which is
1519 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001520 final long identity = Binder.clearCallingIdentity();
1521 try {
1522 final Phone phone = getPhone(subId);
1523 if (phone != null) {
1524 phone.updateServiceLocation();
1525 }
1526 } finally {
1527 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
1530
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001531 @Override
1532 public boolean isRadioOn(String callingPackage) {
1533 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001534 }
1535
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001536 @Override
1537 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001539 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001540 return false;
1541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001542
1543 final long identity = Binder.clearCallingIdentity();
1544 try {
1545 return isRadioOnForSubscriber(subId);
1546 } finally {
1547 Binder.restoreCallingIdentity(identity);
1548 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001549 }
1550
1551 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001552 final long identity = Binder.clearCallingIdentity();
1553 try {
1554 final Phone phone = getPhone(subId);
1555 if (phone != null) {
1556 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1557 } else {
1558 return false;
1559 }
1560 } finally {
1561 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
1564
1565 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001566 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 }
Wink Saville36469e72014-06-11 15:17:00 -07001568
Wink Savilleb564aae2014-10-23 10:18:09 -07001569 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001571
1572 final long identity = Binder.clearCallingIdentity();
1573 try {
1574 final Phone phone = getPhone(subId);
1575 if (phone != null) {
1576 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1577 }
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 }
Wink Saville36469e72014-06-11 15:17:00 -07001581 }
1582
1583 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001584 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001585 }
1586
Wink Savilleb564aae2014-10-23 10:18:09 -07001587 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001588 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001589
1590 final long identity = Binder.clearCallingIdentity();
1591 try {
1592 final Phone phone = getPhone(subId);
1593 if (phone == null) {
1594 return false;
1595 }
1596 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1597 toggleRadioOnOffForSubscriber(subId);
1598 }
1599 return true;
1600 } finally {
1601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 }
Wink Saville36469e72014-06-11 15:17:00 -07001604
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001605 public boolean needMobileRadioShutdown() {
1606 /*
1607 * If any of the Radios are available, it will need to be
1608 * shutdown. So return true if any Radio is available.
1609 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001610 final long identity = Binder.clearCallingIdentity();
1611 try {
1612 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1613 Phone phone = PhoneFactory.getPhone(i);
1614 if (phone != null && phone.isRadioAvailable()) return true;
1615 }
1616 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1617 return false;
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001620 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001621 }
1622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001623 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001624 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001625 enforceModifyPermission();
1626
1627 final long identity = Binder.clearCallingIdentity();
1628 try {
1629 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1630 logv("Shutting down Phone " + i);
1631 shutdownRadioUsingPhoneId(i);
1632 }
1633 } finally {
1634 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001635 }
1636 }
1637
1638 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001639 Phone phone = PhoneFactory.getPhone(phoneId);
1640 if (phone != null && phone.isRadioAvailable()) {
1641 phone.shutdownRadio();
1642 }
1643 }
1644
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001646 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001647
1648 final long identity = Binder.clearCallingIdentity();
1649 try {
1650 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1651 if (defaultPhone != null) {
1652 defaultPhone.setRadioPower(turnOn);
1653 return true;
1654 } else {
1655 loge("There's no default phone.");
1656 return false;
1657 }
1658 } finally {
1659 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001660 }
Wink Saville36469e72014-06-11 15:17:00 -07001661 }
1662
Wink Savilleb564aae2014-10-23 10:18:09 -07001663 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001665
1666 final long identity = Binder.clearCallingIdentity();
1667 try {
1668 final Phone phone = getPhone(subId);
1669 if (phone != null) {
1670 phone.setRadioPower(turnOn);
1671 return true;
1672 } else {
1673 return false;
1674 }
1675 } finally {
1676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 }
1679
Wink Saville36469e72014-06-11 15:17:00 -07001680 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001681 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 public boolean enableDataConnectivity() {
1683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001684
1685 final long identity = Binder.clearCallingIdentity();
1686 try {
1687 int subId = mSubscriptionController.getDefaultDataSubId();
1688 final Phone phone = getPhone(subId);
1689 if (phone != null) {
1690 phone.setUserDataEnabled(true);
1691 return true;
1692 } else {
1693 return false;
1694 }
1695 } finally {
1696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 }
1699
Wink Saville36469e72014-06-11 15:17:00 -07001700 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 public boolean disableDataConnectivity() {
1703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001704
1705 final long identity = Binder.clearCallingIdentity();
1706 try {
1707 int subId = mSubscriptionController.getDefaultDataSubId();
1708 final Phone phone = getPhone(subId);
1709 if (phone != null) {
1710 phone.setUserDataEnabled(false);
1711 return true;
1712 } else {
1713 return false;
1714 }
1715 } finally {
1716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 }
1719
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001721 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001722 final long identity = Binder.clearCallingIdentity();
1723 try {
1724 final Phone phone = getPhone(subId);
1725 if (phone != null) {
1726 return phone.isDataAllowed();
1727 } else {
1728 return false;
1729 }
1730 } finally {
1731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 }
1734
1735 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001736 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001737 }
1738
pkanwarae03a6b2016-11-06 20:37:09 -08001739 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001740 enforceCallPermission();
1741
1742 final long identity = Binder.clearCallingIdentity();
1743 try {
1744 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1745 return;
1746 }
1747 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1748 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
1751 }
pkanwar32d516d2016-10-14 19:37:38 -07001752 };
1753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1760 return false;
1761 }
1762 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 }
1767
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001769 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001770 }
1771
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001772 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001773 final long identity = Binder.clearCallingIdentity();
1774 try {
1775 Phone phone = PhoneFactory.getPhone(slotIndex);
1776 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1777 PhoneConstantConversions.convertCallState(phone.getState());
1778 } finally {
1779 Binder.restoreCallingIdentity(identity);
1780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 }
1782
Sanket Padawe356d7632015-06-22 14:03:32 -07001783 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1788 if (phone != null) {
1789 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1790 } else {
1791 return PhoneConstantConversions.convertDataState(
1792 PhoneConstants.DataState.DISCONNECTED);
1793 }
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
Sanket Padawe356d7632015-06-22 14:03:32 -07001799 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001800 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1804 if (phone != null) {
1805 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1806 } else {
1807 return TelephonyManager.DATA_ACTIVITY_NONE;
1808 }
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 }
1813
1814 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001815 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001816 mPhone.getContext().getSystemService(AppOpsManager.class)
1817 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001818 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001819 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001820 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 }
1822
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001823 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001824 final long identity = Binder.clearCallingIdentity();
1825 try {
1826 if (DBG_LOC) log("getCellLocation: is active user");
1827 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001828 int subId = mSubscriptionController.getDefaultDataSubId();
1829 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1830 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001831 return data;
1832 } finally {
1833 Binder.restoreCallingIdentity(identity);
1834 }
Svetoslav64fad262015-04-14 14:35:21 -07001835 }
1836
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001838 public String getNetworkCountryIsoForPhone(int phoneId) {
1839 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1840 // registered cell info, so return a NULL country instead.
1841 final long identity = Binder.clearCallingIdentity();
1842 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001843 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1844 // Get default phone in this case.
1845 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1846 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001847 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001848 // Todo: fix this when we can get the actual cellular network info when the device
1849 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001850 if (TelephonyManager.NETWORK_TYPE_IWLAN
1851 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1852 return "";
1853 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001854 Phone phone = PhoneFactory.getPhone(phoneId);
1855 if (phone != null) {
1856 ServiceStateTracker sst = phone.getServiceStateTracker();
1857 if (sst != null) {
1858 LocaleTracker lt = sst.getLocaleTracker();
1859 if (lt != null) {
1860 return lt.getCurrentCountry();
1861 }
1862 }
1863 }
1864 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001865 } finally {
1866 Binder.restoreCallingIdentity(identity);
1867 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001868 }
1869
1870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001872 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001873 }
1874
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001876 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 mApp.enforceCallingOrSelfPermission(
1878 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001879
1880 final long identity = Binder.clearCallingIdentity();
1881 try {
1882 final Phone phone = getPhone(subId);
1883 if (phone != null) {
1884 phone.enableLocationUpdates();
1885 }
1886 } finally {
1887 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 }
1890
1891 @Override
1892 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001893 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001894 }
1895
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001897 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 mApp.enforceCallingOrSelfPermission(
1899 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001900
1901 final long identity = Binder.clearCallingIdentity();
1902 try {
1903 final Phone phone = getPhone(subId);
1904 if (phone != null) {
1905 phone.disableLocationUpdates();
1906 }
1907 } finally {
1908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
1911
1912 @Override
1913 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001914 public List<NeighboringCellInfo>
1915 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001916 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1917 throw new SecurityException(
1918 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1919 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001920
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1922 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1923 return null;
1924 }
Svetoslav64fad262015-04-14 14:35:21 -07001925
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001926 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927
Nathan Haroldf180aac2018-06-01 18:43:55 -07001928 List<CellInfo> info = getAllCellInfo(callingPackage);
1929 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930
Nathan Haroldf180aac2018-06-01 18:43:55 -07001931 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1932 for (CellInfo ci : info) {
1933 if (ci instanceof CellInfoGsm) {
1934 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1935 } else if (ci instanceof CellInfoWcdma) {
1936 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001939 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941
1942
1943 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001944 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001945 mPhone.getContext().getSystemService(AppOpsManager.class)
1946 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001947 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001948 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001949 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 }
1951
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001952 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001953 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001954 final long identity = Binder.clearCallingIdentity();
1955 try {
1956 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1957 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001958 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1959 CMD_GET_ALL_CELL_INFO,
1960 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001961 if (info != null) cellInfos.addAll(info);
1962 }
1963 return cellInfos;
1964 } finally {
1965 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967 }
1968
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001969 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001971 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001972 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001973
1974 final long identity = Binder.clearCallingIdentity();
1975 try {
1976 mPhone.setCellInfoListRate(rateInMillis, workSource);
1977 } finally {
1978 Binder.restoreCallingIdentity(identity);
1979 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 }
1981
Shishir Agrawala9f32182016-04-12 12:00:16 -07001982 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001983 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001984 Phone phone = PhoneFactory.getPhone(slotIndex);
1985 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001986 return null;
1987 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001988 int subId = phone.getSubId();
1989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1990 mApp, subId, callingPackage, "getImeiForSlot")) {
1991 return null;
1992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001993
1994 final long identity = Binder.clearCallingIdentity();
1995 try {
1996 return phone.getImei();
1997 } finally {
1998 Binder.restoreCallingIdentity(identity);
1999 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002000 }
2001
2002 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002003 public String getTypeAllocationCodeForSlot(int slotIndex) {
2004 Phone phone = PhoneFactory.getPhone(slotIndex);
2005 String tac = null;
2006 if (phone != null) {
2007 String imei = phone.getImei();
2008 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2009 }
2010 return tac;
2011 }
2012
2013 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002014 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002015 Phone phone = PhoneFactory.getPhone(slotIndex);
2016 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002017 return null;
2018 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002019 int subId = phone.getSubId();
2020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2021 mApp, subId, callingPackage, "getMeidForSlot")) {
2022 return null;
2023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024
2025 final long identity = Binder.clearCallingIdentity();
2026 try {
2027 return phone.getMeid();
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
2030 }
Jack Yu2af8d712017-03-15 17:14:14 -07002031 }
2032
2033 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002034 public String getManufacturerCodeForSlot(int slotIndex) {
2035 Phone phone = PhoneFactory.getPhone(slotIndex);
2036 String manufacturerCode = null;
2037 if (phone != null) {
2038 String meid = phone.getMeid();
2039 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2040 }
2041 return manufacturerCode;
2042 }
2043
2044 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002045 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002046 Phone phone = PhoneFactory.getPhone(slotIndex);
2047 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002048 return null;
2049 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002050 int subId = phone.getSubId();
2051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2052 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2053 return null;
2054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002055
2056 final long identity = Binder.clearCallingIdentity();
2057 try {
2058 return phone.getDeviceSvn();
2059 } finally {
2060 Binder.restoreCallingIdentity(identity);
2061 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002062 }
2063
fionaxu43304da2017-11-27 22:51:16 -08002064 @Override
2065 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002066 final long identity = Binder.clearCallingIdentity();
2067 try {
2068 final Phone phone = getPhone(subId);
2069 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2070 } finally {
2071 Binder.restoreCallingIdentity(identity);
2072 }
fionaxu43304da2017-11-27 22:51:16 -08002073 }
2074
2075 @Override
2076 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 final Phone phone = getPhone(subId);
2080 return phone == null ? null : phone.getCarrierName();
2081 } finally {
2082 Binder.restoreCallingIdentity(identity);
2083 }
fionaxu43304da2017-11-27 22:51:16 -08002084 }
2085
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 //
2087 // Internal helper methods.
2088 //
2089
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002090 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2092 *
2093 * @throws SecurityException if the caller does not have the required permission
2094 */
2095 private void enforceModifyPermission() {
2096 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2097 }
2098
2099 /**
2100 * Make sure the caller has the CALL_PHONE permission.
2101 *
2102 * @throws SecurityException if the caller does not have the required permission
2103 */
2104 private void enforceCallPermission() {
2105 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2106 }
2107
Stuart Scott8eef64f2015-04-08 15:13:54 -07002108 private void enforceConnectivityInternalPermission() {
2109 mApp.enforceCallingOrSelfPermission(
2110 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2111 "ConnectivityService");
2112 }
2113
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 private String createTelUrl(String number) {
2115 if (TextUtils.isEmpty(number)) {
2116 return null;
2117 }
2118
Jake Hambye994d462014-02-03 13:10:13 -08002119 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 }
2121
Ihab Awadf9e92732013-12-05 18:02:52 -08002122 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2124 }
2125
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002126 private static void logv(String msg) {
2127 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2128 }
2129
Ihab Awadf9e92732013-12-05 18:02:52 -08002130 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002131 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2132 }
2133
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002134 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002136 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002137 }
2138
Sanket Padawe356d7632015-06-22 14:03:32 -07002139 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002140 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002141 final long identity = Binder.clearCallingIdentity();
2142 try {
2143 final Phone phone = PhoneFactory.getPhone(slotIndex);
2144 if (phone == null) {
2145 return PhoneConstants.PHONE_TYPE_NONE;
2146 } else {
2147 return phone.getPhoneType();
2148 }
2149 } finally {
2150 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 }
2153
2154 /**
2155 * Returns the CDMA ERI icon index to display
2156 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002157 @Override
2158 public int getCdmaEriIconIndex(String callingPackage) {
2159 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002160 }
2161
Sanket Padawe356d7632015-06-22 14:03:32 -07002162 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002163 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002165 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002166 return -1;
2167 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002168
2169 final long identity = Binder.clearCallingIdentity();
2170 try {
2171 final Phone phone = getPhone(subId);
2172 if (phone != null) {
2173 return phone.getCdmaEriIconIndex();
2174 } else {
2175 return -1;
2176 }
2177 } finally {
2178 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 }
2181
2182 /**
2183 * Returns the CDMA ERI icon mode,
2184 * 0 - ON
2185 * 1 - FLASHING
2186 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002187 @Override
2188 public int getCdmaEriIconMode(String callingPackage) {
2189 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002190 }
2191
Sanket Padawe356d7632015-06-22 14:03:32 -07002192 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002193 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002195 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002196 return -1;
2197 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002198
2199 final long identity = Binder.clearCallingIdentity();
2200 try {
2201 final Phone phone = getPhone(subId);
2202 if (phone != null) {
2203 return phone.getCdmaEriIconMode();
2204 } else {
2205 return -1;
2206 }
2207 } finally {
2208 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
2212 /**
2213 * Returns the CDMA ERI text,
2214 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002215 @Override
2216 public String getCdmaEriText(String callingPackage) {
2217 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002218 }
2219
Sanket Padawe356d7632015-06-22 14:03:32 -07002220 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002221 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002223 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002224 return null;
2225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226
2227 final long identity = Binder.clearCallingIdentity();
2228 try {
2229 final Phone phone = getPhone(subId);
2230 if (phone != null) {
2231 return phone.getCdmaEriText();
2232 } else {
2233 return null;
2234 }
2235 } finally {
2236 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 }
2239
2240 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002241 * Returns the CDMA MDN.
2242 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002243 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002244 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2246 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247
2248 final long identity = Binder.clearCallingIdentity();
2249 try {
2250 final Phone phone = getPhone(subId);
2251 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2252 return phone.getLine1Number();
2253 } else {
2254 return null;
2255 }
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002258 }
2259 }
2260
2261 /**
2262 * Returns the CDMA MIN.
2263 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002264 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002265 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2267 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268
2269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 final Phone phone = getPhone(subId);
2272 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2273 return phone.getCdmaMin();
2274 } else {
2275 return null;
2276 }
2277 } finally {
2278 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002279 }
2280 }
2281
2282 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 * Returns true if CDMA provisioning needs to run.
2284 */
2285 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286 final long identity = Binder.clearCallingIdentity();
2287 try {
2288 return mPhone.needsOtaServiceProvisioning();
2289 } finally {
2290 Binder.restoreCallingIdentity(identity);
2291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 }
2293
2294 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002295 * Sets the voice mail number of a given subId.
2296 */
2297 @Override
2298 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002299 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002300
2301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2304 new Pair<String, String>(alphaTag, number), new Integer(subId));
2305 return success;
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
2308 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002309 }
2310
Ta-wei Yen87c49842016-05-13 21:19:52 -07002311 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002312 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2314 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2315 if (!TextUtils.equals(callingPackage, systemDialer)) {
2316 throw new SecurityException("caller must be system dialer");
2317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002318
2319 final long identity = Binder.clearCallingIdentity();
2320 try {
2321 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2322 if (phoneAccountHandle == null) {
2323 return null;
2324 }
2325 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2326 } finally {
2327 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002328 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002329 }
2330
2331 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002332 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002333 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002335 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002336 return null;
2337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 return RemoteVvmTaskManager
2342 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
2345 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002346 }
2347
2348 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002349 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2350 VisualVoicemailSmsFilterSettings settings) {
2351 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352
2353 final long identity = Binder.clearCallingIdentity();
2354 try {
2355 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2356 mPhone.getContext(), callingPackage, subId, settings);
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
2359 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002360 }
2361
2362 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002363 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2364 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002365
2366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2369 mPhone.getContext(), callingPackage, subId);
2370 } finally {
2371 Binder.restoreCallingIdentity(identity);
2372 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002373 }
2374
2375 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002376 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2377 String callingPackage, int subId) {
2378 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2383 mPhone.getContext(), callingPackage, subId);
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
2386 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002387 }
2388
2389 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002390 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002391 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002392
2393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2396 mPhone.getContext(), subId);
2397 } finally {
2398 Binder.restoreCallingIdentity(identity);
2399 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002400 }
2401
2402 @Override
2403 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2404 String number, int port, String text, PendingIntent sentIntent) {
2405 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002406 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002407 enforceSendSmsPermission();
2408 // Make the calls as the phone process.
2409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2412 if (port == 0) {
2413 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2414 sentIntent, null, false);
2415 } else {
2416 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2417 smsManager.sendDataMessageWithSelfPermissions(number, null,
2418 (short) port, data, sentIntent, null);
2419 }
2420 } finally {
2421 Binder.restoreCallingIdentity(identity);
2422 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002423 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002424 /**
fionaxu0152e512016-11-14 13:36:14 -08002425 * Sets the voice activation state of a given subId.
2426 */
2427 @Override
2428 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2430 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431
2432 final long identity = Binder.clearCallingIdentity();
2433 try {
2434 final Phone phone = getPhone(subId);
2435 if (phone != null) {
2436 phone.setVoiceActivationState(activationState);
2437 } else {
2438 loge("setVoiceActivationState fails with invalid subId: " + subId);
2439 }
2440 } finally {
2441 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002442 }
2443 }
2444
2445 /**
2446 * Sets the data activation state of a given subId.
2447 */
2448 @Override
2449 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2451 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 final Phone phone = getPhone(subId);
2456 if (phone != null) {
2457 phone.setDataActivationState(activationState);
2458 } else {
2459 loge("setVoiceActivationState fails with invalid subId: " + subId);
2460 }
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002463 }
2464 }
2465
2466 /**
2467 * Returns the voice activation state of a given subId.
2468 */
2469 @Override
2470 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002471 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472
fionaxu0152e512016-11-14 13:36:14 -08002473 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 if (phone != null) {
2477 return phone.getVoiceActivationState();
2478 } else {
2479 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2480 }
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002483 }
2484 }
2485
2486 /**
2487 * Returns the data activation state of a given subId.
2488 */
2489 @Override
2490 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002491 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492
fionaxu0152e512016-11-14 13:36:14 -08002493 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494 final long identity = Binder.clearCallingIdentity();
2495 try {
2496 if (phone != null) {
2497 return phone.getDataActivationState();
2498 } else {
2499 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2500 }
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002503 }
2504 }
2505
2506 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 * Returns the unread count of voicemails
2508 */
2509 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002510 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002511 }
2512
2513 /**
2514 * Returns the unread count of voicemails for a subId
2515 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002517 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518 final long identity = Binder.clearCallingIdentity();
2519 try {
2520 final Phone phone = getPhone(subId);
2521 if (phone != null) {
2522 return phone.getVoiceMessageCount();
2523 } else {
2524 return 0;
2525 }
2526 } finally {
2527 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 }
2530
2531 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002532 * returns true, if the device is in a state where both voice and data
2533 * are supported simultaneously. This can change based on location or network condition.
2534 */
2535 @Override
2536 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 final Phone phone = getPhone(subId);
2540 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
2543 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002544 }
2545
2546 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002547 * Send the dialer code if called from the current default dialer or the caller has
2548 * carrier privilege.
2549 * @param inputCode The dialer code to send
2550 */
2551 @Override
2552 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2553 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2554 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2555 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002556 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2557 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559
2560 final long identity = Binder.clearCallingIdentity();
2561 try {
2562 mPhone.sendDialerSpecialCode(inputCode);
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
2565 }
fionaxu235cc5e2017-03-06 22:25:57 -08002566 }
2567
2568 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002569 * Returns the data network type.
2570 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 *
2572 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2573 */
2574 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002575 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576 final long identity = Binder.clearCallingIdentity();
2577 try {
2578 final Phone phone = getPhone(getDefaultSubscription());
2579 if (phone != null) {
2580 return phone.getServiceState().getDataNetworkType();
2581 } else {
2582 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2583 }
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002586 }
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Pengquan Menga1bb6272018-09-06 09:59:22 -07002589 @Override
2590 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002591 if (!isActiveSubscription(subId)) {
2592 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2593 }
2594
Pengquan Menga1bb6272018-09-06 09:59:22 -07002595 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2596 }
2597
Wink Saville36469e72014-06-11 15:17:00 -07002598 /**
2599 * Returns the network type for a subId
2600 */
2601 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002602 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002604 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002605 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2606 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 final Phone phone = getPhone(subId);
2611 if (phone != null) {
2612 return phone.getServiceState().getDataNetworkType();
2613 } else {
2614 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 }
2620
2621 /**
2622 * Returns the data network type
2623 */
2624 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002625 public int getDataNetworkType(String callingPackage) {
2626 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002627 }
2628
2629 /**
2630 * Returns the data network type for a subId
2631 */
2632 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002633 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002635 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002636 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2637 }
2638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 final Phone phone = getPhone(subId);
2642 if (phone != null) {
2643 return phone.getServiceState().getDataNetworkType();
2644 } else {
2645 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2646 }
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 }
2651
2652 /**
Wink Saville36469e72014-06-11 15:17:00 -07002653 * Returns the Voice network type for a subId
2654 */
2655 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002656 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002658 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002659 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2660 }
2661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 if (phone != null) {
2666 return phone.getServiceState().getVoiceNetworkType();
2667 } else {
2668 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 }
2674
2675 /**
2676 * @return true if a ICC card is present
2677 */
2678 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002679 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002680 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2681 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002682 }
2683
2684 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002685 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002686 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002687 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002688 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 final Phone phone = PhoneFactory.getPhone(slotIndex);
2692 if (phone != null) {
2693 return phone.getIccCard().hasIccCard();
2694 } else {
2695 return false;
2696 }
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 }
2701
2702 /**
2703 * Return if the current radio is LTE on CDMA. This
2704 * is a tri-state return value as for a period of time
2705 * the mode may be unknown.
2706 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002707 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002709 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002711 @Override
2712 public int getLteOnCdmaMode(String callingPackage) {
2713 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002714 }
2715
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002717 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002719 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002720 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2721 }
2722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 final Phone phone = getPhone(subId);
2726 if (phone == null) {
2727 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2728 } else {
2729 return phone.getLteOnCdmaMode();
2730 }
2731 } finally {
2732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002733 }
Wink Saville36469e72014-06-11 15:17:00 -07002734 }
2735
2736 public void setPhone(Phone phone) {
2737 mPhone = phone;
2738 }
2739
2740 /**
2741 * {@hide}
2742 * Returns Default subId, 0 in the case of single standby.
2743 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002744 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002745 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002746 }
2747
Shishir Agrawala9f32182016-04-12 12:00:16 -07002748 private int getSlotForDefaultSubscription() {
2749 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2750 }
2751
Wink Savilleb564aae2014-10-23 10:18:09 -07002752 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002753 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002755
Pengquan Menge92a50d2018-09-21 15:54:48 -07002756 private boolean isActiveSubscription(int subId) {
2757 return mSubscriptionController.isActiveSubId(subId);
2758 }
2759
Ihab Awadf2177b72013-11-25 13:33:23 -08002760 /**
2761 * @see android.telephony.TelephonyManager.WifiCallingChoices
2762 */
2763 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2767 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2768 getWhenToMakeWifiCallsDefaultPreference());
2769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002772 }
2773
2774 /**
2775 * @see android.telephony.TelephonyManager.WifiCallingChoices
2776 */
2777 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2781 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2782 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2783 } finally {
2784 Binder.restoreCallingIdentity(identity);
2785 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002786 }
2787
Sailesh Nepald1e68152013-12-12 19:08:02 -08002788 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002789 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002790 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002791 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002792
Shishir Agrawal566b7612013-10-28 14:41:00 -07002793 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002794 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2795 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2797 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800 final long identity = Binder.clearCallingIdentity();
2801 try {
2802 if (TextUtils.equals(ISDR_AID, aid)) {
2803 // Only allows LPA to open logical channel to ISD-R.
2804 ComponentInfo bestComponent =
2805 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2806 if (bestComponent == null
2807 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2808 loge("The calling package is not allowed to access ISD-R.");
2809 throw new SecurityException(
2810 "The calling package is not allowed to access ISD-R.");
2811 }
Derek Tan740e1672017-06-27 14:56:27 -07002812 }
Derek Tan740e1672017-06-27 14:56:27 -07002813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 if (DBG) {
2815 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2816 }
2817 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2818 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2819 if (DBG) log("iccOpenLogicalChannel: " + response);
2820 return response;
2821 } finally {
2822 Binder.restoreCallingIdentity(identity);
2823 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002824 }
2825
2826 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002827 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2829 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2834 if (channel < 0) {
2835 return false;
2836 }
2837 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2838 if (DBG) log("iccCloseLogicalChannel: " + success);
2839 return success;
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002842 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002843 }
2844
2845 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002846 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002847 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2849 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 if (DBG) {
2854 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2855 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2856 + p3 + " data=" + data);
2857 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859 if (channel < 0) {
2860 return "";
2861 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2864 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2865 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 // Append the returned status code to the end of the response payload.
2868 String s = Integer.toHexString(
2869 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2870 if (response.payload != null) {
2871 s = IccUtils.bytesToHexString(response.payload) + s;
2872 }
2873 return s;
2874 } finally {
2875 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002876 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002877 }
Jake Hambye994d462014-02-03 13:10:13 -08002878
Evan Charltonc66da362014-05-16 14:06:40 -07002879 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002880 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2881 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2883 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2889 && TextUtils.equals(ISDR_AID, data)) {
2890 // Only allows LPA to select ISD-R.
2891 ComponentInfo bestComponent =
2892 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2893 if (bestComponent == null
2894 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2895 loge("The calling package is not allowed to select ISD-R.");
2896 throw new SecurityException(
2897 "The calling package is not allowed to select ISD-R.");
2898 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002899 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 if (DBG) {
2902 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2903 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2904 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2907 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2908 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 // Append the returned status code to the end of the response payload.
2911 String s = Integer.toHexString(
2912 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2913 if (response.payload != null) {
2914 s = IccUtils.bytesToHexString(response.payload) + s;
2915 }
2916 return s;
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002919 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002920 }
2921
2922 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002923 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002924 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2926 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 if (DBG) {
2931 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2932 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2933 }
2934
2935 IccIoResult response =
2936 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2937 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2938 subId);
2939
2940 if (DBG) {
2941 log("Exchange SIM_IO [R]" + response);
2942 }
2943
2944 byte[] result = null;
2945 int length = 2;
2946 if (response.payload != null) {
2947 length = 2 + response.payload.length;
2948 result = new byte[length];
2949 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2950 } else {
2951 result = new byte[length];
2952 }
2953
2954 result[length - 1] = (byte) response.sw2;
2955 result[length - 2] = (byte) response.sw1;
2956 return result;
2957 } finally {
2958 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002959 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002960 }
2961
Nathan Haroldb3014052017-01-25 15:57:32 -08002962 /**
2963 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2964 * on a particular subscription
2965 */
sqianb6e41952018-03-12 14:54:01 -07002966 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2968 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2969 return null;
2970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 if (appType != TelephonyManager.APPTYPE_USIM
2975 && appType != TelephonyManager.APPTYPE_SIM) {
2976 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2977 return null;
2978 }
2979 Object response = sendRequest(
2980 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2981 if (response instanceof String[]) {
2982 return (String[]) response;
2983 }
2984 // Response is an Exception of some kind,
2985 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08002986 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 } finally {
2988 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002989 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002990 }
2991
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002992 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002993 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2995 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3000 if (response.payload == null) {
3001 return "";
3002 }
Evan Charltonc66da362014-05-16 14:06:40 -07003003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003004 // Append the returned status code to the end of the response payload.
3005 String s = Integer.toHexString(
3006 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3007 s = IccUtils.bytesToHexString(response.payload) + s;
3008 return s;
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
Evan Charltonc66da362014-05-16 14:06:40 -07003012 }
3013
Jake Hambye994d462014-02-03 13:10:13 -08003014 /**
3015 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3016 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3017 *
3018 * @param itemID the ID of the item to read
3019 * @return the NV item as a String, or null on error.
3020 */
3021 @Override
3022 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003023 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3025 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003030 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3032 return value;
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
3035 }
Jake Hambye994d462014-02-03 13:10:13 -08003036 }
3037
3038 /**
3039 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3040 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3041 *
3042 * @param itemID the ID of the item to read
3043 * @param itemValue the value to write, as a String
3044 * @return true on success; false on any failure
3045 */
3046 @Override
3047 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003048 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3050 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
3054 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3055 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003056 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003057 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3058 return success;
3059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
Jake Hambye994d462014-02-03 13:10:13 -08003062 }
3063
3064 /**
3065 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3066 * Used for device configuration by some CDMA operators.
3067 *
3068 * @param preferredRoamingList byte array containing the new PRL
3069 * @return true on success; false on any failure
3070 */
3071 @Override
3072 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3074 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075
3076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3079 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3080 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3081 return success;
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
3084 }
Jake Hambye994d462014-02-03 13:10:13 -08003085 }
3086
3087 /**
3088 * Perform the specified type of NV config reset.
3089 * Used for device configuration by some CDMA operators.
3090 *
3091 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3092 * @return true on success; false on any failure
3093 */
3094 @Override
3095 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3097 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003098
3099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 if (DBG) log("nvResetConfig: type " + resetType);
3102 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3103 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3104 return success;
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
Jake Hambye994d462014-02-03 13:10:13 -08003108 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003109
Svet Ganovb320e182015-04-16 12:30:10 -07003110 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003112 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003113 return new String[0];
3114 }
3115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 return mPhone.getPcscfAddress(apnType);
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
Wink Saville36469e72014-06-11 15:17:00 -07003122 }
3123
Brad Ebinger51f743a2017-01-23 13:50:20 -08003124 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003125 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3126 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003127 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003128 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003129 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130
3131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 PhoneFactory.getImsResolver().enableIms(slotId);
3134 } finally {
3135 Binder.restoreCallingIdentity(identity);
3136 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003137 }
3138
3139 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003140 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3141 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003142 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003143 public void disableIms(int slotId) {
3144 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145
3146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 PhoneFactory.getImsResolver().disableIms(slotId);
3149 } finally {
3150 Binder.restoreCallingIdentity(identity);
3151 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003152 }
3153
3154 /**
3155 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3156 * feature or {@link null} if the service is not available. If the feature is available, the
3157 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3158 */
3159 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003160 IImsServiceFeatureCallback callback) {
3161 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162
3163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
3168 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003169 }
3170
3171 /**
3172 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3173 * feature during emergency calling or {@link null} if the service is not available. If the
3174 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3175 * listener for feature updates.
3176 */
3177 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3178 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179
3180 final long identity = Binder.clearCallingIdentity();
3181 try {
3182 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003186 }
3187
Brad Ebinger5f64b052017-12-14 14:26:15 -08003188 /**
3189 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3190 * specified.
3191 */
3192 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3193 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003201 }
3202
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003203 /**
3204 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3205 * specified.
3206 */
3207 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3208 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003216 }
3217
Brad Ebinger884c07b2018-02-15 16:17:40 -08003218 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003219 * Sets the ImsService Package Name that Telephony will bind to.
3220 *
3221 * @param slotId the slot ID that the ImsService should bind for.
3222 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3223 * ImsService is the device default ImsService.
3224 * @param packageName The package name of the application that contains the ImsService to bind
3225 * to.
3226 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3227 * @hide
3228 */
3229 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003230 int[] subIds = SubscriptionManager.getSubId(slotId);
3231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3232 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3233 "setImsService");
3234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3238 isCarrierImsService, packageName);
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003242 }
3243
3244 /**
3245 * Return the ImsService configuration.
3246 *
3247 * @param slotId The slot that the ImsService is associated with.
3248 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3249 * the device default.
3250 * @return the package name of the ImsService configuration.
3251 */
3252 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003253 int[] subIds = SubscriptionManager.getSubId(slotId);
3254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3255 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3256 "getImsService");
3257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3261 isCarrierImsService);
3262 } finally {
3263 Binder.restoreCallingIdentity(identity);
3264 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003265 }
3266
Wink Saville36469e72014-06-11 15:17:00 -07003267 public void setImsRegistrationState(boolean registered) {
3268 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269
3270 final long identity = Binder.clearCallingIdentity();
3271 try {
3272 mPhone.setImsRegistrationState(registered);
3273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
Wink Saville36469e72014-06-11 15:17:00 -07003276 }
3277
3278 /**
Stuart Scott54788802015-03-30 13:18:01 -07003279 * Set the network selection mode to automatic.
3280 *
3281 */
3282 @Override
3283 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3285 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286
Pengquan Menge92a50d2018-09-21 15:54:48 -07003287 if (!isActiveSubscription(subId)) {
3288 return;
3289 }
3290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3294 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3295 } finally {
3296 Binder.restoreCallingIdentity(identity);
3297 }
Stuart Scott54788802015-03-30 13:18:01 -07003298 }
3299
Pengquan Mengea84e042018-09-20 14:57:26 -07003300 /**
3301 * Ask the radio to connect to the input network and change selection mode to manual.
3302 *
3303 * @param subId the id of the subscription.
3304 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3305 * the operator to attach to.
3306 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3307 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3308 * normal network selection next time.
3309 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003310 */
3311 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003312 public boolean setNetworkSelectionModeManual(
3313 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3315 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003316
3317 if (!isActiveSubscription(subId)) {
3318 return false;
3319 }
3320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003321 final long identity = Binder.clearCallingIdentity();
3322 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003323 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003325 if (DBG) {
3326 log("setNetworkSelectionModeManual: subId: " + subId
3327 + " operator: " + operatorInfo);
3328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003333 }
3334
3335 /**
3336 * Scans for available networks.
3337 */
3338 @Override
3339 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3341 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342
Pengquan Menga1bb6272018-09-06 09:59:22 -07003343 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344 try {
3345 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003346 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 } finally {
3349 Binder.restoreCallingIdentity(identity);
3350 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003351 }
3352
3353 /**
yinxub1bed742017-04-17 11:45:04 -07003354 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003355 *
yinxub1bed742017-04-17 11:45:04 -07003356 * @param subId id of the subscription
3357 * @param request contains the radio access networks with bands/channels to scan
3358 * @param messenger callback messenger for scan results or errors
3359 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003360 * @return the id of the requested scan which can be used to stop the scan.
3361 */
3362 @Override
3363 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3364 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3366 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367
3368 final long identity = Binder.clearCallingIdentity();
3369 try {
3370 return mNetworkScanRequestTracker.startNetworkScan(
3371 request, messenger, binder, getPhone(subId));
3372 } finally {
3373 Binder.restoreCallingIdentity(identity);
3374 }
yinxu504e1392017-04-12 16:03:22 -07003375 }
3376
3377 /**
3378 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003379 *
3380 * @param subId id of the subscription
3381 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003382 */
3383 @Override
3384 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3386 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387
3388 final long identity = Binder.clearCallingIdentity();
3389 try {
3390 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
yinxu504e1392017-04-12 16:03:22 -07003394 }
3395
3396 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003397 * Get the calculated preferred network type.
3398 * Used for debugging incorrect network type.
3399 *
3400 * @return the preferred network type, defined in RILConstants.java.
3401 */
3402 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003403 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003405 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003406 return RILConstants.PREFERRED_NETWORK_MODE;
3407 }
3408
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 // FIXME: need to get SubId from somewhere.
3412 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
Junda Liu84d15a22014-07-02 11:21:04 -07003416 }
3417
3418 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003419 * Get the preferred network type.
3420 * Used for device configuration by some CDMA operators.
3421 *
3422 * @return the preferred network type, defined in RILConstants.java.
3423 */
3424 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003425 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3427 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003428
3429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 if (DBG) log("getPreferredNetworkType");
3432 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3433 int networkType = (result != null ? result[0] : -1);
3434 if (DBG) log("getPreferredNetworkType: " + networkType);
3435 return networkType;
3436 } finally {
3437 Binder.restoreCallingIdentity(identity);
3438 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003439 }
3440
3441 /**
3442 * Set the preferred network type.
3443 * Used for device configuration by some CDMA operators.
3444 *
3445 * @param networkType the preferred network type, defined in RILConstants.java.
3446 * @return true on success; false on any failure.
3447 */
3448 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003449 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3451 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452
3453 final long identity = Binder.clearCallingIdentity();
3454 try {
3455 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3456 Boolean success = (Boolean) sendRequest(
3457 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3458 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3459 if (success) {
3460 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3461 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3462 }
3463 return success;
3464 } finally {
3465 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003466 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003467 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003468
3469 /**
Junda Liu475951f2014-11-07 16:45:03 -08003470 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3471 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3472 * tethering.
3473 *
3474 * @return 0: Not required. 1: required. 2: Not set.
3475 * @hide
3476 */
3477 @Override
3478 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003479 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3484 Settings.Global.TETHER_DUN_REQUIRED, 2);
3485 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3486 // config_tether_apndata.
3487 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3488 dunRequired = 1;
3489 }
3490 return dunRequired;
3491 } finally {
3492 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003493 }
Junda Liu475951f2014-11-07 16:45:03 -08003494 }
3495
3496 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003497 * Set mobile data enabled
3498 * Used by the user through settings etc to turn on/off mobile data
3499 *
3500 * @param enable {@code true} turn turn data on, else {@code false}
3501 */
3502 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003503 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3505 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 int phoneId = mSubscriptionController.getPhoneId(subId);
3510 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3511 Phone phone = PhoneFactory.getPhone(phoneId);
3512 if (phone != null) {
3513 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3514 phone.setUserDataEnabled(enable);
3515 } else {
3516 loge("setUserDataEnabled: no phone for subId=" + subId);
3517 }
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003520 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003521 }
3522
3523 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003524 * Get the user enabled state of Mobile Data.
3525 *
3526 * TODO: remove and use isUserDataEnabled.
3527 * This can't be removed now because some vendor codes
3528 * calls through ITelephony directly while they should
3529 * use TelephonyManager.
3530 *
3531 * @return true on enabled
3532 */
3533 @Override
3534 public boolean getDataEnabled(int subId) {
3535 return isUserDataEnabled(subId);
3536 }
3537
3538 /**
3539 * Get whether mobile data is enabled per user setting.
3540 *
3541 * There are other factors deciding whether mobile data is actually enabled, but they are
3542 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003543 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003544 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003545 *
3546 * @return {@code true} if data is enabled else {@code false}
3547 */
3548 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003549 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003550 try {
3551 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3552 null);
3553 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3555 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 int phoneId = mSubscriptionController.getPhoneId(subId);
3561 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3562 Phone phone = PhoneFactory.getPhone(phoneId);
3563 if (phone != null) {
3564 boolean retVal = phone.isUserDataEnabled();
3565 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3566 return retVal;
3567 } else {
3568 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3569 return false;
3570 }
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003573 }
3574 }
3575
3576 /**
3577 * Get whether mobile data is enabled.
3578 *
3579 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3580 * whether mobile data is actually enabled.
3581 *
3582 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3583 *
3584 * @return {@code true} if data is enabled else {@code false}
3585 */
3586 @Override
3587 public boolean isDataEnabled(int subId) {
3588 try {
3589 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3590 null);
3591 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3593 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 int phoneId = mSubscriptionController.getPhoneId(subId);
3599 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3600 Phone phone = PhoneFactory.getPhone(phoneId);
3601 if (phone != null) {
3602 boolean retVal = phone.isDataEnabled();
3603 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3604 return retVal;
3605 } else {
3606 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3607 return false;
3608 }
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003611 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003612 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003613
3614 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003615 public int getCarrierPrivilegeStatus(int subId) {
3616 final Phone phone = getPhone(subId);
3617 if (phone == null) {
3618 loge("getCarrierPrivilegeStatus: Invalid subId");
3619 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3620 }
3621 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003622 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003623 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003624 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3625 }
3626 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003627 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003628 }
Junda Liu29340342014-07-10 15:23:27 -07003629
3630 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003631 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3632 final Phone phone = getPhone(subId);
3633 if (phone == null) {
3634 loge("getCarrierPrivilegeStatus: Invalid subId");
3635 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3636 }
3637 UiccProfile profile =
3638 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3639 if (profile == null) {
3640 loge("getCarrierPrivilegeStatus: No UICC");
3641 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3642 }
3643 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3644 }
3645
3646 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003647 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003648 if (TextUtils.isEmpty(pkgName))
3649 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003650 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003651 if (card == null) {
3652 loge("checkCarrierPrivilegesForPackage: No UICC");
3653 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3654 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003655 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3656 }
3657
3658 @Override
3659 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003660 if (TextUtils.isEmpty(pkgName))
3661 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003662 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3663 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3664 UiccCard card = UiccController.getInstance().getUiccCard(i);
3665 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003666 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003667 continue;
3668 }
3669
3670 result = card.getCarrierPrivilegeStatus(
3671 mPhone.getContext().getPackageManager(), pkgName);
3672 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3673 break;
3674 }
3675 }
3676
3677 return result;
Junda Liu29340342014-07-10 15:23:27 -07003678 }
Derek Tan89e89d42014-07-08 17:00:10 -07003679
3680 @Override
Junda Liue64de782015-04-16 17:19:16 -07003681 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3682 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3683 loge("phoneId " + phoneId + " is not valid.");
3684 return null;
3685 }
3686 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003687 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003688 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003689 return null ;
3690 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003691 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003692 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003693 }
3694
Amith Yamasani6e118872016-02-19 12:53:51 -08003695 @Override
3696 public List<String> getPackagesWithCarrierPrivileges() {
3697 PackageManager pm = mPhone.getContext().getPackageManager();
3698 List<String> privilegedPackages = new ArrayList<>();
3699 List<PackageInfo> packages = null;
3700 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3701 UiccCard card = UiccController.getInstance().getUiccCard(i);
3702 if (card == null) {
3703 // No UICC in that slot.
3704 continue;
3705 }
3706 if (card.hasCarrierPrivilegeRules()) {
3707 if (packages == null) {
3708 // Only check packages in user 0 for now
3709 packages = pm.getInstalledPackagesAsUser(
3710 PackageManager.MATCH_DISABLED_COMPONENTS
3711 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3712 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3713 }
3714 for (int p = packages.size() - 1; p >= 0; p--) {
3715 PackageInfo pkgInfo = packages.get(p);
3716 if (pkgInfo != null && pkgInfo.packageName != null
3717 && card.getCarrierPrivilegeStatus(pkgInfo)
3718 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3719 privilegedPackages.add(pkgInfo.packageName);
3720 }
3721 }
3722 }
3723 }
3724 return privilegedPackages;
3725 }
3726
Wink Savilleb564aae2014-10-23 10:18:09 -07003727 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003728 final Phone phone = getPhone(subId);
3729 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003730 if (card == null) {
3731 loge("getIccId: No UICC");
3732 return null;
3733 }
3734 String iccId = card.getIccId();
3735 if (TextUtils.isEmpty(iccId)) {
3736 loge("getIccId: ICC ID is null or empty.");
3737 return null;
3738 }
3739 return iccId;
3740 }
3741
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003742 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003743 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3744 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003745 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3746 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 final String iccId = getIccId(subId);
3751 final Phone phone = getPhone(subId);
3752 if (phone == null) {
3753 return false;
3754 }
3755 final String subscriberId = phone.getSubscriberId();
3756
3757 if (DBG_MERGE) {
3758 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3759 + subscriberId + " to " + number);
3760 }
3761
3762 if (TextUtils.isEmpty(iccId)) {
3763 return false;
3764 }
3765
3766 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3767
3768 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3769 if (alphaTag == null) {
3770 editor.remove(alphaTagPrefKey);
3771 } else {
3772 editor.putString(alphaTagPrefKey, alphaTag);
3773 }
3774
3775 // Record both the line number and IMSI for this ICCID, since we need to
3776 // track all merged IMSIs based on line number
3777 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3778 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3779 if (number == null) {
3780 editor.remove(numberPrefKey);
3781 editor.remove(subscriberPrefKey);
3782 } else {
3783 editor.putString(numberPrefKey, number);
3784 editor.putString(subscriberPrefKey, subscriberId);
3785 }
3786
3787 editor.commit();
3788 return true;
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003791 }
Derek Tan7226c842014-07-02 17:42:23 -07003792 }
3793
3794 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003795 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003796 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003798 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003799 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003800 return null;
3801 }
Derek Tan97ebb422014-09-05 16:55:38 -07003802
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 final long identity = Binder.clearCallingIdentity();
3804 try {
3805 String iccId = getIccId(subId);
3806 if (iccId != null) {
3807 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3808 if (DBG_MERGE) {
3809 log("getLine1NumberForDisplay returning "
3810 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3811 }
3812 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3815 return null;
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003818 }
Derek Tan7226c842014-07-02 17:42:23 -07003819 }
3820
3821 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003822 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003824 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003825 return null;
3826 }
Derek Tan97ebb422014-09-05 16:55:38 -07003827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 String iccId = getIccId(subId);
3831 if (iccId != null) {
3832 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3833 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3834 }
3835 return null;
3836 } finally {
3837 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003838 }
Derek Tan7226c842014-07-02 17:42:23 -07003839 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003840
3841 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003842 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003843 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3844 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003846 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3847 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003848 return null;
3849 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003850
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003851 final long identity = Binder.clearCallingIdentity();
3852 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853 final Context context = mPhone.getContext();
3854 final TelephonyManager tele = TelephonyManager.from(context);
3855 final SubscriptionManager sub = SubscriptionManager.from(context);
3856
3857 // Figure out what subscribers are currently active
3858 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3859 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3860 // the process, where TelephonyManager was instantiated.
3861 // Otherwise AppOps check will fail.
3862
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003863 final int[] subIds = sub.getActiveSubscriptionIdList();
3864 for (int subId : subIds) {
3865 activeSubscriberIds.add(tele.getSubscriberId(subId));
3866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867
3868 // First pass, find a number override for an active subscriber
3869 String mergeNumber = null;
3870 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3871 for (String key : prefs.keySet()) {
3872 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3873 final String subscriberId = (String) prefs.get(key);
3874 if (activeSubscriberIds.contains(subscriberId)) {
3875 final String iccId = key.substring(
3876 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3877 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3878 mergeNumber = (String) prefs.get(numberKey);
3879 if (DBG_MERGE) {
3880 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3881 + " for active subscriber " + subscriberId);
3882 }
3883 if (!TextUtils.isEmpty(mergeNumber)) {
3884 break;
3885 }
3886 }
3887 }
3888 }
3889
3890 // Shortcut when no active merged subscribers
3891 if (TextUtils.isEmpty(mergeNumber)) {
3892 return null;
3893 }
3894
3895 // Second pass, find all subscribers under that line override
3896 final ArraySet<String> result = new ArraySet<>();
3897 for (String key : prefs.keySet()) {
3898 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3899 final String number = (String) prefs.get(key);
3900 if (mergeNumber.equals(number)) {
3901 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3902 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3903 final String subscriberId = (String) prefs.get(subscriberKey);
3904 if (!TextUtils.isEmpty(subscriberId)) {
3905 result.add(subscriberId);
3906 }
3907 }
3908 }
3909 }
3910
3911 final String[] resultArray = result.toArray(new String[result.size()]);
3912 Arrays.sort(resultArray);
3913 if (DBG_MERGE) {
3914 Slog.d(LOG_TAG,
3915 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3916 }
3917 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003918 } finally {
3919 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003920 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003921 }
3922
3923 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003924 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003925 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3926 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
3928 final long identity = Binder.clearCallingIdentity();
3929 try {
3930 final Phone phone = getPhone(subId);
3931 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3932 } finally {
3933 Binder.restoreCallingIdentity(identity);
3934 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003935 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003936
3937 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003938 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003939 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3940 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003941 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942
3943 final long identity = Binder.clearCallingIdentity();
3944 try {
3945 final Phone phone = getPhone(subId);
3946 if (phone == null) {
3947 return false;
3948 }
3949 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3950 cdmaNonRoamingList);
3951 } finally {
3952 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003953 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003954 }
3955
3956 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003957 @Deprecated
3958 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3959 enforceModifyPermission();
3960
3961 int returnValue = 0;
3962 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07003963 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003964 if(result.exception == null) {
3965 if (result.result != null) {
3966 byte[] responseData = (byte[])(result.result);
3967 if(responseData.length > oemResp.length) {
3968 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3969 responseData.length + "bytes. Buffer Size is " +
3970 oemResp.length + "bytes.");
3971 }
3972 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3973 returnValue = responseData.length;
3974 }
3975 } else {
3976 CommandException ex = (CommandException) result.exception;
3977 returnValue = ex.getCommandError().ordinal();
3978 if(returnValue > 0) returnValue *= -1;
3979 }
3980 } catch (RuntimeException e) {
3981 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3982 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3983 if(returnValue > 0) returnValue *= -1;
3984 }
3985
3986 return returnValue;
3987 }
3988
3989 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003990 public void setRadioCapability(RadioAccessFamily[] rafs) {
3991 try {
3992 ProxyController.getInstance().setRadioCapability(rafs);
3993 } catch (RuntimeException e) {
3994 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3995 }
3996 }
3997
3998 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003999 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004000 Phone phone = PhoneFactory.getPhone(phoneId);
4001 if (phone == null) {
4002 return RadioAccessFamily.RAF_UNKNOWN;
4003 }
4004 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004006 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004007 return RadioAccessFamily.RAF_UNKNOWN;
4008 }
4009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
4015 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004016 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004017
4018 @Override
4019 public void enableVideoCalling(boolean enable) {
4020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
4027 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004028 }
4029
4030 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004031 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4033 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4034 return false;
4035 }
Svet Ganovb320e182015-04-16 12:30:10 -07004036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 // Check the user preference and the system-level IMS setting. Even if the user has
4040 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4041 // In the long run, we may instead need to check if there exists a connection service
4042 // which can support video calling.
4043 ImsManager imsManager =
4044 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4045 return imsManager.isVtEnabledByPlatform()
4046 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4047 && imsManager.isVtEnabledByUser();
4048 } finally {
4049 Binder.restoreCallingIdentity(identity);
4050 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004051 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004052
Andrew Leea1239f22015-03-02 17:44:07 -08004053 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4056 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4057 return false;
4058 }
4059
4060 final long identity = Binder.clearCallingIdentity();
4061 try {
4062 CarrierConfigManager configManager =
4063 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4064 return configManager.getConfigForSubId(mPhone.getSubId())
4065 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4066 } finally {
4067 Binder.restoreCallingIdentity(identity);
4068 }
Andrew Leea1239f22015-03-02 17:44:07 -08004069 }
4070
4071 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072 public boolean isWorldPhone(int subId, String callingPackage) {
4073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4074 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4075 return false;
4076 }
4077
4078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 CarrierConfigManager configManager =
4081 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4082 return configManager.getConfigForSubId(mPhone.getSubId())
4083 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4084 } finally {
4085 Binder.restoreCallingIdentity(identity);
4086 }
Andrew Leea1239f22015-03-02 17:44:07 -08004087 }
4088
Andrew Lee9431b832015-03-09 18:46:45 -07004089 @Override
4090 public boolean isTtyModeSupported() {
4091 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004092 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004093 }
4094
4095 @Override
4096 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
Andrew Lee9431b832015-03-09 18:46:45 -07004103 }
4104
Hall Liu98187582018-01-22 19:15:32 -08004105 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4109 mPhone.getSubId()).getBoolean(
4110 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4111 boolean isDeviceSupported =
4112 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4113 return isCarrierSupported && isDeviceSupported;
4114 } finally {
4115 Binder.restoreCallingIdentity(identity);
4116 }
Hall Liu98187582018-01-22 19:15:32 -08004117 }
4118
Hall Liu3ad5f012018-04-06 16:23:39 -07004119 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120 final long identity = Binder.clearCallingIdentity();
4121 try {
4122 return isRttSupported() && Settings.Secure.getInt(
4123 mPhone.getContext().getContentResolver(),
4124 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004128 }
4129
Sanket Padawe7310cc72015-01-14 09:53:20 -08004130 /**
4131 * Returns the unique device ID of phone, for example, the IMEI for
4132 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4133 *
4134 * <p>Requires Permission:
4135 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4136 */
4137 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004138 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004139 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004140 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004141 return null;
4142 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004143 int subId = phone.getSubId();
4144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4145 mApp, subId, callingPackage, "getDeviceId")) {
4146 return null;
4147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148
4149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 return phone.getDeviceId();
4152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004155 }
4156
Ping Sunc67b7c22016-03-02 19:16:45 +08004157 /**
4158 * {@hide}
4159 * Returns the IMS Registration Status on a particular subid
4160 *
4161 * @param subId
4162 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004163 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004164 Phone phone = getPhone(subId);
4165 if (phone != null) {
4166 return phone.isImsRegistered();
4167 } else {
4168 return false;
4169 }
4170 }
4171
Santos Cordon7a1885b2015-02-03 11:15:19 -08004172 @Override
4173 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4177 } finally {
4178 Binder.restoreCallingIdentity(identity);
4179 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004180 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004181
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004182 /**
4183 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004184 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004185 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 Phone phone = getPhone(subId);
4189 if (phone != null) {
4190 return phone.isWifiCallingEnabled();
4191 } else {
4192 return false;
4193 }
4194 } finally {
4195 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004196 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004197 }
4198
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004199 /**
4200 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004201 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004202 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 Phone phone = getPhone(subId);
4206 if (phone != null) {
4207 return phone.isVolteEnabled();
4208 } else {
4209 return false;
4210 }
4211 } finally {
4212 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004213 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004214 }
Svet Ganovb320e182015-04-16 12:30:10 -07004215
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004216 /**
4217 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004218 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004219 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 Phone phone = getPhone(subId);
4223 if (phone != null) {
4224 return phone.isVideoEnabled();
4225 } else {
4226 return false;
4227 }
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004230 }
4231 }
4232
4233 /**
4234 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4235 * defined in {@link ImsRegistrationImplBase}.
4236 */
4237 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238 final long identity = Binder.clearCallingIdentity();
4239 try {
4240 Phone phone = getPhone(subId);
4241 if (phone != null) {
4242 return phone.getImsRegistrationTech();
4243 } else {
4244 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4245 }
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004248 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004249 }
4250
Stuart Scott8eef64f2015-04-08 15:13:54 -07004251 @Override
4252 public void factoryReset(int subId) {
4253 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004254 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4255 return;
4256 }
4257
Svet Ganovcc087f82015-05-12 20:35:54 -07004258 final long identity = Binder.clearCallingIdentity();
4259 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004260 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4261 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004262 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004263 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004264 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4265 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004266 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004267 }
4268 } finally {
4269 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004270 }
4271 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004272
4273 @Override
4274 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275 final long identity = Binder.clearCallingIdentity();
4276 try {
4277 // We query all subscriptions instead of just the active ones, because
4278 // this might be called early on in the provisioning flow when the
4279 // subscriptions potentially aren't active yet.
4280 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4281 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004282 return null;
4283 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 // This function may be called very early, say, from the setup wizard, at
4286 // which point we won't have a default subscription set. If that's the case
4287 // we just choose the first, which will be valid in "most cases".
4288 final int defaultSubId = getDefaultSubscription();
4289 SubscriptionInfo info = null;
4290 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4291 info = slist.get(0);
4292 } else {
4293 for (SubscriptionInfo item : slist) {
4294 if (item.getSubscriptionId() == defaultSubId) {
4295 info = item;
4296 break;
4297 }
4298 }
4299
4300 if (info == null) {
4301 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004302 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004303 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 // Try and fetch the locale from the carrier properties or from the SIM language
4306 // preferences (EF-PL and EF-LI)...
4307 final int mcc = info.getMcc();
4308 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4309 String simLanguage = null;
4310 if (defaultPhone != null) {
4311 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4312 if (localeFromDefaultSim != null) {
4313 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4314 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4315 return localeFromDefaultSim.toLanguageTag();
4316 } else {
4317 simLanguage = localeFromDefaultSim.getLanguage();
4318 }
4319 }
4320 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322 // The SIM language preferences only store a language (e.g. fr = French), not an
4323 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4324 // the SIM and carrier preferences does not include a country we add the country
4325 // determined from the SIM MCC to provide an exact locale.
4326 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4327 simLanguage);
4328 if (mccLocale != null) {
4329 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4330 return mccLocale.toLanguageTag();
4331 }
4332
4333 if (DBG) log("No locale found - returning null");
4334 return null;
4335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004338 }
4339
4340 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341 return mSubscriptionController.getAllSubInfoList(
4342 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004343 }
4344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 /**
4346 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4347 */
4348 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4349 return mSubscriptionController.getActiveSubscriptionInfoList(
4350 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004351 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004352
Chenjie Yu1ba97252018-01-11 18:16:20 -08004353 private final ModemActivityInfo mLastModemActivityInfo =
4354 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4355
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004356 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004357 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4358 * representing the state of the modem.
4359 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004360 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4361 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004362 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004363 */
4364 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004365 public void requestModemActivityInfo(ResultReceiver result) {
4366 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004367 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368
4369 final long identity = Binder.clearCallingIdentity();
4370 try {
4371 ModemActivityInfo ret = null;
4372 synchronized (mLastModemActivityInfo) {
4373 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4374 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004375 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004376 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4378 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4379 mergedTxTimeMs[i] =
4380 info.getTxTimeMillis()[i]
4381 + mLastModemActivityInfo.getTxTimeMillis()[i];
4382 }
4383 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4384 mLastModemActivityInfo.setSleepTimeMillis(
4385 info.getSleepTimeMillis()
4386 + mLastModemActivityInfo.getSleepTimeMillis());
4387 mLastModemActivityInfo.setIdleTimeMillis(
4388 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4389 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4390 mLastModemActivityInfo.setRxTimeMillis(
4391 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4392 mLastModemActivityInfo.setEnergyUsed(
4393 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4396 mLastModemActivityInfo.getSleepTimeMillis(),
4397 mLastModemActivityInfo.getIdleTimeMillis(),
4398 mLastModemActivityInfo.getTxTimeMillis(),
4399 mLastModemActivityInfo.getRxTimeMillis(),
4400 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 Bundle bundle = new Bundle();
4403 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4404 result.send(0, bundle);
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004407 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004408 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004409
Siddharth Rayb8114062018-06-17 15:02:38 -07004410 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4411 // less than total activity duration.
4412 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4413 if (info == null) {
4414 return false;
4415 }
4416 int activityDurationMs =
4417 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4418 int totalTxTimeMs = 0;
4419 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4420 totalTxTimeMs += info.getTxTimeMillis()[i];
4421 }
4422 return (info.isValid()
4423 && (info.getSleepTimeMillis() <= activityDurationMs)
4424 && (info.getIdleTimeMillis() <= activityDurationMs)
4425 && (info.getRxTimeMillis() <= activityDurationMs)
4426 && (totalTxTimeMs <= activityDurationMs));
4427 }
4428
Jack Yu85bd38a2015-11-09 11:34:32 -08004429 /**
4430 * {@hide}
4431 * Returns the service state information on specified subscription.
4432 */
4433 @Override
4434 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004435 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004436 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004437 return null;
4438 }
4439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 final long identity = Binder.clearCallingIdentity();
4441 try {
4442 final Phone phone = getPhone(subId);
4443 if (phone == null) {
4444 return null;
4445 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 return phone.getServiceState();
4448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004451 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004452
4453 /**
4454 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4455 *
4456 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4457 * voicemail ringtone.
4458 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4459 * PhoneAccount.
4460 */
4461 @Override
4462 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004463 final long identity = Binder.clearCallingIdentity();
4464 try {
4465 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4466 if (phone == null) {
4467 phone = mPhone;
4468 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004474 }
4475
4476 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004477 * Sets the per-account voicemail ringtone.
4478 *
4479 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4480 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4481 *
4482 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4483 * voicemail ringtone.
4484 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4485 * PhoneAccount.
4486 */
4487 @Override
4488 public void setVoicemailRingtoneUri(String callingPackage,
4489 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4491 if (!TextUtils.equals(callingPackage,
4492 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4494 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4495 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497
4498 final long identity = Binder.clearCallingIdentity();
4499 try {
4500 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4501 if (phone == null) {
4502 phone = mPhone;
4503 }
4504 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4505 } finally {
4506 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004507 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004508 }
4509
4510 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004511 * Returns whether vibration is set for voicemail notification in Phone settings.
4512 *
4513 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4514 * voicemail vibration setting.
4515 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4516 */
4517 @Override
4518 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 final long identity = Binder.clearCallingIdentity();
4520 try {
4521 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4522 if (phone == null) {
4523 phone = mPhone;
4524 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4527 } finally {
4528 Binder.restoreCallingIdentity(identity);
4529 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004530 }
4531
Youhan Wange64578a2016-05-02 15:32:42 -07004532 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004533 * Sets the per-account voicemail vibration.
4534 *
4535 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4536 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4537 *
4538 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4539 * voicemail vibration setting.
4540 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4541 * specific PhoneAccount.
4542 */
4543 @Override
4544 public void setVoicemailVibrationEnabled(String callingPackage,
4545 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4546 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4547 if (!TextUtils.equals(callingPackage,
4548 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4550 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4551 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004552 }
4553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 final long identity = Binder.clearCallingIdentity();
4555 try {
4556 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4557 if (phone == null) {
4558 phone = mPhone;
4559 }
4560 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004563 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004564 }
4565
4566 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004567 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4568 *
4569 * @throws SecurityException if the caller does not have the required permission
4570 */
4571 private void enforceReadPrivilegedPermission() {
4572 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4573 null);
4574 }
4575
4576 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004577 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4578 * permission.
4579 *
4580 * @throws SecurityException if the caller does not have the required permission
4581 */
4582 private void enforceSendSmsPermission() {
4583 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4584 }
4585
4586 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004587 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004588 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004589 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004590 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004591 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 final long identity = Binder.clearCallingIdentity();
4593 try {
4594 ComponentName componentName =
4595 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4596 if (componentName == null) {
4597 throw new SecurityException(
4598 "Caller not current active visual voicemail package[null]");
4599 }
4600 String vvmPackage = componentName.getPackageName();
4601 if (!callingPackage.equals(vvmPackage)) {
4602 throw new SecurityException("Caller not current active visual voicemail package["
4603 + vvmPackage + "]");
4604 }
4605 } finally {
4606 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004607 }
4608 }
4609
4610 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004611 * Return the application ID for the app type.
4612 *
4613 * @param subId the subscription ID that this request applies to.
4614 * @param appType the uicc app type.
4615 * @return Application ID for specificied app type, or null if no uicc.
4616 */
4617 @Override
4618 public String getAidForAppType(int subId, int appType) {
4619 enforceReadPrivilegedPermission();
4620 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621
4622 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004623 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 if (phone == null) {
4625 return null;
4626 }
4627 String aid = null;
4628 try {
4629 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4630 .getApplicationByType(appType).getAid();
4631 } catch (Exception e) {
4632 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4633 }
4634 return aid;
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004637 }
Youhan Wange64578a2016-05-02 15:32:42 -07004638 }
4639
Youhan Wang4001d252016-05-11 10:29:41 -07004640 /**
4641 * Return the Electronic Serial Number.
4642 *
4643 * @param subId the subscription ID that this request applies to.
4644 * @return ESN or null if error.
4645 */
4646 @Override
4647 public String getEsn(int subId) {
4648 enforceReadPrivilegedPermission();
4649 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650
4651 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004652 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 if (phone == null) {
4654 return null;
4655 }
4656 String esn = null;
4657 try {
4658 esn = phone.getEsn();
4659 } catch (Exception e) {
4660 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4661 }
4662 return esn;
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004665 }
Youhan Wang4001d252016-05-11 10:29:41 -07004666 }
4667
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004668 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004669 * Return the Preferred Roaming List Version.
4670 *
4671 * @param subId the subscription ID that this request applies to.
4672 * @return PRLVersion or null if error.
4673 */
4674 @Override
4675 public String getCdmaPrlVersion(int subId) {
4676 enforceReadPrivilegedPermission();
4677 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004678
4679 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004680 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681 if (phone == null) {
4682 return null;
4683 }
4684 String cdmaPrlVersion = null;
4685 try {
4686 cdmaPrlVersion = phone.getCdmaPrlVersion();
4687 } catch (Exception e) {
4688 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4689 }
4690 return cdmaPrlVersion;
4691 } finally {
4692 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004693 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004694 }
4695
4696 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004697 * Get snapshot of Telephony histograms
4698 * @return List of Telephony histograms
4699 * @hide
4700 */
4701 @Override
4702 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4704 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705
4706 final long identity = Binder.clearCallingIdentity();
4707 try {
4708 return RIL.getTelephonyRILTimingHistograms();
4709 } finally {
4710 Binder.restoreCallingIdentity(identity);
4711 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004712 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004713
4714 /**
4715 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004716 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004717 * Require system privileges. In the future we may add this to carrier APIs.
4718 *
4719 * @return The number of carriers set successfully, should match length of carriers
4720 */
4721 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004722 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004723 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004724 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004725
Meng Wang9b7c4e92017-02-17 11:41:27 -08004726 if (carriers == null) {
4727 throw new NullPointerException("carriers cannot be null");
4728 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730 final long identity = Binder.clearCallingIdentity();
4731 try {
4732 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004733 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4734 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 return retVal[0];
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004739 }
4740
4741 /**
4742 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004743 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004744 * Require system privileges. In the future we may add this to carrier APIs.
4745 *
4746 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4747 * means all carriers are allowed.
4748 */
4749 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004750 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004751 enforceReadPrivilegedPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004752 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753
4754 final long identity = Binder.clearCallingIdentity();
4755 try {
4756 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004757 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4758 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004762 }
4763
fionaxu59545b42016-05-25 15:53:37 -07004764 /**
4765 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4766 * @param subId the subscription ID that this action applies to.
4767 * @param enabled control enable or disable metered apns.
4768 * {@hide}
4769 */
4770 @Override
4771 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4772 enforceModifyPermission();
4773 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774
4775 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004776 if (phone == null) {
4777 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4778 return;
4779 }
4780 try {
4781 phone.carrierActionSetMeteredApnsEnabled(enabled);
4782 } catch (Exception e) {
4783 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 } finally {
4785 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004786 }
4787 }
4788
4789 /**
4790 * Action set from carrier signalling broadcast receivers to enable/disable radio
4791 * @param subId the subscription ID that this action applies to.
4792 * @param enabled control enable or disable radio.
4793 * {@hide}
4794 */
4795 @Override
4796 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4797 enforceModifyPermission();
4798 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799
4800 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004801 if (phone == null) {
4802 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4803 return;
4804 }
4805 try {
4806 phone.carrierActionSetRadioEnabled(enabled);
4807 } catch (Exception e) {
4808 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 } finally {
4810 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004811 }
4812 }
4813
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004814 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004815 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4816 * network status based on which carrier apps could apply actions accordingly,
4817 * enable/disable default url handler for example.
4818 *
4819 * @param subId the subscription ID that this action applies to.
4820 * @param report control start/stop reporting the default network status.
4821 * {@hide}
4822 */
4823 @Override
4824 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4825 enforceModifyPermission();
4826 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827
4828 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004829 if (phone == null) {
4830 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4831 return;
4832 }
4833 try {
4834 phone.carrierActionReportDefaultNetworkStatus(report);
4835 } catch (Exception e) {
4836 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837 } finally {
4838 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004839 }
4840 }
4841
4842 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004843 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4844 * bug report is being generated.
4845 */
4846 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004847 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004848 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4849 != PackageManager.PERMISSION_GRANTED) {
4850 writer.println("Permission Denial: can't dump Phone from pid="
4851 + Binder.getCallingPid()
4852 + ", uid=" + Binder.getCallingUid()
4853 + "without permission "
4854 + android.Manifest.permission.DUMP);
4855 return;
4856 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004857 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004858 }
Jack Yueb89b242016-06-22 13:27:47 -07004859
Brad Ebingerdac2f002018-04-03 15:17:52 -07004860 @Override
4861 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4862 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4863 throws RemoteException {
4864 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4865 }
4866
Jack Yueb89b242016-06-22 13:27:47 -07004867 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004868 * Get aggregated video call data usage since boot.
4869 *
4870 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4871 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004872 * {@hide}
4873 */
4874 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004875 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004876 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4877 null);
4878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 // NetworkStatsService keeps tracking the active network interface and identity. It
4882 // records the delta with the corresponding network identity.
4883 // We just return the total video call data usage snapshot since boot.
4884 Phone phone = getPhone(subId);
4885 if (phone != null) {
4886 return phone.getVtDataUsage(perUidStats);
4887 }
4888 return null;
4889 } finally {
4890 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004891 }
Jack Yueb89b242016-06-22 13:27:47 -07004892 }
Jack Yu75ab2952016-07-08 14:29:33 -07004893
4894 /**
4895 * Policy control of data connection. Usually used when data limit is passed.
4896 * @param enabled True if enabling the data, otherwise disabling.
4897 * @param subId Subscription index
4898 * {@hide}
4899 */
4900 @Override
4901 public void setPolicyDataEnabled(boolean enabled, int subId) {
4902 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903
4904 final long identity = Binder.clearCallingIdentity();
4905 try {
4906 Phone phone = getPhone(subId);
4907 if (phone != null) {
4908 phone.setPolicyDataEnabled(enabled);
4909 }
4910 } finally {
4911 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004912 }
4913 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004914
4915 /**
4916 * Get Client request stats
4917 * @return List of Client Request Stats
4918 * @hide
4919 */
4920 @Override
4921 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004923 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004924 return null;
4925 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004926 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 if (phone != null) {
4931 return phone.getClientRequestStats();
4932 }
4933
4934 return null;
4935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004938 }
4939
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004940 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004941 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004942 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004943 }
Jack Yueb4124c2017-02-16 15:32:43 -08004944
4945 /**
Grace Chen70990072017-03-24 17:21:30 -07004946 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004947 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004948 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004949 * @param state State of SIM (power down, power up, pass through)
4950 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4951 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4952 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004953 *
4954 **/
4955 @Override
Grace Chen70990072017-03-24 17:21:30 -07004956 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004957 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004958 Phone phone = PhoneFactory.getPhone(slotIndex);
4959
vagdeviaf9a5b92018-08-15 16:01:53 -07004960 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004965 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 }
4967 } finally {
4968 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004969 }
4970 }
Shuo Qiandd210312017-04-12 22:11:33 +00004971
Tyler Gunn65d45c22017-06-05 11:22:26 -07004972 private boolean isUssdApiAllowed(int subId) {
4973 CarrierConfigManager configManager =
4974 (CarrierConfigManager) mPhone.getContext().getSystemService(
4975 Context.CARRIER_CONFIG_SERVICE);
4976 if (configManager == null) {
4977 return false;
4978 }
4979 PersistableBundle pb = configManager.getConfigForSubId(subId);
4980 if (pb == null) {
4981 return false;
4982 }
4983 return pb.getBoolean(
4984 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4985 }
4986
Shuo Qiandd210312017-04-12 22:11:33 +00004987 /**
4988 * Check if phone is in emergency callback mode
4989 * @return true if phone is in emergency callback mode
4990 * @param subId sub id
4991 */
goneil9c5f4872017-12-05 14:07:56 -08004992 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004993 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004994 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004995 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996
4997 final long identity = Binder.clearCallingIdentity();
4998 try {
4999 if (phone != null) {
5000 return phone.isInEcm();
5001 } else {
5002 return false;
5003 }
5004 } finally {
5005 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005006 }
5007 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005008
5009 /**
5010 * Get the current signal strength information for the given subscription.
5011 * Because this information is not updated when the device is in a low power state
5012 * it should not be relied-upon to be current.
5013 * @param subId Subscription index
5014 * @return the most recent cached signal strength info from the modem
5015 */
5016 @Override
5017 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 final long identity = Binder.clearCallingIdentity();
5019 try {
5020 Phone p = getPhone(subId);
5021 if (p == null) {
5022 return null;
5023 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 return p.getSignalStrength();
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
5028 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005029 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005030
Pengquan Meng77b7f132018-08-22 14:49:57 -07005031 /**
5032 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5033 *
5034 * <p>Requires one of the following permissions:
5035 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5036 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5037 * privileges.
5038 *
5039 * @param subId subscription id
5040 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5041 * {@code false}.
5042 */
5043 @Override
5044 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005045 boolean isEnabled = false;
5046 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005047 try {
5048 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005049 null /* message */);
5050 Phone phone = getPhone(subId);
5051 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005052 } catch (Exception e) {
5053 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5054 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005055 } finally {
5056 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005057 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005058 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005059 }
5060
5061
5062 /**
5063 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5064 *
5065 * <p> Requires permission:
5066 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5067 * privileges.
5068 *
5069 * @param subId subscription id
5070 * @param isEnabled {@code true} means enable, {@code false} means disable.
5071 */
5072 @Override
5073 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5077 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005078
Pengquan Menga1bb6272018-09-06 09:59:22 -07005079 Phone phone = getPhone(subId);
5080 if (phone != null) {
5081 phone.setDataRoamingEnabled(isEnabled);
5082 }
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005085 }
5086 }
5087
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005088 @Override
5089 public UiccSlotInfo[] getUiccSlotsInfo() {
5090 enforceReadPrivilegedPermission();
5091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 final long identity = Binder.clearCallingIdentity();
5093 try {
5094 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5095 if (slots == null) {
5096 Rlog.i(LOG_TAG, "slots is null.");
5097 return null;
5098 }
5099
5100 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5101 for (int i = 0; i < slots.length; i++) {
5102 UiccSlot slot = slots[i];
5103 if (slot == null) {
5104 continue;
5105 }
5106
5107 String cardId;
5108 UiccCard card = slot.getUiccCard();
5109 if (card != null) {
5110 cardId = card.getCardId();
5111 } else {
5112 cardId = slot.getIccId();
5113 }
5114
5115 int cardState = 0;
5116 switch (slot.getCardState()) {
5117 case CARDSTATE_ABSENT:
5118 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5119 break;
5120 case CARDSTATE_PRESENT:
5121 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5122 break;
5123 case CARDSTATE_ERROR:
5124 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5125 break;
5126 case CARDSTATE_RESTRICTED:
5127 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5128 break;
5129 default:
5130 break;
5131
5132 }
5133
5134 infos[i] = new UiccSlotInfo(
5135 slot.isActive(),
5136 slot.isEuicc(),
5137 cardId,
5138 cardState,
5139 slot.getPhoneId(),
5140 slot.isExtendedApduSupported());
5141 }
5142 return infos;
5143 } finally {
5144 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005145 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005146 }
5147
5148 @Override
5149 public boolean switchSlots(int[] physicalSlots) {
5150 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151
5152 final long identity = Binder.clearCallingIdentity();
5153 try {
5154 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5155 } finally {
5156 Binder.restoreCallingIdentity(identity);
5157 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005158 }
Jack Yu4c988042018-02-27 15:30:01 -08005159
5160 @Override
5161 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5162 enforceModifyPermission();
5163 final Phone phone = getPhone(subId);
5164 if (phone == null) {
5165 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5166 return;
5167 }
5168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 phone.setRadioIndicationUpdateMode(filters, mode);
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
5174 }
Jack Yu4c988042018-02-27 15:30:01 -08005175 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005176
5177 /**
goneil47ffb6e2018-04-06 15:40:58 -07005178 * A test API to reload the UICC profile.
5179 *
5180 * <p>Requires that the calling app has permission
5181 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5182 * @hide
5183 */
5184 @Override
5185 public void refreshUiccProfile(int subId) {
5186 enforceModifyPermission();
5187
5188 final long identity = Binder.clearCallingIdentity();
5189 try {
5190 Phone phone = getPhone(subId);
5191 if (phone == null) {
5192 return;
5193 }
5194 UiccCard uiccCard = phone.getUiccCard();
5195 if (uiccCard == null) {
5196 return;
5197 }
5198 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5199 if (uiccProfile == null) {
5200 return;
5201 }
5202 uiccProfile.refresh();
5203 } finally {
5204 Binder.restoreCallingIdentity(identity);
5205 }
5206 }
5207
5208 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005209 * Returns false if the mobile data is disabled by default, otherwise return true.
5210 */
5211 private boolean getDefaultDataEnabled() {
5212 return "true".equalsIgnoreCase(
5213 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5214 }
5215
5216 /**
5217 * Returns true if the data roaming is enabled by default, i.e the system property
5218 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5219 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5220 */
5221 private boolean getDefaultDataRoamingEnabled(int subId) {
5222 final CarrierConfigManager configMgr = (CarrierConfigManager)
5223 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5224 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5225 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5226 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5227 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5228 return isDataRoamingEnabled;
5229 }
5230
5231 /**
5232 * Returns the default network type for the given {@code subId}, if the default network type is
5233 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5234 */
5235 private int getDefaultNetworkType(int subId) {
5236 return Integer.parseInt(
5237 TelephonyManager.getTelephonyProperty(
5238 mSubscriptionController.getPhoneId(subId),
5239 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5240 String.valueOf(Phone.PREFERRED_NT_MODE)));
5241 }
fionaxua13278b2018-03-21 00:08:13 -07005242
5243 @Override
5244 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5245 gid1, String gid2, String plmn, String spn) {
5246 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247
5248 final long identity = Binder.clearCallingIdentity();
5249 try {
5250 final Phone phone = getPhone(subId);
5251 if (phone == null) {
5252 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5253 return;
5254 }
5255 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5256 } finally {
5257 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005258 }
fionaxua13278b2018-03-21 00:08:13 -07005259 }
5260
5261 @Override
5262 public int getCarrierIdListVersion(int subId) {
5263 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264
5265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 final Phone phone = getPhone(subId);
5268 if (phone == null) {
5269 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5270 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5271 }
5272 return phone.getCarrierIdListVersion();
5273 } finally {
5274 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005275 }
fionaxua13278b2018-03-21 00:08:13 -07005276 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005277
5278 @Override
5279 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5281 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5282 return -1;
5283 }
5284
5285 final long identity = Binder.clearCallingIdentity();
5286 try {
5287 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
5290 }
5291 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005292
5293 @Override
5294 public int getCdmaRoamingMode(int subId) {
5295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5296 mApp, subId, "getCdmaRoamingMode");
5297
5298 final long identity = Binder.clearCallingIdentity();
5299 try {
5300 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
5304 }
5305
5306 @Override
5307 public boolean setCdmaRoamingMode(int subId, int mode) {
5308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5309 mApp, subId, "setCdmaRoamingMode");
5310
5311 final long identity = Binder.clearCallingIdentity();
5312 try {
5313 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
5317 }
5318
5319 @Override
5320 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5322 mApp, subId, "setCdmaSubscriptionMode");
5323
5324 final long identity = Binder.clearCallingIdentity();
5325 try {
5326 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
5329 }
5330 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005331
5332 private void ensureUserRunning(int userId) {
5333 if (!mUserManager.isUserRunning(userId)) {
5334 throw new IllegalStateException("User " + userId + " does not exist or not running");
5335 }
5336 }
5337
5338 /**
5339 * Returns a list of SMS apps on a given user.
5340 *
5341 * Only the shell user (UID 2000 or 0) can call it.
5342 * Target user must be running.
5343 */
5344 @Override
5345 public String[] getSmsApps(int userId) {
5346 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5347 ensureUserRunning(userId);
5348
5349 final Collection<SmsApplicationData> apps =
5350 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5351
5352 String[] ret = new String[apps.size()];
5353 int i = 0;
5354 for (SmsApplicationData app : apps) {
5355 ret[i++] = app.mPackageName;
5356 }
5357 return ret;
5358 }
5359
5360 /**
5361 * Returns the default SMS app package name on a given user.
5362 *
5363 * Only the shell user (UID 2000 or 0) can call it.
5364 * Target user must be running.
5365 */
5366 @Override
5367 public String getDefaultSmsApp(int userId) {
5368 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5369 ensureUserRunning(userId);
5370
5371 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5372 /* updateIfNeeded= */ true, userId);
5373 return cn == null ? null : cn.getPackageName();
5374 }
5375
5376 /**
5377 * Set a package as the default SMS app on a given user.
5378 *
5379 * Only the shell user (UID 2000 or 0) can call it.
5380 * Target user must be running.
5381 */
5382 @Override
5383 public void setDefaultSmsApp(int userId, String packageName) {
5384 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5385 ensureUserRunning(userId);
5386
5387 boolean found = false;
5388 for (String pkg : getSmsApps(userId)) {
5389 if (TextUtils.equals(packageName, pkg)) {
5390 found = true;
5391 break;
5392 }
5393 }
5394 if (!found) {
5395 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5396 }
5397
5398 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005400}