blob: 0587e0ed06f4c7d39b2faef8319b304e1d188b6a [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070028import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080043import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070046import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070047import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070049import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070050import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070051import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080052import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070053import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080054import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080055import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070056import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070057import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070059import android.telephony.CellInfoGsm;
60import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070061import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070063import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080064import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070065import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080066import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070067import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070068import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070069import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080071import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070072import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080073import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070075import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070076import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000077import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070078import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070079import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070080import android.telephony.cdma.CdmaCellLocation;
81import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070082import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080083import android.telephony.ims.aidl.IImsConfig;
84import android.telephony.ims.aidl.IImsMmTelFeature;
85import android.telephony.ims.aidl.IImsRcsFeature;
86import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070087import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080088import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080092import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080093import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080094
Brad Ebinger35c841c2018-10-01 10:40:55 -070095import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070096import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080097import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070098import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070099import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700100import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700101import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700102import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800105import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700106import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100107import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700108import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700109import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700111import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800112import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700113import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700114import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700115import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700116import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700117import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700118import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700119import com.android.internal.telephony.SmsApplication;
120import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800121import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800122import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700123import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.uicc.IccIoResult;
125import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800126import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700127import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800128import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800130import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000131import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700132import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800133import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700134import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800135import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700136import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700137import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800138
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700139import java.io.FileDescriptor;
140import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800141import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800143import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700144import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800145import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100146import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800147import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148
149/**
150 * Implementation of the ITelephony interface.
151 */
Santos Cordon117fee72014-05-16 17:56:12 -0700152public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153 private static final String LOG_TAG = "PhoneInterfaceManager";
154 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
155 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800156 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157
158 // Message codes used with mMainThreadHandler
159 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700160 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
161 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162 private static final int CMD_OPEN_CHANNEL = 9;
163 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
164 private static final int CMD_CLOSE_CHANNEL = 11;
165 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800166 private static final int CMD_NV_READ_ITEM = 13;
167 private static final int EVENT_NV_READ_ITEM_DONE = 14;
168 private static final int CMD_NV_WRITE_ITEM = 15;
169 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
170 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
171 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
172 private static final int CMD_NV_RESET_CONFIG = 19;
173 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800174 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
175 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
176 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
177 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800178 private static final int CMD_SEND_ENVELOPE = 25;
179 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000180 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
181 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700182 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
183 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
184 private static final int CMD_EXCHANGE_SIM_IO = 31;
185 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800186 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
187 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700188 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
189 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700190 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
191 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700192 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
193 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
194 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
195 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700196 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
197 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
198 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
199 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700200 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
202 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000203 private static final int CMD_SWITCH_SLOTS = 50;
204 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700205 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
206 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
207 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
208 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
209 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
210 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
211 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
212 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700213 private static final int CMD_GET_ALL_CELL_INFO = 60;
214 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
215 private static final int CMD_GET_CELL_LOCATION = 62;
216 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800218 // Parameters of select command.
219 private static final int SELECT_COMMAND = 0xA4;
220 private static final int SELECT_P1 = 0x04;
221 private static final int SELECT_P2 = 0;
222 private static final int SELECT_P3 = 0x10;
223
Pengquan Meng85728fb2018-03-12 16:31:21 -0700224 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
225 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
226 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
227
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228 /** The singleton instance. */
229 private static PhoneInterfaceManager sInstance;
230
Wink Saville3ab207e2014-11-20 13:07:20 -0800231 private PhoneGlobals mApp;
232 private Phone mPhone;
233 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700234 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800235 private AppOpsManager mAppOps;
236 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800237 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800238 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700239 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240
Derek Tan97ebb422014-09-05 16:55:38 -0700241 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
242 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800243 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700244
Derek Tan740e1672017-06-27 14:56:27 -0700245 // The AID of ISD-R.
246 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
247
yinxub1bed742017-04-17 11:45:04 -0700248 private NetworkScanRequestTracker mNetworkScanRequestTracker;
249
David Kelly5e06a7f2018-03-12 14:10:59 +0000250 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
251 private static final int MANUFACTURER_CODE_LENGTH = 8;
252
Derek Tan89e89d42014-07-08 17:00:10 -0700253 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700254 * A request object to use for transmitting data to an ICC.
255 */
256 private static final class IccAPDUArgument {
257 public int channel, cla, command, p1, p2, p3;
258 public String data;
259
260 public IccAPDUArgument(int channel, int cla, int command,
261 int p1, int p2, int p3, String data) {
262 this.channel = channel;
263 this.cla = cla;
264 this.command = command;
265 this.p1 = p1;
266 this.p2 = p2;
267 this.p3 = p3;
268 this.data = data;
269 }
270 }
271
272 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700273 * A request object to use for transmitting data to an ICC.
274 */
275 private static final class ManualNetworkSelectionArgument {
276 public OperatorInfo operatorInfo;
277 public boolean persistSelection;
278
279 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
280 this.operatorInfo = operatorInfo;
281 this.persistSelection = persistSelection;
282 }
283 }
284
285 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
287 * request after sending. The main thread will notify the request when it is complete.
288 */
289 private static final class MainThreadRequest {
290 /** The argument to use for the request */
291 public Object argument;
292 /** The result of the request that is run on the main thread */
293 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800294 // The subscriber id that this request applies to. Defaults to
295 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
296 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297
Nathan Harold92bed182018-10-12 18:16:49 -0700298 // In cases where subId is unavailable, the caller needs to specify the phone.
299 public Phone phone;
300
vagdeviaf9a5b92018-08-15 16:01:53 -0700301 public WorkSource workSource;
302
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303 public MainThreadRequest(Object argument) {
304 this.argument = argument;
305 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800306
Nathan Harold92bed182018-10-12 18:16:49 -0700307 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
308 this.argument = argument;
309 if (phone != null) {
310 this.phone = phone;
311 }
312 this.workSource = workSource;
313 }
314
vagdeviaf9a5b92018-08-15 16:01:53 -0700315 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800316 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800317 if (subId != null) {
318 this.subId = subId;
319 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700320 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 }
323
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800324 private static final class IncomingThirdPartyCallArgs {
325 public final ComponentName component;
326 public final String callId;
327 public final String callerDisplayName;
328
329 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
330 String callerDisplayName) {
331 this.component = component;
332 this.callId = callId;
333 this.callerDisplayName = callerDisplayName;
334 }
335 }
336
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 /**
338 * A handler that processes messages on the main thread in the phone process. Since many
339 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
340 * inbound binder threads to the main thread in the phone process. The Binder thread
341 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
342 * on, which will be notified when the operation completes and will contain the result of the
343 * request.
344 *
345 * <p>If a MainThreadRequest object is provided in the msg.obj field,
346 * note that request.result must be set to something non-null for the calling thread to
347 * unblock.
348 */
349 private final class MainThreadHandler extends Handler {
350 @Override
351 public void handleMessage(Message msg) {
352 MainThreadRequest request;
353 Message onCompleted;
354 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800355 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700356 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
358 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700359 case CMD_HANDLE_USSD_REQUEST: {
360 request = (MainThreadRequest) msg.obj;
361 final Phone phone = getPhoneFromRequest(request);
362 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
363 String ussdRequest = ussdObject.first;
364 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700365
Pengquan Menga1bb6272018-09-06 09:59:22 -0700366 if (!isUssdApiAllowed(request.subId)) {
367 // Carrier does not support use of this API, return failure.
368 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
369 UssdResponse response = new UssdResponse(ussdRequest, null);
370 Bundle returnData = new Bundle();
371 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
372 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700373
Pengquan Menga1bb6272018-09-06 09:59:22 -0700374 request.result = true;
375 notifyRequester(request);
376 return;
377 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700378
Pengquan Menga1bb6272018-09-06 09:59:22 -0700379 try {
380 request.result = phone != null
381 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
382 } catch (CallStateException cse) {
383 request.result = false;
384 }
385 // Wake up the requesting thread
386 notifyRequester(request);
387 break;
pkanwar32d516d2016-10-14 19:37:38 -0700388 }
389
Yorke Lee716f67e2015-06-17 15:39:16 -0700390 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700392 final Phone phone = getPhoneFromRequest(request);
393 request.result = phone != null ?
394 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
395 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700397 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700402 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700403 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800404 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700405 if (uiccCard == null) {
406 loge("iccTransmitApduLogicalChannel: No UICC");
407 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700408 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700409 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700410 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
411 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700412 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 iccArgument.channel, iccArgument.cla, iccArgument.command,
414 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700415 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700416 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 break;
418
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700420 ar = (AsyncResult) msg.obj;
421 request = (MainThreadRequest) ar.userObj;
422 if (ar.exception == null && ar.result != null) {
423 request.result = ar.result;
424 } else {
425 request.result = new IccIoResult(0x6F, 0, (byte[])null);
426 if (ar.result == null) {
427 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800428 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800430 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 } else {
432 loge("iccTransmitApduLogicalChannel: Unknown exception");
433 }
434 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700435 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 break;
437
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
439 request = (MainThreadRequest) msg.obj;
440 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800441 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 if (uiccCard == null) {
443 loge("iccTransmitApduBasicChannel: No UICC");
444 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 } else {
447 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
448 request);
449 uiccCard.iccTransmitApduBasicChannel(
450 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
451 iccArgument.p3, iccArgument.data, onCompleted);
452 }
453 break;
454
455 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
456 ar = (AsyncResult) msg.obj;
457 request = (MainThreadRequest) ar.userObj;
458 if (ar.exception == null && ar.result != null) {
459 request.result = ar.result;
460 } else {
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
462 if (ar.result == null) {
463 loge("iccTransmitApduBasicChannel: Empty response");
464 } else if (ar.exception instanceof CommandException) {
465 loge("iccTransmitApduBasicChannel: CommandException: " +
466 ar.exception);
467 } else {
468 loge("iccTransmitApduBasicChannel: Unknown exception");
469 }
470 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700471 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 break;
473
474 case CMD_EXCHANGE_SIM_IO:
475 request = (MainThreadRequest) msg.obj;
476 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800477 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 if (uiccCard == null) {
479 loge("iccExchangeSimIO: No UICC");
480 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 } else {
483 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
484 request);
485 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
486 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
487 iccArgument.data, onCompleted);
488 }
489 break;
490
491 case EVENT_EXCHANGE_SIM_IO_DONE:
492 ar = (AsyncResult) msg.obj;
493 request = (MainThreadRequest) ar.userObj;
494 if (ar.exception == null && ar.result != null) {
495 request.result = ar.result;
496 } else {
497 request.result = new IccIoResult(0x6f, 0, (byte[])null);
498 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700499 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 break;
501
Derek Tan4d5e5c12014-02-04 11:54:58 -0800502 case CMD_SEND_ENVELOPE:
503 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800504 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700505 if (uiccCard == null) {
506 loge("sendEnvelopeWithStatus: No UICC");
507 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700509 } else {
510 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
511 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
512 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800513 break;
514
515 case EVENT_SEND_ENVELOPE_DONE:
516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800520 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
522 if (ar.result == null) {
523 loge("sendEnvelopeWithStatus: Empty response");
524 } else if (ar.exception instanceof CommandException) {
525 loge("sendEnvelopeWithStatus: CommandException: " +
526 ar.exception);
527 } else {
528 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
529 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800532 break;
533
Shishir Agrawal566b7612013-10-28 14:41:00 -0700534 case CMD_OPEN_CHANNEL:
535 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800536 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800537 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 if (uiccCard == null) {
539 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800540 request.result = new IccOpenLogicalChannelResponse(-1,
541 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800545 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
546 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 break;
549
550 case EVENT_OPEN_CHANNEL_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 int[] result = (int[]) ar.result;
556 int channelId = result[0];
557 byte[] selectResponse = null;
558 if (result.length > 1) {
559 selectResponse = new byte[result.length - 1];
560 for (int i = 1; i < result.length; ++i) {
561 selectResponse[i - 1] = (byte) result[i];
562 }
563 }
564 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700565 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 if (ar.result == null) {
568 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 if (ar.exception != null) {
571 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
572 }
573
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700574 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700575 if (ar.exception instanceof CommandException) {
576 CommandException.Error error =
577 ((CommandException) (ar.exception)).getCommandError();
578 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700579 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700580 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700581 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 }
583 }
584 openChannelResp = new IccOpenLogicalChannelResponse(
585 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700587 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
591 case CMD_CLOSE_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 if (uiccCard == null) {
595 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900596 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 } else {
599 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
600 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
601 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 break;
603
604 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800605 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
606 break;
607
608 case CMD_NV_READ_ITEM:
609 request = (MainThreadRequest) msg.obj;
610 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700611 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800612 break;
613
614 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 ar = (AsyncResult) msg.obj;
616 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800617 if (ar.exception == null && ar.result != null) {
618 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800620 request.result = "";
621 if (ar.result == null) {
622 loge("nvReadItem: Empty response");
623 } else if (ar.exception instanceof CommandException) {
624 loge("nvReadItem: CommandException: " +
625 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800627 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 }
629 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 break;
632
Jake Hambye994d462014-02-03 13:10:13 -0800633 case CMD_NV_WRITE_ITEM:
634 request = (MainThreadRequest) msg.obj;
635 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
636 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700637 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
638 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800639 break;
640
641 case EVENT_NV_WRITE_ITEM_DONE:
642 handleNullReturnEvent(msg, "nvWriteItem");
643 break;
644
645 case CMD_NV_WRITE_CDMA_PRL:
646 request = (MainThreadRequest) msg.obj;
647 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
648 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
649 break;
650
651 case EVENT_NV_WRITE_CDMA_PRL_DONE:
652 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
653 break;
654
655 case CMD_NV_RESET_CONFIG:
656 request = (MainThreadRequest) msg.obj;
657 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
658 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
659 break;
660
661 case EVENT_NV_RESET_CONFIG_DONE:
662 handleNullReturnEvent(msg, "nvResetConfig");
663 break;
664
Jake Hamby7c27be32014-03-03 13:25:59 -0800665 case CMD_GET_PREFERRED_NETWORK_TYPE:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700668 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800669 break;
670
671 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
672 ar = (AsyncResult) msg.obj;
673 request = (MainThreadRequest) ar.userObj;
674 if (ar.exception == null && ar.result != null) {
675 request.result = ar.result; // Integer
676 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800677 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800678 if (ar.result == null) {
679 loge("getPreferredNetworkType: Empty response");
680 } else if (ar.exception instanceof CommandException) {
681 loge("getPreferredNetworkType: CommandException: " +
682 ar.exception);
683 } else {
684 loge("getPreferredNetworkType: Unknown exception");
685 }
686 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800688 break;
689
690 case CMD_SET_PREFERRED_NETWORK_TYPE:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
693 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700694 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800695 break;
696
697 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
698 handleNullReturnEvent(msg, "setPreferredNetworkType");
699 break;
700
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000701 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
702 request = (MainThreadRequest)msg.obj;
703 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700704 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000705 break;
706
707 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
708 ar = (AsyncResult)msg.obj;
709 request = (MainThreadRequest)ar.userObj;
710 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700711 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000712 break;
713
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800714 case CMD_SET_VOICEMAIL_NUMBER:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
717 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800718 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
719 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800720 break;
721
722 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
723 handleNullReturnEvent(msg, "setVoicemailNumber");
724 break;
725
Stuart Scott54788802015-03-30 13:18:01 -0700726 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
729 request);
730 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
731 break;
732
733 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
734 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
735 break;
736
Shishir Agrawal302c8692015-06-19 13:49:39 -0700737 case CMD_PERFORM_NETWORK_SCAN:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
740 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
741 break;
742
743 case EVENT_PERFORM_NETWORK_SCAN_DONE:
744 ar = (AsyncResult) msg.obj;
745 request = (MainThreadRequest) ar.userObj;
746 CellNetworkScanResult cellScanResult;
747 if (ar.exception == null && ar.result != null) {
748 cellScanResult = new CellNetworkScanResult(
749 CellNetworkScanResult.STATUS_SUCCESS,
750 (List<OperatorInfo>) ar.result);
751 } else {
752 if (ar.result == null) {
753 loge("getCellNetworkScanResults: Empty response");
754 }
755 if (ar.exception != null) {
756 loge("getCellNetworkScanResults: Exception: " + ar.exception);
757 }
758 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
759 if (ar.exception instanceof CommandException) {
760 CommandException.Error error =
761 ((CommandException) (ar.exception)).getCommandError();
762 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
763 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
764 } else if (error == CommandException.Error.GENERIC_FAILURE) {
765 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
766 }
767 }
768 cellScanResult = new CellNetworkScanResult(errorCode, null);
769 }
770 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700772 break;
773
774 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
775 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700776 ManualNetworkSelectionArgument selArg =
777 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700778 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
779 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700780 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
781 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700782 break;
783
784 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700785 ar = (AsyncResult) msg.obj;
786 request = (MainThreadRequest) ar.userObj;
787 if (ar.exception == null) {
788 request.result = true;
789 } else {
790 request.result = false;
791 loge("setNetworkSelectionModeManual " + ar.exception);
792 }
793 notifyRequester(request);
794 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 break;
796
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700797 case CMD_GET_MODEM_ACTIVITY_INFO:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700800 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700801 break;
802
803 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 if (ar.exception == null && ar.result != null) {
807 request.result = ar.result;
808 } else {
809 if (ar.result == null) {
810 loge("queryModemActivityInfo: Empty response");
811 } else if (ar.exception instanceof CommandException) {
812 loge("queryModemActivityInfo: CommandException: " +
813 ar.exception);
814 } else {
815 loge("queryModemActivityInfo: Unknown exception");
816 }
817 }
Amit Mahajand4766222016-01-28 15:28:28 -0800818 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
819 if (request.result == null) {
820 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
821 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700822 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700823 break;
824
Meng Wang1a7c35a2016-05-05 20:56:15 -0700825 case CMD_SET_ALLOWED_CARRIERS:
826 request = (MainThreadRequest) msg.obj;
827 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
828 mPhone.setAllowedCarriers(
829 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700830 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700831 break;
832
833 case EVENT_SET_ALLOWED_CARRIERS_DONE:
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null && ar.result != null) {
837 request.result = ar.result;
838 } else {
839 if (ar.result == null) {
840 loge("setAllowedCarriers: Empty response");
841 } else if (ar.exception instanceof CommandException) {
842 loge("setAllowedCarriers: CommandException: " +
843 ar.exception);
844 } else {
845 loge("setAllowedCarriers: Unknown exception");
846 }
847 }
848 // Result cannot be null. Return -1 on error.
849 if (request.result == null) {
850 request.result = new int[]{-1};
851 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700852 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 break;
854
855 case CMD_GET_ALLOWED_CARRIERS:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700858 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700859 break;
860
861 case EVENT_GET_ALLOWED_CARRIERS_DONE:
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null && ar.result != null) {
865 request.result = ar.result;
866 } else {
867 if (ar.result == null) {
868 loge("getAllowedCarriers: Empty response");
869 } else if (ar.exception instanceof CommandException) {
870 loge("getAllowedCarriers: CommandException: " +
871 ar.exception);
872 } else {
873 loge("getAllowedCarriers: Unknown exception");
874 }
875 }
876 // Result cannot be null. Return empty list of CarrierIdentifier.
877 if (request.result == null) {
878 request.result = new ArrayList<CarrierIdentifier>(0);
879 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700880 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 break;
882
Nathan Haroldb3014052017-01-25 15:57:32 -0800883 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
889 request.result = new IllegalArgumentException(
890 "Failed to retrieve Forbidden Plmns");
891 if (ar.result == null) {
892 loge("getForbiddenPlmns: Empty response");
893 } else {
894 loge("getForbiddenPlmns: Unknown exception");
895 }
896 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700897 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800898 break;
899
900 case CMD_GET_FORBIDDEN_PLMNS:
901 request = (MainThreadRequest) msg.obj;
902 uiccCard = getUiccCardFromRequest(request);
903 if (uiccCard == null) {
904 loge("getForbiddenPlmns() UiccCard is null");
905 request.result = new IllegalArgumentException(
906 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700907 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800908 break;
909 }
910 Integer appType = (Integer) request.argument;
911 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
912 if (uiccApp == null) {
913 loge("getForbiddenPlmns() no app with specified type -- "
914 + appType);
915 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800917 break;
918 } else {
919 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
920 + " specified type -- " + appType);
921 }
922 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
923 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
924 onCompleted);
925 break;
926
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000927 case CMD_SWITCH_SLOTS:
928 request = (MainThreadRequest) msg.obj;
929 int[] physicalSlots = (int[]) request.argument;
930 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
931 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
932 break;
933
934 case EVENT_SWITCH_SLOTS_DONE:
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700938 notifyRequester(request);
939 break;
940 case CMD_GET_NETWORK_SELECTION_MODE:
941 request = (MainThreadRequest) msg.obj;
942 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
943 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
944 break;
945
946 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
947 ar = (AsyncResult) msg.obj;
948 request = (MainThreadRequest) ar.userObj;
949 if (ar.exception != null) {
950 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
951 } else {
952 int mode = ((int[]) ar.result)[0];
953 if (mode == 0) {
954 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
955 } else {
956 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
957 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000958 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700959 notifyRequester(request);
960 break;
961 case CMD_GET_CDMA_ROAMING_MODE:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
964 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
965 break;
966 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 if (ar.exception != null) {
970 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
971 } else {
972 request.result = ((int[]) ar.result)[0];
973 }
974 notifyRequester(request);
975 break;
976 case CMD_SET_CDMA_ROAMING_MODE:
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
979 int mode = (int) request.argument;
980 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
981 break;
982 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 request.result = ar.exception == null;
986 notifyRequester(request);
987 break;
988 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
991 int subscriptionMode = (int) request.argument;
992 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
993 break;
994 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 request.result = ar.exception == null;
998 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000999 break;
1000
Nathan Harold3ff88932018-08-14 10:19:49 -07001001 case CMD_GET_ALL_CELL_INFO:
1002 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001003 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001004 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001005 break;
1006
1007 case EVENT_GET_ALL_CELL_INFO_DONE:
1008 ar = (AsyncResult) msg.obj;
1009 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001010 // If a timeout occurs, the response will be null
1011 request.result = (ar.exception == null && ar.result != null)
1012 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001013 synchronized (request) {
1014 request.notifyAll();
1015 }
1016 break;
1017
1018 case CMD_GET_CELL_LOCATION: {
1019 request = (MainThreadRequest) msg.obj;
1020 WorkSource ws = (WorkSource) request.argument;
1021 Phone phone = getPhoneFromRequest(request);
1022 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1023 break;
1024 }
1025
1026 case EVENT_GET_CELL_LOCATION_DONE: {
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 if (ar.exception == null) {
1030 request.result = ar.result;
1031 } else {
1032 Phone phone = getPhoneFromRequest(request);
1033 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1034 ? new CdmaCellLocation() : new GsmCellLocation();
1035 }
1036
1037 synchronized (request) {
1038 request.notifyAll();
1039 }
1040 break;
1041 }
1042
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001043 default:
1044 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1045 break;
1046 }
1047 }
Jake Hambye994d462014-02-03 13:10:13 -08001048
Pengquan Menga1bb6272018-09-06 09:59:22 -07001049 private void notifyRequester(MainThreadRequest request) {
1050 synchronized (request) {
1051 request.notifyAll();
1052 }
1053 }
1054
Jake Hambye994d462014-02-03 13:10:13 -08001055 private void handleNullReturnEvent(Message msg, String command) {
1056 AsyncResult ar = (AsyncResult) msg.obj;
1057 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1058 if (ar.exception == null) {
1059 request.result = true;
1060 } else {
1061 request.result = false;
1062 if (ar.exception instanceof CommandException) {
1063 loge(command + ": CommandException: " + ar.exception);
1064 } else {
1065 loge(command + ": Unknown exception");
1066 }
1067 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001068 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001069 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001070 }
1071
1072 /**
1073 * Posts the specified command to be executed on the main thread,
1074 * waits for the request to complete, and returns the result.
1075 * @see #sendRequestAsync
1076 */
1077 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001078 return sendRequest(
1079 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001080 }
1081
1082 /**
1083 * Posts the specified command to be executed on the main thread,
1084 * waits for the request to complete, and returns the result.
1085 * @see #sendRequestAsync
1086 */
1087 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1088 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001089 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001090 }
1091
1092 /**
1093 * Posts the specified command to be executed on the main thread,
1094 * waits for the request to complete, and returns the result.
1095 * @see #sendRequestAsync
1096 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001097 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001098 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001099 }
1100
1101 /**
1102 * Posts the specified command to be executed on the main thread,
1103 * waits for the request to complete, and returns the result.
1104 * @see #sendRequestAsync
1105 */
Nathan Harold92bed182018-10-12 18:16:49 -07001106 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1107 return sendRequest(command, argument, subId, null, workSource);
1108 }
1109
1110 /**
1111 * Posts the specified command to be executed on the main thread,
1112 * waits for the request to complete, and returns the result.
1113 * @see #sendRequestAsync
1114 */
1115 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1116 return sendRequest(
1117 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1118 }
1119
1120 /**
1121 * Posts the specified command to be executed on the main thread,
1122 * waits for the request to complete, and returns the result.
1123 * @see #sendRequestAsync
1124 */
1125 private Object sendRequest(
1126 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001127 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1128 throw new RuntimeException("This method will deadlock if called from the main thread.");
1129 }
1130
Nathan Harold92bed182018-10-12 18:16:49 -07001131 MainThreadRequest request = null;
1132 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1133 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1134 } else if (phone != null) {
1135 request = new MainThreadRequest(argument, phone, workSource);
1136 } else {
1137 request = new MainThreadRequest(argument, subId, workSource);
1138 }
1139
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 Message msg = mMainThreadHandler.obtainMessage(command, request);
1141 msg.sendToTarget();
1142
1143 // Wait for the request to complete
1144 synchronized (request) {
1145 while (request.result == null) {
1146 try {
1147 request.wait();
1148 } catch (InterruptedException e) {
1149 // Do nothing, go back and wait until the request is complete
1150 }
1151 }
1152 }
1153 return request.result;
1154 }
1155
1156 /**
1157 * Asynchronous ("fire and forget") version of sendRequest():
1158 * Posts the specified command to be executed on the main thread, and
1159 * returns immediately.
1160 * @see #sendRequest
1161 */
1162 private void sendRequestAsync(int command) {
1163 mMainThreadHandler.sendEmptyMessage(command);
1164 }
1165
1166 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001167 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1168 * @see {@link #sendRequest(int,Object)}
1169 */
1170 private void sendRequestAsync(int command, Object argument) {
1171 MainThreadRequest request = new MainThreadRequest(argument);
1172 Message msg = mMainThreadHandler.obtainMessage(command, request);
1173 msg.sendToTarget();
1174 }
1175
1176 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001177 * Initialize the singleton PhoneInterfaceManager instance.
1178 * This is only done once, at startup, from PhoneApp.onCreate().
1179 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001180 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001181 synchronized (PhoneInterfaceManager.class) {
1182 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001183 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184 } else {
1185 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1186 }
1187 return sInstance;
1188 }
1189 }
1190
1191 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001192 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001193 mApp = app;
1194 mPhone = phone;
1195 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001196 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1198 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001199 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001200 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001201 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001202 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001203 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001204
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 publish();
1206 }
1207
1208 private void publish() {
1209 if (DBG) log("publish: " + this);
1210
1211 ServiceManager.addService("phone", this);
1212 }
1213
Stuart Scott584921c2015-01-15 17:10:34 -08001214 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001215 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1216 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001217 }
1218
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001219 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1220 Phone phone = getPhoneFromRequest(request);
1221 return phone == null ? null :
1222 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1223 }
1224
Wink Saville36469e72014-06-11 15:17:00 -07001225 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001226 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001227 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229
1230 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001231 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001232 }
1233
Wink Savilleb564aae2014-10-23 10:18:09 -07001234 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 if (DBG) log("dial: " + number);
1236 // No permission check needed here: This is just a wrapper around the
1237 // ACTION_DIAL intent, which is available to any app since it puts up
1238 // the UI before it does anything.
1239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001240 final long identity = Binder.clearCallingIdentity();
1241 try {
1242 String url = createTelUrl(number);
1243 if (url == null) {
1244 return;
1245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001247 // PENDING: should we just silently fail if phone is offhook or ringing?
1248 PhoneConstants.State state = mCM.getState(subId);
1249 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1250 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1251 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1252 mApp.startActivity(intent);
1253 }
1254 } finally {
1255 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001256 }
1257 }
1258
1259 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001260 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001261 }
1262
Wink Savilleb564aae2014-10-23 10:18:09 -07001263 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 if (DBG) log("call: " + number);
1265
1266 // This is just a wrapper around the ACTION_CALL intent, but we still
1267 // need to do a permission check since we're calling startActivity()
1268 // from the context of the phone app.
1269 enforceCallPermission();
1270
1271 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1272 != AppOpsManager.MODE_ALLOWED) {
1273 return;
1274 }
1275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001276 final long identity = Binder.clearCallingIdentity();
1277 try {
1278 String url = createTelUrl(number);
1279 if (url == null) {
1280 return;
1281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001283 boolean isValid = false;
1284 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1285 if (slist != null) {
1286 for (SubscriptionInfo subInfoRecord : slist) {
1287 if (subInfoRecord.getSubscriptionId() == subId) {
1288 isValid = true;
1289 break;
1290 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001291 }
Wink Saville08874612014-08-31 19:19:58 -07001292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001293 if (!isValid) {
1294 return;
1295 }
Wink Saville08874612014-08-31 19:19:58 -07001296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001297 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1298 intent.putExtra(SUBSCRIPTION_KEY, subId);
1299 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1300 mApp.startActivity(intent);
1301 } finally {
1302 Binder.restoreCallingIdentity(identity);
1303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 }
1305
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001307 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001308 }
1309
Wink Savilleb564aae2014-10-23 10:18:09 -07001310 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001311 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001312 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1313 }
1314
1315 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001316 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001317 }
1318
Wink Savilleb564aae2014-10-23 10:18:09 -07001319 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001321 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1322 }
1323
1324 /** {@hide} */
1325 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001326 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001327 }
1328
Wink Savilleb564aae2014-10-23 10:18:09 -07001329 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001331
1332 final long identity = Binder.clearCallingIdentity();
1333 try {
1334 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1335 checkSimPin.start();
1336 return checkSimPin.unlockSim(null, pin);
1337 } finally {
1338 Binder.restoreCallingIdentity(identity);
1339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001340 }
1341
Wink Saville9de0f752013-10-22 19:04:03 -07001342 /** {@hide} */
1343 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001344 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001345 }
1346
Wink Savilleb564aae2014-10-23 10:18:09 -07001347 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001349
1350 final long identity = Binder.clearCallingIdentity();
1351 try {
1352 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1353 checkSimPuk.start();
1354 return checkSimPuk.unlockSim(puk, pin);
1355 } finally {
1356 Binder.restoreCallingIdentity(identity);
1357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 }
1359
1360 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001361 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 * a synchronous one.
1363 */
1364 private static class UnlockSim extends Thread {
1365
1366 private final IccCard mSimCard;
1367
1368 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001369 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1370 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371
1372 // For replies from SimCard interface
1373 private Handler mHandler;
1374
1375 // For async handler to identify request type
1376 private static final int SUPPLY_PIN_COMPLETE = 100;
1377
1378 public UnlockSim(IccCard simCard) {
1379 mSimCard = simCard;
1380 }
1381
1382 @Override
1383 public void run() {
1384 Looper.prepare();
1385 synchronized (UnlockSim.this) {
1386 mHandler = new Handler() {
1387 @Override
1388 public void handleMessage(Message msg) {
1389 AsyncResult ar = (AsyncResult) msg.obj;
1390 switch (msg.what) {
1391 case SUPPLY_PIN_COMPLETE:
1392 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1393 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001394 mRetryCount = msg.arg1;
1395 if (ar.exception != null) {
1396 if (ar.exception instanceof CommandException &&
1397 ((CommandException)(ar.exception)).getCommandError()
1398 == CommandException.Error.PASSWORD_INCORRECT) {
1399 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1400 } else {
1401 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1402 }
1403 } else {
1404 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 mDone = true;
1407 UnlockSim.this.notifyAll();
1408 }
1409 break;
1410 }
1411 }
1412 };
1413 UnlockSim.this.notifyAll();
1414 }
1415 Looper.loop();
1416 }
1417
1418 /*
1419 * Use PIN or PUK to unlock SIM card
1420 *
1421 * If PUK is null, unlock SIM card with PIN
1422 *
1423 * If PUK is not null, unlock SIM card with PUK and set PIN code
1424 */
Wink Saville9de0f752013-10-22 19:04:03 -07001425 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426
1427 while (mHandler == null) {
1428 try {
1429 wait();
1430 } catch (InterruptedException e) {
1431 Thread.currentThread().interrupt();
1432 }
1433 }
1434 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1435
1436 if (puk == null) {
1437 mSimCard.supplyPin(pin, callback);
1438 } else {
1439 mSimCard.supplyPuk(puk, pin, callback);
1440 }
1441
1442 while (!mDone) {
1443 try {
1444 Log.d(LOG_TAG, "wait for done");
1445 wait();
1446 } catch (InterruptedException e) {
1447 // Restore the interrupted status
1448 Thread.currentThread().interrupt();
1449 }
1450 }
1451 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001452 int[] resultArray = new int[2];
1453 resultArray[0] = mResult;
1454 resultArray[1] = mRetryCount;
1455 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 }
1457 }
1458
1459 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001460 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001461
1462 }
1463
Wink Savilleb564aae2014-10-23 10:18:09 -07001464 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 // No permission check needed here: this call is harmless, and it's
1466 // needed for the ServiceState.requestStateUpdate() call (which is
1467 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001468 final long identity = Binder.clearCallingIdentity();
1469 try {
1470 final Phone phone = getPhone(subId);
1471 if (phone != null) {
1472 phone.updateServiceLocation();
1473 }
1474 } finally {
1475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477 }
1478
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001479 @Override
1480 public boolean isRadioOn(String callingPackage) {
1481 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001482 }
1483
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001484 @Override
1485 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001487 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001488 return false;
1489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001490
1491 final long identity = Binder.clearCallingIdentity();
1492 try {
1493 return isRadioOnForSubscriber(subId);
1494 } finally {
1495 Binder.restoreCallingIdentity(identity);
1496 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001497 }
1498
1499 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001500 final long identity = Binder.clearCallingIdentity();
1501 try {
1502 final Phone phone = getPhone(subId);
1503 if (phone != null) {
1504 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1505 } else {
1506 return false;
1507 }
1508 } finally {
1509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 }
1512
1513 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001514 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515 }
Wink Saville36469e72014-06-11 15:17:00 -07001516
Wink Savilleb564aae2014-10-23 10:18:09 -07001517 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001519
1520 final long identity = Binder.clearCallingIdentity();
1521 try {
1522 final Phone phone = getPhone(subId);
1523 if (phone != null) {
1524 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1525 }
1526 } finally {
1527 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001528 }
Wink Saville36469e72014-06-11 15:17:00 -07001529 }
1530
1531 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001532 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001536 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001537
1538 final long identity = Binder.clearCallingIdentity();
1539 try {
1540 final Phone phone = getPhone(subId);
1541 if (phone == null) {
1542 return false;
1543 }
1544 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1545 toggleRadioOnOffForSubscriber(subId);
1546 }
1547 return true;
1548 } finally {
1549 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001551 }
Wink Saville36469e72014-06-11 15:17:00 -07001552
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001553 public boolean needMobileRadioShutdown() {
1554 /*
1555 * If any of the Radios are available, it will need to be
1556 * shutdown. So return true if any Radio is available.
1557 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001558 final long identity = Binder.clearCallingIdentity();
1559 try {
1560 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1561 Phone phone = PhoneFactory.getPhone(i);
1562 if (phone != null && phone.isRadioAvailable()) return true;
1563 }
1564 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1565 return false;
1566 } finally {
1567 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001568 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001569 }
1570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001571 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001572 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001573 enforceModifyPermission();
1574
1575 final long identity = Binder.clearCallingIdentity();
1576 try {
1577 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1578 logv("Shutting down Phone " + i);
1579 shutdownRadioUsingPhoneId(i);
1580 }
1581 } finally {
1582 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001583 }
1584 }
1585
1586 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001587 Phone phone = PhoneFactory.getPhone(phoneId);
1588 if (phone != null && phone.isRadioAvailable()) {
1589 phone.shutdownRadio();
1590 }
1591 }
1592
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001594 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001595
1596 final long identity = Binder.clearCallingIdentity();
1597 try {
1598 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1599 if (defaultPhone != null) {
1600 defaultPhone.setRadioPower(turnOn);
1601 return true;
1602 } else {
1603 loge("There's no default phone.");
1604 return false;
1605 }
1606 } finally {
1607 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001608 }
Wink Saville36469e72014-06-11 15:17:00 -07001609 }
1610
Wink Savilleb564aae2014-10-23 10:18:09 -07001611 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001613
1614 final long identity = Binder.clearCallingIdentity();
1615 try {
1616 final Phone phone = getPhone(subId);
1617 if (phone != null) {
1618 phone.setRadioPower(turnOn);
1619 return true;
1620 } else {
1621 return false;
1622 }
1623 } finally {
1624 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001626 }
1627
Wink Saville36469e72014-06-11 15:17:00 -07001628 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 public boolean enableDataConnectivity() {
1631 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001632
1633 final long identity = Binder.clearCallingIdentity();
1634 try {
1635 int subId = mSubscriptionController.getDefaultDataSubId();
1636 final Phone phone = getPhone(subId);
1637 if (phone != null) {
1638 phone.setUserDataEnabled(true);
1639 return true;
1640 } else {
1641 return false;
1642 }
1643 } finally {
1644 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001645 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 }
1647
Wink Saville36469e72014-06-11 15:17:00 -07001648 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001649 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 public boolean disableDataConnectivity() {
1651 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001652
1653 final long identity = Binder.clearCallingIdentity();
1654 try {
1655 int subId = mSubscriptionController.getDefaultDataSubId();
1656 final Phone phone = getPhone(subId);
1657 if (phone != null) {
1658 phone.setUserDataEnabled(false);
1659 return true;
1660 } else {
1661 return false;
1662 }
1663 } finally {
1664 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 }
1667
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001669 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001670 final long identity = Binder.clearCallingIdentity();
1671 try {
1672 final Phone phone = getPhone(subId);
1673 if (phone != null) {
1674 return phone.isDataAllowed();
1675 } else {
1676 return false;
1677 }
1678 } finally {
1679 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682
1683 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001684 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001685 }
1686
pkanwarae03a6b2016-11-06 20:37:09 -08001687 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001688 enforceCallPermission();
1689
1690 final long identity = Binder.clearCallingIdentity();
1691 try {
1692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1693 return;
1694 }
1695 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1696 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
1699 }
pkanwar32d516d2016-10-14 19:37:38 -07001700 };
1701
Wink Savilleb564aae2014-10-23 10:18:09 -07001702 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001704
1705 final long identity = Binder.clearCallingIdentity();
1706 try {
1707 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1708 return false;
1709 }
1710 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1711 } finally {
1712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 }
1715
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001717 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001718 }
1719
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001720 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001721 final long identity = Binder.clearCallingIdentity();
1722 try {
1723 Phone phone = PhoneFactory.getPhone(slotIndex);
1724 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1725 PhoneConstantConversions.convertCallState(phone.getState());
1726 } finally {
1727 Binder.restoreCallingIdentity(identity);
1728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 }
1730
Sanket Padawe356d7632015-06-22 14:03:32 -07001731 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1736 if (phone != null) {
1737 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1738 } else {
1739 return PhoneConstantConversions.convertDataState(
1740 PhoneConstants.DataState.DISCONNECTED);
1741 }
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1752 if (phone != null) {
1753 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1754 } else {
1755 return TelephonyManager.DATA_ACTIVITY_NONE;
1756 }
1757 } finally {
1758 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 }
1761
1762 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001763 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001764 mPhone.getContext().getSystemService(AppOpsManager.class)
1765 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001766 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001767 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001768 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001771 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001772 final long identity = Binder.clearCallingIdentity();
1773 try {
1774 if (DBG_LOC) log("getCellLocation: is active user");
1775 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001776 int subId = mSubscriptionController.getDefaultDataSubId();
1777 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1778 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779 return data;
1780 } finally {
1781 Binder.restoreCallingIdentity(identity);
1782 }
Svetoslav64fad262015-04-14 14:35:21 -07001783 }
1784
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001786 public String getNetworkCountryIsoForPhone(int phoneId) {
1787 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1788 // registered cell info, so return a NULL country instead.
1789 final long identity = Binder.clearCallingIdentity();
1790 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001791 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1792 // Get default phone in this case.
1793 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1794 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001795 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001796 // Todo: fix this when we can get the actual cellular network info when the device
1797 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001798 if (TelephonyManager.NETWORK_TYPE_IWLAN
1799 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1800 return "";
1801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802 Phone phone = PhoneFactory.getPhone(phoneId);
1803 if (phone != null) {
1804 ServiceStateTracker sst = phone.getServiceStateTracker();
1805 if (sst != null) {
1806 LocaleTracker lt = sst.getLocaleTracker();
1807 if (lt != null) {
1808 return lt.getCurrentCountry();
1809 }
1810 }
1811 }
1812 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001813 } finally {
1814 Binder.restoreCallingIdentity(identity);
1815 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001816 }
1817
1818 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001820 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001821 }
1822
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001824 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 mApp.enforceCallingOrSelfPermission(
1826 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001827
1828 final long identity = Binder.clearCallingIdentity();
1829 try {
1830 final Phone phone = getPhone(subId);
1831 if (phone != null) {
1832 phone.enableLocationUpdates();
1833 }
1834 } finally {
1835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 }
1838
1839 @Override
1840 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001841 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001842 }
1843
Sanket Padawe356d7632015-06-22 14:03:32 -07001844 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001845 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 mApp.enforceCallingOrSelfPermission(
1847 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001848
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 final Phone phone = getPhone(subId);
1852 if (phone != null) {
1853 phone.disableLocationUpdates();
1854 }
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
Nathan Harold31d7ff32018-10-15 20:20:30 -07001860 /**
1861 * Returns the target SDK version number for a given package name.
1862 *
1863 * @return target SDK if the package is found or INT_MAX.
1864 */
1865 private int getTargetSdk(String packageName) {
1866 try {
1867 final ApplicationInfo ai =
1868 mPhone.getContext().getPackageManager().getApplicationInfo(packageName, 0);
1869 if (ai != null) return ai.targetSdkVersion;
1870 } catch (PackageManager.NameNotFoundException unexpected) {
1871 }
1872 return Integer.MAX_VALUE;
1873 }
1874
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 @Override
1876 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001877 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1878 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001879 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1880 throw new SecurityException(
1881 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1882 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001883
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1885 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1886 return null;
1887 }
Svetoslav64fad262015-04-14 14:35:21 -07001888
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001889 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890
Nathan Haroldf180aac2018-06-01 18:43:55 -07001891 List<CellInfo> info = getAllCellInfo(callingPackage);
1892 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893
Nathan Haroldf180aac2018-06-01 18:43:55 -07001894 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1895 for (CellInfo ci : info) {
1896 if (ci instanceof CellInfoGsm) {
1897 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1898 } else if (ci instanceof CellInfoWcdma) {
1899 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001902 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905
1906 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001907 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001908 mPhone.getContext().getSystemService(AppOpsManager.class)
1909 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001910 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001911 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001912 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001915 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001916 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1920 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001921 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07001922 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001923 if (info != null) cellInfos.addAll(info);
1924 }
1925 return cellInfos;
1926 } finally {
1927 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 }
1929 }
1930
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001931 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001933 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001934 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001935
1936 final long identity = Binder.clearCallingIdentity();
1937 try {
1938 mPhone.setCellInfoListRate(rateInMillis, workSource);
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
1941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Shishir Agrawala9f32182016-04-12 12:00:16 -07001944 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001945 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001946 Phone phone = PhoneFactory.getPhone(slotIndex);
1947 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001948 return null;
1949 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001950 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001951 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1952 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001953 return null;
1954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955
1956 final long identity = Binder.clearCallingIdentity();
1957 try {
1958 return phone.getImei();
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
1961 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001962 }
1963
1964 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001965 public String getTypeAllocationCodeForSlot(int slotIndex) {
1966 Phone phone = PhoneFactory.getPhone(slotIndex);
1967 String tac = null;
1968 if (phone != null) {
1969 String imei = phone.getImei();
1970 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1971 }
1972 return tac;
1973 }
1974
1975 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001976 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001977 Phone phone = PhoneFactory.getPhone(slotIndex);
1978 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001979 return null;
1980 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001981 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07001982 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
1983 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001984 return null;
1985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986
1987 final long identity = Binder.clearCallingIdentity();
1988 try {
1989 return phone.getMeid();
1990 } finally {
1991 Binder.restoreCallingIdentity(identity);
1992 }
Jack Yu2af8d712017-03-15 17:14:14 -07001993 }
1994
1995 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001996 public String getManufacturerCodeForSlot(int slotIndex) {
1997 Phone phone = PhoneFactory.getPhone(slotIndex);
1998 String manufacturerCode = null;
1999 if (phone != null) {
2000 String meid = phone.getMeid();
2001 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2002 }
2003 return manufacturerCode;
2004 }
2005
2006 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002007 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002008 Phone phone = PhoneFactory.getPhone(slotIndex);
2009 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002010 return null;
2011 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002012 int subId = phone.getSubId();
2013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2014 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2015 return null;
2016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002017
2018 final long identity = Binder.clearCallingIdentity();
2019 try {
2020 return phone.getDeviceSvn();
2021 } finally {
2022 Binder.restoreCallingIdentity(identity);
2023 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002024 }
2025
fionaxu43304da2017-11-27 22:51:16 -08002026 @Override
2027 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028 final long identity = Binder.clearCallingIdentity();
2029 try {
2030 final Phone phone = getPhone(subId);
2031 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
2034 }
fionaxu43304da2017-11-27 22:51:16 -08002035 }
2036
2037 @Override
2038 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039 final long identity = Binder.clearCallingIdentity();
2040 try {
2041 final Phone phone = getPhone(subId);
2042 return phone == null ? null : phone.getCarrierName();
2043 } finally {
2044 Binder.restoreCallingIdentity(identity);
2045 }
fionaxu43304da2017-11-27 22:51:16 -08002046 }
2047
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 //
2049 // Internal helper methods.
2050 //
2051
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002052 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2054 *
2055 * @throws SecurityException if the caller does not have the required permission
2056 */
2057 private void enforceModifyPermission() {
2058 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2059 }
2060
2061 /**
2062 * Make sure the caller has the CALL_PHONE permission.
2063 *
2064 * @throws SecurityException if the caller does not have the required permission
2065 */
2066 private void enforceCallPermission() {
2067 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2068 }
2069
Stuart Scott8eef64f2015-04-08 15:13:54 -07002070 private void enforceConnectivityInternalPermission() {
2071 mApp.enforceCallingOrSelfPermission(
2072 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2073 "ConnectivityService");
2074 }
2075
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002076 private String createTelUrl(String number) {
2077 if (TextUtils.isEmpty(number)) {
2078 return null;
2079 }
2080
Jake Hambye994d462014-02-03 13:10:13 -08002081 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 }
2083
Ihab Awadf9e92732013-12-05 18:02:52 -08002084 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2086 }
2087
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002088 private static void logv(String msg) {
2089 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2090 }
2091
Ihab Awadf9e92732013-12-05 18:02:52 -08002092 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2094 }
2095
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002096 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002098 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002099 }
2100
Sanket Padawe356d7632015-06-22 14:03:32 -07002101 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002102 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 final Phone phone = PhoneFactory.getPhone(slotIndex);
2106 if (phone == null) {
2107 return PhoneConstants.PHONE_TYPE_NONE;
2108 } else {
2109 return phone.getPhoneType();
2110 }
2111 } finally {
2112 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 }
2115
2116 /**
2117 * Returns the CDMA ERI icon index to display
2118 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002119 @Override
2120 public int getCdmaEriIconIndex(String callingPackage) {
2121 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002122 }
2123
Sanket Padawe356d7632015-06-22 14:03:32 -07002124 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002125 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002126 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002127 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002128 return -1;
2129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002130
2131 final long identity = Binder.clearCallingIdentity();
2132 try {
2133 final Phone phone = getPhone(subId);
2134 if (phone != null) {
2135 return phone.getCdmaEriIconIndex();
2136 } else {
2137 return -1;
2138 }
2139 } finally {
2140 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 }
2143
2144 /**
2145 * Returns the CDMA ERI icon mode,
2146 * 0 - ON
2147 * 1 - FLASHING
2148 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002149 @Override
2150 public int getCdmaEriIconMode(String callingPackage) {
2151 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002152 }
2153
Sanket Padawe356d7632015-06-22 14:03:32 -07002154 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002155 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002157 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002158 return -1;
2159 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160
2161 final long identity = Binder.clearCallingIdentity();
2162 try {
2163 final Phone phone = getPhone(subId);
2164 if (phone != null) {
2165 return phone.getCdmaEriIconMode();
2166 } else {
2167 return -1;
2168 }
2169 } finally {
2170 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 }
2173
2174 /**
2175 * Returns the CDMA ERI text,
2176 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002177 @Override
2178 public String getCdmaEriText(String callingPackage) {
2179 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002180 }
2181
Sanket Padawe356d7632015-06-22 14:03:32 -07002182 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002183 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002185 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002186 return null;
2187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188
2189 final long identity = Binder.clearCallingIdentity();
2190 try {
2191 final Phone phone = getPhone(subId);
2192 if (phone != null) {
2193 return phone.getCdmaEriText();
2194 } else {
2195 return null;
2196 }
2197 } finally {
2198 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
2202 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002203 * Returns the CDMA MDN.
2204 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002205 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002206 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2208 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209
2210 final long identity = Binder.clearCallingIdentity();
2211 try {
2212 final Phone phone = getPhone(subId);
2213 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2214 return phone.getLine1Number();
2215 } else {
2216 return null;
2217 }
2218 } finally {
2219 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002220 }
2221 }
2222
2223 /**
2224 * Returns the CDMA MIN.
2225 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002226 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002227 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2229 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230
2231 final long identity = Binder.clearCallingIdentity();
2232 try {
2233 final Phone phone = getPhone(subId);
2234 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2235 return phone.getCdmaMin();
2236 } else {
2237 return null;
2238 }
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002241 }
2242 }
2243
2244 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 * Returns true if CDMA provisioning needs to run.
2246 */
2247 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002248 final long identity = Binder.clearCallingIdentity();
2249 try {
2250 return mPhone.needsOtaServiceProvisioning();
2251 } finally {
2252 Binder.restoreCallingIdentity(identity);
2253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 }
2255
2256 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002257 * Sets the voice mail number of a given subId.
2258 */
2259 @Override
2260 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002261 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262
2263 final long identity = Binder.clearCallingIdentity();
2264 try {
2265 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2266 new Pair<String, String>(alphaTag, number), new Integer(subId));
2267 return success;
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
2270 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002271 }
2272
Ta-wei Yen87c49842016-05-13 21:19:52 -07002273 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002274 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2275 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2276 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2277 if (!TextUtils.equals(callingPackage, systemDialer)) {
2278 throw new SecurityException("caller must be system dialer");
2279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002280
2281 final long identity = Binder.clearCallingIdentity();
2282 try {
2283 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2284 if (phoneAccountHandle == null) {
2285 return null;
2286 }
2287 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2288 } finally {
2289 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002290 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002291 }
2292
2293 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002294 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002295 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002297 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002298 return null;
2299 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002300
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 return RemoteVvmTaskManager
2304 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2305 } finally {
2306 Binder.restoreCallingIdentity(identity);
2307 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002308 }
2309
2310 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002311 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2312 VisualVoicemailSmsFilterSettings settings) {
2313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002314
2315 final long identity = Binder.clearCallingIdentity();
2316 try {
2317 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2318 mPhone.getContext(), callingPackage, subId, settings);
2319 } finally {
2320 Binder.restoreCallingIdentity(identity);
2321 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002322 }
2323
2324 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002325 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2326 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2331 mPhone.getContext(), callingPackage, subId);
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
2334 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002335 }
2336
2337 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002338 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2339 String callingPackage, int subId) {
2340 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341
2342 final long identity = Binder.clearCallingIdentity();
2343 try {
2344 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2345 mPhone.getContext(), callingPackage, subId);
2346 } finally {
2347 Binder.restoreCallingIdentity(identity);
2348 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002349 }
2350
2351 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002352 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002353 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002354
2355 final long identity = Binder.clearCallingIdentity();
2356 try {
2357 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2358 mPhone.getContext(), subId);
2359 } finally {
2360 Binder.restoreCallingIdentity(identity);
2361 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002362 }
2363
2364 @Override
2365 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2366 String number, int port, String text, PendingIntent sentIntent) {
2367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002368 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002369 enforceSendSmsPermission();
2370 // Make the calls as the phone process.
2371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2374 if (port == 0) {
2375 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2376 sentIntent, null, false);
2377 } else {
2378 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2379 smsManager.sendDataMessageWithSelfPermissions(number, null,
2380 (short) port, data, sentIntent, null);
2381 }
2382 } finally {
2383 Binder.restoreCallingIdentity(identity);
2384 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002385 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002386 /**
fionaxu0152e512016-11-14 13:36:14 -08002387 * Sets the voice activation state of a given subId.
2388 */
2389 @Override
2390 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2392 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393
2394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 final Phone phone = getPhone(subId);
2397 if (phone != null) {
2398 phone.setVoiceActivationState(activationState);
2399 } else {
2400 loge("setVoiceActivationState fails with invalid subId: " + subId);
2401 }
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002404 }
2405 }
2406
2407 /**
2408 * Sets the data activation state of a given subId.
2409 */
2410 @Override
2411 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2413 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002414
2415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 final Phone phone = getPhone(subId);
2418 if (phone != null) {
2419 phone.setDataActivationState(activationState);
2420 } else {
2421 loge("setVoiceActivationState fails with invalid subId: " + subId);
2422 }
2423 } finally {
2424 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002425 }
2426 }
2427
2428 /**
2429 * Returns the voice activation state of a given subId.
2430 */
2431 @Override
2432 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002433 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434
fionaxu0152e512016-11-14 13:36:14 -08002435 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436 final long identity = Binder.clearCallingIdentity();
2437 try {
2438 if (phone != null) {
2439 return phone.getVoiceActivationState();
2440 } else {
2441 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2442 }
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002445 }
2446 }
2447
2448 /**
2449 * Returns the data activation state of a given subId.
2450 */
2451 @Override
2452 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002453 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002454
fionaxu0152e512016-11-14 13:36:14 -08002455 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456 final long identity = Binder.clearCallingIdentity();
2457 try {
2458 if (phone != null) {
2459 return phone.getDataActivationState();
2460 } else {
2461 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2462 }
2463 } finally {
2464 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002465 }
2466 }
2467
2468 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 * Returns the unread count of voicemails
2470 */
2471 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002472 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002473 }
2474
2475 /**
2476 * Returns the unread count of voicemails for a subId
2477 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002478 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002479 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 final Phone phone = getPhone(subId);
2483 if (phone != null) {
2484 return phone.getVoiceMessageCount();
2485 } else {
2486 return 0;
2487 }
2488 } finally {
2489 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 }
2492
2493 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002494 * returns true, if the device is in a state where both voice and data
2495 * are supported simultaneously. This can change based on location or network condition.
2496 */
2497 @Override
2498 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 final Phone phone = getPhone(subId);
2502 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2503 } finally {
2504 Binder.restoreCallingIdentity(identity);
2505 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002506 }
2507
2508 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002509 * Send the dialer code if called from the current default dialer or the caller has
2510 * carrier privilege.
2511 * @param inputCode The dialer code to send
2512 */
2513 @Override
2514 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2516 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2517 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002518 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2519 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521
2522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 mPhone.sendDialerSpecialCode(inputCode);
2525 } finally {
2526 Binder.restoreCallingIdentity(identity);
2527 }
fionaxu235cc5e2017-03-06 22:25:57 -08002528 }
2529
2530 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002531 * Returns the data network type.
2532 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 *
2534 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2535 */
2536 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002537 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538 final long identity = Binder.clearCallingIdentity();
2539 try {
2540 final Phone phone = getPhone(getDefaultSubscription());
2541 if (phone != null) {
2542 return phone.getServiceState().getDataNetworkType();
2543 } else {
2544 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2545 }
2546 } finally {
2547 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002548 }
Wink Saville36469e72014-06-11 15:17:00 -07002549 }
2550
Pengquan Menga1bb6272018-09-06 09:59:22 -07002551 @Override
2552 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002553 if (!isActiveSubscription(subId)) {
2554 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2555 }
2556
Pengquan Menga1bb6272018-09-06 09:59:22 -07002557 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2558 }
2559
Brad Ebinger35c841c2018-10-01 10:40:55 -07002560 @Override
2561 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2562 String callingPackage) throws RemoteException {
2563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2564 "addImsRegistrationCallback")) {
2565 return;
2566 }
2567 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2568 final long token = Binder.clearCallingIdentity();
2569 try {
2570 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2571 .addRegistrationCallbackForSubscription(c, subId);
2572 } finally {
2573 Binder.restoreCallingIdentity(token);
2574 }
2575 }
2576
2577 @Override
2578 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2579 String callingPackage) {
2580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2581 "removeImsRegistrationCallback")) {
2582 return;
2583 }
2584 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2585 Binder.withCleanCallingIdentity(() ->
2586 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2587 .removeRegistrationCallbackForSubscription(c, subId));
2588 }
2589
2590 @Override
2591 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2592 String callingPackage) throws RemoteException {
2593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2594 "addMmTelCapabilityCallback")) {
2595 return;
2596 }
2597 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2598 final long token = Binder.clearCallingIdentity();
2599 try {
2600 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2601 .addCapabilitiesCallbackForSubscription(c, subId);
2602 } finally {
2603 Binder.restoreCallingIdentity(token);
2604 }
2605 }
2606
2607 @Override
2608 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2609 String callingPackage) {
2610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2611 "removeMmTelCapabilityCallback")) {
2612 return;
2613 }
2614 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2615 Binder.withCleanCallingIdentity(() ->
2616 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2617 .removeCapabilitiesCallbackForSubscription(c, subId));
2618 }
2619
2620 @Override
2621 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2623 "isCapable")) {
2624 return false;
2625 }
2626 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2627 final long token = Binder.clearCallingIdentity();
2628 try {
2629 return ImsManager.getInstance(mPhone.getContext(),
2630 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2631 } catch (ImsException e) {
2632 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2633 return false;
2634 } finally {
2635 Binder.restoreCallingIdentity(token);
2636 }
2637 }
2638
2639 @Override
2640 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2642 "isAvailable")) {
2643 return false;
2644 }
2645 final long token = Binder.clearCallingIdentity();
2646 try {
2647 Phone phone = getPhone(subId);
2648 if (phone == null) return false;
2649 return phone.isImsCapabilityAvailable(capability, regTech);
2650 } finally {
2651 Binder.restoreCallingIdentity(token);
2652 }
2653 }
2654
2655 @Override
2656 public boolean isAdvancedCallingSettingEnabled(int subId) {
2657 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2658 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2659 final long token = Binder.clearCallingIdentity();
2660 try {
2661 return ImsManager.getInstance(mPhone.getContext(),
2662 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2663 } finally {
2664 Binder.restoreCallingIdentity(token);
2665 }
2666 }
2667
2668 @Override
2669 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2671 "setAdvancedCallingSetting");
2672 final long identity = Binder.clearCallingIdentity();
2673 try {
2674 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2675 ImsManager.getInstance(mPhone.getContext(),
2676 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2677 } finally {
2678 Binder.restoreCallingIdentity(identity);
2679 }
2680 }
2681
2682 @Override
2683 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2685 "isVtSettingEnabled")) {
2686 return false;
2687 }
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2691 return ImsManager.getInstance(mPhone.getContext(),
2692 getSlotIndexOrException(subId)).isVtEnabledByUser();
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
2695 }
2696 }
2697
2698 @Override
2699 public void setVtSetting(int subId, boolean isEnabled) {
2700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2701 "setVtSetting");
2702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2705 ImsManager.getInstance(mPhone.getContext(),
2706 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
2710 }
2711
2712 @Override
2713 public boolean isVoWiFiSettingEnabled(int subId) {
2714 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2718 return ImsManager.getInstance(mPhone.getContext(),
2719 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
2722 }
2723 }
2724
2725 @Override
2726 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2728 "setVoWiFiSetting");
2729 final long identity = Binder.clearCallingIdentity();
2730 try {
2731 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2732 ImsManager.getInstance(mPhone.getContext(),
2733 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
2736 }
2737 }
2738
2739 @Override
2740 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2741 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2745 return ImsManager.getInstance(mPhone.getContext(),
2746 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
2749 }
2750 }
2751
2752 @Override
2753 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2755 "setVoWiFiRoamingSetting");
2756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2759 ImsManager.getInstance(mPhone.getContext(),
2760 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2761 } finally {
2762 Binder.restoreCallingIdentity(identity);
2763 }
2764 }
2765
2766 @Override
2767 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2769 "setVoWiFiNonPersistent");
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2773 ImsManager.getInstance(mPhone.getContext(),
2774 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
2777 }
2778 }
2779
2780 @Override
2781 public int getVoWiFiModeSetting(int subId) {
2782 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2786 return ImsManager.getInstance(mPhone.getContext(),
2787 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
2790 }
2791 }
2792
2793 @Override
2794 public void setVoWiFiModeSetting(int subId, int mode) {
2795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2796 "setVoWiFiModeSetting");
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2800 ImsManager.getInstance(mPhone.getContext(),
2801 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2802 } finally {
2803 Binder.restoreCallingIdentity(identity);
2804 }
2805 }
2806
2807 @Override
2808 public int getVoWiFiRoamingModeSetting(int subId) {
2809 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2813 return ImsManager.getInstance(mPhone.getContext(),
2814 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
2818 }
2819
2820 @Override
2821 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2823 "setVoWiFiRoamingModeSetting");
2824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2827 ImsManager.getInstance(mPhone.getContext(),
2828 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
2831 }
2832 }
2833
2834 @Override
2835 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2837 "setRttCapabilityEnabled");
2838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2841 ImsManager.getInstance(mPhone.getContext(),
2842 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
2845 }
2846 }
2847
2848 @Override
2849 public boolean isTtyOverVolteEnabled(int subId) {
2850 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2854 return ImsManager.getInstance(mPhone.getContext(),
2855 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
2859 }
2860
2861 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2862 int slotId = SubscriptionManager.getSlotIndex(subId);
2863 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2864 throw new IllegalArgumentException("Invalid Subscription Id.");
2865 }
2866 return slotId;
2867 }
2868
Wink Saville36469e72014-06-11 15:17:00 -07002869 /**
2870 * Returns the network type for a subId
2871 */
2872 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002873 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002875 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002876 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2877 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 final Phone phone = getPhone(subId);
2882 if (phone != null) {
2883 return phone.getServiceState().getDataNetworkType();
2884 } else {
2885 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2886 }
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
2892 /**
2893 * Returns the data network type
2894 */
2895 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002896 public int getDataNetworkType(String callingPackage) {
2897 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002898 }
2899
2900 /**
2901 * Returns the data network type for a subId
2902 */
2903 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002904 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002906 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002907 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2908 }
2909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 if (phone != null) {
2914 return phone.getServiceState().getDataNetworkType();
2915 } else {
2916 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2917 }
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921 }
2922
2923 /**
Wink Saville36469e72014-06-11 15:17:00 -07002924 * Returns the Voice network type for a subId
2925 */
2926 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002927 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002929 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002930 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2931 }
2932
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 final Phone phone = getPhone(subId);
2936 if (phone != null) {
2937 return phone.getServiceState().getVoiceNetworkType();
2938 } else {
2939 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2940 }
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002944 }
2945
2946 /**
2947 * @return true if a ICC card is present
2948 */
2949 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002950 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002951 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2952 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002953 }
2954
2955 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002956 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002957 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002958 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002959 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 final Phone phone = PhoneFactory.getPhone(slotIndex);
2963 if (phone != null) {
2964 return phone.getIccCard().hasIccCard();
2965 } else {
2966 return false;
2967 }
2968 } finally {
2969 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
2972
2973 /**
2974 * Return if the current radio is LTE on CDMA. This
2975 * is a tri-state return value as for a period of time
2976 * the mode may be unknown.
2977 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002978 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002979 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002980 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002981 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002982 @Override
2983 public int getLteOnCdmaMode(String callingPackage) {
2984 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002985 }
2986
Sanket Padawe356d7632015-06-22 14:03:32 -07002987 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002988 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002990 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002991 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2992 }
2993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 final Phone phone = getPhone(subId);
2997 if (phone == null) {
2998 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2999 } else {
3000 return phone.getLteOnCdmaMode();
3001 }
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003004 }
Wink Saville36469e72014-06-11 15:17:00 -07003005 }
3006
3007 public void setPhone(Phone phone) {
3008 mPhone = phone;
3009 }
3010
3011 /**
3012 * {@hide}
3013 * Returns Default subId, 0 in the case of single standby.
3014 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003015 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003016 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003017 }
3018
Shishir Agrawala9f32182016-04-12 12:00:16 -07003019 private int getSlotForDefaultSubscription() {
3020 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3021 }
3022
Wink Savilleb564aae2014-10-23 10:18:09 -07003023 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003024 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003025 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003026
Pengquan Menge92a50d2018-09-21 15:54:48 -07003027 private boolean isActiveSubscription(int subId) {
3028 return mSubscriptionController.isActiveSubId(subId);
3029 }
3030
Ihab Awadf2177b72013-11-25 13:33:23 -08003031 /**
3032 * @see android.telephony.TelephonyManager.WifiCallingChoices
3033 */
3034 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3038 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3039 getWhenToMakeWifiCallsDefaultPreference());
3040 } finally {
3041 Binder.restoreCallingIdentity(identity);
3042 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003043 }
3044
3045 /**
3046 * @see android.telephony.TelephonyManager.WifiCallingChoices
3047 */
3048 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3052 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3053 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003057 }
3058
Sailesh Nepald1e68152013-12-12 19:08:02 -08003059 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003060 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003061 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003062 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003063
Shishir Agrawal566b7612013-10-28 14:41:00 -07003064 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003065 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3066 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3068 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 if (TextUtils.equals(ISDR_AID, aid)) {
3074 // Only allows LPA to open logical channel to ISD-R.
3075 ComponentInfo bestComponent =
3076 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3077 if (bestComponent == null
3078 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3079 loge("The calling package is not allowed to access ISD-R.");
3080 throw new SecurityException(
3081 "The calling package is not allowed to access ISD-R.");
3082 }
Derek Tan740e1672017-06-27 14:56:27 -07003083 }
Derek Tan740e1672017-06-27 14:56:27 -07003084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085 if (DBG) {
3086 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3087 }
3088 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3089 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3090 if (DBG) log("iccOpenLogicalChannel: " + response);
3091 return response;
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003095 }
3096
3097 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003098 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3100 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3105 if (channel < 0) {
3106 return false;
3107 }
3108 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3109 if (DBG) log("iccCloseLogicalChannel: " + success);
3110 return success;
3111 } finally {
3112 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003113 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003114 }
3115
3116 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003117 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003118 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3120 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003121
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 if (DBG) {
3125 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3126 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3127 + p3 + " data=" + data);
3128 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130 if (channel < 0) {
3131 return "";
3132 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3135 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3136 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 // Append the returned status code to the end of the response payload.
3139 String s = Integer.toHexString(
3140 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3141 if (response.payload != null) {
3142 s = IccUtils.bytesToHexString(response.payload) + s;
3143 }
3144 return s;
3145 } finally {
3146 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003147 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003148 }
Jake Hambye994d462014-02-03 13:10:13 -08003149
Evan Charltonc66da362014-05-16 14:06:40 -07003150 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003151 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3152 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3154 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003155 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3160 && TextUtils.equals(ISDR_AID, data)) {
3161 // Only allows LPA to select ISD-R.
3162 ComponentInfo bestComponent =
3163 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3164 if (bestComponent == null
3165 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3166 loge("The calling package is not allowed to select ISD-R.");
3167 throw new SecurityException(
3168 "The calling package is not allowed to select ISD-R.");
3169 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003170 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172 if (DBG) {
3173 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3174 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3175 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3178 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3179 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181 // Append the returned status code to the end of the response payload.
3182 String s = Integer.toHexString(
3183 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3184 if (response.payload != null) {
3185 s = IccUtils.bytesToHexString(response.payload) + s;
3186 }
3187 return s;
3188 } finally {
3189 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003190 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003191 }
3192
3193 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003194 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003195 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3197 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 if (DBG) {
3202 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3203 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3204 }
3205
3206 IccIoResult response =
3207 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3208 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3209 subId);
3210
3211 if (DBG) {
3212 log("Exchange SIM_IO [R]" + response);
3213 }
3214
3215 byte[] result = null;
3216 int length = 2;
3217 if (response.payload != null) {
3218 length = 2 + response.payload.length;
3219 result = new byte[length];
3220 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3221 } else {
3222 result = new byte[length];
3223 }
3224
3225 result[length - 1] = (byte) response.sw2;
3226 result[length - 2] = (byte) response.sw1;
3227 return result;
3228 } finally {
3229 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003230 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003231 }
3232
Nathan Haroldb3014052017-01-25 15:57:32 -08003233 /**
3234 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3235 * on a particular subscription
3236 */
sqianb6e41952018-03-12 14:54:01 -07003237 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3239 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3240 return null;
3241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242
3243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 if (appType != TelephonyManager.APPTYPE_USIM
3246 && appType != TelephonyManager.APPTYPE_SIM) {
3247 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3248 return null;
3249 }
3250 Object response = sendRequest(
3251 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3252 if (response instanceof String[]) {
3253 return (String[]) response;
3254 }
3255 // Response is an Exception of some kind,
3256 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003257 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258 } finally {
3259 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003260 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003261 }
3262
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003263 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003264 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3266 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3271 if (response.payload == null) {
3272 return "";
3273 }
Evan Charltonc66da362014-05-16 14:06:40 -07003274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275 // Append the returned status code to the end of the response payload.
3276 String s = Integer.toHexString(
3277 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3278 s = IccUtils.bytesToHexString(response.payload) + s;
3279 return s;
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
Evan Charltonc66da362014-05-16 14:06:40 -07003283 }
3284
Jake Hambye994d462014-02-03 13:10:13 -08003285 /**
3286 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3287 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3288 *
3289 * @param itemID the ID of the item to read
3290 * @return the NV item as a String, or null on error.
3291 */
3292 @Override
3293 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003294 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3296 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003297
3298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003301 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003302 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3303 return value;
3304 } finally {
3305 Binder.restoreCallingIdentity(identity);
3306 }
Jake Hambye994d462014-02-03 13:10:13 -08003307 }
3308
3309 /**
3310 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3311 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3312 *
3313 * @param itemID the ID of the item to read
3314 * @param itemValue the value to write, as a String
3315 * @return true on success; false on any failure
3316 */
3317 @Override
3318 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3321 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322
3323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3326 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003327 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003328 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3329 return success;
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
Jake Hambye994d462014-02-03 13:10:13 -08003333 }
3334
3335 /**
3336 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3337 * Used for device configuration by some CDMA operators.
3338 *
3339 * @param preferredRoamingList byte array containing the new PRL
3340 * @return true on success; false on any failure
3341 */
3342 @Override
3343 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3345 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3350 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3351 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3352 return success;
3353 } finally {
3354 Binder.restoreCallingIdentity(identity);
3355 }
Jake Hambye994d462014-02-03 13:10:13 -08003356 }
3357
3358 /**
3359 * Perform the specified type of NV config reset.
3360 * Used for device configuration by some CDMA operators.
3361 *
3362 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3363 * @return true on success; false on any failure
3364 */
3365 @Override
3366 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3368 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003369
3370 final long identity = Binder.clearCallingIdentity();
3371 try {
3372 if (DBG) log("nvResetConfig: type " + resetType);
3373 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3374 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3375 return success;
3376 } finally {
3377 Binder.restoreCallingIdentity(identity);
3378 }
Jake Hambye994d462014-02-03 13:10:13 -08003379 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003380
Svet Ganovb320e182015-04-16 12:30:10 -07003381 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003383 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003384 return new String[0];
3385 }
3386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 return mPhone.getPcscfAddress(apnType);
3390 } finally {
3391 Binder.restoreCallingIdentity(identity);
3392 }
Wink Saville36469e72014-06-11 15:17:00 -07003393 }
3394
Brad Ebinger51f743a2017-01-23 13:50:20 -08003395 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003396 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3397 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003398 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003399 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003400 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003401
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 PhoneFactory.getImsResolver().enableIms(slotId);
3405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003408 }
3409
3410 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003411 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3412 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003413 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003414 public void disableIms(int slotId) {
3415 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003416
3417 final long identity = Binder.clearCallingIdentity();
3418 try {
3419 PhoneFactory.getImsResolver().disableIms(slotId);
3420 } finally {
3421 Binder.restoreCallingIdentity(identity);
3422 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003423 }
3424
3425 /**
3426 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3427 * feature or {@link null} if the service is not available. If the feature is available, the
3428 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3429 */
3430 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003431 IImsServiceFeatureCallback callback) {
3432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003433
3434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3437 } finally {
3438 Binder.restoreCallingIdentity(identity);
3439 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003440 }
3441
3442 /**
3443 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3444 * feature during emergency calling or {@link null} if the service is not available. If the
3445 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3446 * listener for feature updates.
3447 */
3448 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3449 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450
3451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3454 } finally {
3455 Binder.restoreCallingIdentity(identity);
3456 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003457 }
3458
Brad Ebinger5f64b052017-12-14 14:26:15 -08003459 /**
3460 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3461 * specified.
3462 */
3463 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3464 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465
3466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3469 } finally {
3470 Binder.restoreCallingIdentity(identity);
3471 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003472 }
3473
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003474 /**
3475 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3476 * specified.
3477 */
3478 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3479 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3484 } finally {
3485 Binder.restoreCallingIdentity(identity);
3486 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003487 }
3488
Brad Ebinger884c07b2018-02-15 16:17:40 -08003489 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003490 * Sets the ImsService Package Name that Telephony will bind to.
3491 *
3492 * @param slotId the slot ID that the ImsService should bind for.
3493 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3494 * ImsService is the device default ImsService.
3495 * @param packageName The package name of the application that contains the ImsService to bind
3496 * to.
3497 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3498 * @hide
3499 */
3500 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003501 int[] subIds = SubscriptionManager.getSubId(slotId);
3502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3503 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3504 "setImsService");
3505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506 final long identity = Binder.clearCallingIdentity();
3507 try {
3508 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3509 isCarrierImsService, packageName);
3510 } finally {
3511 Binder.restoreCallingIdentity(identity);
3512 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003513 }
3514
3515 /**
3516 * Return the ImsService configuration.
3517 *
3518 * @param slotId The slot that the ImsService is associated with.
3519 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3520 * the device default.
3521 * @return the package name of the ImsService configuration.
3522 */
3523 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003524 int[] subIds = SubscriptionManager.getSubId(slotId);
3525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3526 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3527 "getImsService");
3528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3532 isCarrierImsService);
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003536 }
3537
Wink Saville36469e72014-06-11 15:17:00 -07003538 public void setImsRegistrationState(boolean registered) {
3539 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540
3541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 mPhone.setImsRegistrationState(registered);
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
Wink Saville36469e72014-06-11 15:17:00 -07003547 }
3548
3549 /**
Stuart Scott54788802015-03-30 13:18:01 -07003550 * Set the network selection mode to automatic.
3551 *
3552 */
3553 @Override
3554 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3556 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
Pengquan Menge92a50d2018-09-21 15:54:48 -07003558 if (!isActiveSubscription(subId)) {
3559 return;
3560 }
3561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3565 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
3568 }
Stuart Scott54788802015-03-30 13:18:01 -07003569 }
3570
Pengquan Mengea84e042018-09-20 14:57:26 -07003571 /**
3572 * Ask the radio to connect to the input network and change selection mode to manual.
3573 *
3574 * @param subId the id of the subscription.
3575 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3576 * the operator to attach to.
3577 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3578 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3579 * normal network selection next time.
3580 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003581 */
3582 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003583 public boolean setNetworkSelectionModeManual(
3584 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3586 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003587
3588 if (!isActiveSubscription(subId)) {
3589 return false;
3590 }
3591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592 final long identity = Binder.clearCallingIdentity();
3593 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003594 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003596 if (DBG) {
3597 log("setNetworkSelectionModeManual: subId: " + subId
3598 + " operator: " + operatorInfo);
3599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003600 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3601 } finally {
3602 Binder.restoreCallingIdentity(identity);
3603 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003604 }
3605
3606 /**
3607 * Scans for available networks.
3608 */
3609 @Override
3610 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3612 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003613
Pengquan Menga1bb6272018-09-06 09:59:22 -07003614 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003615 try {
3616 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003617 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003618 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619 } finally {
3620 Binder.restoreCallingIdentity(identity);
3621 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003622 }
3623
3624 /**
yinxub1bed742017-04-17 11:45:04 -07003625 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003626 *
yinxub1bed742017-04-17 11:45:04 -07003627 * @param subId id of the subscription
3628 * @param request contains the radio access networks with bands/channels to scan
3629 * @param messenger callback messenger for scan results or errors
3630 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003631 * @return the id of the requested scan which can be used to stop the scan.
3632 */
3633 @Override
3634 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3635 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3637 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638
3639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 return mNetworkScanRequestTracker.startNetworkScan(
3642 request, messenger, binder, getPhone(subId));
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
yinxu504e1392017-04-12 16:03:22 -07003646 }
3647
3648 /**
3649 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003650 *
3651 * @param subId id of the subscription
3652 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003653 */
3654 @Override
3655 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3657 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
yinxu504e1392017-04-12 16:03:22 -07003665 }
3666
3667 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003668 * Get the calculated preferred network type.
3669 * Used for debugging incorrect network type.
3670 *
3671 * @return the preferred network type, defined in RILConstants.java.
3672 */
3673 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003674 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003676 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003677 return RILConstants.PREFERRED_NETWORK_MODE;
3678 }
3679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 // FIXME: need to get SubId from somewhere.
3683 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
3686 }
Junda Liu84d15a22014-07-02 11:21:04 -07003687 }
3688
3689 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003690 * Get the preferred network type.
3691 * Used for device configuration by some CDMA operators.
3692 *
3693 * @return the preferred network type, defined in RILConstants.java.
3694 */
3695 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003696 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3698 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 if (DBG) log("getPreferredNetworkType");
3703 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3704 int networkType = (result != null ? result[0] : -1);
3705 if (DBG) log("getPreferredNetworkType: " + networkType);
3706 return networkType;
3707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003710 }
3711
3712 /**
3713 * Set the preferred network type.
3714 * Used for device configuration by some CDMA operators.
3715 *
3716 * @param networkType the preferred network type, defined in RILConstants.java.
3717 * @return true on success; false on any failure.
3718 */
3719 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003720 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3722 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3727 Boolean success = (Boolean) sendRequest(
3728 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3729 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3730 if (success) {
3731 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3732 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3733 }
3734 return success;
3735 } finally {
3736 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003737 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003738 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003739
3740 /**
Junda Liu475951f2014-11-07 16:45:03 -08003741 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3742 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3743 * tethering.
3744 *
3745 * @return 0: Not required. 1: required. 2: Not set.
3746 * @hide
3747 */
3748 @Override
3749 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003750 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751
3752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3755 Settings.Global.TETHER_DUN_REQUIRED, 2);
3756 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3757 // config_tether_apndata.
3758 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3759 dunRequired = 1;
3760 }
3761 return dunRequired;
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003764 }
Junda Liu475951f2014-11-07 16:45:03 -08003765 }
3766
3767 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003768 * Set mobile data enabled
3769 * Used by the user through settings etc to turn on/off mobile data
3770 *
3771 * @param enable {@code true} turn turn data on, else {@code false}
3772 */
3773 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003774 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3776 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777
3778 final long identity = Binder.clearCallingIdentity();
3779 try {
3780 int phoneId = mSubscriptionController.getPhoneId(subId);
3781 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3782 Phone phone = PhoneFactory.getPhone(phoneId);
3783 if (phone != null) {
3784 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3785 phone.setUserDataEnabled(enable);
3786 } else {
3787 loge("setUserDataEnabled: no phone for subId=" + subId);
3788 }
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003791 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003792 }
3793
3794 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003795 * Get the user enabled state of Mobile Data.
3796 *
3797 * TODO: remove and use isUserDataEnabled.
3798 * This can't be removed now because some vendor codes
3799 * calls through ITelephony directly while they should
3800 * use TelephonyManager.
3801 *
3802 * @return true on enabled
3803 */
3804 @Override
3805 public boolean getDataEnabled(int subId) {
3806 return isUserDataEnabled(subId);
3807 }
3808
3809 /**
3810 * Get whether mobile data is enabled per user setting.
3811 *
3812 * There are other factors deciding whether mobile data is actually enabled, but they are
3813 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003814 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003815 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003816 *
3817 * @return {@code true} if data is enabled else {@code false}
3818 */
3819 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003820 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003821 try {
3822 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3823 null);
3824 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3826 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003827 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828
3829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 int phoneId = mSubscriptionController.getPhoneId(subId);
3832 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3833 Phone phone = PhoneFactory.getPhone(phoneId);
3834 if (phone != null) {
3835 boolean retVal = phone.isUserDataEnabled();
3836 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3837 return retVal;
3838 } else {
3839 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3840 return false;
3841 }
3842 } finally {
3843 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003844 }
3845 }
3846
3847 /**
3848 * Get whether mobile data is enabled.
3849 *
3850 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3851 * whether mobile data is actually enabled.
3852 *
3853 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3854 *
3855 * @return {@code true} if data is enabled else {@code false}
3856 */
3857 @Override
3858 public boolean isDataEnabled(int subId) {
3859 try {
3860 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3861 null);
3862 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3864 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003866
3867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 int phoneId = mSubscriptionController.getPhoneId(subId);
3870 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3871 Phone phone = PhoneFactory.getPhone(phoneId);
3872 if (phone != null) {
3873 boolean retVal = phone.isDataEnabled();
3874 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3875 return retVal;
3876 } else {
3877 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3878 return false;
3879 }
3880 } finally {
3881 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003882 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003883 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003884
3885 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003886 public int getCarrierPrivilegeStatus(int subId) {
3887 final Phone phone = getPhone(subId);
3888 if (phone == null) {
3889 loge("getCarrierPrivilegeStatus: Invalid subId");
3890 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3891 }
3892 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003893 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003894 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3896 }
3897 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003898 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003899 }
Junda Liu29340342014-07-10 15:23:27 -07003900
3901 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003902 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3903 final Phone phone = getPhone(subId);
3904 if (phone == null) {
3905 loge("getCarrierPrivilegeStatus: Invalid subId");
3906 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3907 }
3908 UiccProfile profile =
3909 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3910 if (profile == null) {
3911 loge("getCarrierPrivilegeStatus: No UICC");
3912 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3913 }
3914 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3915 }
3916
3917 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003918 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003919 if (TextUtils.isEmpty(pkgName))
3920 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003921 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003922 if (card == null) {
3923 loge("checkCarrierPrivilegesForPackage: No UICC");
3924 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3925 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003926 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3927 }
3928
3929 @Override
3930 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003931 if (TextUtils.isEmpty(pkgName))
3932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003933 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3934 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3935 UiccCard card = UiccController.getInstance().getUiccCard(i);
3936 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003937 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003938 continue;
3939 }
3940
3941 result = card.getCarrierPrivilegeStatus(
3942 mPhone.getContext().getPackageManager(), pkgName);
3943 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3944 break;
3945 }
3946 }
3947
3948 return result;
Junda Liu29340342014-07-10 15:23:27 -07003949 }
Derek Tan89e89d42014-07-08 17:00:10 -07003950
3951 @Override
Junda Liue64de782015-04-16 17:19:16 -07003952 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3953 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3954 loge("phoneId " + phoneId + " is not valid.");
3955 return null;
3956 }
3957 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003958 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003959 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003960 return null ;
3961 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003962 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003963 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003964 }
3965
Amith Yamasani6e118872016-02-19 12:53:51 -08003966 @Override
3967 public List<String> getPackagesWithCarrierPrivileges() {
3968 PackageManager pm = mPhone.getContext().getPackageManager();
3969 List<String> privilegedPackages = new ArrayList<>();
3970 List<PackageInfo> packages = null;
3971 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3972 UiccCard card = UiccController.getInstance().getUiccCard(i);
3973 if (card == null) {
3974 // No UICC in that slot.
3975 continue;
3976 }
3977 if (card.hasCarrierPrivilegeRules()) {
3978 if (packages == null) {
3979 // Only check packages in user 0 for now
3980 packages = pm.getInstalledPackagesAsUser(
3981 PackageManager.MATCH_DISABLED_COMPONENTS
3982 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3983 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3984 }
3985 for (int p = packages.size() - 1; p >= 0; p--) {
3986 PackageInfo pkgInfo = packages.get(p);
3987 if (pkgInfo != null && pkgInfo.packageName != null
3988 && card.getCarrierPrivilegeStatus(pkgInfo)
3989 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3990 privilegedPackages.add(pkgInfo.packageName);
3991 }
3992 }
3993 }
3994 }
3995 return privilegedPackages;
3996 }
3997
Wink Savilleb564aae2014-10-23 10:18:09 -07003998 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003999 final Phone phone = getPhone(subId);
4000 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004001 if (card == null) {
4002 loge("getIccId: No UICC");
4003 return null;
4004 }
4005 String iccId = card.getIccId();
4006 if (TextUtils.isEmpty(iccId)) {
4007 loge("getIccId: ICC ID is null or empty.");
4008 return null;
4009 }
4010 return iccId;
4011 }
4012
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004013 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004014 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4015 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004016 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4017 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 final String iccId = getIccId(subId);
4022 final Phone phone = getPhone(subId);
4023 if (phone == null) {
4024 return false;
4025 }
4026 final String subscriberId = phone.getSubscriberId();
4027
4028 if (DBG_MERGE) {
4029 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4030 + subscriberId + " to " + number);
4031 }
4032
4033 if (TextUtils.isEmpty(iccId)) {
4034 return false;
4035 }
4036
4037 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4038
4039 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4040 if (alphaTag == null) {
4041 editor.remove(alphaTagPrefKey);
4042 } else {
4043 editor.putString(alphaTagPrefKey, alphaTag);
4044 }
4045
4046 // Record both the line number and IMSI for this ICCID, since we need to
4047 // track all merged IMSIs based on line number
4048 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4049 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4050 if (number == null) {
4051 editor.remove(numberPrefKey);
4052 editor.remove(subscriberPrefKey);
4053 } else {
4054 editor.putString(numberPrefKey, number);
4055 editor.putString(subscriberPrefKey, subscriberId);
4056 }
4057
4058 editor.commit();
4059 return true;
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004062 }
Derek Tan7226c842014-07-02 17:42:23 -07004063 }
4064
4065 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004066 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004067 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004069 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004070 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004071 return null;
4072 }
Derek Tan97ebb422014-09-05 16:55:38 -07004073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 String iccId = getIccId(subId);
4077 if (iccId != null) {
4078 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4079 if (DBG_MERGE) {
4080 log("getLine1NumberForDisplay returning "
4081 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4082 }
4083 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4086 return null;
4087 } finally {
4088 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004089 }
Derek Tan7226c842014-07-02 17:42:23 -07004090 }
4091
4092 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004093 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004095 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004096 return null;
4097 }
Derek Tan97ebb422014-09-05 16:55:38 -07004098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 String iccId = getIccId(subId);
4102 if (iccId != null) {
4103 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4104 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4105 }
4106 return null;
4107 } finally {
4108 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004109 }
Derek Tan7226c842014-07-02 17:42:23 -07004110 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004111
4112 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004113 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004114 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4115 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004117 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4118 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004119 return null;
4120 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004121
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004122 final long identity = Binder.clearCallingIdentity();
4123 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 final Context context = mPhone.getContext();
4125 final TelephonyManager tele = TelephonyManager.from(context);
4126 final SubscriptionManager sub = SubscriptionManager.from(context);
4127
4128 // Figure out what subscribers are currently active
4129 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4130 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4131 // the process, where TelephonyManager was instantiated.
4132 // Otherwise AppOps check will fail.
4133
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004134 final int[] subIds = sub.getActiveSubscriptionIdList();
4135 for (int subId : subIds) {
4136 activeSubscriberIds.add(tele.getSubscriberId(subId));
4137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138
4139 // First pass, find a number override for an active subscriber
4140 String mergeNumber = null;
4141 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4142 for (String key : prefs.keySet()) {
4143 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4144 final String subscriberId = (String) prefs.get(key);
4145 if (activeSubscriberIds.contains(subscriberId)) {
4146 final String iccId = key.substring(
4147 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4148 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4149 mergeNumber = (String) prefs.get(numberKey);
4150 if (DBG_MERGE) {
4151 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4152 + " for active subscriber " + subscriberId);
4153 }
4154 if (!TextUtils.isEmpty(mergeNumber)) {
4155 break;
4156 }
4157 }
4158 }
4159 }
4160
4161 // Shortcut when no active merged subscribers
4162 if (TextUtils.isEmpty(mergeNumber)) {
4163 return null;
4164 }
4165
4166 // Second pass, find all subscribers under that line override
4167 final ArraySet<String> result = new ArraySet<>();
4168 for (String key : prefs.keySet()) {
4169 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4170 final String number = (String) prefs.get(key);
4171 if (mergeNumber.equals(number)) {
4172 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4173 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4174 final String subscriberId = (String) prefs.get(subscriberKey);
4175 if (!TextUtils.isEmpty(subscriberId)) {
4176 result.add(subscriberId);
4177 }
4178 }
4179 }
4180 }
4181
4182 final String[] resultArray = result.toArray(new String[result.size()]);
4183 Arrays.sort(resultArray);
4184 if (DBG_MERGE) {
4185 Slog.d(LOG_TAG,
4186 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4187 }
4188 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004189 } finally {
4190 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004191 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004192 }
4193
4194 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004195 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004196 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4197 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198
4199 final long identity = Binder.clearCallingIdentity();
4200 try {
4201 final Phone phone = getPhone(subId);
4202 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4203 } finally {
4204 Binder.restoreCallingIdentity(identity);
4205 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004206 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004207
4208 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004209 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004210 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4211 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004212 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213
4214 final long identity = Binder.clearCallingIdentity();
4215 try {
4216 final Phone phone = getPhone(subId);
4217 if (phone == null) {
4218 return false;
4219 }
4220 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4221 cdmaNonRoamingList);
4222 } finally {
4223 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004224 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004225 }
4226
4227 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004228 @Deprecated
4229 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4230 enforceModifyPermission();
4231
4232 int returnValue = 0;
4233 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004234 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004235 if(result.exception == null) {
4236 if (result.result != null) {
4237 byte[] responseData = (byte[])(result.result);
4238 if(responseData.length > oemResp.length) {
4239 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4240 responseData.length + "bytes. Buffer Size is " +
4241 oemResp.length + "bytes.");
4242 }
4243 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4244 returnValue = responseData.length;
4245 }
4246 } else {
4247 CommandException ex = (CommandException) result.exception;
4248 returnValue = ex.getCommandError().ordinal();
4249 if(returnValue > 0) returnValue *= -1;
4250 }
4251 } catch (RuntimeException e) {
4252 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4253 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4254 if(returnValue > 0) returnValue *= -1;
4255 }
4256
4257 return returnValue;
4258 }
4259
4260 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004261 public void setRadioCapability(RadioAccessFamily[] rafs) {
4262 try {
4263 ProxyController.getInstance().setRadioCapability(rafs);
4264 } catch (RuntimeException e) {
4265 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4266 }
4267 }
4268
4269 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004270 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004271 Phone phone = PhoneFactory.getPhone(phoneId);
4272 if (phone == null) {
4273 return RadioAccessFamily.RAF_UNKNOWN;
4274 }
4275 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004277 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004278 return RadioAccessFamily.RAF_UNKNOWN;
4279 }
4280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004287 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004288
4289 @Override
4290 public void enableVideoCalling(boolean enable) {
4291 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292
4293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004299 }
4300
4301 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004302 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4304 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4305 return false;
4306 }
Svet Ganovb320e182015-04-16 12:30:10 -07004307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 // Check the user preference and the system-level IMS setting. Even if the user has
4311 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4312 // In the long run, we may instead need to check if there exists a connection service
4313 // which can support video calling.
4314 ImsManager imsManager =
4315 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4316 return imsManager.isVtEnabledByPlatform()
4317 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4318 && imsManager.isVtEnabledByUser();
4319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004322 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004323
Andrew Leea1239f22015-03-02 17:44:07 -08004324 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4327 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4328 return false;
4329 }
4330
4331 final long identity = Binder.clearCallingIdentity();
4332 try {
4333 CarrierConfigManager configManager =
4334 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4335 return configManager.getConfigForSubId(mPhone.getSubId())
4336 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4337 } finally {
4338 Binder.restoreCallingIdentity(identity);
4339 }
Andrew Leea1239f22015-03-02 17:44:07 -08004340 }
4341
4342 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 public boolean isWorldPhone(int subId, String callingPackage) {
4344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4345 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4346 return false;
4347 }
4348
4349 final long identity = Binder.clearCallingIdentity();
4350 try {
4351 CarrierConfigManager configManager =
4352 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4353 return configManager.getConfigForSubId(mPhone.getSubId())
4354 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
Andrew Leea1239f22015-03-02 17:44:07 -08004358 }
4359
Andrew Lee9431b832015-03-09 18:46:45 -07004360 @Override
4361 public boolean isTtyModeSupported() {
4362 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004363 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004364 }
4365
4366 @Override
4367 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 final long identity = Binder.clearCallingIdentity();
4369 try {
4370 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
Andrew Lee9431b832015-03-09 18:46:45 -07004374 }
4375
Hall Liu98187582018-01-22 19:15:32 -08004376 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4380 mPhone.getSubId()).getBoolean(
4381 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4382 boolean isDeviceSupported =
4383 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4384 return isCarrierSupported && isDeviceSupported;
4385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
Hall Liu98187582018-01-22 19:15:32 -08004388 }
4389
Hall Liu3ad5f012018-04-06 16:23:39 -07004390 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004391 final long identity = Binder.clearCallingIdentity();
4392 try {
4393 return isRttSupported() && Settings.Secure.getInt(
4394 mPhone.getContext().getContentResolver(),
4395 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004399 }
4400
Sanket Padawe7310cc72015-01-14 09:53:20 -08004401 /**
4402 * Returns the unique device ID of phone, for example, the IMEI for
4403 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4404 *
4405 * <p>Requires Permission:
4406 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4407 */
4408 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004409 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004410 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004411 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004412 return null;
4413 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004414 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004415 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4416 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004417 return null;
4418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419
4420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 return phone.getDeviceId();
4423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004426 }
4427
Ping Sunc67b7c22016-03-02 19:16:45 +08004428 /**
4429 * {@hide}
4430 * Returns the IMS Registration Status on a particular subid
4431 *
4432 * @param subId
4433 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004434 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004435 Phone phone = getPhone(subId);
4436 if (phone != null) {
4437 return phone.isImsRegistered();
4438 } else {
4439 return false;
4440 }
4441 }
4442
Santos Cordon7a1885b2015-02-03 11:15:19 -08004443 @Override
4444 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 final long identity = Binder.clearCallingIdentity();
4446 try {
4447 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004451 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004452
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004453 /**
4454 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004455 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004456 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 final long identity = Binder.clearCallingIdentity();
4458 try {
4459 Phone phone = getPhone(subId);
4460 if (phone != null) {
4461 return phone.isWifiCallingEnabled();
4462 } else {
4463 return false;
4464 }
4465 } finally {
4466 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004467 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004468 }
4469
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004470 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004471 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004472 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004473 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 final long identity = Binder.clearCallingIdentity();
4475 try {
4476 Phone phone = getPhone(subId);
4477 if (phone != null) {
4478 return phone.isVideoEnabled();
4479 } else {
4480 return false;
4481 }
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004484 }
4485 }
4486
4487 /**
4488 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4489 * defined in {@link ImsRegistrationImplBase}.
4490 */
4491 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 final long identity = Binder.clearCallingIdentity();
4493 try {
4494 Phone phone = getPhone(subId);
4495 if (phone != null) {
4496 return phone.getImsRegistrationTech();
4497 } else {
4498 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4499 }
4500 } finally {
4501 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004502 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004503 }
4504
Stuart Scott8eef64f2015-04-08 15:13:54 -07004505 @Override
4506 public void factoryReset(int subId) {
4507 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004508 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4509 return;
4510 }
4511
Svet Ganovcc087f82015-05-12 20:35:54 -07004512 final long identity = Binder.clearCallingIdentity();
4513 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004514 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4515 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004516 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004517 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004518 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4519 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004520 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004521 }
4522 } finally {
4523 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004524 }
4525 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004526
4527 @Override
4528 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 final long identity = Binder.clearCallingIdentity();
4530 try {
4531 // We query all subscriptions instead of just the active ones, because
4532 // this might be called early on in the provisioning flow when the
4533 // subscriptions potentially aren't active yet.
4534 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4535 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004536 return null;
4537 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004538
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539 // This function may be called very early, say, from the setup wizard, at
4540 // which point we won't have a default subscription set. If that's the case
4541 // we just choose the first, which will be valid in "most cases".
4542 final int defaultSubId = getDefaultSubscription();
4543 SubscriptionInfo info = null;
4544 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4545 info = slist.get(0);
4546 } else {
4547 for (SubscriptionInfo item : slist) {
4548 if (item.getSubscriptionId() == defaultSubId) {
4549 info = item;
4550 break;
4551 }
4552 }
4553
4554 if (info == null) {
4555 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004556 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004557 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 // Try and fetch the locale from the carrier properties or from the SIM language
4560 // preferences (EF-PL and EF-LI)...
4561 final int mcc = info.getMcc();
4562 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4563 String simLanguage = null;
4564 if (defaultPhone != null) {
4565 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4566 if (localeFromDefaultSim != null) {
4567 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4568 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4569 return localeFromDefaultSim.toLanguageTag();
4570 } else {
4571 simLanguage = localeFromDefaultSim.getLanguage();
4572 }
4573 }
4574 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 // The SIM language preferences only store a language (e.g. fr = French), not an
4577 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4578 // the SIM and carrier preferences does not include a country we add the country
4579 // determined from the SIM MCC to provide an exact locale.
4580 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4581 simLanguage);
4582 if (mccLocale != null) {
4583 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4584 return mccLocale.toLanguageTag();
4585 }
4586
4587 if (DBG) log("No locale found - returning null");
4588 return null;
4589 } finally {
4590 Binder.restoreCallingIdentity(identity);
4591 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004592 }
4593
4594 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 return mSubscriptionController.getAllSubInfoList(
4596 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004597 }
4598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599 /**
4600 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4601 */
4602 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4603 return mSubscriptionController.getActiveSubscriptionInfoList(
4604 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004605 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004606
Chenjie Yu1ba97252018-01-11 18:16:20 -08004607 private final ModemActivityInfo mLastModemActivityInfo =
4608 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4609
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004610 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004611 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4612 * representing the state of the modem.
4613 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004614 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4615 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004616 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004617 */
4618 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004619 public void requestModemActivityInfo(ResultReceiver result) {
4620 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004621 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622
4623 final long identity = Binder.clearCallingIdentity();
4624 try {
4625 ModemActivityInfo ret = null;
4626 synchronized (mLastModemActivityInfo) {
4627 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4628 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004629 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004630 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4632 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4633 mergedTxTimeMs[i] =
4634 info.getTxTimeMillis()[i]
4635 + mLastModemActivityInfo.getTxTimeMillis()[i];
4636 }
4637 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4638 mLastModemActivityInfo.setSleepTimeMillis(
4639 info.getSleepTimeMillis()
4640 + mLastModemActivityInfo.getSleepTimeMillis());
4641 mLastModemActivityInfo.setIdleTimeMillis(
4642 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4643 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4644 mLastModemActivityInfo.setRxTimeMillis(
4645 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4646 mLastModemActivityInfo.setEnergyUsed(
4647 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4650 mLastModemActivityInfo.getSleepTimeMillis(),
4651 mLastModemActivityInfo.getIdleTimeMillis(),
4652 mLastModemActivityInfo.getTxTimeMillis(),
4653 mLastModemActivityInfo.getRxTimeMillis(),
4654 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 Bundle bundle = new Bundle();
4657 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4658 result.send(0, bundle);
4659 } finally {
4660 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004661 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004662 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004663
Siddharth Rayb8114062018-06-17 15:02:38 -07004664 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4665 // less than total activity duration.
4666 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4667 if (info == null) {
4668 return false;
4669 }
4670 int activityDurationMs =
4671 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4672 int totalTxTimeMs = 0;
4673 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4674 totalTxTimeMs += info.getTxTimeMillis()[i];
4675 }
4676 return (info.isValid()
4677 && (info.getSleepTimeMillis() <= activityDurationMs)
4678 && (info.getIdleTimeMillis() <= activityDurationMs)
4679 && (info.getRxTimeMillis() <= activityDurationMs)
4680 && (totalTxTimeMs <= activityDurationMs));
4681 }
4682
Jack Yu85bd38a2015-11-09 11:34:32 -08004683 /**
4684 * {@hide}
4685 * Returns the service state information on specified subscription.
4686 */
4687 @Override
4688 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004690 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004691 return null;
4692 }
4693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004694 final long identity = Binder.clearCallingIdentity();
4695 try {
4696 final Phone phone = getPhone(subId);
4697 if (phone == null) {
4698 return null;
4699 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701 return phone.getServiceState();
4702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004705 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004706
4707 /**
4708 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4709 *
4710 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4711 * voicemail ringtone.
4712 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4713 * PhoneAccount.
4714 */
4715 @Override
4716 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 final long identity = Binder.clearCallingIdentity();
4718 try {
4719 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4720 if (phone == null) {
4721 phone = mPhone;
4722 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004728 }
4729
4730 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004731 * Sets the per-account voicemail ringtone.
4732 *
4733 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4734 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4735 *
4736 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4737 * voicemail ringtone.
4738 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4739 * PhoneAccount.
4740 */
4741 @Override
4742 public void setVoicemailRingtoneUri(String callingPackage,
4743 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4744 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4745 if (!TextUtils.equals(callingPackage,
4746 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4748 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4749 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004750 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004751
4752 final long identity = Binder.clearCallingIdentity();
4753 try {
4754 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4755 if (phone == null) {
4756 phone = mPhone;
4757 }
4758 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4759 } finally {
4760 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004761 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004762 }
4763
4764 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004765 * Returns whether vibration is set for voicemail notification in Phone settings.
4766 *
4767 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4768 * voicemail vibration setting.
4769 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4770 */
4771 @Override
4772 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773 final long identity = Binder.clearCallingIdentity();
4774 try {
4775 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4776 if (phone == null) {
4777 phone = mPhone;
4778 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004784 }
4785
Youhan Wange64578a2016-05-02 15:32:42 -07004786 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004787 * Sets the per-account voicemail vibration.
4788 *
4789 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4790 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4791 *
4792 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4793 * voicemail vibration setting.
4794 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4795 * specific PhoneAccount.
4796 */
4797 @Override
4798 public void setVoicemailVibrationEnabled(String callingPackage,
4799 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4800 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4801 if (!TextUtils.equals(callingPackage,
4802 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4804 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4805 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004806 }
4807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004808 final long identity = Binder.clearCallingIdentity();
4809 try {
4810 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4811 if (phone == null) {
4812 phone = mPhone;
4813 }
4814 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4815 } finally {
4816 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004817 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004818 }
4819
4820 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004821 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4822 *
4823 * @throws SecurityException if the caller does not have the required permission
4824 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004825 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004826 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004827 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004828 }
4829
4830 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004831 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4832 * permission.
4833 *
4834 * @throws SecurityException if the caller does not have the required permission
4835 */
4836 private void enforceSendSmsPermission() {
4837 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4838 }
4839
4840 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004841 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004842 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004843 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004844 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004845 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 ComponentName componentName =
4849 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4850 if (componentName == null) {
4851 throw new SecurityException(
4852 "Caller not current active visual voicemail package[null]");
4853 }
4854 String vvmPackage = componentName.getPackageName();
4855 if (!callingPackage.equals(vvmPackage)) {
4856 throw new SecurityException("Caller not current active visual voicemail package["
4857 + vvmPackage + "]");
4858 }
4859 } finally {
4860 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004861 }
4862 }
4863
4864 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004865 * Return the application ID for the app type.
4866 *
4867 * @param subId the subscription ID that this request applies to.
4868 * @param appType the uicc app type.
4869 * @return Application ID for specificied app type, or null if no uicc.
4870 */
4871 @Override
4872 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004873 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07004874 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875
4876 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004877 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878 if (phone == null) {
4879 return null;
4880 }
4881 String aid = null;
4882 try {
4883 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4884 .getApplicationByType(appType).getAid();
4885 } catch (Exception e) {
4886 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4887 }
4888 return aid;
4889 } finally {
4890 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004891 }
Youhan Wange64578a2016-05-02 15:32:42 -07004892 }
4893
Youhan Wang4001d252016-05-11 10:29:41 -07004894 /**
4895 * Return the Electronic Serial Number.
4896 *
4897 * @param subId the subscription ID that this request applies to.
4898 * @return ESN or null if error.
4899 */
4900 @Override
4901 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004902 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07004903 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904
4905 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004906 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 if (phone == null) {
4908 return null;
4909 }
4910 String esn = null;
4911 try {
4912 esn = phone.getEsn();
4913 } catch (Exception e) {
4914 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4915 }
4916 return esn;
4917 } finally {
4918 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004919 }
Youhan Wang4001d252016-05-11 10:29:41 -07004920 }
4921
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004922 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004923 * Return the Preferred Roaming List Version.
4924 *
4925 * @param subId the subscription ID that this request applies to.
4926 * @return PRLVersion or null if error.
4927 */
4928 @Override
4929 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004930 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07004931 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932
4933 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004934 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 if (phone == null) {
4936 return null;
4937 }
4938 String cdmaPrlVersion = null;
4939 try {
4940 cdmaPrlVersion = phone.getCdmaPrlVersion();
4941 } catch (Exception e) {
4942 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4943 }
4944 return cdmaPrlVersion;
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004947 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004948 }
4949
4950 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004951 * Get snapshot of Telephony histograms
4952 * @return List of Telephony histograms
4953 * @hide
4954 */
4955 @Override
4956 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4958 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959
4960 final long identity = Binder.clearCallingIdentity();
4961 try {
4962 return RIL.getTelephonyRILTimingHistograms();
4963 } finally {
4964 Binder.restoreCallingIdentity(identity);
4965 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004966 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004967
4968 /**
4969 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004970 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004971 * Require system privileges. In the future we may add this to carrier APIs.
4972 *
4973 * @return The number of carriers set successfully, should match length of carriers
4974 */
4975 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004976 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004977 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004978 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004979
Meng Wang9b7c4e92017-02-17 11:41:27 -08004980 if (carriers == null) {
4981 throw new NullPointerException("carriers cannot be null");
4982 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 final long identity = Binder.clearCallingIdentity();
4985 try {
4986 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004987 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4988 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 return retVal[0];
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004993 }
4994
4995 /**
4996 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004997 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004998 * Require system privileges. In the future we may add this to carrier APIs.
4999 *
5000 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5001 * means all carriers are allowed.
5002 */
5003 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005004 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005005 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005006 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007
5008 final long identity = Binder.clearCallingIdentity();
5009 try {
5010 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005011 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5012 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005016 }
5017
fionaxu59545b42016-05-25 15:53:37 -07005018 /**
5019 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5020 * @param subId the subscription ID that this action applies to.
5021 * @param enabled control enable or disable metered apns.
5022 * {@hide}
5023 */
5024 @Override
5025 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5026 enforceModifyPermission();
5027 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028
5029 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005030 if (phone == null) {
5031 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5032 return;
5033 }
5034 try {
5035 phone.carrierActionSetMeteredApnsEnabled(enabled);
5036 } catch (Exception e) {
5037 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 } finally {
5039 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005040 }
5041 }
5042
5043 /**
5044 * Action set from carrier signalling broadcast receivers to enable/disable radio
5045 * @param subId the subscription ID that this action applies to.
5046 * @param enabled control enable or disable radio.
5047 * {@hide}
5048 */
5049 @Override
5050 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5051 enforceModifyPermission();
5052 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053
5054 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005055 if (phone == null) {
5056 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5057 return;
5058 }
5059 try {
5060 phone.carrierActionSetRadioEnabled(enabled);
5061 } catch (Exception e) {
5062 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 } finally {
5064 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005065 }
5066 }
5067
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005068 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005069 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5070 * network status based on which carrier apps could apply actions accordingly,
5071 * enable/disable default url handler for example.
5072 *
5073 * @param subId the subscription ID that this action applies to.
5074 * @param report control start/stop reporting the default network status.
5075 * {@hide}
5076 */
5077 @Override
5078 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5079 enforceModifyPermission();
5080 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081
5082 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005083 if (phone == null) {
5084 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5085 return;
5086 }
5087 try {
5088 phone.carrierActionReportDefaultNetworkStatus(report);
5089 } catch (Exception e) {
5090 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 } finally {
5092 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005093 }
5094 }
5095
5096 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005097 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5098 * bug report is being generated.
5099 */
5100 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005101 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005102 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5103 != PackageManager.PERMISSION_GRANTED) {
5104 writer.println("Permission Denial: can't dump Phone from pid="
5105 + Binder.getCallingPid()
5106 + ", uid=" + Binder.getCallingUid()
5107 + "without permission "
5108 + android.Manifest.permission.DUMP);
5109 return;
5110 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005111 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005112 }
Jack Yueb89b242016-06-22 13:27:47 -07005113
Brad Ebingerdac2f002018-04-03 15:17:52 -07005114 @Override
5115 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5116 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5117 throws RemoteException {
5118 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5119 }
5120
Jack Yueb89b242016-06-22 13:27:47 -07005121 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005122 * Get aggregated video call data usage since boot.
5123 *
5124 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5125 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005126 * {@hide}
5127 */
5128 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005129 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005130 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5131 null);
5132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 // NetworkStatsService keeps tracking the active network interface and identity. It
5136 // records the delta with the corresponding network identity.
5137 // We just return the total video call data usage snapshot since boot.
5138 Phone phone = getPhone(subId);
5139 if (phone != null) {
5140 return phone.getVtDataUsage(perUidStats);
5141 }
5142 return null;
5143 } finally {
5144 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005145 }
Jack Yueb89b242016-06-22 13:27:47 -07005146 }
Jack Yu75ab2952016-07-08 14:29:33 -07005147
5148 /**
5149 * Policy control of data connection. Usually used when data limit is passed.
5150 * @param enabled True if enabling the data, otherwise disabling.
5151 * @param subId Subscription index
5152 * {@hide}
5153 */
5154 @Override
5155 public void setPolicyDataEnabled(boolean enabled, int subId) {
5156 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157
5158 final long identity = Binder.clearCallingIdentity();
5159 try {
5160 Phone phone = getPhone(subId);
5161 if (phone != null) {
5162 phone.setPolicyDataEnabled(enabled);
5163 }
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005166 }
5167 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005168
5169 /**
5170 * Get Client request stats
5171 * @return List of Client Request Stats
5172 * @hide
5173 */
5174 @Override
5175 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005177 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005178 return null;
5179 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005180 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 final long identity = Binder.clearCallingIdentity();
5183 try {
5184 if (phone != null) {
5185 return phone.getClientRequestStats();
5186 }
5187
5188 return null;
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005192 }
5193
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005194 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005195 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005196 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005197 }
Jack Yueb4124c2017-02-16 15:32:43 -08005198
5199 /**
Grace Chen70990072017-03-24 17:21:30 -07005200 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005201 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005202 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005203 * @param state State of SIM (power down, power up, pass through)
5204 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5205 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5206 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005207 *
5208 **/
5209 @Override
Grace Chen70990072017-03-24 17:21:30 -07005210 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005211 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005212 Phone phone = PhoneFactory.getPhone(slotIndex);
5213
vagdeviaf9a5b92018-08-15 16:01:53 -07005214 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 final long identity = Binder.clearCallingIdentity();
5217 try {
5218 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005219 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 }
5221 } finally {
5222 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005223 }
5224 }
Shuo Qiandd210312017-04-12 22:11:33 +00005225
Tyler Gunn65d45c22017-06-05 11:22:26 -07005226 private boolean isUssdApiAllowed(int subId) {
5227 CarrierConfigManager configManager =
5228 (CarrierConfigManager) mPhone.getContext().getSystemService(
5229 Context.CARRIER_CONFIG_SERVICE);
5230 if (configManager == null) {
5231 return false;
5232 }
5233 PersistableBundle pb = configManager.getConfigForSubId(subId);
5234 if (pb == null) {
5235 return false;
5236 }
5237 return pb.getBoolean(
5238 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5239 }
5240
Shuo Qiandd210312017-04-12 22:11:33 +00005241 /**
5242 * Check if phone is in emergency callback mode
5243 * @return true if phone is in emergency callback mode
5244 * @param subId sub id
5245 */
goneil9c5f4872017-12-05 14:07:56 -08005246 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005247 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005248 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005249 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250
5251 final long identity = Binder.clearCallingIdentity();
5252 try {
5253 if (phone != null) {
5254 return phone.isInEcm();
5255 } else {
5256 return false;
5257 }
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005260 }
5261 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005262
5263 /**
5264 * Get the current signal strength information for the given subscription.
5265 * Because this information is not updated when the device is in a low power state
5266 * it should not be relied-upon to be current.
5267 * @param subId Subscription index
5268 * @return the most recent cached signal strength info from the modem
5269 */
5270 @Override
5271 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272 final long identity = Binder.clearCallingIdentity();
5273 try {
5274 Phone p = getPhone(subId);
5275 if (p == null) {
5276 return null;
5277 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 return p.getSignalStrength();
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005283 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005284
Pengquan Meng77b7f132018-08-22 14:49:57 -07005285 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005286 * Get the current modem radio state for the given slot.
5287 * @param slotIndex slot index.
5288 * @param callingPackage the name of the package making the call.
5289 * @return the current radio power state from the modem
5290 */
5291 @Override
5292 public int getRadioPowerState(int slotIndex, String callingPackage) {
5293 Phone phone = PhoneFactory.getPhone(slotIndex);
5294 if (phone != null) {
5295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5296 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5297 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5298 }
5299
5300 final long identity = Binder.clearCallingIdentity();
5301 try {
5302 return phone.getRadioPowerState();
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
5306 }
5307 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5308 }
5309
5310 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005311 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5312 *
5313 * <p>Requires one of the following permissions:
5314 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5315 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5316 * privileges.
5317 *
5318 * @param subId subscription id
5319 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5320 * {@code false}.
5321 */
5322 @Override
5323 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005324 boolean isEnabled = false;
5325 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005326 try {
5327 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005328 null /* message */);
5329 Phone phone = getPhone(subId);
5330 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005331 } catch (Exception e) {
5332 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5333 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005334 } finally {
5335 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005336 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005337 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005338 }
5339
5340
5341 /**
5342 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5343 *
5344 * <p> Requires permission:
5345 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5346 * privileges.
5347 *
5348 * @param subId subscription id
5349 * @param isEnabled {@code true} means enable, {@code false} means disable.
5350 */
5351 @Override
5352 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005353 final long identity = Binder.clearCallingIdentity();
5354 try {
5355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5356 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005357
Pengquan Menga1bb6272018-09-06 09:59:22 -07005358 Phone phone = getPhone(subId);
5359 if (phone != null) {
5360 phone.setDataRoamingEnabled(isEnabled);
5361 }
5362 } finally {
5363 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005364 }
5365 }
5366
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005367 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005368 public boolean isManualNetworkSelectionAllowed(int subId) {
5369 boolean isAllowed = true;
5370 final long identity = Binder.clearCallingIdentity();
5371 try {
5372 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5373 mApp, subId, "isManualNetworkSelectionAllowed");
5374 Phone phone = getPhone(subId);
5375 if (phone != null) {
5376 isAllowed = phone.isCspPlmnEnabled();
5377 }
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
5380 }
5381 return isAllowed;
5382 }
5383
5384 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005385 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005386 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5391 if (slots == null) {
5392 Rlog.i(LOG_TAG, "slots is null.");
5393 return null;
5394 }
5395
5396 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5397 for (int i = 0; i < slots.length; i++) {
5398 UiccSlot slot = slots[i];
5399 if (slot == null) {
5400 continue;
5401 }
5402
5403 String cardId;
5404 UiccCard card = slot.getUiccCard();
5405 if (card != null) {
5406 cardId = card.getCardId();
5407 } else {
5408 cardId = slot.getIccId();
5409 }
5410
5411 int cardState = 0;
5412 switch (slot.getCardState()) {
5413 case CARDSTATE_ABSENT:
5414 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5415 break;
5416 case CARDSTATE_PRESENT:
5417 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5418 break;
5419 case CARDSTATE_ERROR:
5420 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5421 break;
5422 case CARDSTATE_RESTRICTED:
5423 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5424 break;
5425 default:
5426 break;
5427
5428 }
5429
5430 infos[i] = new UiccSlotInfo(
5431 slot.isActive(),
5432 slot.isEuicc(),
5433 cardId,
5434 cardState,
5435 slot.getPhoneId(),
5436 slot.isExtendedApduSupported());
5437 }
5438 return infos;
5439 } finally {
5440 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005441 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005442 }
5443
5444 @Override
5445 public boolean switchSlots(int[] physicalSlots) {
5446 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447
5448 final long identity = Binder.clearCallingIdentity();
5449 try {
5450 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
5453 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005454 }
Jack Yu4c988042018-02-27 15:30:01 -08005455
5456 @Override
5457 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5458 enforceModifyPermission();
5459 final Phone phone = getPhone(subId);
5460 if (phone == null) {
5461 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5462 return;
5463 }
5464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 phone.setRadioIndicationUpdateMode(filters, mode);
5468 } finally {
5469 Binder.restoreCallingIdentity(identity);
5470 }
Jack Yu4c988042018-02-27 15:30:01 -08005471 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005472
5473 /**
goneil47ffb6e2018-04-06 15:40:58 -07005474 * A test API to reload the UICC profile.
5475 *
5476 * <p>Requires that the calling app has permission
5477 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5478 * @hide
5479 */
5480 @Override
5481 public void refreshUiccProfile(int subId) {
5482 enforceModifyPermission();
5483
5484 final long identity = Binder.clearCallingIdentity();
5485 try {
5486 Phone phone = getPhone(subId);
5487 if (phone == null) {
5488 return;
5489 }
5490 UiccCard uiccCard = phone.getUiccCard();
5491 if (uiccCard == null) {
5492 return;
5493 }
5494 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5495 if (uiccProfile == null) {
5496 return;
5497 }
5498 uiccProfile.refresh();
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501 }
5502 }
5503
5504 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005505 * Returns false if the mobile data is disabled by default, otherwise return true.
5506 */
5507 private boolean getDefaultDataEnabled() {
5508 return "true".equalsIgnoreCase(
5509 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5510 }
5511
5512 /**
5513 * Returns true if the data roaming is enabled by default, i.e the system property
5514 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5515 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5516 */
5517 private boolean getDefaultDataRoamingEnabled(int subId) {
5518 final CarrierConfigManager configMgr = (CarrierConfigManager)
5519 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5520 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5521 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5522 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5523 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5524 return isDataRoamingEnabled;
5525 }
5526
5527 /**
5528 * Returns the default network type for the given {@code subId}, if the default network type is
5529 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5530 */
5531 private int getDefaultNetworkType(int subId) {
5532 return Integer.parseInt(
5533 TelephonyManager.getTelephonyProperty(
5534 mSubscriptionController.getPhoneId(subId),
5535 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5536 String.valueOf(Phone.PREFERRED_NT_MODE)));
5537 }
fionaxua13278b2018-03-21 00:08:13 -07005538
5539 @Override
5540 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5541 gid1, String gid2, String plmn, String spn) {
5542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543
5544 final long identity = Binder.clearCallingIdentity();
5545 try {
5546 final Phone phone = getPhone(subId);
5547 if (phone == null) {
5548 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5549 return;
5550 }
5551 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5552 } finally {
5553 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005554 }
fionaxua13278b2018-03-21 00:08:13 -07005555 }
5556
5557 @Override
5558 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005559 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 final Phone phone = getPhone(subId);
5564 if (phone == null) {
5565 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5566 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5567 }
5568 return phone.getCarrierIdListVersion();
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005571 }
fionaxua13278b2018-03-21 00:08:13 -07005572 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005573
5574 @Override
5575 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5577 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5578 return -1;
5579 }
5580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
5587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005588
5589 @Override
5590 public int getCdmaRoamingMode(int subId) {
5591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5592 mApp, subId, "getCdmaRoamingMode");
5593
5594 final long identity = Binder.clearCallingIdentity();
5595 try {
5596 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
5600 }
5601
5602 @Override
5603 public boolean setCdmaRoamingMode(int subId, int mode) {
5604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5605 mApp, subId, "setCdmaRoamingMode");
5606
5607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
5612 }
5613 }
5614
5615 @Override
5616 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5618 mApp, subId, "setCdmaSubscriptionMode");
5619
5620 final long identity = Binder.clearCallingIdentity();
5621 try {
5622 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
5626 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005627
5628 private void ensureUserRunning(int userId) {
5629 if (!mUserManager.isUserRunning(userId)) {
5630 throw new IllegalStateException("User " + userId + " does not exist or not running");
5631 }
5632 }
5633
5634 /**
5635 * Returns a list of SMS apps on a given user.
5636 *
5637 * Only the shell user (UID 2000 or 0) can call it.
5638 * Target user must be running.
5639 */
5640 @Override
5641 public String[] getSmsApps(int userId) {
5642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5643 ensureUserRunning(userId);
5644
5645 final Collection<SmsApplicationData> apps =
5646 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5647
5648 String[] ret = new String[apps.size()];
5649 int i = 0;
5650 for (SmsApplicationData app : apps) {
5651 ret[i++] = app.mPackageName;
5652 }
5653 return ret;
5654 }
5655
5656 /**
5657 * Returns the default SMS app package name on a given user.
5658 *
5659 * Only the shell user (UID 2000 or 0) can call it.
5660 * Target user must be running.
5661 */
5662 @Override
5663 public String getDefaultSmsApp(int userId) {
5664 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5665 ensureUserRunning(userId);
5666
5667 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5668 /* updateIfNeeded= */ true, userId);
5669 return cn == null ? null : cn.getPackageName();
5670 }
5671
5672 /**
5673 * Set a package as the default SMS app on a given user.
5674 *
5675 * Only the shell user (UID 2000 or 0) can call it.
5676 * Target user must be running.
5677 */
5678 @Override
5679 public void setDefaultSmsApp(int userId, String packageName) {
5680 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5681 ensureUserRunning(userId);
5682
5683 boolean found = false;
5684 for (String pkg : getSmsApps(userId)) {
5685 if (TextUtils.equals(packageName, pkg)) {
5686 found = true;
5687 break;
5688 }
5689 }
5690 if (!found) {
5691 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5692 }
5693
5694 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005696}