blob: 038f8b1d94b72dfcb77e68006de44593b2245a6c [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:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
772 if (ar.exception == null) {
773 request.result = true;
774 } else {
775 request.result = false;
776 loge("setNetworkSelectionModeManual " + ar.exception);
777 }
778 notifyRequester(request);
779 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700780 break;
781
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700782 case CMD_GET_MODEM_ACTIVITY_INFO:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700785 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700786 break;
787
788 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
789 ar = (AsyncResult) msg.obj;
790 request = (MainThreadRequest) ar.userObj;
791 if (ar.exception == null && ar.result != null) {
792 request.result = ar.result;
793 } else {
794 if (ar.result == null) {
795 loge("queryModemActivityInfo: Empty response");
796 } else if (ar.exception instanceof CommandException) {
797 loge("queryModemActivityInfo: CommandException: " +
798 ar.exception);
799 } else {
800 loge("queryModemActivityInfo: Unknown exception");
801 }
802 }
Amit Mahajand4766222016-01-28 15:28:28 -0800803 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
804 if (request.result == null) {
805 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
806 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700807 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700808 break;
809
Meng Wang1a7c35a2016-05-05 20:56:15 -0700810 case CMD_SET_ALLOWED_CARRIERS:
811 request = (MainThreadRequest) msg.obj;
812 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
813 mPhone.setAllowedCarriers(
814 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700815 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700816 break;
817
818 case EVENT_SET_ALLOWED_CARRIERS_DONE:
819 ar = (AsyncResult) msg.obj;
820 request = (MainThreadRequest) ar.userObj;
821 if (ar.exception == null && ar.result != null) {
822 request.result = ar.result;
823 } else {
824 if (ar.result == null) {
825 loge("setAllowedCarriers: Empty response");
826 } else if (ar.exception instanceof CommandException) {
827 loge("setAllowedCarriers: CommandException: " +
828 ar.exception);
829 } else {
830 loge("setAllowedCarriers: Unknown exception");
831 }
832 }
833 // Result cannot be null. Return -1 on error.
834 if (request.result == null) {
835 request.result = new int[]{-1};
836 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700837 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700838 break;
839
840 case CMD_GET_ALLOWED_CARRIERS:
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700843 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700844 break;
845
846 case EVENT_GET_ALLOWED_CARRIERS_DONE:
847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null && ar.result != null) {
850 request.result = ar.result;
851 } else {
852 if (ar.result == null) {
853 loge("getAllowedCarriers: Empty response");
854 } else if (ar.exception instanceof CommandException) {
855 loge("getAllowedCarriers: CommandException: " +
856 ar.exception);
857 } else {
858 loge("getAllowedCarriers: Unknown exception");
859 }
860 }
861 // Result cannot be null. Return empty list of CarrierIdentifier.
862 if (request.result == null) {
863 request.result = new ArrayList<CarrierIdentifier>(0);
864 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700865 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 break;
867
Nathan Haroldb3014052017-01-25 15:57:32 -0800868 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
874 request.result = new IllegalArgumentException(
875 "Failed to retrieve Forbidden Plmns");
876 if (ar.result == null) {
877 loge("getForbiddenPlmns: Empty response");
878 } else {
879 loge("getForbiddenPlmns: Unknown exception");
880 }
881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800883 break;
884
885 case CMD_GET_FORBIDDEN_PLMNS:
886 request = (MainThreadRequest) msg.obj;
887 uiccCard = getUiccCardFromRequest(request);
888 if (uiccCard == null) {
889 loge("getForbiddenPlmns() UiccCard is null");
890 request.result = new IllegalArgumentException(
891 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700892 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800893 break;
894 }
895 Integer appType = (Integer) request.argument;
896 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
897 if (uiccApp == null) {
898 loge("getForbiddenPlmns() no app with specified type -- "
899 + appType);
900 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700901 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800902 break;
903 } else {
904 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
905 + " specified type -- " + appType);
906 }
907 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
908 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
909 onCompleted);
910 break;
911
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000912 case CMD_SWITCH_SLOTS:
913 request = (MainThreadRequest) msg.obj;
914 int[] physicalSlots = (int[]) request.argument;
915 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
916 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
917 break;
918
919 case EVENT_SWITCH_SLOTS_DONE:
920 ar = (AsyncResult) msg.obj;
921 request = (MainThreadRequest) ar.userObj;
922 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700923 notifyRequester(request);
924 break;
925 case CMD_GET_NETWORK_SELECTION_MODE:
926 request = (MainThreadRequest) msg.obj;
927 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
928 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
929 break;
930
931 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
932 ar = (AsyncResult) msg.obj;
933 request = (MainThreadRequest) ar.userObj;
934 if (ar.exception != null) {
935 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
936 } else {
937 int mode = ((int[]) ar.result)[0];
938 if (mode == 0) {
939 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
940 } else {
941 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
942 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000943 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700944 notifyRequester(request);
945 break;
946 case CMD_GET_CDMA_ROAMING_MODE:
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
949 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
950 break;
951 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
952 ar = (AsyncResult) msg.obj;
953 request = (MainThreadRequest) ar.userObj;
954 if (ar.exception != null) {
955 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
956 } else {
957 request.result = ((int[]) ar.result)[0];
958 }
959 notifyRequester(request);
960 break;
961 case CMD_SET_CDMA_ROAMING_MODE:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
964 int mode = (int) request.argument;
965 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
966 break;
967 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
970 request.result = ar.exception == null;
971 notifyRequester(request);
972 break;
973 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
976 int subscriptionMode = (int) request.argument;
977 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
978 break;
979 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 request.result = ar.exception == null;
983 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000984 break;
985
Nathan Harold3ff88932018-08-14 10:19:49 -0700986 case CMD_GET_ALL_CELL_INFO:
987 request = (MainThreadRequest) msg.obj;
988 Pair<Phone, WorkSource> args = (Pair<Phone, WorkSource>) request.argument;
989 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
990 ((Phone) args.first).getAllCellInfo(args.second, onCompleted);
991 break;
992
993 case EVENT_GET_ALL_CELL_INFO_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 request.result = (ar.exception == null) ? ar.result : new ArrayList<CellInfo>();
997 synchronized (request) {
998 request.notifyAll();
999 }
1000 break;
1001
1002 case CMD_GET_CELL_LOCATION: {
1003 request = (MainThreadRequest) msg.obj;
1004 WorkSource ws = (WorkSource) request.argument;
1005 Phone phone = getPhoneFromRequest(request);
1006 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1007 break;
1008 }
1009
1010 case EVENT_GET_CELL_LOCATION_DONE: {
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 if (ar.exception == null) {
1014 request.result = ar.result;
1015 } else {
1016 Phone phone = getPhoneFromRequest(request);
1017 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1018 ? new CdmaCellLocation() : new GsmCellLocation();
1019 }
1020
1021 synchronized (request) {
1022 request.notifyAll();
1023 }
1024 break;
1025 }
1026
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001027 default:
1028 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1029 break;
1030 }
1031 }
Jake Hambye994d462014-02-03 13:10:13 -08001032
Pengquan Menga1bb6272018-09-06 09:59:22 -07001033 private void notifyRequester(MainThreadRequest request) {
1034 synchronized (request) {
1035 request.notifyAll();
1036 }
1037 }
1038
Jake Hambye994d462014-02-03 13:10:13 -08001039 private void handleNullReturnEvent(Message msg, String command) {
1040 AsyncResult ar = (AsyncResult) msg.obj;
1041 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1042 if (ar.exception == null) {
1043 request.result = true;
1044 } else {
1045 request.result = false;
1046 if (ar.exception instanceof CommandException) {
1047 loge(command + ": CommandException: " + ar.exception);
1048 } else {
1049 loge(command + ": Unknown exception");
1050 }
1051 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001052 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001054 }
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) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001062 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1063 }
1064
1065 /**
1066 * Posts the specified command to be executed on the main thread,
1067 * waits for the request to complete, and returns the result.
1068 * @see #sendRequestAsync
1069 */
1070 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1071 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1072 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001073 }
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 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001080 private Object sendRequest(int command, Object argument, Integer subId) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001081 return sendRequest(command, argument, subId, null);
1082 }
1083
1084 /**
1085 * Posts the specified command to be executed on the main thread,
1086 * waits for the request to complete, and returns the result.
1087 * @see #sendRequestAsync
1088 */
1089 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1091 throw new RuntimeException("This method will deadlock if called from the main thread.");
1092 }
1093
vagdeviaf9a5b92018-08-15 16:01:53 -07001094 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001095 Message msg = mMainThreadHandler.obtainMessage(command, request);
1096 msg.sendToTarget();
1097
1098 // Wait for the request to complete
1099 synchronized (request) {
1100 while (request.result == null) {
1101 try {
1102 request.wait();
1103 } catch (InterruptedException e) {
1104 // Do nothing, go back and wait until the request is complete
1105 }
1106 }
1107 }
1108 return request.result;
1109 }
1110
1111 /**
1112 * Asynchronous ("fire and forget") version of sendRequest():
1113 * Posts the specified command to be executed on the main thread, and
1114 * returns immediately.
1115 * @see #sendRequest
1116 */
1117 private void sendRequestAsync(int command) {
1118 mMainThreadHandler.sendEmptyMessage(command);
1119 }
1120
1121 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001122 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1123 * @see {@link #sendRequest(int,Object)}
1124 */
1125 private void sendRequestAsync(int command, Object argument) {
1126 MainThreadRequest request = new MainThreadRequest(argument);
1127 Message msg = mMainThreadHandler.obtainMessage(command, request);
1128 msg.sendToTarget();
1129 }
1130
1131 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001132 * Initialize the singleton PhoneInterfaceManager instance.
1133 * This is only done once, at startup, from PhoneApp.onCreate().
1134 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001135 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 synchronized (PhoneInterfaceManager.class) {
1137 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001138 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 } else {
1140 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1141 }
1142 return sInstance;
1143 }
1144 }
1145
1146 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001147 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 mApp = app;
1149 mPhone = phone;
1150 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001151 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001152 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1153 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001154 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001155 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001156 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001157 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001158 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001159
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 publish();
1161 }
1162
1163 private void publish() {
1164 if (DBG) log("publish: " + this);
1165
1166 ServiceManager.addService("phone", this);
1167 }
1168
Stuart Scott584921c2015-01-15 17:10:34 -08001169 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001170 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1171 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001172 }
1173
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001174 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1175 Phone phone = getPhoneFromRequest(request);
1176 return phone == null ? null :
1177 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1178 }
1179
Wink Saville36469e72014-06-11 15:17:00 -07001180 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001181 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001182 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184 //
1185 // Implementation of the ITelephony interface.
1186 //
1187
1188 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001189 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001190 }
1191
Wink Savilleb564aae2014-10-23 10:18:09 -07001192 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001193 if (DBG) log("dial: " + number);
1194 // No permission check needed here: This is just a wrapper around the
1195 // ACTION_DIAL intent, which is available to any app since it puts up
1196 // the UI before it does anything.
1197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001198 final long identity = Binder.clearCallingIdentity();
1199 try {
1200 String url = createTelUrl(number);
1201 if (url == null) {
1202 return;
1203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001205 // PENDING: should we just silently fail if phone is offhook or ringing?
1206 PhoneConstants.State state = mCM.getState(subId);
1207 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1208 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1209 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1210 mApp.startActivity(intent);
1211 }
1212 } finally {
1213 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 }
1215 }
1216
1217 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001218 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001219 }
1220
Wink Savilleb564aae2014-10-23 10:18:09 -07001221 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 if (DBG) log("call: " + number);
1223
1224 // This is just a wrapper around the ACTION_CALL intent, but we still
1225 // need to do a permission check since we're calling startActivity()
1226 // from the context of the phone app.
1227 enforceCallPermission();
1228
1229 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1230 != AppOpsManager.MODE_ALLOWED) {
1231 return;
1232 }
1233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001234 final long identity = Binder.clearCallingIdentity();
1235 try {
1236 String url = createTelUrl(number);
1237 if (url == null) {
1238 return;
1239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001241 boolean isValid = false;
1242 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1243 if (slist != null) {
1244 for (SubscriptionInfo subInfoRecord : slist) {
1245 if (subInfoRecord.getSubscriptionId() == subId) {
1246 isValid = true;
1247 break;
1248 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001249 }
Wink Saville08874612014-08-31 19:19:58 -07001250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001251 if (!isValid) {
1252 return;
1253 }
Wink Saville08874612014-08-31 19:19:58 -07001254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001255 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1256 intent.putExtra(SUBSCRIPTION_KEY, subId);
1257 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1258 mApp.startActivity(intent);
1259 } finally {
1260 Binder.restoreCallingIdentity(identity);
1261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 }
1263
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 /**
1265 * End a call based on call state
1266 * @return true is a call was ended
1267 */
1268 public boolean endCall() {
Hall Liu91943182018-09-14 17:42:41 -07001269 return false;
Wink Saville36469e72014-06-11 15:17:00 -07001270 }
1271
1272 /**
1273 * End a call based on the call state of the subId
1274 * @return true is a call was ended
1275 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001276 public boolean endCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001277 return false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 }
1279
1280 public void answerRingingCall() {
Hall Liu91943182018-09-14 17:42:41 -07001281 // Deprecated.
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
Wink Savilleb564aae2014-10-23 10:18:09 -07001284 public void answerRingingCallForSubscriber(int subId) {
Hall Liu91943182018-09-14 17:42:41 -07001285 // Deprecated
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 }
1287
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001289 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001291 public void silenceRinger() {
1292 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 }
1294
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001295 @Override
1296 public boolean isOffhook(String callingPackage) {
1297 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001298 }
1299
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001300 @Override
1301 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001303 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001304 return false;
1305 }
1306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001307 final long identity = Binder.clearCallingIdentity();
1308 try {
1309 final Phone phone = getPhone(subId);
1310 if (phone != null) {
1311 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1312 } else {
1313 return false;
1314 }
1315 } finally {
1316 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 }
1319
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001320 @Override
1321 public boolean isRinging(String callingPackage) {
1322 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001323 }
1324
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001325 @Override
1326 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001328 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001329 return false;
1330 }
1331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001332 final long identity = Binder.clearCallingIdentity();
1333 try {
1334 final Phone phone = getPhone(subId);
1335 if (phone != null) {
1336 return (phone.getState() == PhoneConstants.State.RINGING);
1337 } else {
1338 return false;
1339 }
1340 } finally {
1341 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 }
1344
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001345 @Override
1346 public boolean isIdle(String callingPackage) {
1347 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001348 }
1349
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001350 @Override
1351 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001353 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001354 return false;
1355 }
1356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001357 final long identity = Binder.clearCallingIdentity();
1358 try {
1359 final Phone phone = getPhone(subId);
1360 if (phone != null) {
1361 return (phone.getState() == PhoneConstants.State.IDLE);
1362 } else {
1363 return false;
1364 }
1365 } finally {
1366 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 }
1369
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001370 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001371 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
1373
Wink Savilleb564aae2014-10-23 10:18:09 -07001374 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001376 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1377 }
1378
1379 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001380 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001381 }
1382
Wink Savilleb564aae2014-10-23 10:18:09 -07001383 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001384 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001385 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1386 }
1387
1388 /** {@hide} */
1389 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001390 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001391 }
1392
Wink Savilleb564aae2014-10-23 10:18:09 -07001393 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001395
1396 final long identity = Binder.clearCallingIdentity();
1397 try {
1398 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1399 checkSimPin.start();
1400 return checkSimPin.unlockSim(null, pin);
1401 } finally {
1402 Binder.restoreCallingIdentity(identity);
1403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 }
1405
Wink Saville9de0f752013-10-22 19:04:03 -07001406 /** {@hide} */
1407 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001408 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001409 }
1410
Wink Savilleb564aae2014-10-23 10:18:09 -07001411 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001413
1414 final long identity = Binder.clearCallingIdentity();
1415 try {
1416 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1417 checkSimPuk.start();
1418 return checkSimPuk.unlockSim(puk, pin);
1419 } finally {
1420 Binder.restoreCallingIdentity(identity);
1421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001422 }
1423
1424 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001425 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426 * a synchronous one.
1427 */
1428 private static class UnlockSim extends Thread {
1429
1430 private final IccCard mSimCard;
1431
1432 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001433 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1434 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001435
1436 // For replies from SimCard interface
1437 private Handler mHandler;
1438
1439 // For async handler to identify request type
1440 private static final int SUPPLY_PIN_COMPLETE = 100;
1441
1442 public UnlockSim(IccCard simCard) {
1443 mSimCard = simCard;
1444 }
1445
1446 @Override
1447 public void run() {
1448 Looper.prepare();
1449 synchronized (UnlockSim.this) {
1450 mHandler = new Handler() {
1451 @Override
1452 public void handleMessage(Message msg) {
1453 AsyncResult ar = (AsyncResult) msg.obj;
1454 switch (msg.what) {
1455 case SUPPLY_PIN_COMPLETE:
1456 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1457 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001458 mRetryCount = msg.arg1;
1459 if (ar.exception != null) {
1460 if (ar.exception instanceof CommandException &&
1461 ((CommandException)(ar.exception)).getCommandError()
1462 == CommandException.Error.PASSWORD_INCORRECT) {
1463 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1464 } else {
1465 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1466 }
1467 } else {
1468 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470 mDone = true;
1471 UnlockSim.this.notifyAll();
1472 }
1473 break;
1474 }
1475 }
1476 };
1477 UnlockSim.this.notifyAll();
1478 }
1479 Looper.loop();
1480 }
1481
1482 /*
1483 * Use PIN or PUK to unlock SIM card
1484 *
1485 * If PUK is null, unlock SIM card with PIN
1486 *
1487 * If PUK is not null, unlock SIM card with PUK and set PIN code
1488 */
Wink Saville9de0f752013-10-22 19:04:03 -07001489 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490
1491 while (mHandler == null) {
1492 try {
1493 wait();
1494 } catch (InterruptedException e) {
1495 Thread.currentThread().interrupt();
1496 }
1497 }
1498 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1499
1500 if (puk == null) {
1501 mSimCard.supplyPin(pin, callback);
1502 } else {
1503 mSimCard.supplyPuk(puk, pin, callback);
1504 }
1505
1506 while (!mDone) {
1507 try {
1508 Log.d(LOG_TAG, "wait for done");
1509 wait();
1510 } catch (InterruptedException e) {
1511 // Restore the interrupted status
1512 Thread.currentThread().interrupt();
1513 }
1514 }
1515 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001516 int[] resultArray = new int[2];
1517 resultArray[0] = mResult;
1518 resultArray[1] = mRetryCount;
1519 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 }
1521 }
1522
1523 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001524 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001525
1526 }
1527
Wink Savilleb564aae2014-10-23 10:18:09 -07001528 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 // No permission check needed here: this call is harmless, and it's
1530 // needed for the ServiceState.requestStateUpdate() call (which is
1531 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001532 final long identity = Binder.clearCallingIdentity();
1533 try {
1534 final Phone phone = getPhone(subId);
1535 if (phone != null) {
1536 phone.updateServiceLocation();
1537 }
1538 } finally {
1539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 }
1542
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001543 @Override
1544 public boolean isRadioOn(String callingPackage) {
1545 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001546 }
1547
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001548 @Override
1549 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001551 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001552 return false;
1553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001554
1555 final long identity = Binder.clearCallingIdentity();
1556 try {
1557 return isRadioOnForSubscriber(subId);
1558 } finally {
1559 Binder.restoreCallingIdentity(identity);
1560 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001561 }
1562
1563 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001564 final long identity = Binder.clearCallingIdentity();
1565 try {
1566 final Phone phone = getPhone(subId);
1567 if (phone != null) {
1568 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1569 } else {
1570 return false;
1571 }
1572 } finally {
1573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 }
1576
1577 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001578 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 }
Wink Saville36469e72014-06-11 15:17:00 -07001580
Wink Savilleb564aae2014-10-23 10:18:09 -07001581 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001583
1584 final long identity = Binder.clearCallingIdentity();
1585 try {
1586 final Phone phone = getPhone(subId);
1587 if (phone != null) {
1588 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1589 }
1590 } finally {
1591 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001592 }
Wink Saville36469e72014-06-11 15:17:00 -07001593 }
1594
1595 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001596 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001597 }
1598
Wink Savilleb564aae2014-10-23 10:18:09 -07001599 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001600 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001601
1602 final long identity = Binder.clearCallingIdentity();
1603 try {
1604 final Phone phone = getPhone(subId);
1605 if (phone == null) {
1606 return false;
1607 }
1608 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1609 toggleRadioOnOffForSubscriber(subId);
1610 }
1611 return true;
1612 } finally {
1613 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
Wink Saville36469e72014-06-11 15:17:00 -07001616
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001617 public boolean needMobileRadioShutdown() {
1618 /*
1619 * If any of the Radios are available, it will need to be
1620 * shutdown. So return true if any Radio is available.
1621 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001622 final long identity = Binder.clearCallingIdentity();
1623 try {
1624 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1625 Phone phone = PhoneFactory.getPhone(i);
1626 if (phone != null && phone.isRadioAvailable()) return true;
1627 }
1628 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1629 return false;
1630 } finally {
1631 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001632 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001633 }
1634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001635 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001636 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001637 enforceModifyPermission();
1638
1639 final long identity = Binder.clearCallingIdentity();
1640 try {
1641 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1642 logv("Shutting down Phone " + i);
1643 shutdownRadioUsingPhoneId(i);
1644 }
1645 } finally {
1646 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001647 }
1648 }
1649
1650 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001651 Phone phone = PhoneFactory.getPhone(phoneId);
1652 if (phone != null && phone.isRadioAvailable()) {
1653 phone.shutdownRadio();
1654 }
1655 }
1656
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001659
1660 final long identity = Binder.clearCallingIdentity();
1661 try {
1662 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1663 if (defaultPhone != null) {
1664 defaultPhone.setRadioPower(turnOn);
1665 return true;
1666 } else {
1667 loge("There's no default phone.");
1668 return false;
1669 }
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001672 }
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
1674
Wink Savilleb564aae2014-10-23 10:18:09 -07001675 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001677
1678 final long identity = Binder.clearCallingIdentity();
1679 try {
1680 final Phone phone = getPhone(subId);
1681 if (phone != null) {
1682 phone.setRadioPower(turnOn);
1683 return true;
1684 } else {
1685 return false;
1686 }
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
1691
Wink Saville36469e72014-06-11 15:17:00 -07001692 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 public boolean enableDataConnectivity() {
1695 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001696
1697 final long identity = Binder.clearCallingIdentity();
1698 try {
1699 int subId = mSubscriptionController.getDefaultDataSubId();
1700 final Phone phone = getPhone(subId);
1701 if (phone != null) {
1702 phone.setUserDataEnabled(true);
1703 return true;
1704 } else {
1705 return false;
1706 }
1707 } finally {
1708 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 }
1711
Wink Saville36469e72014-06-11 15:17:00 -07001712 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 public boolean disableDataConnectivity() {
1715 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716
1717 final long identity = Binder.clearCallingIdentity();
1718 try {
1719 int subId = mSubscriptionController.getDefaultDataSubId();
1720 final Phone phone = getPhone(subId);
1721 if (phone != null) {
1722 phone.setUserDataEnabled(false);
1723 return true;
1724 } else {
1725 return false;
1726 }
1727 } finally {
1728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 }
1731
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001733 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
1738 return phone.isDataAllowed();
1739 } else {
1740 return false;
1741 }
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
1747 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001748 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001749 }
1750
pkanwarae03a6b2016-11-06 20:37:09 -08001751 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752 enforceCallPermission();
1753
1754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1757 return;
1758 }
1759 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1760 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1761 } finally {
1762 Binder.restoreCallingIdentity(identity);
1763 }
pkanwar32d516d2016-10-14 19:37:38 -07001764 };
1765
Wink Savilleb564aae2014-10-23 10:18:09 -07001766 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768
1769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1772 return false;
1773 }
1774 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1775 } finally {
1776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001781 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001782 }
1783
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001784 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 Phone phone = PhoneFactory.getPhone(slotIndex);
1788 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1789 PhoneConstantConversions.convertCallState(phone.getState());
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
1792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
Sanket Padawe356d7632015-06-22 14:03:32 -07001795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1800 if (phone != null) {
1801 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1802 } else {
1803 return PhoneConstantConversions.convertDataState(
1804 PhoneConstants.DataState.DISCONNECTED);
1805 }
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1816 if (phone != null) {
1817 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1818 } else {
1819 return TelephonyManager.DATA_ACTIVITY_NONE;
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
1826 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001827 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001828 mPhone.getContext().getSystemService(AppOpsManager.class)
1829 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001830 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001831 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001832 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 }
1834
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001835 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 if (DBG_LOC) log("getCellLocation: is active user");
1839 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001840 int subId = mSubscriptionController.getDefaultDataSubId();
1841 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1842 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001843 return data;
1844 } finally {
1845 Binder.restoreCallingIdentity(identity);
1846 }
Svetoslav64fad262015-04-14 14:35:21 -07001847 }
1848
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001850 public String getNetworkCountryIsoForPhone(int phoneId) {
1851 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1852 // registered cell info, so return a NULL country instead.
1853 final long identity = Binder.clearCallingIdentity();
1854 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001855 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1856 // Get default phone in this case.
1857 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1858 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001859 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001860 // Todo: fix this when we can get the actual cellular network info when the device
1861 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001862 if (TelephonyManager.NETWORK_TYPE_IWLAN
1863 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1864 return "";
1865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 Phone phone = PhoneFactory.getPhone(phoneId);
1867 if (phone != null) {
1868 ServiceStateTracker sst = phone.getServiceStateTracker();
1869 if (sst != null) {
1870 LocaleTracker lt = sst.getLocaleTracker();
1871 if (lt != null) {
1872 return lt.getCurrentCountry();
1873 }
1874 }
1875 }
1876 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001877 } finally {
1878 Binder.restoreCallingIdentity(identity);
1879 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001880 }
1881
1882 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001884 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001885 }
1886
Sanket Padawe356d7632015-06-22 14:03:32 -07001887 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001888 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 mApp.enforceCallingOrSelfPermission(
1890 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891
1892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 final Phone phone = getPhone(subId);
1895 if (phone != null) {
1896 phone.enableLocationUpdates();
1897 }
1898 } finally {
1899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 }
1902
1903 @Override
1904 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001905 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001906 }
1907
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001909 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 mApp.enforceCallingOrSelfPermission(
1911 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001912
1913 final long identity = Binder.clearCallingIdentity();
1914 try {
1915 final Phone phone = getPhone(subId);
1916 if (phone != null) {
1917 phone.disableLocationUpdates();
1918 }
1919 } finally {
1920 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923
1924 @Override
1925 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001926 public List<NeighboringCellInfo>
1927 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001928 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1929 throw new SecurityException(
1930 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1931 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001932
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1934 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1935 return null;
1936 }
Svetoslav64fad262015-04-14 14:35:21 -07001937
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001938 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939
Nathan Haroldf180aac2018-06-01 18:43:55 -07001940 List<CellInfo> info = getAllCellInfo(callingPackage);
1941 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942
Nathan Haroldf180aac2018-06-01 18:43:55 -07001943 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1944 for (CellInfo ci : info) {
1945 if (ci instanceof CellInfoGsm) {
1946 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1947 } else if (ci instanceof CellInfoWcdma) {
1948 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001951 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
1953
1954
1955 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001956 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001957 mPhone.getContext().getSystemService(AppOpsManager.class)
1958 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001959 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001960 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001961 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001964 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001965 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 final long identity = Binder.clearCallingIdentity();
1967 try {
1968 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1969 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001970 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1971 CMD_GET_ALL_CELL_INFO,
1972 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001973 if (info != null) cellInfos.addAll(info);
1974 }
1975 return cellInfos;
1976 } finally {
1977 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979 }
1980
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001981 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001983 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001984 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985
1986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 mPhone.setCellInfoListRate(rateInMillis, workSource);
1989 } finally {
1990 Binder.restoreCallingIdentity(identity);
1991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 }
1993
Shishir Agrawala9f32182016-04-12 12:00:16 -07001994 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001995 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001996 Phone phone = PhoneFactory.getPhone(slotIndex);
1997 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001998 return null;
1999 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002000 int subId = phone.getSubId();
2001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2002 mApp, subId, callingPackage, "getImeiForSlot")) {
2003 return null;
2004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002005
2006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 return phone.getImei();
2009 } finally {
2010 Binder.restoreCallingIdentity(identity);
2011 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002012 }
2013
2014 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002015 public String getTypeAllocationCodeForSlot(int slotIndex) {
2016 Phone phone = PhoneFactory.getPhone(slotIndex);
2017 String tac = null;
2018 if (phone != null) {
2019 String imei = phone.getImei();
2020 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2021 }
2022 return tac;
2023 }
2024
2025 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002026 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002027 Phone phone = PhoneFactory.getPhone(slotIndex);
2028 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002029 return null;
2030 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002031 int subId = phone.getSubId();
2032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2033 mApp, subId, callingPackage, "getMeidForSlot")) {
2034 return null;
2035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036
2037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 return phone.getMeid();
2040 } finally {
2041 Binder.restoreCallingIdentity(identity);
2042 }
Jack Yu2af8d712017-03-15 17:14:14 -07002043 }
2044
2045 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002046 public String getManufacturerCodeForSlot(int slotIndex) {
2047 Phone phone = PhoneFactory.getPhone(slotIndex);
2048 String manufacturerCode = null;
2049 if (phone != null) {
2050 String meid = phone.getMeid();
2051 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2052 }
2053 return manufacturerCode;
2054 }
2055
2056 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002057 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002058 Phone phone = PhoneFactory.getPhone(slotIndex);
2059 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002060 return null;
2061 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002062 int subId = phone.getSubId();
2063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2064 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2065 return null;
2066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002067
2068 final long identity = Binder.clearCallingIdentity();
2069 try {
2070 return phone.getDeviceSvn();
2071 } finally {
2072 Binder.restoreCallingIdentity(identity);
2073 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002074 }
2075
fionaxu43304da2017-11-27 22:51:16 -08002076 @Override
2077 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 final Phone phone = getPhone(subId);
2081 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
2084 }
fionaxu43304da2017-11-27 22:51:16 -08002085 }
2086
2087 @Override
2088 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002089 final long identity = Binder.clearCallingIdentity();
2090 try {
2091 final Phone phone = getPhone(subId);
2092 return phone == null ? null : phone.getCarrierName();
2093 } finally {
2094 Binder.restoreCallingIdentity(identity);
2095 }
fionaxu43304da2017-11-27 22:51:16 -08002096 }
2097
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 //
2099 // Internal helper methods.
2100 //
2101
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002102 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2104 *
2105 * @throws SecurityException if the caller does not have the required permission
2106 */
2107 private void enforceModifyPermission() {
2108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2109 }
2110
2111 /**
2112 * Make sure the caller has the CALL_PHONE permission.
2113 *
2114 * @throws SecurityException if the caller does not have the required permission
2115 */
2116 private void enforceCallPermission() {
2117 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2118 }
2119
Stuart Scott8eef64f2015-04-08 15:13:54 -07002120 private void enforceConnectivityInternalPermission() {
2121 mApp.enforceCallingOrSelfPermission(
2122 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2123 "ConnectivityService");
2124 }
2125
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 private String createTelUrl(String number) {
2127 if (TextUtils.isEmpty(number)) {
2128 return null;
2129 }
2130
Jake Hambye994d462014-02-03 13:10:13 -08002131 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
2133
Ihab Awadf9e92732013-12-05 18:02:52 -08002134 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2136 }
2137
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002138 private static void logv(String msg) {
2139 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2140 }
2141
Ihab Awadf9e92732013-12-05 18:02:52 -08002142 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2144 }
2145
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002146 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002148 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002149 }
2150
Sanket Padawe356d7632015-06-22 14:03:32 -07002151 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002152 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 final Phone phone = PhoneFactory.getPhone(slotIndex);
2156 if (phone == null) {
2157 return PhoneConstants.PHONE_TYPE_NONE;
2158 } else {
2159 return phone.getPhoneType();
2160 }
2161 } finally {
2162 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002163 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 }
2165
2166 /**
2167 * Returns the CDMA ERI icon index to display
2168 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 @Override
2170 public int getCdmaEriIconIndex(String callingPackage) {
2171 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002172 }
2173
Sanket Padawe356d7632015-06-22 14:03:32 -07002174 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002175 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002177 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002178 return -1;
2179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180
2181 final long identity = Binder.clearCallingIdentity();
2182 try {
2183 final Phone phone = getPhone(subId);
2184 if (phone != null) {
2185 return phone.getCdmaEriIconIndex();
2186 } else {
2187 return -1;
2188 }
2189 } finally {
2190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193
2194 /**
2195 * Returns the CDMA ERI icon mode,
2196 * 0 - ON
2197 * 1 - FLASHING
2198 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002199 @Override
2200 public int getCdmaEriIconMode(String callingPackage) {
2201 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002202 }
2203
Sanket Padawe356d7632015-06-22 14:03:32 -07002204 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002205 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002207 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002208 return -1;
2209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210
2211 final long identity = Binder.clearCallingIdentity();
2212 try {
2213 final Phone phone = getPhone(subId);
2214 if (phone != null) {
2215 return phone.getCdmaEriIconMode();
2216 } else {
2217 return -1;
2218 }
2219 } finally {
2220 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 }
2223
2224 /**
2225 * Returns the CDMA ERI text,
2226 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002227 @Override
2228 public String getCdmaEriText(String callingPackage) {
2229 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002230 }
2231
Sanket Padawe356d7632015-06-22 14:03:32 -07002232 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002235 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002236 return null;
2237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238
2239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 final Phone phone = getPhone(subId);
2242 if (phone != null) {
2243 return phone.getCdmaEriText();
2244 } else {
2245 return null;
2246 }
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
2252 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002253 * Returns the CDMA MDN.
2254 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002255 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002256 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2258 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259
2260 final long identity = Binder.clearCallingIdentity();
2261 try {
2262 final Phone phone = getPhone(subId);
2263 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2264 return phone.getLine1Number();
2265 } else {
2266 return null;
2267 }
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002270 }
2271 }
2272
2273 /**
2274 * Returns the CDMA MIN.
2275 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002277 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2279 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002280
2281 final long identity = Binder.clearCallingIdentity();
2282 try {
2283 final Phone phone = getPhone(subId);
2284 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2285 return phone.getCdmaMin();
2286 } else {
2287 return null;
2288 }
2289 } finally {
2290 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002291 }
2292 }
2293
2294 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 * Returns true if CDMA provisioning needs to run.
2296 */
2297 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 return mPhone.needsOtaServiceProvisioning();
2301 } finally {
2302 Binder.restoreCallingIdentity(identity);
2303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 }
2305
2306 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002307 * Sets the voice mail number of a given subId.
2308 */
2309 @Override
2310 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002311 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2316 new Pair<String, String>(alphaTag, number), new Integer(subId));
2317 return success;
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
2320 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002321 }
2322
Ta-wei Yen87c49842016-05-13 21:19:52 -07002323 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002324 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2325 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2326 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2327 if (!TextUtils.equals(callingPackage, systemDialer)) {
2328 throw new SecurityException("caller must be system dialer");
2329 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
2333 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2334 if (phoneAccountHandle == null) {
2335 return null;
2336 }
2337 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002340 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002341 }
2342
2343 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002344 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002345 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002346 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002347 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002348 return null;
2349 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002351 final long identity = Binder.clearCallingIdentity();
2352 try {
2353 return RemoteVvmTaskManager
2354 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
2357 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002358 }
2359
2360 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002361 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2362 VisualVoicemailSmsFilterSettings settings) {
2363 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002364
2365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2368 mPhone.getContext(), callingPackage, subId, settings);
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
2371 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002372 }
2373
2374 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002375 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2376 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2381 mPhone.getContext(), callingPackage, subId);
2382 } finally {
2383 Binder.restoreCallingIdentity(identity);
2384 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002385 }
2386
2387 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002388 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2389 String callingPackage, int subId) {
2390 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002391
2392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2395 mPhone.getContext(), callingPackage, subId);
2396 } finally {
2397 Binder.restoreCallingIdentity(identity);
2398 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002399 }
2400
2401 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002402 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002403 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002404
2405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2408 mPhone.getContext(), subId);
2409 } finally {
2410 Binder.restoreCallingIdentity(identity);
2411 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002412 }
2413
2414 @Override
2415 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2416 String number, int port, String text, PendingIntent sentIntent) {
2417 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002418 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002419 enforceSendSmsPermission();
2420 // Make the calls as the phone process.
2421 final long identity = Binder.clearCallingIdentity();
2422 try {
2423 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2424 if (port == 0) {
2425 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2426 sentIntent, null, false);
2427 } else {
2428 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2429 smsManager.sendDataMessageWithSelfPermissions(number, null,
2430 (short) port, data, sentIntent, null);
2431 }
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
2434 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002435 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002436 /**
fionaxu0152e512016-11-14 13:36:14 -08002437 * Sets the voice activation state of a given subId.
2438 */
2439 @Override
2440 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2442 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443
2444 final long identity = Binder.clearCallingIdentity();
2445 try {
2446 final Phone phone = getPhone(subId);
2447 if (phone != null) {
2448 phone.setVoiceActivationState(activationState);
2449 } else {
2450 loge("setVoiceActivationState fails with invalid subId: " + subId);
2451 }
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002454 }
2455 }
2456
2457 /**
2458 * Sets the data activation state of a given subId.
2459 */
2460 @Override
2461 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2463 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 final Phone phone = getPhone(subId);
2468 if (phone != null) {
2469 phone.setDataActivationState(activationState);
2470 } else {
2471 loge("setVoiceActivationState fails with invalid subId: " + subId);
2472 }
2473 } finally {
2474 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002475 }
2476 }
2477
2478 /**
2479 * Returns the voice activation state of a given subId.
2480 */
2481 @Override
2482 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002483 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484
fionaxu0152e512016-11-14 13:36:14 -08002485 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 if (phone != null) {
2489 return phone.getVoiceActivationState();
2490 } else {
2491 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2492 }
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002495 }
2496 }
2497
2498 /**
2499 * Returns the data activation state of a given subId.
2500 */
2501 @Override
2502 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002503 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504
fionaxu0152e512016-11-14 13:36:14 -08002505 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 if (phone != null) {
2509 return phone.getDataActivationState();
2510 } else {
2511 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2512 }
2513 } finally {
2514 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002515 }
2516 }
2517
2518 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 * Returns the unread count of voicemails
2520 */
2521 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002522 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002523 }
2524
2525 /**
2526 * Returns the unread count of voicemails for a subId
2527 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002529 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 final Phone phone = getPhone(subId);
2533 if (phone != null) {
2534 return phone.getVoiceMessageCount();
2535 } else {
2536 return 0;
2537 }
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 }
2542
2543 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002544 * returns true, if the device is in a state where both voice and data
2545 * are supported simultaneously. This can change based on location or network condition.
2546 */
2547 @Override
2548 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 final Phone phone = getPhone(subId);
2552 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2553 } finally {
2554 Binder.restoreCallingIdentity(identity);
2555 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002556 }
2557
2558 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002559 * Send the dialer code if called from the current default dialer or the caller has
2560 * carrier privilege.
2561 * @param inputCode The dialer code to send
2562 */
2563 @Override
2564 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2565 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2566 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2567 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002568 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2569 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 mPhone.sendDialerSpecialCode(inputCode);
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
fionaxu235cc5e2017-03-06 22:25:57 -08002578 }
2579
2580 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002581 * Returns the data network type.
2582 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 *
2584 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2585 */
2586 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002587 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 final Phone phone = getPhone(getDefaultSubscription());
2591 if (phone != null) {
2592 return phone.getServiceState().getDataNetworkType();
2593 } else {
2594 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2595 }
2596 } finally {
2597 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002598 }
Wink Saville36469e72014-06-11 15:17:00 -07002599 }
2600
Pengquan Menga1bb6272018-09-06 09:59:22 -07002601 @Override
2602 public int getNetworkSelectionMode(int subId) {
2603 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2604 }
2605
Wink Saville36469e72014-06-11 15:17:00 -07002606 /**
2607 * Returns the network type for a subId
2608 */
2609 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002610 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002612 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002613 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2614 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 final Phone phone = getPhone(subId);
2619 if (phone != null) {
2620 return phone.getServiceState().getDataNetworkType();
2621 } else {
2622 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002626 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 }
2628
2629 /**
2630 * Returns the data network type
2631 */
2632 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002633 public int getDataNetworkType(String callingPackage) {
2634 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002635 }
2636
2637 /**
2638 * Returns the data network type for a subId
2639 */
2640 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002641 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002643 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002644 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2645 }
2646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 final Phone phone = getPhone(subId);
2650 if (phone != null) {
2651 return phone.getServiceState().getDataNetworkType();
2652 } else {
2653 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2654 }
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
2660 /**
Wink Saville36469e72014-06-11 15:17:00 -07002661 * Returns the Voice network type for a subId
2662 */
2663 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002664 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002666 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002667 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2668 }
2669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670 final long identity = Binder.clearCallingIdentity();
2671 try {
2672 final Phone phone = getPhone(subId);
2673 if (phone != null) {
2674 return phone.getServiceState().getVoiceNetworkType();
2675 } else {
2676 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2677 }
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 }
2682
2683 /**
2684 * @return true if a ICC card is present
2685 */
2686 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002687 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002688 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2689 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002690 }
2691
2692 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002693 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002694 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002695 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002696 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 final Phone phone = PhoneFactory.getPhone(slotIndex);
2700 if (phone != null) {
2701 return phone.getIccCard().hasIccCard();
2702 } else {
2703 return false;
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 }
2709
2710 /**
2711 * Return if the current radio is LTE on CDMA. This
2712 * is a tri-state return value as for a period of time
2713 * the mode may be unknown.
2714 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002715 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002717 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002719 @Override
2720 public int getLteOnCdmaMode(String callingPackage) {
2721 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002722 }
2723
Sanket Padawe356d7632015-06-22 14:03:32 -07002724 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002725 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002727 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002728 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2729 }
2730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 final long identity = Binder.clearCallingIdentity();
2732 try {
2733 final Phone phone = getPhone(subId);
2734 if (phone == null) {
2735 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2736 } else {
2737 return phone.getLteOnCdmaMode();
2738 }
2739 } finally {
2740 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002741 }
Wink Saville36469e72014-06-11 15:17:00 -07002742 }
2743
2744 public void setPhone(Phone phone) {
2745 mPhone = phone;
2746 }
2747
2748 /**
2749 * {@hide}
2750 * Returns Default subId, 0 in the case of single standby.
2751 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002752 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002753 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002754 }
2755
Shishir Agrawala9f32182016-04-12 12:00:16 -07002756 private int getSlotForDefaultSubscription() {
2757 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2758 }
2759
Wink Savilleb564aae2014-10-23 10:18:09 -07002760 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002761 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002763
2764 /**
2765 * @see android.telephony.TelephonyManager.WifiCallingChoices
2766 */
2767 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2771 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2772 getWhenToMakeWifiCallsDefaultPreference());
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002776 }
2777
2778 /**
2779 * @see android.telephony.TelephonyManager.WifiCallingChoices
2780 */
2781 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2785 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2786 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
2789 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002790 }
2791
Sailesh Nepald1e68152013-12-12 19:08:02 -08002792 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002793 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002794 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002795 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002796
Shishir Agrawal566b7612013-10-28 14:41:00 -07002797 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002798 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2799 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2801 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 if (TextUtils.equals(ISDR_AID, aid)) {
2807 // Only allows LPA to open logical channel to ISD-R.
2808 ComponentInfo bestComponent =
2809 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2810 if (bestComponent == null
2811 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2812 loge("The calling package is not allowed to access ISD-R.");
2813 throw new SecurityException(
2814 "The calling package is not allowed to access ISD-R.");
2815 }
Derek Tan740e1672017-06-27 14:56:27 -07002816 }
Derek Tan740e1672017-06-27 14:56:27 -07002817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 if (DBG) {
2819 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2820 }
2821 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2822 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2823 if (DBG) log("iccOpenLogicalChannel: " + response);
2824 return response;
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
2827 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002828 }
2829
2830 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002831 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2833 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2838 if (channel < 0) {
2839 return false;
2840 }
2841 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2842 if (DBG) log("iccCloseLogicalChannel: " + success);
2843 return success;
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002846 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002847 }
2848
2849 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002850 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002851 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2853 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 if (DBG) {
2858 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2859 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2860 + p3 + " data=" + data);
2861 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863 if (channel < 0) {
2864 return "";
2865 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2868 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2869 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 // Append the returned status code to the end of the response payload.
2872 String s = Integer.toHexString(
2873 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2874 if (response.payload != null) {
2875 s = IccUtils.bytesToHexString(response.payload) + s;
2876 }
2877 return s;
2878 } finally {
2879 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002880 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002881 }
Jake Hambye994d462014-02-03 13:10:13 -08002882
Evan Charltonc66da362014-05-16 14:06:40 -07002883 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002884 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2885 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2887 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2893 && TextUtils.equals(ISDR_AID, data)) {
2894 // Only allows LPA to select ISD-R.
2895 ComponentInfo bestComponent =
2896 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2897 if (bestComponent == null
2898 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2899 loge("The calling package is not allowed to select ISD-R.");
2900 throw new SecurityException(
2901 "The calling package is not allowed to select ISD-R.");
2902 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002903 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 if (DBG) {
2906 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2907 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2908 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2911 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2912 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914 // Append the returned status code to the end of the response payload.
2915 String s = Integer.toHexString(
2916 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2917 if (response.payload != null) {
2918 s = IccUtils.bytesToHexString(response.payload) + s;
2919 }
2920 return s;
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002923 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002924 }
2925
2926 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002927 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002928 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2930 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 if (DBG) {
2935 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2936 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2937 }
2938
2939 IccIoResult response =
2940 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2941 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2942 subId);
2943
2944 if (DBG) {
2945 log("Exchange SIM_IO [R]" + response);
2946 }
2947
2948 byte[] result = null;
2949 int length = 2;
2950 if (response.payload != null) {
2951 length = 2 + response.payload.length;
2952 result = new byte[length];
2953 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2954 } else {
2955 result = new byte[length];
2956 }
2957
2958 result[length - 1] = (byte) response.sw2;
2959 result[length - 2] = (byte) response.sw1;
2960 return result;
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002963 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002964 }
2965
Nathan Haroldb3014052017-01-25 15:57:32 -08002966 /**
2967 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2968 * on a particular subscription
2969 */
sqianb6e41952018-03-12 14:54:01 -07002970 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2972 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2973 return null;
2974 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975
2976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 if (appType != TelephonyManager.APPTYPE_USIM
2979 && appType != TelephonyManager.APPTYPE_SIM) {
2980 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2981 return null;
2982 }
2983 Object response = sendRequest(
2984 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2985 if (response instanceof String[]) {
2986 return (String[]) response;
2987 }
2988 // Response is an Exception of some kind,
2989 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08002990 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 } finally {
2992 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002993 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002994 }
2995
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002996 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002997 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2999 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3004 if (response.payload == null) {
3005 return "";
3006 }
Evan Charltonc66da362014-05-16 14:06:40 -07003007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 // Append the returned status code to the end of the response payload.
3009 String s = Integer.toHexString(
3010 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3011 s = IccUtils.bytesToHexString(response.payload) + s;
3012 return s;
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
3015 }
Evan Charltonc66da362014-05-16 14:06:40 -07003016 }
3017
Jake Hambye994d462014-02-03 13:10:13 -08003018 /**
3019 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3020 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3021 *
3022 * @param itemID the ID of the item to read
3023 * @return the NV item as a String, or null on error.
3024 */
3025 @Override
3026 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003027 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3029 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003034 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3036 return value;
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Jake Hambye994d462014-02-03 13:10:13 -08003040 }
3041
3042 /**
3043 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3044 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3045 *
3046 * @param itemID the ID of the item to read
3047 * @param itemValue the value to write, as a String
3048 * @return true on success; false on any failure
3049 */
3050 @Override
3051 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003052 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3054 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055
3056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3059 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003060 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3062 return success;
3063 } finally {
3064 Binder.restoreCallingIdentity(identity);
3065 }
Jake Hambye994d462014-02-03 13:10:13 -08003066 }
3067
3068 /**
3069 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3070 * Used for device configuration by some CDMA operators.
3071 *
3072 * @param preferredRoamingList byte array containing the new PRL
3073 * @return true on success; false on any failure
3074 */
3075 @Override
3076 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3078 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003079
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3083 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3084 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3085 return success;
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
Jake Hambye994d462014-02-03 13:10:13 -08003089 }
3090
3091 /**
3092 * Perform the specified type of NV config reset.
3093 * Used for device configuration by some CDMA operators.
3094 *
3095 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3096 * @return true on success; false on any failure
3097 */
3098 @Override
3099 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3101 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102
3103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 if (DBG) log("nvResetConfig: type " + resetType);
3106 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3107 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3108 return success;
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
Jake Hambye994d462014-02-03 13:10:13 -08003112 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003113
Svet Ganovb320e182015-04-16 12:30:10 -07003114 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003116 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003117 return new String[0];
3118 }
3119
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120 final long identity = Binder.clearCallingIdentity();
3121 try {
3122 return mPhone.getPcscfAddress(apnType);
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
3125 }
Wink Saville36469e72014-06-11 15:17:00 -07003126 }
3127
Brad Ebinger51f743a2017-01-23 13:50:20 -08003128 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003129 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3130 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003131 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003132 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134
3135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 PhoneFactory.getImsResolver().enableIms(slotId);
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
3140 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003141 }
3142
3143 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003144 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3145 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003146 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003147 public void disableIms(int slotId) {
3148 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 PhoneFactory.getImsResolver().disableIms(slotId);
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003156 }
3157
3158 /**
3159 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3160 * feature or {@link null} if the service is not available. If the feature is available, the
3161 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3162 */
3163 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003164 IImsServiceFeatureCallback callback) {
3165 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166
3167 final long identity = Binder.clearCallingIdentity();
3168 try {
3169 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
3172 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003173 }
3174
3175 /**
3176 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3177 * feature during emergency calling or {@link null} if the service is not available. If the
3178 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3179 * listener for feature updates.
3180 */
3181 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183
3184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003190 }
3191
Brad Ebinger5f64b052017-12-14 14:26:15 -08003192 /**
3193 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3194 * specified.
3195 */
3196 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3197 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198
3199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
3204 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003205 }
3206
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003207 /**
3208 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3209 * specified.
3210 */
3211 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3212 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213
3214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003220 }
3221
Brad Ebinger884c07b2018-02-15 16:17:40 -08003222 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003223 * Sets the ImsService Package Name that Telephony will bind to.
3224 *
3225 * @param slotId the slot ID that the ImsService should bind for.
3226 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3227 * ImsService is the device default ImsService.
3228 * @param packageName The package name of the application that contains the ImsService to bind
3229 * to.
3230 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3231 * @hide
3232 */
3233 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003234 int[] subIds = SubscriptionManager.getSubId(slotId);
3235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3236 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3237 "setImsService");
3238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3242 isCarrierImsService, packageName);
3243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003246 }
3247
3248 /**
3249 * Return the ImsService configuration.
3250 *
3251 * @param slotId The slot that the ImsService is associated with.
3252 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3253 * the device default.
3254 * @return the package name of the ImsService configuration.
3255 */
3256 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003257 int[] subIds = SubscriptionManager.getSubId(slotId);
3258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3259 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3260 "getImsService");
3261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3265 isCarrierImsService);
3266 } finally {
3267 Binder.restoreCallingIdentity(identity);
3268 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003269 }
3270
Wink Saville36469e72014-06-11 15:17:00 -07003271 public void setImsRegistrationState(boolean registered) {
3272 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 mPhone.setImsRegistrationState(registered);
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
Wink Saville36469e72014-06-11 15:17:00 -07003280 }
3281
3282 /**
Stuart Scott54788802015-03-30 13:18:01 -07003283 * Set the network selection mode to automatic.
3284 *
3285 */
3286 @Override
3287 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3289 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290
3291 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");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 final long identity = Binder.clearCallingIdentity();
3317 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003318 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003320 if (DBG) {
3321 log("setNetworkSelectionModeManual: subId: " + subId
3322 + " operator: " + operatorInfo);
3323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003328 }
3329
3330 /**
3331 * Scans for available networks.
3332 */
3333 @Override
3334 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3336 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337
Pengquan Menga1bb6272018-09-06 09:59:22 -07003338 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 try {
3340 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003341 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003346 }
3347
3348 /**
yinxub1bed742017-04-17 11:45:04 -07003349 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003350 *
yinxub1bed742017-04-17 11:45:04 -07003351 * @param subId id of the subscription
3352 * @param request contains the radio access networks with bands/channels to scan
3353 * @param messenger callback messenger for scan results or errors
3354 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003355 * @return the id of the requested scan which can be used to stop the scan.
3356 */
3357 @Override
3358 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3359 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3361 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362
3363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 return mNetworkScanRequestTracker.startNetworkScan(
3366 request, messenger, binder, getPhone(subId));
3367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
yinxu504e1392017-04-12 16:03:22 -07003370 }
3371
3372 /**
3373 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003374 *
3375 * @param subId id of the subscription
3376 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003377 */
3378 @Override
3379 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3381 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
yinxu504e1392017-04-12 16:03:22 -07003389 }
3390
3391 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003392 * Get the calculated preferred network type.
3393 * Used for debugging incorrect network type.
3394 *
3395 * @return the preferred network type, defined in RILConstants.java.
3396 */
3397 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003398 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003400 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003401 return RILConstants.PREFERRED_NETWORK_MODE;
3402 }
3403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 final long identity = Binder.clearCallingIdentity();
3405 try {
3406 // FIXME: need to get SubId from somewhere.
3407 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
Junda Liu84d15a22014-07-02 11:21:04 -07003411 }
3412
3413 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003414 * Get the preferred network type.
3415 * Used for device configuration by some CDMA operators.
3416 *
3417 * @return the preferred network type, defined in RILConstants.java.
3418 */
3419 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003420 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3422 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423
3424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 if (DBG) log("getPreferredNetworkType");
3427 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3428 int networkType = (result != null ? result[0] : -1);
3429 if (DBG) log("getPreferredNetworkType: " + networkType);
3430 return networkType;
3431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003434 }
3435
3436 /**
3437 * Set the preferred network type.
3438 * Used for device configuration by some CDMA operators.
3439 *
3440 * @param networkType the preferred network type, defined in RILConstants.java.
3441 * @return true on success; false on any failure.
3442 */
3443 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003444 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3446 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3451 Boolean success = (Boolean) sendRequest(
3452 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3453 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3454 if (success) {
3455 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3456 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3457 }
3458 return success;
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003461 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003462 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003463
3464 /**
Junda Liu475951f2014-11-07 16:45:03 -08003465 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3466 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3467 * tethering.
3468 *
3469 * @return 0: Not required. 1: required. 2: Not set.
3470 * @hide
3471 */
3472 @Override
3473 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003475
3476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3479 Settings.Global.TETHER_DUN_REQUIRED, 2);
3480 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3481 // config_tether_apndata.
3482 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3483 dunRequired = 1;
3484 }
3485 return dunRequired;
3486 } finally {
3487 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003488 }
Junda Liu475951f2014-11-07 16:45:03 -08003489 }
3490
3491 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003492 * Set mobile data enabled
3493 * Used by the user through settings etc to turn on/off mobile data
3494 *
3495 * @param enable {@code true} turn turn data on, else {@code false}
3496 */
3497 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003498 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3500 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003501
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 int phoneId = mSubscriptionController.getPhoneId(subId);
3505 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3506 Phone phone = PhoneFactory.getPhone(phoneId);
3507 if (phone != null) {
3508 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3509 phone.setUserDataEnabled(enable);
3510 } else {
3511 loge("setUserDataEnabled: no phone for subId=" + subId);
3512 }
3513 } finally {
3514 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003515 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003516 }
3517
3518 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003519 * Get the user enabled state of Mobile Data.
3520 *
3521 * TODO: remove and use isUserDataEnabled.
3522 * This can't be removed now because some vendor codes
3523 * calls through ITelephony directly while they should
3524 * use TelephonyManager.
3525 *
3526 * @return true on enabled
3527 */
3528 @Override
3529 public boolean getDataEnabled(int subId) {
3530 return isUserDataEnabled(subId);
3531 }
3532
3533 /**
3534 * Get whether mobile data is enabled per user setting.
3535 *
3536 * There are other factors deciding whether mobile data is actually enabled, but they are
3537 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003538 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003539 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003540 *
3541 * @return {@code true} if data is enabled else {@code false}
3542 */
3543 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003544 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003545 try {
3546 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3547 null);
3548 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3550 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003552
3553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 int phoneId = mSubscriptionController.getPhoneId(subId);
3556 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3557 Phone phone = PhoneFactory.getPhone(phoneId);
3558 if (phone != null) {
3559 boolean retVal = phone.isUserDataEnabled();
3560 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3561 return retVal;
3562 } else {
3563 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3564 return false;
3565 }
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003568 }
3569 }
3570
3571 /**
3572 * Get whether mobile data is enabled.
3573 *
3574 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3575 * whether mobile data is actually enabled.
3576 *
3577 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3578 *
3579 * @return {@code true} if data is enabled else {@code false}
3580 */
3581 @Override
3582 public boolean isDataEnabled(int subId) {
3583 try {
3584 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3585 null);
3586 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3588 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003590
3591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 int phoneId = mSubscriptionController.getPhoneId(subId);
3594 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3595 Phone phone = PhoneFactory.getPhone(phoneId);
3596 if (phone != null) {
3597 boolean retVal = phone.isDataEnabled();
3598 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3599 return retVal;
3600 } else {
3601 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3602 return false;
3603 }
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003606 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003607 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003608
3609 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003610 public int getCarrierPrivilegeStatus(int subId) {
3611 final Phone phone = getPhone(subId);
3612 if (phone == null) {
3613 loge("getCarrierPrivilegeStatus: Invalid subId");
3614 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3615 }
3616 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003617 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003618 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003619 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3620 }
3621 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003622 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003623 }
Junda Liu29340342014-07-10 15:23:27 -07003624
3625 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003626 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3627 final Phone phone = getPhone(subId);
3628 if (phone == null) {
3629 loge("getCarrierPrivilegeStatus: Invalid subId");
3630 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3631 }
3632 UiccProfile profile =
3633 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3634 if (profile == null) {
3635 loge("getCarrierPrivilegeStatus: No UICC");
3636 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3637 }
3638 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3639 }
3640
3641 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003642 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003643 if (TextUtils.isEmpty(pkgName))
3644 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003645 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003646 if (card == null) {
3647 loge("checkCarrierPrivilegesForPackage: No UICC");
3648 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3649 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003650 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3651 }
3652
3653 @Override
3654 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003655 if (TextUtils.isEmpty(pkgName))
3656 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003657 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3658 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3659 UiccCard card = UiccController.getInstance().getUiccCard(i);
3660 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003661 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003662 continue;
3663 }
3664
3665 result = card.getCarrierPrivilegeStatus(
3666 mPhone.getContext().getPackageManager(), pkgName);
3667 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3668 break;
3669 }
3670 }
3671
3672 return result;
Junda Liu29340342014-07-10 15:23:27 -07003673 }
Derek Tan89e89d42014-07-08 17:00:10 -07003674
3675 @Override
Junda Liue64de782015-04-16 17:19:16 -07003676 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3677 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3678 loge("phoneId " + phoneId + " is not valid.");
3679 return null;
3680 }
3681 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003682 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003683 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003684 return null ;
3685 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003686 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003687 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003688 }
3689
Amith Yamasani6e118872016-02-19 12:53:51 -08003690 @Override
3691 public List<String> getPackagesWithCarrierPrivileges() {
3692 PackageManager pm = mPhone.getContext().getPackageManager();
3693 List<String> privilegedPackages = new ArrayList<>();
3694 List<PackageInfo> packages = null;
3695 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3696 UiccCard card = UiccController.getInstance().getUiccCard(i);
3697 if (card == null) {
3698 // No UICC in that slot.
3699 continue;
3700 }
3701 if (card.hasCarrierPrivilegeRules()) {
3702 if (packages == null) {
3703 // Only check packages in user 0 for now
3704 packages = pm.getInstalledPackagesAsUser(
3705 PackageManager.MATCH_DISABLED_COMPONENTS
3706 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3707 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3708 }
3709 for (int p = packages.size() - 1; p >= 0; p--) {
3710 PackageInfo pkgInfo = packages.get(p);
3711 if (pkgInfo != null && pkgInfo.packageName != null
3712 && card.getCarrierPrivilegeStatus(pkgInfo)
3713 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3714 privilegedPackages.add(pkgInfo.packageName);
3715 }
3716 }
3717 }
3718 }
3719 return privilegedPackages;
3720 }
3721
Wink Savilleb564aae2014-10-23 10:18:09 -07003722 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003723 final Phone phone = getPhone(subId);
3724 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003725 if (card == null) {
3726 loge("getIccId: No UICC");
3727 return null;
3728 }
3729 String iccId = card.getIccId();
3730 if (TextUtils.isEmpty(iccId)) {
3731 loge("getIccId: ICC ID is null or empty.");
3732 return null;
3733 }
3734 return iccId;
3735 }
3736
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003737 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003738 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3739 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003740 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3741 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 final String iccId = getIccId(subId);
3746 final Phone phone = getPhone(subId);
3747 if (phone == null) {
3748 return false;
3749 }
3750 final String subscriberId = phone.getSubscriberId();
3751
3752 if (DBG_MERGE) {
3753 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3754 + subscriberId + " to " + number);
3755 }
3756
3757 if (TextUtils.isEmpty(iccId)) {
3758 return false;
3759 }
3760
3761 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3762
3763 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3764 if (alphaTag == null) {
3765 editor.remove(alphaTagPrefKey);
3766 } else {
3767 editor.putString(alphaTagPrefKey, alphaTag);
3768 }
3769
3770 // Record both the line number and IMSI for this ICCID, since we need to
3771 // track all merged IMSIs based on line number
3772 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3773 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3774 if (number == null) {
3775 editor.remove(numberPrefKey);
3776 editor.remove(subscriberPrefKey);
3777 } else {
3778 editor.putString(numberPrefKey, number);
3779 editor.putString(subscriberPrefKey, subscriberId);
3780 }
3781
3782 editor.commit();
3783 return true;
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003786 }
Derek Tan7226c842014-07-02 17:42:23 -07003787 }
3788
3789 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003790 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003791 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003793 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003794 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003795 return null;
3796 }
Derek Tan97ebb422014-09-05 16:55:38 -07003797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 String iccId = getIccId(subId);
3801 if (iccId != null) {
3802 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3803 if (DBG_MERGE) {
3804 log("getLine1NumberForDisplay returning "
3805 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3806 }
3807 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3810 return null;
3811 } finally {
3812 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003813 }
Derek Tan7226c842014-07-02 17:42:23 -07003814 }
3815
3816 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003817 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003818 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003819 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003820 return null;
3821 }
Derek Tan97ebb422014-09-05 16:55:38 -07003822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 String iccId = getIccId(subId);
3826 if (iccId != null) {
3827 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3828 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3829 }
3830 return null;
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003833 }
Derek Tan7226c842014-07-02 17:42:23 -07003834 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003835
3836 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003837 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003838 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3839 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003841 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3842 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003843 return null;
3844 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003845
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003846 final long identity = Binder.clearCallingIdentity();
3847 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 final Context context = mPhone.getContext();
3849 final TelephonyManager tele = TelephonyManager.from(context);
3850 final SubscriptionManager sub = SubscriptionManager.from(context);
3851
3852 // Figure out what subscribers are currently active
3853 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3854 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3855 // the process, where TelephonyManager was instantiated.
3856 // Otherwise AppOps check will fail.
3857
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003858 final int[] subIds = sub.getActiveSubscriptionIdList();
3859 for (int subId : subIds) {
3860 activeSubscriberIds.add(tele.getSubscriberId(subId));
3861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003862
3863 // First pass, find a number override for an active subscriber
3864 String mergeNumber = null;
3865 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3866 for (String key : prefs.keySet()) {
3867 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3868 final String subscriberId = (String) prefs.get(key);
3869 if (activeSubscriberIds.contains(subscriberId)) {
3870 final String iccId = key.substring(
3871 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3872 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3873 mergeNumber = (String) prefs.get(numberKey);
3874 if (DBG_MERGE) {
3875 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3876 + " for active subscriber " + subscriberId);
3877 }
3878 if (!TextUtils.isEmpty(mergeNumber)) {
3879 break;
3880 }
3881 }
3882 }
3883 }
3884
3885 // Shortcut when no active merged subscribers
3886 if (TextUtils.isEmpty(mergeNumber)) {
3887 return null;
3888 }
3889
3890 // Second pass, find all subscribers under that line override
3891 final ArraySet<String> result = new ArraySet<>();
3892 for (String key : prefs.keySet()) {
3893 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3894 final String number = (String) prefs.get(key);
3895 if (mergeNumber.equals(number)) {
3896 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3897 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3898 final String subscriberId = (String) prefs.get(subscriberKey);
3899 if (!TextUtils.isEmpty(subscriberId)) {
3900 result.add(subscriberId);
3901 }
3902 }
3903 }
3904 }
3905
3906 final String[] resultArray = result.toArray(new String[result.size()]);
3907 Arrays.sort(resultArray);
3908 if (DBG_MERGE) {
3909 Slog.d(LOG_TAG,
3910 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3911 }
3912 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003913 } finally {
3914 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003915 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003916 }
3917
3918 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003919 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003920 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3921 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003922
3923 final long identity = Binder.clearCallingIdentity();
3924 try {
3925 final Phone phone = getPhone(subId);
3926 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3927 } finally {
3928 Binder.restoreCallingIdentity(identity);
3929 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003930 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003931
3932 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003933 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003934 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3935 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003936 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937
3938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 final Phone phone = getPhone(subId);
3941 if (phone == null) {
3942 return false;
3943 }
3944 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3945 cdmaNonRoamingList);
3946 } finally {
3947 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003948 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003949 }
3950
3951 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003952 @Deprecated
3953 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3954 enforceModifyPermission();
3955
3956 int returnValue = 0;
3957 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07003958 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003959 if(result.exception == null) {
3960 if (result.result != null) {
3961 byte[] responseData = (byte[])(result.result);
3962 if(responseData.length > oemResp.length) {
3963 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3964 responseData.length + "bytes. Buffer Size is " +
3965 oemResp.length + "bytes.");
3966 }
3967 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3968 returnValue = responseData.length;
3969 }
3970 } else {
3971 CommandException ex = (CommandException) result.exception;
3972 returnValue = ex.getCommandError().ordinal();
3973 if(returnValue > 0) returnValue *= -1;
3974 }
3975 } catch (RuntimeException e) {
3976 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3977 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3978 if(returnValue > 0) returnValue *= -1;
3979 }
3980
3981 return returnValue;
3982 }
3983
3984 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003985 public void setRadioCapability(RadioAccessFamily[] rafs) {
3986 try {
3987 ProxyController.getInstance().setRadioCapability(rafs);
3988 } catch (RuntimeException e) {
3989 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3990 }
3991 }
3992
3993 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003994 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003995 Phone phone = PhoneFactory.getPhone(phoneId);
3996 if (phone == null) {
3997 return RadioAccessFamily.RAF_UNKNOWN;
3998 }
3999 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004001 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004002 return RadioAccessFamily.RAF_UNKNOWN;
4003 }
4004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4008 } finally {
4009 Binder.restoreCallingIdentity(identity);
4010 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004011 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004012
4013 @Override
4014 public void enableVideoCalling(boolean enable) {
4015 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016
4017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4020 } finally {
4021 Binder.restoreCallingIdentity(identity);
4022 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004023 }
4024
4025 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004026 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4028 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4029 return false;
4030 }
Svet Ganovb320e182015-04-16 12:30:10 -07004031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 // Check the user preference and the system-level IMS setting. Even if the user has
4035 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4036 // In the long run, we may instead need to check if there exists a connection service
4037 // which can support video calling.
4038 ImsManager imsManager =
4039 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4040 return imsManager.isVtEnabledByPlatform()
4041 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4042 && imsManager.isVtEnabledByUser();
4043 } finally {
4044 Binder.restoreCallingIdentity(identity);
4045 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004046 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004047
Andrew Leea1239f22015-03-02 17:44:07 -08004048 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4051 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4052 return false;
4053 }
4054
4055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 CarrierConfigManager configManager =
4058 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4059 return configManager.getConfigForSubId(mPhone.getSubId())
4060 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
Andrew Leea1239f22015-03-02 17:44:07 -08004064 }
4065
4066 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067 public boolean isWorldPhone(int subId, String callingPackage) {
4068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4069 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4070 return false;
4071 }
4072
4073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 CarrierConfigManager configManager =
4076 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4077 return configManager.getConfigForSubId(mPhone.getSubId())
4078 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4079 } finally {
4080 Binder.restoreCallingIdentity(identity);
4081 }
Andrew Leea1239f22015-03-02 17:44:07 -08004082 }
4083
Andrew Lee9431b832015-03-09 18:46:45 -07004084 @Override
4085 public boolean isTtyModeSupported() {
4086 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004087 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004088 }
4089
4090 @Override
4091 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4095 } finally {
4096 Binder.restoreCallingIdentity(identity);
4097 }
Andrew Lee9431b832015-03-09 18:46:45 -07004098 }
4099
Hall Liu98187582018-01-22 19:15:32 -08004100 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4104 mPhone.getSubId()).getBoolean(
4105 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4106 boolean isDeviceSupported =
4107 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4108 return isCarrierSupported && isDeviceSupported;
4109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
Hall Liu98187582018-01-22 19:15:32 -08004112 }
4113
Hall Liu3ad5f012018-04-06 16:23:39 -07004114 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 return isRttSupported() && Settings.Secure.getInt(
4118 mPhone.getContext().getContentResolver(),
4119 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4120 } finally {
4121 Binder.restoreCallingIdentity(identity);
4122 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004123 }
4124
Sanket Padawe7310cc72015-01-14 09:53:20 -08004125 /**
4126 * Returns the unique device ID of phone, for example, the IMEI for
4127 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4128 *
4129 * <p>Requires Permission:
4130 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4131 */
4132 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004133 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004134 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004135 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004136 return null;
4137 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004138 int subId = phone.getSubId();
4139 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4140 mApp, subId, callingPackage, "getDeviceId")) {
4141 return null;
4142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143
4144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 return phone.getDeviceId();
4147 } finally {
4148 Binder.restoreCallingIdentity(identity);
4149 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004150 }
4151
Ping Sunc67b7c22016-03-02 19:16:45 +08004152 /**
4153 * {@hide}
4154 * Returns the IMS Registration Status on a particular subid
4155 *
4156 * @param subId
4157 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004158 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004159 Phone phone = getPhone(subId);
4160 if (phone != null) {
4161 return phone.isImsRegistered();
4162 } else {
4163 return false;
4164 }
4165 }
4166
Santos Cordon7a1885b2015-02-03 11:15:19 -08004167 @Override
4168 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4172 } finally {
4173 Binder.restoreCallingIdentity(identity);
4174 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004175 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004176
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004177 /**
4178 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004179 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004180 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004181 final long identity = Binder.clearCallingIdentity();
4182 try {
4183 Phone phone = getPhone(subId);
4184 if (phone != null) {
4185 return phone.isWifiCallingEnabled();
4186 } else {
4187 return false;
4188 }
4189 } finally {
4190 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004191 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004192 }
4193
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004194 /**
4195 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004196 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004197 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 Phone phone = getPhone(subId);
4201 if (phone != null) {
4202 return phone.isVolteEnabled();
4203 } else {
4204 return false;
4205 }
4206 } finally {
4207 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004208 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004209 }
Svet Ganovb320e182015-04-16 12:30:10 -07004210
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004211 /**
4212 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004213 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004214 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 Phone phone = getPhone(subId);
4218 if (phone != null) {
4219 return phone.isVideoEnabled();
4220 } else {
4221 return false;
4222 }
4223 } finally {
4224 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004225 }
4226 }
4227
4228 /**
4229 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4230 * defined in {@link ImsRegistrationImplBase}.
4231 */
4232 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004233 final long identity = Binder.clearCallingIdentity();
4234 try {
4235 Phone phone = getPhone(subId);
4236 if (phone != null) {
4237 return phone.getImsRegistrationTech();
4238 } else {
4239 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4240 }
4241 } finally {
4242 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004243 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004244 }
4245
Stuart Scott8eef64f2015-04-08 15:13:54 -07004246 @Override
4247 public void factoryReset(int subId) {
4248 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004249 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4250 return;
4251 }
4252
Svet Ganovcc087f82015-05-12 20:35:54 -07004253 final long identity = Binder.clearCallingIdentity();
4254 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004255 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4256 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004257 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004258 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004259 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4260 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004261 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004262 }
4263 } finally {
4264 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004265 }
4266 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004267
4268 @Override
4269 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 final long identity = Binder.clearCallingIdentity();
4271 try {
4272 // We query all subscriptions instead of just the active ones, because
4273 // this might be called early on in the provisioning flow when the
4274 // subscriptions potentially aren't active yet.
4275 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4276 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004277 return null;
4278 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004280 // This function may be called very early, say, from the setup wizard, at
4281 // which point we won't have a default subscription set. If that's the case
4282 // we just choose the first, which will be valid in "most cases".
4283 final int defaultSubId = getDefaultSubscription();
4284 SubscriptionInfo info = null;
4285 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4286 info = slist.get(0);
4287 } else {
4288 for (SubscriptionInfo item : slist) {
4289 if (item.getSubscriptionId() == defaultSubId) {
4290 info = item;
4291 break;
4292 }
4293 }
4294
4295 if (info == null) {
4296 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004297 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004298 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004300 // Try and fetch the locale from the carrier properties or from the SIM language
4301 // preferences (EF-PL and EF-LI)...
4302 final int mcc = info.getMcc();
4303 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4304 String simLanguage = null;
4305 if (defaultPhone != null) {
4306 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4307 if (localeFromDefaultSim != null) {
4308 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4309 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4310 return localeFromDefaultSim.toLanguageTag();
4311 } else {
4312 simLanguage = localeFromDefaultSim.getLanguage();
4313 }
4314 }
4315 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 // The SIM language preferences only store a language (e.g. fr = French), not an
4318 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4319 // the SIM and carrier preferences does not include a country we add the country
4320 // determined from the SIM MCC to provide an exact locale.
4321 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4322 simLanguage);
4323 if (mccLocale != null) {
4324 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4325 return mccLocale.toLanguageTag();
4326 }
4327
4328 if (DBG) log("No locale found - returning null");
4329 return null;
4330 } finally {
4331 Binder.restoreCallingIdentity(identity);
4332 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004333 }
4334
4335 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336 return mSubscriptionController.getAllSubInfoList(
4337 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004338 }
4339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004340 /**
4341 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4342 */
4343 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4344 return mSubscriptionController.getActiveSubscriptionInfoList(
4345 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004346 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004347
Chenjie Yu1ba97252018-01-11 18:16:20 -08004348 private final ModemActivityInfo mLastModemActivityInfo =
4349 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4350
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004351 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004352 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4353 * representing the state of the modem.
4354 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004355 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4356 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004357 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004358 */
4359 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004360 public void requestModemActivityInfo(ResultReceiver result) {
4361 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004362 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363
4364 final long identity = Binder.clearCallingIdentity();
4365 try {
4366 ModemActivityInfo ret = null;
4367 synchronized (mLastModemActivityInfo) {
4368 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4369 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004370 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004371 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4373 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4374 mergedTxTimeMs[i] =
4375 info.getTxTimeMillis()[i]
4376 + mLastModemActivityInfo.getTxTimeMillis()[i];
4377 }
4378 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4379 mLastModemActivityInfo.setSleepTimeMillis(
4380 info.getSleepTimeMillis()
4381 + mLastModemActivityInfo.getSleepTimeMillis());
4382 mLastModemActivityInfo.setIdleTimeMillis(
4383 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4384 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4385 mLastModemActivityInfo.setRxTimeMillis(
4386 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4387 mLastModemActivityInfo.setEnergyUsed(
4388 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004390 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4391 mLastModemActivityInfo.getSleepTimeMillis(),
4392 mLastModemActivityInfo.getIdleTimeMillis(),
4393 mLastModemActivityInfo.getTxTimeMillis(),
4394 mLastModemActivityInfo.getRxTimeMillis(),
4395 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004396 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 Bundle bundle = new Bundle();
4398 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4399 result.send(0, bundle);
4400 } finally {
4401 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004402 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004403 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004404
Siddharth Rayb8114062018-06-17 15:02:38 -07004405 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4406 // less than total activity duration.
4407 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4408 if (info == null) {
4409 return false;
4410 }
4411 int activityDurationMs =
4412 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4413 int totalTxTimeMs = 0;
4414 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4415 totalTxTimeMs += info.getTxTimeMillis()[i];
4416 }
4417 return (info.isValid()
4418 && (info.getSleepTimeMillis() <= activityDurationMs)
4419 && (info.getIdleTimeMillis() <= activityDurationMs)
4420 && (info.getRxTimeMillis() <= activityDurationMs)
4421 && (totalTxTimeMs <= activityDurationMs));
4422 }
4423
Jack Yu85bd38a2015-11-09 11:34:32 -08004424 /**
4425 * {@hide}
4426 * Returns the service state information on specified subscription.
4427 */
4428 @Override
4429 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004430 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004431 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004432 return null;
4433 }
4434
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 final long identity = Binder.clearCallingIdentity();
4436 try {
4437 final Phone phone = getPhone(subId);
4438 if (phone == null) {
4439 return null;
4440 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 return phone.getServiceState();
4443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004446 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004447
4448 /**
4449 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4450 *
4451 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4452 * voicemail ringtone.
4453 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4454 * PhoneAccount.
4455 */
4456 @Override
4457 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458 final long identity = Binder.clearCallingIdentity();
4459 try {
4460 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4461 if (phone == null) {
4462 phone = mPhone;
4463 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004465 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004469 }
4470
4471 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004472 * Sets the per-account voicemail ringtone.
4473 *
4474 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4475 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4476 *
4477 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4478 * voicemail ringtone.
4479 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4480 * PhoneAccount.
4481 */
4482 @Override
4483 public void setVoicemailRingtoneUri(String callingPackage,
4484 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4486 if (!TextUtils.equals(callingPackage,
4487 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4489 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4490 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492
4493 final long identity = Binder.clearCallingIdentity();
4494 try {
4495 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4496 if (phone == null) {
4497 phone = mPhone;
4498 }
4499 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4500 } finally {
4501 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004502 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004503 }
4504
4505 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004506 * Returns whether vibration is set for voicemail notification in Phone settings.
4507 *
4508 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4509 * voicemail vibration setting.
4510 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4511 */
4512 @Override
4513 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 final long identity = Binder.clearCallingIdentity();
4515 try {
4516 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4517 if (phone == null) {
4518 phone = mPhone;
4519 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004525 }
4526
Youhan Wange64578a2016-05-02 15:32:42 -07004527 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004528 * Sets the per-account voicemail vibration.
4529 *
4530 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4531 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4532 *
4533 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4534 * voicemail vibration setting.
4535 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4536 * specific PhoneAccount.
4537 */
4538 @Override
4539 public void setVoicemailVibrationEnabled(String callingPackage,
4540 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4541 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4542 if (!TextUtils.equals(callingPackage,
4543 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4545 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4546 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004547 }
4548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549 final long identity = Binder.clearCallingIdentity();
4550 try {
4551 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4552 if (phone == null) {
4553 phone = mPhone;
4554 }
4555 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4556 } finally {
4557 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004558 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004559 }
4560
4561 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004562 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4563 *
4564 * @throws SecurityException if the caller does not have the required permission
4565 */
4566 private void enforceReadPrivilegedPermission() {
4567 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4568 null);
4569 }
4570
4571 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004572 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4573 * permission.
4574 *
4575 * @throws SecurityException if the caller does not have the required permission
4576 */
4577 private void enforceSendSmsPermission() {
4578 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4579 }
4580
4581 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004582 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004583 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004584 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004585 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004586 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004587 final long identity = Binder.clearCallingIdentity();
4588 try {
4589 ComponentName componentName =
4590 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4591 if (componentName == null) {
4592 throw new SecurityException(
4593 "Caller not current active visual voicemail package[null]");
4594 }
4595 String vvmPackage = componentName.getPackageName();
4596 if (!callingPackage.equals(vvmPackage)) {
4597 throw new SecurityException("Caller not current active visual voicemail package["
4598 + vvmPackage + "]");
4599 }
4600 } finally {
4601 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004602 }
4603 }
4604
4605 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004606 * Return the application ID for the app type.
4607 *
4608 * @param subId the subscription ID that this request applies to.
4609 * @param appType the uicc app type.
4610 * @return Application ID for specificied app type, or null if no uicc.
4611 */
4612 @Override
4613 public String getAidForAppType(int subId, int appType) {
4614 enforceReadPrivilegedPermission();
4615 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616
4617 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004618 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004619 if (phone == null) {
4620 return null;
4621 }
4622 String aid = null;
4623 try {
4624 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4625 .getApplicationByType(appType).getAid();
4626 } catch (Exception e) {
4627 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4628 }
4629 return aid;
4630 } finally {
4631 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004632 }
Youhan Wange64578a2016-05-02 15:32:42 -07004633 }
4634
Youhan Wang4001d252016-05-11 10:29:41 -07004635 /**
4636 * Return the Electronic Serial Number.
4637 *
4638 * @param subId the subscription ID that this request applies to.
4639 * @return ESN or null if error.
4640 */
4641 @Override
4642 public String getEsn(int subId) {
4643 enforceReadPrivilegedPermission();
4644 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645
4646 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004647 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 if (phone == null) {
4649 return null;
4650 }
4651 String esn = null;
4652 try {
4653 esn = phone.getEsn();
4654 } catch (Exception e) {
4655 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4656 }
4657 return esn;
4658 } finally {
4659 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004660 }
Youhan Wang4001d252016-05-11 10:29:41 -07004661 }
4662
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004663 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004664 * Return the Preferred Roaming List Version.
4665 *
4666 * @param subId the subscription ID that this request applies to.
4667 * @return PRLVersion or null if error.
4668 */
4669 @Override
4670 public String getCdmaPrlVersion(int subId) {
4671 enforceReadPrivilegedPermission();
4672 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673
4674 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004675 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004676 if (phone == null) {
4677 return null;
4678 }
4679 String cdmaPrlVersion = null;
4680 try {
4681 cdmaPrlVersion = phone.getCdmaPrlVersion();
4682 } catch (Exception e) {
4683 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4684 }
4685 return cdmaPrlVersion;
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004688 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004689 }
4690
4691 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004692 * Get snapshot of Telephony histograms
4693 * @return List of Telephony histograms
4694 * @hide
4695 */
4696 @Override
4697 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4699 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700
4701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 return RIL.getTelephonyRILTimingHistograms();
4704 } finally {
4705 Binder.restoreCallingIdentity(identity);
4706 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004707 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004708
4709 /**
4710 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004711 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004712 * Require system privileges. In the future we may add this to carrier APIs.
4713 *
4714 * @return The number of carriers set successfully, should match length of carriers
4715 */
4716 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004717 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004718 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004719 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004720
Meng Wang9b7c4e92017-02-17 11:41:27 -08004721 if (carriers == null) {
4722 throw new NullPointerException("carriers cannot be null");
4723 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725 final long identity = Binder.clearCallingIdentity();
4726 try {
4727 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004728 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4729 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730 return retVal[0];
4731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004734 }
4735
4736 /**
4737 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004738 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004739 * Require system privileges. In the future we may add this to carrier APIs.
4740 *
4741 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4742 * means all carriers are allowed.
4743 */
4744 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004745 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004746 enforceReadPrivilegedPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004747 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004748
4749 final long identity = Binder.clearCallingIdentity();
4750 try {
4751 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004752 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4753 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004757 }
4758
fionaxu59545b42016-05-25 15:53:37 -07004759 /**
4760 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4761 * @param subId the subscription ID that this action applies to.
4762 * @param enabled control enable or disable metered apns.
4763 * {@hide}
4764 */
4765 @Override
4766 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4767 enforceModifyPermission();
4768 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769
4770 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004771 if (phone == null) {
4772 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4773 return;
4774 }
4775 try {
4776 phone.carrierActionSetMeteredApnsEnabled(enabled);
4777 } catch (Exception e) {
4778 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 } finally {
4780 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004781 }
4782 }
4783
4784 /**
4785 * Action set from carrier signalling broadcast receivers to enable/disable radio
4786 * @param subId the subscription ID that this action applies to.
4787 * @param enabled control enable or disable radio.
4788 * {@hide}
4789 */
4790 @Override
4791 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4792 enforceModifyPermission();
4793 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004794
4795 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004796 if (phone == null) {
4797 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4798 return;
4799 }
4800 try {
4801 phone.carrierActionSetRadioEnabled(enabled);
4802 } catch (Exception e) {
4803 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804 } finally {
4805 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004806 }
4807 }
4808
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004809 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004810 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4811 * network status based on which carrier apps could apply actions accordingly,
4812 * enable/disable default url handler for example.
4813 *
4814 * @param subId the subscription ID that this action applies to.
4815 * @param report control start/stop reporting the default network status.
4816 * {@hide}
4817 */
4818 @Override
4819 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4820 enforceModifyPermission();
4821 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822
4823 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004824 if (phone == null) {
4825 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4826 return;
4827 }
4828 try {
4829 phone.carrierActionReportDefaultNetworkStatus(report);
4830 } catch (Exception e) {
4831 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832 } finally {
4833 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004834 }
4835 }
4836
4837 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004838 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4839 * bug report is being generated.
4840 */
4841 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004842 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004843 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4844 != PackageManager.PERMISSION_GRANTED) {
4845 writer.println("Permission Denial: can't dump Phone from pid="
4846 + Binder.getCallingPid()
4847 + ", uid=" + Binder.getCallingUid()
4848 + "without permission "
4849 + android.Manifest.permission.DUMP);
4850 return;
4851 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004852 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004853 }
Jack Yueb89b242016-06-22 13:27:47 -07004854
Brad Ebingerdac2f002018-04-03 15:17:52 -07004855 @Override
4856 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4857 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4858 throws RemoteException {
4859 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4860 }
4861
Jack Yueb89b242016-06-22 13:27:47 -07004862 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004863 * Get aggregated video call data usage since boot.
4864 *
4865 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4866 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004867 * {@hide}
4868 */
4869 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004870 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004871 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4872 null);
4873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 // NetworkStatsService keeps tracking the active network interface and identity. It
4877 // records the delta with the corresponding network identity.
4878 // We just return the total video call data usage snapshot since boot.
4879 Phone phone = getPhone(subId);
4880 if (phone != null) {
4881 return phone.getVtDataUsage(perUidStats);
4882 }
4883 return null;
4884 } finally {
4885 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004886 }
Jack Yueb89b242016-06-22 13:27:47 -07004887 }
Jack Yu75ab2952016-07-08 14:29:33 -07004888
4889 /**
4890 * Policy control of data connection. Usually used when data limit is passed.
4891 * @param enabled True if enabling the data, otherwise disabling.
4892 * @param subId Subscription index
4893 * {@hide}
4894 */
4895 @Override
4896 public void setPolicyDataEnabled(boolean enabled, int subId) {
4897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898
4899 final long identity = Binder.clearCallingIdentity();
4900 try {
4901 Phone phone = getPhone(subId);
4902 if (phone != null) {
4903 phone.setPolicyDataEnabled(enabled);
4904 }
4905 } finally {
4906 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004907 }
4908 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004909
4910 /**
4911 * Get Client request stats
4912 * @return List of Client Request Stats
4913 * @hide
4914 */
4915 @Override
4916 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004918 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004919 return null;
4920 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004921 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 final long identity = Binder.clearCallingIdentity();
4924 try {
4925 if (phone != null) {
4926 return phone.getClientRequestStats();
4927 }
4928
4929 return null;
4930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004933 }
4934
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004935 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004936 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004937 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004938 }
Jack Yueb4124c2017-02-16 15:32:43 -08004939
4940 /**
Grace Chen70990072017-03-24 17:21:30 -07004941 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004942 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004943 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004944 * @param state State of SIM (power down, power up, pass through)
4945 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4946 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4947 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004948 *
4949 **/
4950 @Override
Grace Chen70990072017-03-24 17:21:30 -07004951 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004952 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004953 Phone phone = PhoneFactory.getPhone(slotIndex);
4954
vagdeviaf9a5b92018-08-15 16:01:53 -07004955 WorkSource workSource = getWorkSource(Binder.getCallingUid());
4956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957 final long identity = Binder.clearCallingIdentity();
4958 try {
4959 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004960 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961 }
4962 } finally {
4963 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004964 }
4965 }
Shuo Qiandd210312017-04-12 22:11:33 +00004966
Tyler Gunn65d45c22017-06-05 11:22:26 -07004967 private boolean isUssdApiAllowed(int subId) {
4968 CarrierConfigManager configManager =
4969 (CarrierConfigManager) mPhone.getContext().getSystemService(
4970 Context.CARRIER_CONFIG_SERVICE);
4971 if (configManager == null) {
4972 return false;
4973 }
4974 PersistableBundle pb = configManager.getConfigForSubId(subId);
4975 if (pb == null) {
4976 return false;
4977 }
4978 return pb.getBoolean(
4979 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4980 }
4981
Shuo Qiandd210312017-04-12 22:11:33 +00004982 /**
4983 * Check if phone is in emergency callback mode
4984 * @return true if phone is in emergency callback mode
4985 * @param subId sub id
4986 */
goneil9c5f4872017-12-05 14:07:56 -08004987 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004988 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004989 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004990 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991
4992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 if (phone != null) {
4995 return phone.isInEcm();
4996 } else {
4997 return false;
4998 }
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005001 }
5002 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005003
5004 /**
5005 * Get the current signal strength information for the given subscription.
5006 * Because this information is not updated when the device is in a low power state
5007 * it should not be relied-upon to be current.
5008 * @param subId Subscription index
5009 * @return the most recent cached signal strength info from the modem
5010 */
5011 @Override
5012 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 final long identity = Binder.clearCallingIdentity();
5014 try {
5015 Phone p = getPhone(subId);
5016 if (p == null) {
5017 return null;
5018 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 return p.getSignalStrength();
5021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005024 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005025
Pengquan Meng77b7f132018-08-22 14:49:57 -07005026 /**
5027 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5028 *
5029 * <p>Requires one of the following permissions:
5030 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5031 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5032 * privileges.
5033 *
5034 * @param subId subscription id
5035 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5036 * {@code false}.
5037 */
5038 @Override
5039 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005040 boolean isEnabled = false;
5041 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005042 try {
5043 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005044 null /* message */);
5045 Phone phone = getPhone(subId);
5046 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005047 } catch (Exception e) {
5048 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5049 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005050 } finally {
5051 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005052 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005053 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005054 }
5055
5056
5057 /**
5058 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5059 *
5060 * <p> Requires permission:
5061 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5062 * privileges.
5063 *
5064 * @param subId subscription id
5065 * @param isEnabled {@code true} means enable, {@code false} means disable.
5066 */
5067 @Override
5068 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005069 final long identity = Binder.clearCallingIdentity();
5070 try {
5071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5072 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005073
Pengquan Menga1bb6272018-09-06 09:59:22 -07005074 Phone phone = getPhone(subId);
5075 if (phone != null) {
5076 phone.setDataRoamingEnabled(isEnabled);
5077 }
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005080 }
5081 }
5082
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005083 @Override
5084 public UiccSlotInfo[] getUiccSlotsInfo() {
5085 enforceReadPrivilegedPermission();
5086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5090 if (slots == null) {
5091 Rlog.i(LOG_TAG, "slots is null.");
5092 return null;
5093 }
5094
5095 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5096 for (int i = 0; i < slots.length; i++) {
5097 UiccSlot slot = slots[i];
5098 if (slot == null) {
5099 continue;
5100 }
5101
5102 String cardId;
5103 UiccCard card = slot.getUiccCard();
5104 if (card != null) {
5105 cardId = card.getCardId();
5106 } else {
5107 cardId = slot.getIccId();
5108 }
5109
5110 int cardState = 0;
5111 switch (slot.getCardState()) {
5112 case CARDSTATE_ABSENT:
5113 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5114 break;
5115 case CARDSTATE_PRESENT:
5116 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5117 break;
5118 case CARDSTATE_ERROR:
5119 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5120 break;
5121 case CARDSTATE_RESTRICTED:
5122 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5123 break;
5124 default:
5125 break;
5126
5127 }
5128
5129 infos[i] = new UiccSlotInfo(
5130 slot.isActive(),
5131 slot.isEuicc(),
5132 cardId,
5133 cardState,
5134 slot.getPhoneId(),
5135 slot.isExtendedApduSupported());
5136 }
5137 return infos;
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005140 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005141 }
5142
5143 @Override
5144 public boolean switchSlots(int[] physicalSlots) {
5145 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146
5147 final long identity = Binder.clearCallingIdentity();
5148 try {
5149 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005153 }
Jack Yu4c988042018-02-27 15:30:01 -08005154
5155 @Override
5156 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5157 enforceModifyPermission();
5158 final Phone phone = getPhone(subId);
5159 if (phone == null) {
5160 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5161 return;
5162 }
5163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 final long identity = Binder.clearCallingIdentity();
5165 try {
5166 phone.setRadioIndicationUpdateMode(filters, mode);
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
5169 }
Jack Yu4c988042018-02-27 15:30:01 -08005170 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005171
5172 /**
goneil47ffb6e2018-04-06 15:40:58 -07005173 * A test API to reload the UICC profile.
5174 *
5175 * <p>Requires that the calling app has permission
5176 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5177 * @hide
5178 */
5179 @Override
5180 public void refreshUiccProfile(int subId) {
5181 enforceModifyPermission();
5182
5183 final long identity = Binder.clearCallingIdentity();
5184 try {
5185 Phone phone = getPhone(subId);
5186 if (phone == null) {
5187 return;
5188 }
5189 UiccCard uiccCard = phone.getUiccCard();
5190 if (uiccCard == null) {
5191 return;
5192 }
5193 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5194 if (uiccProfile == null) {
5195 return;
5196 }
5197 uiccProfile.refresh();
5198 } finally {
5199 Binder.restoreCallingIdentity(identity);
5200 }
5201 }
5202
5203 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005204 * Returns false if the mobile data is disabled by default, otherwise return true.
5205 */
5206 private boolean getDefaultDataEnabled() {
5207 return "true".equalsIgnoreCase(
5208 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5209 }
5210
5211 /**
5212 * Returns true if the data roaming is enabled by default, i.e the system property
5213 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5214 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5215 */
5216 private boolean getDefaultDataRoamingEnabled(int subId) {
5217 final CarrierConfigManager configMgr = (CarrierConfigManager)
5218 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5219 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5220 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5221 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5222 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5223 return isDataRoamingEnabled;
5224 }
5225
5226 /**
5227 * Returns the default network type for the given {@code subId}, if the default network type is
5228 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5229 */
5230 private int getDefaultNetworkType(int subId) {
5231 return Integer.parseInt(
5232 TelephonyManager.getTelephonyProperty(
5233 mSubscriptionController.getPhoneId(subId),
5234 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5235 String.valueOf(Phone.PREFERRED_NT_MODE)));
5236 }
fionaxua13278b2018-03-21 00:08:13 -07005237
5238 @Override
5239 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5240 gid1, String gid2, String plmn, String spn) {
5241 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242
5243 final long identity = Binder.clearCallingIdentity();
5244 try {
5245 final Phone phone = getPhone(subId);
5246 if (phone == null) {
5247 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5248 return;
5249 }
5250 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5251 } finally {
5252 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005253 }
fionaxua13278b2018-03-21 00:08:13 -07005254 }
5255
5256 @Override
5257 public int getCarrierIdListVersion(int subId) {
5258 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259
5260 final long identity = Binder.clearCallingIdentity();
5261 try {
5262 final Phone phone = getPhone(subId);
5263 if (phone == null) {
5264 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5265 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5266 }
5267 return phone.getCarrierIdListVersion();
5268 } finally {
5269 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005270 }
fionaxua13278b2018-03-21 00:08:13 -07005271 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005272
5273 @Override
5274 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5276 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5277 return -1;
5278 }
5279
5280 final long identity = Binder.clearCallingIdentity();
5281 try {
5282 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005287
5288 @Override
5289 public int getCdmaRoamingMode(int subId) {
5290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5291 mApp, subId, "getCdmaRoamingMode");
5292
5293 final long identity = Binder.clearCallingIdentity();
5294 try {
5295 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5296 } finally {
5297 Binder.restoreCallingIdentity(identity);
5298 }
5299 }
5300
5301 @Override
5302 public boolean setCdmaRoamingMode(int subId, int mode) {
5303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5304 mApp, subId, "setCdmaRoamingMode");
5305
5306 final long identity = Binder.clearCallingIdentity();
5307 try {
5308 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
5312 }
5313
5314 @Override
5315 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5317 mApp, subId, "setCdmaSubscriptionMode");
5318
5319 final long identity = Binder.clearCallingIdentity();
5320 try {
5321 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5322 } finally {
5323 Binder.restoreCallingIdentity(identity);
5324 }
5325 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005326
5327 private void ensureUserRunning(int userId) {
5328 if (!mUserManager.isUserRunning(userId)) {
5329 throw new IllegalStateException("User " + userId + " does not exist or not running");
5330 }
5331 }
5332
5333 /**
5334 * Returns a list of SMS apps on a given user.
5335 *
5336 * Only the shell user (UID 2000 or 0) can call it.
5337 * Target user must be running.
5338 */
5339 @Override
5340 public String[] getSmsApps(int userId) {
5341 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5342 ensureUserRunning(userId);
5343
5344 final Collection<SmsApplicationData> apps =
5345 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5346
5347 String[] ret = new String[apps.size()];
5348 int i = 0;
5349 for (SmsApplicationData app : apps) {
5350 ret[i++] = app.mPackageName;
5351 }
5352 return ret;
5353 }
5354
5355 /**
5356 * Returns the default SMS app package name on a given user.
5357 *
5358 * Only the shell user (UID 2000 or 0) can call it.
5359 * Target user must be running.
5360 */
5361 @Override
5362 public String getDefaultSmsApp(int userId) {
5363 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5364 ensureUserRunning(userId);
5365
5366 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5367 /* updateIfNeeded= */ true, userId);
5368 return cn == null ? null : cn.getPackageName();
5369 }
5370
5371 /**
5372 * Set a package as the default SMS app on a given user.
5373 *
5374 * Only the shell user (UID 2000 or 0) can call it.
5375 * Target user must be running.
5376 */
5377 @Override
5378 public void setDefaultSmsApp(int userId, String packageName) {
5379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5380 ensureUserRunning(userId);
5381
5382 boolean found = false;
5383 for (String pkg : getSmsApps(userId)) {
5384 if (TextUtils.equals(packageName, pkg)) {
5385 found = true;
5386 break;
5387 }
5388 }
5389 if (!found) {
5390 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5391 }
5392
5393 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005395}