blob: 6090d891032c2d386fedb62a8575a435d24080d6 [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
calvinpanffe225e2018-11-01 19:43:06 +08002048 @Override
2049 public int getSubscriptionMNOCarrierId(int subId) {
2050 final long identity = Binder.clearCallingIdentity();
2051 try {
2052 final Phone phone = getPhone(subId);
2053 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getMNOCarrierId();
2054 } finally {
2055 Binder.restoreCallingIdentity(identity);
2056 }
2057 }
2058
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 //
2060 // Internal helper methods.
2061 //
2062
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002063 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2065 *
2066 * @throws SecurityException if the caller does not have the required permission
2067 */
2068 private void enforceModifyPermission() {
2069 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2070 }
2071
2072 /**
2073 * Make sure the caller has the CALL_PHONE permission.
2074 *
2075 * @throws SecurityException if the caller does not have the required permission
2076 */
2077 private void enforceCallPermission() {
2078 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2079 }
2080
Stuart Scott8eef64f2015-04-08 15:13:54 -07002081 private void enforceConnectivityInternalPermission() {
2082 mApp.enforceCallingOrSelfPermission(
2083 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2084 "ConnectivityService");
2085 }
2086
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 private String createTelUrl(String number) {
2088 if (TextUtils.isEmpty(number)) {
2089 return null;
2090 }
2091
Jake Hambye994d462014-02-03 13:10:13 -08002092 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 }
2094
Ihab Awadf9e92732013-12-05 18:02:52 -08002095 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2097 }
2098
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002099 private static void logv(String msg) {
2100 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2101 }
2102
Ihab Awadf9e92732013-12-05 18:02:52 -08002103 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2105 }
2106
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002107 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002109 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002110 }
2111
Sanket Padawe356d7632015-06-22 14:03:32 -07002112 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002113 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 final Phone phone = PhoneFactory.getPhone(slotIndex);
2117 if (phone == null) {
2118 return PhoneConstants.PHONE_TYPE_NONE;
2119 } else {
2120 return phone.getPhoneType();
2121 }
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 }
2126
2127 /**
2128 * Returns the CDMA ERI icon index to display
2129 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002130 @Override
2131 public int getCdmaEriIconIndex(String callingPackage) {
2132 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002133 }
2134
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002136 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002138 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002139 return -1;
2140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002141
2142 final long identity = Binder.clearCallingIdentity();
2143 try {
2144 final Phone phone = getPhone(subId);
2145 if (phone != null) {
2146 return phone.getCdmaEriIconIndex();
2147 } else {
2148 return -1;
2149 }
2150 } finally {
2151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 }
2154
2155 /**
2156 * Returns the CDMA ERI icon mode,
2157 * 0 - ON
2158 * 1 - FLASHING
2159 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002160 @Override
2161 public int getCdmaEriIconMode(String callingPackage) {
2162 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002163 }
2164
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002166 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002168 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 return -1;
2170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 final Phone phone = getPhone(subId);
2175 if (phone != null) {
2176 return phone.getCdmaEriIconMode();
2177 } else {
2178 return -1;
2179 }
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
2184
2185 /**
2186 * Returns the CDMA ERI text,
2187 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002188 @Override
2189 public String getCdmaEriText(String callingPackage) {
2190 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002191 }
2192
Sanket Padawe356d7632015-06-22 14:03:32 -07002193 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002194 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002196 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002197 return null;
2198 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002199
2200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 final Phone phone = getPhone(subId);
2203 if (phone != null) {
2204 return phone.getCdmaEriText();
2205 } else {
2206 return null;
2207 }
2208 } finally {
2209 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212
2213 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002214 * Returns the CDMA MDN.
2215 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002217 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2219 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002220
2221 final long identity = Binder.clearCallingIdentity();
2222 try {
2223 final Phone phone = getPhone(subId);
2224 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2225 return phone.getLine1Number();
2226 } else {
2227 return null;
2228 }
2229 } finally {
2230 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002231 }
2232 }
2233
2234 /**
2235 * Returns the CDMA MIN.
2236 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002237 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002238 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2240 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241
2242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 final Phone phone = getPhone(subId);
2245 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2246 return phone.getCdmaMin();
2247 } else {
2248 return null;
2249 }
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002252 }
2253 }
2254
2255 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 * Returns true if CDMA provisioning needs to run.
2257 */
2258 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 final long identity = Binder.clearCallingIdentity();
2260 try {
2261 return mPhone.needsOtaServiceProvisioning();
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 }
2266
2267 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002268 * Sets the voice mail number of a given subId.
2269 */
2270 @Override
2271 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002272 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002273
2274 final long identity = Binder.clearCallingIdentity();
2275 try {
2276 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2277 new Pair<String, String>(alphaTag, number), new Integer(subId));
2278 return success;
2279 } finally {
2280 Binder.restoreCallingIdentity(identity);
2281 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002282 }
2283
Ta-wei Yen87c49842016-05-13 21:19:52 -07002284 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002285 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2286 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2287 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2288 if (!TextUtils.equals(callingPackage, systemDialer)) {
2289 throw new SecurityException("caller must be system dialer");
2290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002291
2292 final long identity = Binder.clearCallingIdentity();
2293 try {
2294 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2295 if (phoneAccountHandle == null) {
2296 return null;
2297 }
2298 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002301 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002302 }
2303
2304 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002305 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002306 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002308 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002309 return null;
2310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002311
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002312 final long identity = Binder.clearCallingIdentity();
2313 try {
2314 return RemoteVvmTaskManager
2315 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2316 } finally {
2317 Binder.restoreCallingIdentity(identity);
2318 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002319 }
2320
2321 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002322 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2323 VisualVoicemailSmsFilterSettings settings) {
2324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325
2326 final long identity = Binder.clearCallingIdentity();
2327 try {
2328 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2329 mPhone.getContext(), callingPackage, subId, settings);
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002333 }
2334
2335 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002336 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338
2339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2342 mPhone.getContext(), callingPackage, subId);
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
2345 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002346 }
2347
2348 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002349 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2350 String callingPackage, int subId) {
2351 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002352
2353 final long identity = Binder.clearCallingIdentity();
2354 try {
2355 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2356 mPhone.getContext(), callingPackage, subId);
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
2359 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002360 }
2361
2362 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002363 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002364 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002365
2366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2369 mPhone.getContext(), subId);
2370 } finally {
2371 Binder.restoreCallingIdentity(identity);
2372 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002373 }
2374
2375 @Override
2376 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2377 String number, int port, String text, PendingIntent sentIntent) {
2378 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002379 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002380 enforceSendSmsPermission();
2381 // Make the calls as the phone process.
2382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2385 if (port == 0) {
2386 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2387 sentIntent, null, false);
2388 } else {
2389 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2390 smsManager.sendDataMessageWithSelfPermissions(number, null,
2391 (short) port, data, sentIntent, null);
2392 }
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
2395 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002396 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002397 /**
fionaxu0152e512016-11-14 13:36:14 -08002398 * Sets the voice activation state of a given subId.
2399 */
2400 @Override
2401 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2403 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002404
2405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 final Phone phone = getPhone(subId);
2408 if (phone != null) {
2409 phone.setVoiceActivationState(activationState);
2410 } else {
2411 loge("setVoiceActivationState fails with invalid subId: " + subId);
2412 }
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002415 }
2416 }
2417
2418 /**
2419 * Sets the data activation state of a given subId.
2420 */
2421 @Override
2422 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2424 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425
2426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 final Phone phone = getPhone(subId);
2429 if (phone != null) {
2430 phone.setDataActivationState(activationState);
2431 } else {
2432 loge("setVoiceActivationState fails with invalid subId: " + subId);
2433 }
2434 } finally {
2435 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002436 }
2437 }
2438
2439 /**
2440 * Returns the voice activation state of a given subId.
2441 */
2442 @Override
2443 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002444 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445
fionaxu0152e512016-11-14 13:36:14 -08002446 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447 final long identity = Binder.clearCallingIdentity();
2448 try {
2449 if (phone != null) {
2450 return phone.getVoiceActivationState();
2451 } else {
2452 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2453 }
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002456 }
2457 }
2458
2459 /**
2460 * Returns the data activation state of a given subId.
2461 */
2462 @Override
2463 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002464 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465
fionaxu0152e512016-11-14 13:36:14 -08002466 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467 final long identity = Binder.clearCallingIdentity();
2468 try {
2469 if (phone != null) {
2470 return phone.getDataActivationState();
2471 } else {
2472 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2473 }
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002476 }
2477 }
2478
2479 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 * Returns the unread count of voicemails
2481 */
2482 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002483 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002484 }
2485
2486 /**
2487 * Returns the unread count of voicemails for a subId
2488 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002489 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002490 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 final Phone phone = getPhone(subId);
2494 if (phone != null) {
2495 return phone.getVoiceMessageCount();
2496 } else {
2497 return 0;
2498 }
2499 } finally {
2500 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 }
2503
2504 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002505 * returns true, if the device is in a state where both voice and data
2506 * are supported simultaneously. This can change based on location or network condition.
2507 */
2508 @Override
2509 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 final long identity = Binder.clearCallingIdentity();
2511 try {
2512 final Phone phone = getPhone(subId);
2513 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
2516 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002517 }
2518
2519 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002520 * Send the dialer code if called from the current default dialer or the caller has
2521 * carrier privilege.
2522 * @param inputCode The dialer code to send
2523 */
2524 @Override
2525 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2526 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2527 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2528 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002529 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2530 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532
2533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 mPhone.sendDialerSpecialCode(inputCode);
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
2538 }
fionaxu235cc5e2017-03-06 22:25:57 -08002539 }
2540
2541 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002542 * Returns the data network type.
2543 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002544 *
2545 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2546 */
2547 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002548 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 final Phone phone = getPhone(getDefaultSubscription());
2552 if (phone != null) {
2553 return phone.getServiceState().getDataNetworkType();
2554 } else {
2555 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2556 }
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002559 }
Wink Saville36469e72014-06-11 15:17:00 -07002560 }
2561
Pengquan Menga1bb6272018-09-06 09:59:22 -07002562 @Override
2563 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002564 if (!isActiveSubscription(subId)) {
2565 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2566 }
2567
Pengquan Menga1bb6272018-09-06 09:59:22 -07002568 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2569 }
2570
Brad Ebinger35c841c2018-10-01 10:40:55 -07002571 @Override
2572 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2573 String callingPackage) throws RemoteException {
2574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2575 "addImsRegistrationCallback")) {
2576 return;
2577 }
2578 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2579 final long token = Binder.clearCallingIdentity();
2580 try {
2581 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2582 .addRegistrationCallbackForSubscription(c, subId);
2583 } finally {
2584 Binder.restoreCallingIdentity(token);
2585 }
2586 }
2587
2588 @Override
2589 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2590 String callingPackage) {
2591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2592 "removeImsRegistrationCallback")) {
2593 return;
2594 }
2595 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2596 Binder.withCleanCallingIdentity(() ->
2597 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2598 .removeRegistrationCallbackForSubscription(c, subId));
2599 }
2600
2601 @Override
2602 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2603 String callingPackage) throws RemoteException {
2604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2605 "addMmTelCapabilityCallback")) {
2606 return;
2607 }
2608 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2609 final long token = Binder.clearCallingIdentity();
2610 try {
2611 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2612 .addCapabilitiesCallbackForSubscription(c, subId);
2613 } finally {
2614 Binder.restoreCallingIdentity(token);
2615 }
2616 }
2617
2618 @Override
2619 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2620 String callingPackage) {
2621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2622 "removeMmTelCapabilityCallback")) {
2623 return;
2624 }
2625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2626 Binder.withCleanCallingIdentity(() ->
2627 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2628 .removeCapabilitiesCallbackForSubscription(c, subId));
2629 }
2630
2631 @Override
2632 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2634 "isCapable")) {
2635 return false;
2636 }
2637 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2638 final long token = Binder.clearCallingIdentity();
2639 try {
2640 return ImsManager.getInstance(mPhone.getContext(),
2641 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2642 } catch (ImsException e) {
2643 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2644 return false;
2645 } finally {
2646 Binder.restoreCallingIdentity(token);
2647 }
2648 }
2649
2650 @Override
2651 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2653 "isAvailable")) {
2654 return false;
2655 }
2656 final long token = Binder.clearCallingIdentity();
2657 try {
2658 Phone phone = getPhone(subId);
2659 if (phone == null) return false;
2660 return phone.isImsCapabilityAvailable(capability, regTech);
2661 } finally {
2662 Binder.restoreCallingIdentity(token);
2663 }
2664 }
2665
2666 @Override
2667 public boolean isAdvancedCallingSettingEnabled(int subId) {
2668 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2669 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2670 final long token = Binder.clearCallingIdentity();
2671 try {
2672 return ImsManager.getInstance(mPhone.getContext(),
2673 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2674 } finally {
2675 Binder.restoreCallingIdentity(token);
2676 }
2677 }
2678
2679 @Override
2680 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2682 "setAdvancedCallingSetting");
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2686 ImsManager.getInstance(mPhone.getContext(),
2687 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
2690 }
2691 }
2692
2693 @Override
2694 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2696 "isVtSettingEnabled")) {
2697 return false;
2698 }
2699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2702 return ImsManager.getInstance(mPhone.getContext(),
2703 getSlotIndexOrException(subId)).isVtEnabledByUser();
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
2706 }
2707 }
2708
2709 @Override
2710 public void setVtSetting(int subId, boolean isEnabled) {
2711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2712 "setVtSetting");
2713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2716 ImsManager.getInstance(mPhone.getContext(),
2717 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
2720 }
2721 }
2722
2723 @Override
2724 public boolean isVoWiFiSettingEnabled(int subId) {
2725 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2729 return ImsManager.getInstance(mPhone.getContext(),
2730 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2731 } finally {
2732 Binder.restoreCallingIdentity(identity);
2733 }
2734 }
2735
2736 @Override
2737 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2739 "setVoWiFiSetting");
2740 final long identity = Binder.clearCallingIdentity();
2741 try {
2742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2743 ImsManager.getInstance(mPhone.getContext(),
2744 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
2748 }
2749
2750 @Override
2751 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2752 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2753 final long identity = Binder.clearCallingIdentity();
2754 try {
2755 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2756 return ImsManager.getInstance(mPhone.getContext(),
2757 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2758 } finally {
2759 Binder.restoreCallingIdentity(identity);
2760 }
2761 }
2762
2763 @Override
2764 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2766 "setVoWiFiRoamingSetting");
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2770 ImsManager.getInstance(mPhone.getContext(),
2771 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
2774 }
2775 }
2776
2777 @Override
2778 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2780 "setVoWiFiNonPersistent");
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2784 ImsManager.getInstance(mPhone.getContext(),
2785 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
2789 }
2790
2791 @Override
2792 public int getVoWiFiModeSetting(int subId) {
2793 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2797 return ImsManager.getInstance(mPhone.getContext(),
2798 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
2802 }
2803
2804 @Override
2805 public void setVoWiFiModeSetting(int subId, int mode) {
2806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2807 "setVoWiFiModeSetting");
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2811 ImsManager.getInstance(mPhone.getContext(),
2812 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2813 } finally {
2814 Binder.restoreCallingIdentity(identity);
2815 }
2816 }
2817
2818 @Override
2819 public int getVoWiFiRoamingModeSetting(int subId) {
2820 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2824 return ImsManager.getInstance(mPhone.getContext(),
2825 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
2828 }
2829 }
2830
2831 @Override
2832 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2834 "setVoWiFiRoamingModeSetting");
2835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2838 ImsManager.getInstance(mPhone.getContext(),
2839 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2840 } finally {
2841 Binder.restoreCallingIdentity(identity);
2842 }
2843 }
2844
2845 @Override
2846 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2848 "setRttCapabilityEnabled");
2849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2852 ImsManager.getInstance(mPhone.getContext(),
2853 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
2856 }
2857 }
2858
2859 @Override
2860 public boolean isTtyOverVolteEnabled(int subId) {
2861 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2865 return ImsManager.getInstance(mPhone.getContext(),
2866 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
2869 }
2870 }
2871
2872 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2873 int slotId = SubscriptionManager.getSlotIndex(subId);
2874 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2875 throw new IllegalArgumentException("Invalid Subscription Id.");
2876 }
2877 return slotId;
2878 }
2879
Wink Saville36469e72014-06-11 15:17:00 -07002880 /**
2881 * Returns the network type for a subId
2882 */
2883 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002884 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002886 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002887 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2888 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 final Phone phone = getPhone(subId);
2893 if (phone != null) {
2894 return phone.getServiceState().getDataNetworkType();
2895 } else {
2896 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2897 }
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 }
2902
2903 /**
2904 * Returns the data network type
2905 */
2906 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002907 public int getDataNetworkType(String callingPackage) {
2908 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002909 }
2910
2911 /**
2912 * Returns the data network type for a subId
2913 */
2914 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002915 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002917 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002918 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2919 }
2920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 final Phone phone = getPhone(subId);
2924 if (phone != null) {
2925 return phone.getServiceState().getDataNetworkType();
2926 } else {
2927 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2928 }
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 }
2933
2934 /**
Wink Saville36469e72014-06-11 15:17:00 -07002935 * Returns the Voice network type for a subId
2936 */
2937 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002938 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002940 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002941 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2942 }
2943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002944 final long identity = Binder.clearCallingIdentity();
2945 try {
2946 final Phone phone = getPhone(subId);
2947 if (phone != null) {
2948 return phone.getServiceState().getVoiceNetworkType();
2949 } else {
2950 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2951 }
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 }
2956
2957 /**
2958 * @return true if a ICC card is present
2959 */
2960 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002961 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002962 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2963 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002964 }
2965
2966 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002967 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002968 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002969 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002970 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 final Phone phone = PhoneFactory.getPhone(slotIndex);
2974 if (phone != null) {
2975 return phone.getIccCard().hasIccCard();
2976 } else {
2977 return false;
2978 }
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002982 }
2983
2984 /**
2985 * Return if the current radio is LTE on CDMA. This
2986 * is a tri-state return value as for a period of time
2987 * the mode may be unknown.
2988 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002989 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002991 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002993 @Override
2994 public int getLteOnCdmaMode(String callingPackage) {
2995 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002996 }
2997
Sanket Padawe356d7632015-06-22 14:03:32 -07002998 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002999 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003001 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003002 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3003 }
3004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 final long identity = Binder.clearCallingIdentity();
3006 try {
3007 final Phone phone = getPhone(subId);
3008 if (phone == null) {
3009 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3010 } else {
3011 return phone.getLteOnCdmaMode();
3012 }
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 }
Wink Saville36469e72014-06-11 15:17:00 -07003016 }
3017
3018 public void setPhone(Phone phone) {
3019 mPhone = phone;
3020 }
3021
3022 /**
3023 * {@hide}
3024 * Returns Default subId, 0 in the case of single standby.
3025 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003026 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003027 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003028 }
3029
Shishir Agrawala9f32182016-04-12 12:00:16 -07003030 private int getSlotForDefaultSubscription() {
3031 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3032 }
3033
Wink Savilleb564aae2014-10-23 10:18:09 -07003034 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003035 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003036 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003037
Pengquan Menge92a50d2018-09-21 15:54:48 -07003038 private boolean isActiveSubscription(int subId) {
3039 return mSubscriptionController.isActiveSubId(subId);
3040 }
3041
Ihab Awadf2177b72013-11-25 13:33:23 -08003042 /**
3043 * @see android.telephony.TelephonyManager.WifiCallingChoices
3044 */
3045 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
3049 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3050 getWhenToMakeWifiCallsDefaultPreference());
3051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003054 }
3055
3056 /**
3057 * @see android.telephony.TelephonyManager.WifiCallingChoices
3058 */
3059 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
3063 Settings.System.putInt(mPhone.getContext().getContentResolver(),
3064 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003068 }
3069
Sailesh Nepald1e68152013-12-12 19:08:02 -08003070 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003071 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003072 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003073 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003074
Shishir Agrawal566b7612013-10-28 14:41:00 -07003075 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003076 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3077 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3079 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 if (TextUtils.equals(ISDR_AID, aid)) {
3085 // Only allows LPA to open logical channel to ISD-R.
3086 ComponentInfo bestComponent =
3087 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3088 if (bestComponent == null
3089 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3090 loge("The calling package is not allowed to access ISD-R.");
3091 throw new SecurityException(
3092 "The calling package is not allowed to access ISD-R.");
3093 }
Derek Tan740e1672017-06-27 14:56:27 -07003094 }
Derek Tan740e1672017-06-27 14:56:27 -07003095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096 if (DBG) {
3097 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3098 }
3099 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3100 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3101 if (DBG) log("iccOpenLogicalChannel: " + response);
3102 return response;
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003106 }
3107
3108 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003109 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3111 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3116 if (channel < 0) {
3117 return false;
3118 }
3119 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3120 if (DBG) log("iccCloseLogicalChannel: " + success);
3121 return success;
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003124 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003125 }
3126
3127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003128 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003129 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3131 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 if (DBG) {
3136 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3137 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3138 + p3 + " data=" + data);
3139 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141 if (channel < 0) {
3142 return "";
3143 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3146 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3147 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149 // Append the returned status code to the end of the response payload.
3150 String s = Integer.toHexString(
3151 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3152 if (response.payload != null) {
3153 s = IccUtils.bytesToHexString(response.payload) + s;
3154 }
3155 return s;
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003158 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003159 }
Jake Hambye994d462014-02-03 13:10:13 -08003160
Evan Charltonc66da362014-05-16 14:06:40 -07003161 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003162 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3163 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3165 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168 final long identity = Binder.clearCallingIdentity();
3169 try {
3170 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3171 && TextUtils.equals(ISDR_AID, data)) {
3172 // Only allows LPA to select ISD-R.
3173 ComponentInfo bestComponent =
3174 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3175 if (bestComponent == null
3176 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3177 loge("The calling package is not allowed to select ISD-R.");
3178 throw new SecurityException(
3179 "The calling package is not allowed to select ISD-R.");
3180 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003181 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003183 if (DBG) {
3184 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3185 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3186 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3189 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3190 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 // Append the returned status code to the end of the response payload.
3193 String s = Integer.toHexString(
3194 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3195 if (response.payload != null) {
3196 s = IccUtils.bytesToHexString(response.payload) + s;
3197 }
3198 return s;
3199 } finally {
3200 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003201 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003202 }
3203
3204 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003205 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003206 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3208 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 if (DBG) {
3213 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3214 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3215 }
3216
3217 IccIoResult response =
3218 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3219 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3220 subId);
3221
3222 if (DBG) {
3223 log("Exchange SIM_IO [R]" + response);
3224 }
3225
3226 byte[] result = null;
3227 int length = 2;
3228 if (response.payload != null) {
3229 length = 2 + response.payload.length;
3230 result = new byte[length];
3231 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3232 } else {
3233 result = new byte[length];
3234 }
3235
3236 result[length - 1] = (byte) response.sw2;
3237 result[length - 2] = (byte) response.sw1;
3238 return result;
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003241 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003242 }
3243
Nathan Haroldb3014052017-01-25 15:57:32 -08003244 /**
3245 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3246 * on a particular subscription
3247 */
sqianb6e41952018-03-12 14:54:01 -07003248 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3250 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3251 return null;
3252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253
3254 final long identity = Binder.clearCallingIdentity();
3255 try {
3256 if (appType != TelephonyManager.APPTYPE_USIM
3257 && appType != TelephonyManager.APPTYPE_SIM) {
3258 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3259 return null;
3260 }
3261 Object response = sendRequest(
3262 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3263 if (response instanceof String[]) {
3264 return (String[]) response;
3265 }
3266 // Response is an Exception of some kind,
3267 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003268 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 } finally {
3270 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003271 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003272 }
3273
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003274 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003275 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3277 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279 final long identity = Binder.clearCallingIdentity();
3280 try {
3281 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3282 if (response.payload == null) {
3283 return "";
3284 }
Evan Charltonc66da362014-05-16 14:06:40 -07003285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286 // Append the returned status code to the end of the response payload.
3287 String s = Integer.toHexString(
3288 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3289 s = IccUtils.bytesToHexString(response.payload) + s;
3290 return s;
3291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
Evan Charltonc66da362014-05-16 14:06:40 -07003294 }
3295
Jake Hambye994d462014-02-03 13:10:13 -08003296 /**
3297 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3298 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3299 *
3300 * @param itemID the ID of the item to read
3301 * @return the NV item as a String, or null on error.
3302 */
3303 @Override
3304 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003305 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3307 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308
3309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003312 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3314 return value;
3315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
Jake Hambye994d462014-02-03 13:10:13 -08003318 }
3319
3320 /**
3321 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3322 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3323 *
3324 * @param itemID the ID of the item to read
3325 * @param itemValue the value to write, as a String
3326 * @return true on success; false on any failure
3327 */
3328 @Override
3329 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003330 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3332 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333
3334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3337 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003338 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3340 return success;
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
Jake Hambye994d462014-02-03 13:10:13 -08003344 }
3345
3346 /**
3347 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3348 * Used for device configuration by some CDMA operators.
3349 *
3350 * @param preferredRoamingList byte array containing the new PRL
3351 * @return true on success; false on any failure
3352 */
3353 @Override
3354 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3356 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357
3358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3361 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3362 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3363 return success;
3364 } finally {
3365 Binder.restoreCallingIdentity(identity);
3366 }
Jake Hambye994d462014-02-03 13:10:13 -08003367 }
3368
3369 /**
3370 * Perform the specified type of NV config reset.
3371 * Used for device configuration by some CDMA operators.
3372 *
3373 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3374 * @return true on success; false on any failure
3375 */
3376 @Override
3377 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3379 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380
3381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 if (DBG) log("nvResetConfig: type " + resetType);
3384 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3385 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3386 return success;
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
3389 }
Jake Hambye994d462014-02-03 13:10:13 -08003390 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003391
Svet Ganovb320e182015-04-16 12:30:10 -07003392 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003394 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003395 return new String[0];
3396 }
3397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 return mPhone.getPcscfAddress(apnType);
3401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
Wink Saville36469e72014-06-11 15:17:00 -07003404 }
3405
Brad Ebinger51f743a2017-01-23 13:50:20 -08003406 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003407 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3408 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003409 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003410 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003411 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003412
3413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 PhoneFactory.getImsResolver().enableIms(slotId);
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003419 }
3420
3421 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003422 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3423 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003424 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003425 public void disableIms(int slotId) {
3426 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427
3428 final long identity = Binder.clearCallingIdentity();
3429 try {
3430 PhoneFactory.getImsResolver().disableIms(slotId);
3431 } finally {
3432 Binder.restoreCallingIdentity(identity);
3433 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003434 }
3435
3436 /**
3437 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3438 * feature or {@link null} if the service is not available. If the feature is available, the
3439 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3440 */
3441 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003442 IImsServiceFeatureCallback callback) {
3443 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003451 }
3452
3453 /**
3454 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3455 * feature during emergency calling or {@link null} if the service is not available. If the
3456 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3457 * listener for feature updates.
3458 */
3459 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3460 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461
3462 final long identity = Binder.clearCallingIdentity();
3463 try {
3464 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003468 }
3469
Brad Ebinger5f64b052017-12-14 14:26:15 -08003470 /**
3471 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3472 * specified.
3473 */
3474 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3475 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003476
3477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3480 } finally {
3481 Binder.restoreCallingIdentity(identity);
3482 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003483 }
3484
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003485 /**
3486 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3487 * specified.
3488 */
3489 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003498 }
3499
Brad Ebinger884c07b2018-02-15 16:17:40 -08003500 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003501 * Sets the ImsService Package Name that Telephony will bind to.
3502 *
3503 * @param slotId the slot ID that the ImsService should bind for.
3504 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3505 * ImsService is the device default ImsService.
3506 * @param packageName The package name of the application that contains the ImsService to bind
3507 * to.
3508 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3509 * @hide
3510 */
3511 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003512 int[] subIds = SubscriptionManager.getSubId(slotId);
3513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3514 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3515 "setImsService");
3516
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3520 isCarrierImsService, packageName);
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003524 }
3525
3526 /**
3527 * Return the ImsService configuration.
3528 *
3529 * @param slotId The slot that the ImsService is associated with.
3530 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3531 * the device default.
3532 * @return the package name of the ImsService configuration.
3533 */
3534 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003535 int[] subIds = SubscriptionManager.getSubId(slotId);
3536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3537 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3538 "getImsService");
3539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3543 isCarrierImsService);
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003547 }
3548
Wink Saville36469e72014-06-11 15:17:00 -07003549 public void setImsRegistrationState(boolean registered) {
3550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551
3552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 mPhone.setImsRegistrationState(registered);
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
Wink Saville36469e72014-06-11 15:17:00 -07003558 }
3559
3560 /**
Stuart Scott54788802015-03-30 13:18:01 -07003561 * Set the network selection mode to automatic.
3562 *
3563 */
3564 @Override
3565 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3567 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568
Pengquan Menge92a50d2018-09-21 15:54:48 -07003569 if (!isActiveSubscription(subId)) {
3570 return;
3571 }
3572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3576 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
Stuart Scott54788802015-03-30 13:18:01 -07003580 }
3581
Pengquan Mengea84e042018-09-20 14:57:26 -07003582 /**
3583 * Ask the radio to connect to the input network and change selection mode to manual.
3584 *
3585 * @param subId the id of the subscription.
3586 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3587 * the operator to attach to.
3588 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3589 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3590 * normal network selection next time.
3591 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003592 */
3593 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003594 public boolean setNetworkSelectionModeManual(
3595 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3597 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003598
3599 if (!isActiveSubscription(subId)) {
3600 return false;
3601 }
3602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603 final long identity = Binder.clearCallingIdentity();
3604 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003605 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003607 if (DBG) {
3608 log("setNetworkSelectionModeManual: subId: " + subId
3609 + " operator: " + operatorInfo);
3610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
3614 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003615 }
3616
3617 /**
3618 * Scans for available networks.
3619 */
3620 @Override
3621 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3623 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624
Pengquan Menga1bb6272018-09-06 09:59:22 -07003625 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626 try {
3627 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003628 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003633 }
3634
3635 /**
yinxub1bed742017-04-17 11:45:04 -07003636 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003637 *
yinxub1bed742017-04-17 11:45:04 -07003638 * @param subId id of the subscription
3639 * @param request contains the radio access networks with bands/channels to scan
3640 * @param messenger callback messenger for scan results or errors
3641 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003642 * @return the id of the requested scan which can be used to stop the scan.
3643 */
3644 @Override
3645 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3646 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3648 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 return mNetworkScanRequestTracker.startNetworkScan(
3653 request, messenger, binder, getPhone(subId));
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
yinxu504e1392017-04-12 16:03:22 -07003657 }
3658
3659 /**
3660 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003661 *
3662 * @param subId id of the subscription
3663 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003664 */
3665 @Override
3666 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3668 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
3675 }
yinxu504e1392017-04-12 16:03:22 -07003676 }
3677
3678 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003679 * Get the calculated preferred network type.
3680 * Used for debugging incorrect network type.
3681 *
3682 * @return the preferred network type, defined in RILConstants.java.
3683 */
3684 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003685 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003686 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003687 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003688 return RILConstants.PREFERRED_NETWORK_MODE;
3689 }
3690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 // FIXME: need to get SubId from somewhere.
3694 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
Junda Liu84d15a22014-07-02 11:21:04 -07003698 }
3699
3700 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003701 * Get the preferred network type.
3702 * Used for device configuration by some CDMA operators.
3703 *
3704 * @return the preferred network type, defined in RILConstants.java.
3705 */
3706 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003707 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3709 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710
3711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 if (DBG) log("getPreferredNetworkType");
3714 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3715 int networkType = (result != null ? result[0] : -1);
3716 if (DBG) log("getPreferredNetworkType: " + networkType);
3717 return networkType;
3718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003721 }
3722
3723 /**
3724 * Set the preferred network type.
3725 * Used for device configuration by some CDMA operators.
3726 *
3727 * @param networkType the preferred network type, defined in RILConstants.java.
3728 * @return true on success; false on any failure.
3729 */
3730 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003731 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3733 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3738 Boolean success = (Boolean) sendRequest(
3739 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3740 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3741 if (success) {
3742 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3743 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3744 }
3745 return success;
3746 } finally {
3747 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003748 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003749 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003750
3751 /**
Junda Liu475951f2014-11-07 16:45:03 -08003752 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3753 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3754 * tethering.
3755 *
3756 * @return 0: Not required. 1: required. 2: Not set.
3757 * @hide
3758 */
3759 @Override
3760 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762
3763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3766 Settings.Global.TETHER_DUN_REQUIRED, 2);
3767 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3768 // config_tether_apndata.
3769 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3770 dunRequired = 1;
3771 }
3772 return dunRequired;
3773 } finally {
3774 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003775 }
Junda Liu475951f2014-11-07 16:45:03 -08003776 }
3777
3778 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003779 * Set mobile data enabled
3780 * Used by the user through settings etc to turn on/off mobile data
3781 *
3782 * @param enable {@code true} turn turn data on, else {@code false}
3783 */
3784 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003785 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3787 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788
3789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 int phoneId = mSubscriptionController.getPhoneId(subId);
3792 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3793 Phone phone = PhoneFactory.getPhone(phoneId);
3794 if (phone != null) {
3795 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3796 phone.setUserDataEnabled(enable);
3797 } else {
3798 loge("setUserDataEnabled: no phone for subId=" + subId);
3799 }
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003802 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003803 }
3804
3805 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003806 * Get the user enabled state of Mobile Data.
3807 *
3808 * TODO: remove and use isUserDataEnabled.
3809 * This can't be removed now because some vendor codes
3810 * calls through ITelephony directly while they should
3811 * use TelephonyManager.
3812 *
3813 * @return true on enabled
3814 */
3815 @Override
3816 public boolean getDataEnabled(int subId) {
3817 return isUserDataEnabled(subId);
3818 }
3819
3820 /**
3821 * Get whether mobile data is enabled per user setting.
3822 *
3823 * There are other factors deciding whether mobile data is actually enabled, but they are
3824 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003825 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003826 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003827 *
3828 * @return {@code true} if data is enabled else {@code false}
3829 */
3830 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003831 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003832 try {
3833 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3834 null);
3835 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3837 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839
3840 final long identity = Binder.clearCallingIdentity();
3841 try {
3842 int phoneId = mSubscriptionController.getPhoneId(subId);
3843 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3844 Phone phone = PhoneFactory.getPhone(phoneId);
3845 if (phone != null) {
3846 boolean retVal = phone.isUserDataEnabled();
3847 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3848 return retVal;
3849 } else {
3850 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3851 return false;
3852 }
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003855 }
3856 }
3857
3858 /**
3859 * Get whether mobile data is enabled.
3860 *
3861 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3862 * whether mobile data is actually enabled.
3863 *
3864 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3865 *
3866 * @return {@code true} if data is enabled else {@code false}
3867 */
3868 @Override
3869 public boolean isDataEnabled(int subId) {
3870 try {
3871 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3872 null);
3873 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3875 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003877
3878 final long identity = Binder.clearCallingIdentity();
3879 try {
3880 int phoneId = mSubscriptionController.getPhoneId(subId);
3881 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3882 Phone phone = PhoneFactory.getPhone(phoneId);
3883 if (phone != null) {
3884 boolean retVal = phone.isDataEnabled();
3885 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3886 return retVal;
3887 } else {
3888 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3889 return false;
3890 }
3891 } finally {
3892 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003893 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003894 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003895
3896 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003897 public int getCarrierPrivilegeStatus(int subId) {
3898 final Phone phone = getPhone(subId);
3899 if (phone == null) {
3900 loge("getCarrierPrivilegeStatus: Invalid subId");
3901 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3902 }
3903 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003904 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003905 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003906 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3907 }
3908 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003909 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003910 }
Junda Liu29340342014-07-10 15:23:27 -07003911
3912 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003913 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3914 final Phone phone = getPhone(subId);
3915 if (phone == null) {
3916 loge("getCarrierPrivilegeStatus: Invalid subId");
3917 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3918 }
3919 UiccProfile profile =
3920 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3921 if (profile == null) {
3922 loge("getCarrierPrivilegeStatus: No UICC");
3923 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3924 }
3925 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3926 }
3927
3928 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003929 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003930 if (TextUtils.isEmpty(pkgName))
3931 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003932 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003933 if (card == null) {
3934 loge("checkCarrierPrivilegesForPackage: No UICC");
3935 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3936 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003937 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3938 }
3939
3940 @Override
3941 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003942 if (TextUtils.isEmpty(pkgName))
3943 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003944 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3945 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3946 UiccCard card = UiccController.getInstance().getUiccCard(i);
3947 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003948 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003949 continue;
3950 }
3951
3952 result = card.getCarrierPrivilegeStatus(
3953 mPhone.getContext().getPackageManager(), pkgName);
3954 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3955 break;
3956 }
3957 }
3958
3959 return result;
Junda Liu29340342014-07-10 15:23:27 -07003960 }
Derek Tan89e89d42014-07-08 17:00:10 -07003961
3962 @Override
Junda Liue64de782015-04-16 17:19:16 -07003963 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3964 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3965 loge("phoneId " + phoneId + " is not valid.");
3966 return null;
3967 }
3968 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003969 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003970 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003971 return null ;
3972 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003973 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003974 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003975 }
3976
Amith Yamasani6e118872016-02-19 12:53:51 -08003977 @Override
3978 public List<String> getPackagesWithCarrierPrivileges() {
3979 PackageManager pm = mPhone.getContext().getPackageManager();
3980 List<String> privilegedPackages = new ArrayList<>();
3981 List<PackageInfo> packages = null;
3982 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3983 UiccCard card = UiccController.getInstance().getUiccCard(i);
3984 if (card == null) {
3985 // No UICC in that slot.
3986 continue;
3987 }
3988 if (card.hasCarrierPrivilegeRules()) {
3989 if (packages == null) {
3990 // Only check packages in user 0 for now
3991 packages = pm.getInstalledPackagesAsUser(
3992 PackageManager.MATCH_DISABLED_COMPONENTS
3993 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3994 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3995 }
3996 for (int p = packages.size() - 1; p >= 0; p--) {
3997 PackageInfo pkgInfo = packages.get(p);
3998 if (pkgInfo != null && pkgInfo.packageName != null
3999 && card.getCarrierPrivilegeStatus(pkgInfo)
4000 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4001 privilegedPackages.add(pkgInfo.packageName);
4002 }
4003 }
4004 }
4005 }
4006 return privilegedPackages;
4007 }
4008
Wink Savilleb564aae2014-10-23 10:18:09 -07004009 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004010 final Phone phone = getPhone(subId);
4011 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004012 if (card == null) {
4013 loge("getIccId: No UICC");
4014 return null;
4015 }
4016 String iccId = card.getIccId();
4017 if (TextUtils.isEmpty(iccId)) {
4018 loge("getIccId: ICC ID is null or empty.");
4019 return null;
4020 }
4021 return iccId;
4022 }
4023
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004024 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004025 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4026 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004027 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4028 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 final String iccId = getIccId(subId);
4033 final Phone phone = getPhone(subId);
4034 if (phone == null) {
4035 return false;
4036 }
4037 final String subscriberId = phone.getSubscriberId();
4038
4039 if (DBG_MERGE) {
4040 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4041 + subscriberId + " to " + number);
4042 }
4043
4044 if (TextUtils.isEmpty(iccId)) {
4045 return false;
4046 }
4047
4048 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4049
4050 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4051 if (alphaTag == null) {
4052 editor.remove(alphaTagPrefKey);
4053 } else {
4054 editor.putString(alphaTagPrefKey, alphaTag);
4055 }
4056
4057 // Record both the line number and IMSI for this ICCID, since we need to
4058 // track all merged IMSIs based on line number
4059 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4060 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4061 if (number == null) {
4062 editor.remove(numberPrefKey);
4063 editor.remove(subscriberPrefKey);
4064 } else {
4065 editor.putString(numberPrefKey, number);
4066 editor.putString(subscriberPrefKey, subscriberId);
4067 }
4068
4069 editor.commit();
4070 return true;
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004073 }
Derek Tan7226c842014-07-02 17:42:23 -07004074 }
4075
4076 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004077 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004078 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004080 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004081 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004082 return null;
4083 }
Derek Tan97ebb422014-09-05 16:55:38 -07004084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 String iccId = getIccId(subId);
4088 if (iccId != null) {
4089 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4090 if (DBG_MERGE) {
4091 log("getLine1NumberForDisplay returning "
4092 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4093 }
4094 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4097 return null;
4098 } finally {
4099 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004100 }
Derek Tan7226c842014-07-02 17:42:23 -07004101 }
4102
4103 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004104 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004106 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004107 return null;
4108 }
Derek Tan97ebb422014-09-05 16:55:38 -07004109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 String iccId = getIccId(subId);
4113 if (iccId != null) {
4114 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4115 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4116 }
4117 return null;
4118 } finally {
4119 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004120 }
Derek Tan7226c842014-07-02 17:42:23 -07004121 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004122
4123 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004124 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004125 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4126 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004128 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4129 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004130 return null;
4131 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004132
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004133 final long identity = Binder.clearCallingIdentity();
4134 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 final Context context = mPhone.getContext();
4136 final TelephonyManager tele = TelephonyManager.from(context);
4137 final SubscriptionManager sub = SubscriptionManager.from(context);
4138
4139 // Figure out what subscribers are currently active
4140 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4141 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4142 // the process, where TelephonyManager was instantiated.
4143 // Otherwise AppOps check will fail.
4144
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004145 final int[] subIds = sub.getActiveSubscriptionIdList();
4146 for (int subId : subIds) {
4147 activeSubscriberIds.add(tele.getSubscriberId(subId));
4148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149
4150 // First pass, find a number override for an active subscriber
4151 String mergeNumber = null;
4152 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4153 for (String key : prefs.keySet()) {
4154 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4155 final String subscriberId = (String) prefs.get(key);
4156 if (activeSubscriberIds.contains(subscriberId)) {
4157 final String iccId = key.substring(
4158 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4159 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4160 mergeNumber = (String) prefs.get(numberKey);
4161 if (DBG_MERGE) {
4162 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4163 + " for active subscriber " + subscriberId);
4164 }
4165 if (!TextUtils.isEmpty(mergeNumber)) {
4166 break;
4167 }
4168 }
4169 }
4170 }
4171
4172 // Shortcut when no active merged subscribers
4173 if (TextUtils.isEmpty(mergeNumber)) {
4174 return null;
4175 }
4176
4177 // Second pass, find all subscribers under that line override
4178 final ArraySet<String> result = new ArraySet<>();
4179 for (String key : prefs.keySet()) {
4180 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4181 final String number = (String) prefs.get(key);
4182 if (mergeNumber.equals(number)) {
4183 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4184 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4185 final String subscriberId = (String) prefs.get(subscriberKey);
4186 if (!TextUtils.isEmpty(subscriberId)) {
4187 result.add(subscriberId);
4188 }
4189 }
4190 }
4191 }
4192
4193 final String[] resultArray = result.toArray(new String[result.size()]);
4194 Arrays.sort(resultArray);
4195 if (DBG_MERGE) {
4196 Slog.d(LOG_TAG,
4197 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4198 }
4199 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004200 } finally {
4201 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004202 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004203 }
4204
4205 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004206 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004207 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4208 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209
4210 final long identity = Binder.clearCallingIdentity();
4211 try {
4212 final Phone phone = getPhone(subId);
4213 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004217 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004218
4219 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004220 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004221 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4222 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004223 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004224
4225 final long identity = Binder.clearCallingIdentity();
4226 try {
4227 final Phone phone = getPhone(subId);
4228 if (phone == null) {
4229 return false;
4230 }
4231 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4232 cdmaNonRoamingList);
4233 } finally {
4234 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004235 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004236 }
4237
4238 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004239 @Deprecated
4240 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4241 enforceModifyPermission();
4242
4243 int returnValue = 0;
4244 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004245 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004246 if(result.exception == null) {
4247 if (result.result != null) {
4248 byte[] responseData = (byte[])(result.result);
4249 if(responseData.length > oemResp.length) {
4250 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4251 responseData.length + "bytes. Buffer Size is " +
4252 oemResp.length + "bytes.");
4253 }
4254 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4255 returnValue = responseData.length;
4256 }
4257 } else {
4258 CommandException ex = (CommandException) result.exception;
4259 returnValue = ex.getCommandError().ordinal();
4260 if(returnValue > 0) returnValue *= -1;
4261 }
4262 } catch (RuntimeException e) {
4263 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4264 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4265 if(returnValue > 0) returnValue *= -1;
4266 }
4267
4268 return returnValue;
4269 }
4270
4271 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004272 public void setRadioCapability(RadioAccessFamily[] rafs) {
4273 try {
4274 ProxyController.getInstance().setRadioCapability(rafs);
4275 } catch (RuntimeException e) {
4276 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4277 }
4278 }
4279
4280 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004281 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004282 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004283 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004284 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004285 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 final long identity = Binder.clearCallingIdentity();
4288 try {
chen xub97461a2018-10-26 14:17:57 -07004289 TelephonyPermissions
4290 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4291 mApp, phone.getSubId(), "getRadioAccessFamily");
4292 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
chen xub97461a2018-10-26 14:17:57 -07004296 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004297 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004298
4299 @Override
4300 public void enableVideoCalling(boolean enable) {
4301 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004302
4303 final long identity = Binder.clearCallingIdentity();
4304 try {
4305 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4306 } finally {
4307 Binder.restoreCallingIdentity(identity);
4308 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004309 }
4310
4311 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004312 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4314 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4315 return false;
4316 }
Svet Ganovb320e182015-04-16 12:30:10 -07004317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004318 final long identity = Binder.clearCallingIdentity();
4319 try {
4320 // Check the user preference and the system-level IMS setting. Even if the user has
4321 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4322 // In the long run, we may instead need to check if there exists a connection service
4323 // which can support video calling.
4324 ImsManager imsManager =
4325 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4326 return imsManager.isVtEnabledByPlatform()
4327 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4328 && imsManager.isVtEnabledByUser();
4329 } finally {
4330 Binder.restoreCallingIdentity(identity);
4331 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004332 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004333
Andrew Leea1239f22015-03-02 17:44:07 -08004334 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4337 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4338 return false;
4339 }
4340
4341 final long identity = Binder.clearCallingIdentity();
4342 try {
4343 CarrierConfigManager configManager =
4344 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4345 return configManager.getConfigForSubId(mPhone.getSubId())
4346 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4347 } finally {
4348 Binder.restoreCallingIdentity(identity);
4349 }
Andrew Leea1239f22015-03-02 17:44:07 -08004350 }
4351
4352 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 public boolean isWorldPhone(int subId, String callingPackage) {
4354 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4355 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4356 return false;
4357 }
4358
4359 final long identity = Binder.clearCallingIdentity();
4360 try {
4361 CarrierConfigManager configManager =
4362 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4363 return configManager.getConfigForSubId(mPhone.getSubId())
4364 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
Andrew Leea1239f22015-03-02 17:44:07 -08004368 }
4369
Andrew Lee9431b832015-03-09 18:46:45 -07004370 @Override
4371 public boolean isTtyModeSupported() {
4372 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004373 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004374 }
4375
4376 @Override
4377 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 final long identity = Binder.clearCallingIdentity();
4379 try {
4380 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
Andrew Lee9431b832015-03-09 18:46:45 -07004384 }
4385
Hall Liu98187582018-01-22 19:15:32 -08004386 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 final long identity = Binder.clearCallingIdentity();
4388 try {
4389 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4390 mPhone.getSubId()).getBoolean(
4391 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4392 boolean isDeviceSupported =
4393 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4394 return isCarrierSupported && isDeviceSupported;
4395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
Hall Liu98187582018-01-22 19:15:32 -08004398 }
4399
Hall Liu3ad5f012018-04-06 16:23:39 -07004400 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 return isRttSupported() && Settings.Secure.getInt(
4404 mPhone.getContext().getContentResolver(),
4405 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004409 }
4410
Sanket Padawe7310cc72015-01-14 09:53:20 -08004411 /**
4412 * Returns the unique device ID of phone, for example, the IMEI for
4413 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4414 *
4415 * <p>Requires Permission:
4416 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4417 */
4418 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004419 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004420 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004421 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004422 return null;
4423 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004424 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004425 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
4426 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004427 return null;
4428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429
4430 final long identity = Binder.clearCallingIdentity();
4431 try {
4432 return phone.getDeviceId();
4433 } finally {
4434 Binder.restoreCallingIdentity(identity);
4435 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004436 }
4437
Ping Sunc67b7c22016-03-02 19:16:45 +08004438 /**
4439 * {@hide}
4440 * Returns the IMS Registration Status on a particular subid
4441 *
4442 * @param subId
4443 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004444 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004445 Phone phone = getPhone(subId);
4446 if (phone != null) {
4447 return phone.isImsRegistered();
4448 } else {
4449 return false;
4450 }
4451 }
4452
Santos Cordon7a1885b2015-02-03 11:15:19 -08004453 @Override
4454 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 final long identity = Binder.clearCallingIdentity();
4456 try {
4457 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4458 } finally {
4459 Binder.restoreCallingIdentity(identity);
4460 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004461 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004462
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004463 /**
4464 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004465 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004466 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467 final long identity = Binder.clearCallingIdentity();
4468 try {
4469 Phone phone = getPhone(subId);
4470 if (phone != null) {
4471 return phone.isWifiCallingEnabled();
4472 } else {
4473 return false;
4474 }
4475 } finally {
4476 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004477 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004478 }
4479
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004480 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004481 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004482 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004483 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004484 final long identity = Binder.clearCallingIdentity();
4485 try {
4486 Phone phone = getPhone(subId);
4487 if (phone != null) {
4488 return phone.isVideoEnabled();
4489 } else {
4490 return false;
4491 }
4492 } finally {
4493 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004494 }
4495 }
4496
4497 /**
4498 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4499 * defined in {@link ImsRegistrationImplBase}.
4500 */
4501 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502 final long identity = Binder.clearCallingIdentity();
4503 try {
4504 Phone phone = getPhone(subId);
4505 if (phone != null) {
4506 return phone.getImsRegistrationTech();
4507 } else {
4508 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4509 }
4510 } finally {
4511 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004512 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004513 }
4514
Stuart Scott8eef64f2015-04-08 15:13:54 -07004515 @Override
4516 public void factoryReset(int subId) {
4517 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004518 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4519 return;
4520 }
4521
Svet Ganovcc087f82015-05-12 20:35:54 -07004522 final long identity = Binder.clearCallingIdentity();
4523 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004524 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4525 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004526 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004527 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004528 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4529 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004530 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004531 }
4532 } finally {
4533 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004534 }
4535 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004536
4537 @Override
4538 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539 final long identity = Binder.clearCallingIdentity();
4540 try {
4541 // We query all subscriptions instead of just the active ones, because
4542 // this might be called early on in the provisioning flow when the
4543 // subscriptions potentially aren't active yet.
4544 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4545 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004546 return null;
4547 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549 // This function may be called very early, say, from the setup wizard, at
4550 // which point we won't have a default subscription set. If that's the case
4551 // we just choose the first, which will be valid in "most cases".
4552 final int defaultSubId = getDefaultSubscription();
4553 SubscriptionInfo info = null;
4554 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4555 info = slist.get(0);
4556 } else {
4557 for (SubscriptionInfo item : slist) {
4558 if (item.getSubscriptionId() == defaultSubId) {
4559 info = item;
4560 break;
4561 }
4562 }
4563
4564 if (info == null) {
4565 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004566 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004567 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569 // Try and fetch the locale from the carrier properties or from the SIM language
4570 // preferences (EF-PL and EF-LI)...
4571 final int mcc = info.getMcc();
4572 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4573 String simLanguage = null;
4574 if (defaultPhone != null) {
4575 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4576 if (localeFromDefaultSim != null) {
4577 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4578 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4579 return localeFromDefaultSim.toLanguageTag();
4580 } else {
4581 simLanguage = localeFromDefaultSim.getLanguage();
4582 }
4583 }
4584 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586 // The SIM language preferences only store a language (e.g. fr = French), not an
4587 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4588 // the SIM and carrier preferences does not include a country we add the country
4589 // determined from the SIM MCC to provide an exact locale.
4590 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4591 simLanguage);
4592 if (mccLocale != null) {
4593 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4594 return mccLocale.toLanguageTag();
4595 }
4596
4597 if (DBG) log("No locale found - returning null");
4598 return null;
4599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004602 }
4603
4604 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605 return mSubscriptionController.getAllSubInfoList(
4606 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004607 }
4608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004609 /**
4610 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4611 */
4612 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4613 return mSubscriptionController.getActiveSubscriptionInfoList(
4614 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004615 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004616
Chenjie Yu1ba97252018-01-11 18:16:20 -08004617 private final ModemActivityInfo mLastModemActivityInfo =
4618 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4619
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004620 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004621 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4622 * representing the state of the modem.
4623 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004624 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4625 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004626 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004627 */
4628 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004629 public void requestModemActivityInfo(ResultReceiver result) {
4630 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004631 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632
4633 final long identity = Binder.clearCallingIdentity();
4634 try {
4635 ModemActivityInfo ret = null;
4636 synchronized (mLastModemActivityInfo) {
4637 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4638 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004639 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004640 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4642 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4643 mergedTxTimeMs[i] =
4644 info.getTxTimeMillis()[i]
4645 + mLastModemActivityInfo.getTxTimeMillis()[i];
4646 }
4647 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4648 mLastModemActivityInfo.setSleepTimeMillis(
4649 info.getSleepTimeMillis()
4650 + mLastModemActivityInfo.getSleepTimeMillis());
4651 mLastModemActivityInfo.setIdleTimeMillis(
4652 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4653 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4654 mLastModemActivityInfo.setRxTimeMillis(
4655 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4656 mLastModemActivityInfo.setEnergyUsed(
4657 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4660 mLastModemActivityInfo.getSleepTimeMillis(),
4661 mLastModemActivityInfo.getIdleTimeMillis(),
4662 mLastModemActivityInfo.getTxTimeMillis(),
4663 mLastModemActivityInfo.getRxTimeMillis(),
4664 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 Bundle bundle = new Bundle();
4667 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4668 result.send(0, bundle);
4669 } finally {
4670 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004671 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004672 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004673
Siddharth Rayb8114062018-06-17 15:02:38 -07004674 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4675 // less than total activity duration.
4676 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4677 if (info == null) {
4678 return false;
4679 }
4680 int activityDurationMs =
4681 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4682 int totalTxTimeMs = 0;
4683 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4684 totalTxTimeMs += info.getTxTimeMillis()[i];
4685 }
4686 return (info.isValid()
4687 && (info.getSleepTimeMillis() <= activityDurationMs)
4688 && (info.getIdleTimeMillis() <= activityDurationMs)
4689 && (info.getRxTimeMillis() <= activityDurationMs)
4690 && (totalTxTimeMs <= activityDurationMs));
4691 }
4692
Jack Yu85bd38a2015-11-09 11:34:32 -08004693 /**
4694 * {@hide}
4695 * Returns the service state information on specified subscription.
4696 */
4697 @Override
4698 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004700 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004701 return null;
4702 }
4703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704 final long identity = Binder.clearCallingIdentity();
4705 try {
4706 final Phone phone = getPhone(subId);
4707 if (phone == null) {
4708 return null;
4709 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 return phone.getServiceState();
4712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004715 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004716
4717 /**
4718 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4719 *
4720 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4721 * voicemail ringtone.
4722 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4723 * PhoneAccount.
4724 */
4725 @Override
4726 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4730 if (phone == null) {
4731 phone = mPhone;
4732 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004734 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004738 }
4739
4740 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004741 * Sets the per-account voicemail ringtone.
4742 *
4743 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4744 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4745 *
4746 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4747 * voicemail ringtone.
4748 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4749 * PhoneAccount.
4750 */
4751 @Override
4752 public void setVoicemailRingtoneUri(String callingPackage,
4753 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4755 if (!TextUtils.equals(callingPackage,
4756 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4758 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4759 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761
4762 final long identity = Binder.clearCallingIdentity();
4763 try {
4764 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4765 if (phone == null) {
4766 phone = mPhone;
4767 }
4768 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004771 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004772 }
4773
4774 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004775 * Returns whether vibration is set for voicemail notification in Phone settings.
4776 *
4777 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4778 * voicemail vibration setting.
4779 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4780 */
4781 @Override
4782 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 final long identity = Binder.clearCallingIdentity();
4784 try {
4785 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4786 if (phone == null) {
4787 phone = mPhone;
4788 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004789
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4791 } finally {
4792 Binder.restoreCallingIdentity(identity);
4793 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004794 }
4795
Youhan Wange64578a2016-05-02 15:32:42 -07004796 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004797 * Sets the per-account voicemail vibration.
4798 *
4799 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4800 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4801 *
4802 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4803 * voicemail vibration setting.
4804 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4805 * specific PhoneAccount.
4806 */
4807 @Override
4808 public void setVoicemailVibrationEnabled(String callingPackage,
4809 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4810 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4811 if (!TextUtils.equals(callingPackage,
4812 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4814 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4815 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004816 }
4817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 final long identity = Binder.clearCallingIdentity();
4819 try {
4820 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4821 if (phone == null) {
4822 phone = mPhone;
4823 }
4824 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4825 } finally {
4826 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004827 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004828 }
4829
4830 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004831 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4832 *
4833 * @throws SecurityException if the caller does not have the required permission
4834 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004835 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004836 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004837 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004838 }
4839
4840 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004841 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4842 * permission.
4843 *
4844 * @throws SecurityException if the caller does not have the required permission
4845 */
4846 private void enforceSendSmsPermission() {
4847 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4848 }
4849
4850 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004851 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004852 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004853 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004854 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004855 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856 final long identity = Binder.clearCallingIdentity();
4857 try {
4858 ComponentName componentName =
4859 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4860 if (componentName == null) {
4861 throw new SecurityException(
4862 "Caller not current active visual voicemail package[null]");
4863 }
4864 String vvmPackage = componentName.getPackageName();
4865 if (!callingPackage.equals(vvmPackage)) {
4866 throw new SecurityException("Caller not current active visual voicemail package["
4867 + vvmPackage + "]");
4868 }
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004871 }
4872 }
4873
4874 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004875 * Return the application ID for the app type.
4876 *
4877 * @param subId the subscription ID that this request applies to.
4878 * @param appType the uicc app type.
4879 * @return Application ID for specificied app type, or null if no uicc.
4880 */
4881 @Override
4882 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004883 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07004884 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004885
4886 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004887 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 if (phone == null) {
4889 return null;
4890 }
4891 String aid = null;
4892 try {
4893 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4894 .getApplicationByType(appType).getAid();
4895 } catch (Exception e) {
4896 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4897 }
4898 return aid;
4899 } finally {
4900 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004901 }
Youhan Wange64578a2016-05-02 15:32:42 -07004902 }
4903
Youhan Wang4001d252016-05-11 10:29:41 -07004904 /**
4905 * Return the Electronic Serial Number.
4906 *
4907 * @param subId the subscription ID that this request applies to.
4908 * @return ESN or null if error.
4909 */
4910 @Override
4911 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004912 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07004913 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914
4915 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004916 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917 if (phone == null) {
4918 return null;
4919 }
4920 String esn = null;
4921 try {
4922 esn = phone.getEsn();
4923 } catch (Exception e) {
4924 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4925 }
4926 return esn;
4927 } finally {
4928 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004929 }
Youhan Wang4001d252016-05-11 10:29:41 -07004930 }
4931
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004932 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004933 * Return the Preferred Roaming List Version.
4934 *
4935 * @param subId the subscription ID that this request applies to.
4936 * @return PRLVersion or null if error.
4937 */
4938 @Override
4939 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004940 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07004941 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942
4943 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004944 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 if (phone == null) {
4946 return null;
4947 }
4948 String cdmaPrlVersion = null;
4949 try {
4950 cdmaPrlVersion = phone.getCdmaPrlVersion();
4951 } catch (Exception e) {
4952 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4953 }
4954 return cdmaPrlVersion;
4955 } finally {
4956 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004957 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004958 }
4959
4960 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004961 * Get snapshot of Telephony histograms
4962 * @return List of Telephony histograms
4963 * @hide
4964 */
4965 @Override
4966 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4968 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969
4970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 return RIL.getTelephonyRILTimingHistograms();
4973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004976 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004977
4978 /**
4979 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004980 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004981 * Require system privileges. In the future we may add this to carrier APIs.
4982 *
4983 * @return The number of carriers set successfully, should match length of carriers
4984 */
4985 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004986 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004987 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004988 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004989
Meng Wang9b7c4e92017-02-17 11:41:27 -08004990 if (carriers == null) {
4991 throw new NullPointerException("carriers cannot be null");
4992 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 final long identity = Binder.clearCallingIdentity();
4995 try {
4996 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004997 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4998 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 return retVal[0];
5000 } finally {
5001 Binder.restoreCallingIdentity(identity);
5002 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005003 }
5004
5005 /**
5006 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005007 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005008 * Require system privileges. In the future we may add this to carrier APIs.
5009 *
5010 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
5011 * means all carriers are allowed.
5012 */
5013 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005014 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005015 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005016 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017
5018 final long identity = Binder.clearCallingIdentity();
5019 try {
5020 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07005021 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
5022 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 } finally {
5024 Binder.restoreCallingIdentity(identity);
5025 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005026 }
5027
fionaxu59545b42016-05-25 15:53:37 -07005028 /**
5029 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5030 * @param subId the subscription ID that this action applies to.
5031 * @param enabled control enable or disable metered apns.
5032 * {@hide}
5033 */
5034 @Override
5035 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5036 enforceModifyPermission();
5037 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038
5039 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005040 if (phone == null) {
5041 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5042 return;
5043 }
5044 try {
5045 phone.carrierActionSetMeteredApnsEnabled(enabled);
5046 } catch (Exception e) {
5047 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 } finally {
5049 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005050 }
5051 }
5052
5053 /**
5054 * Action set from carrier signalling broadcast receivers to enable/disable radio
5055 * @param subId the subscription ID that this action applies to.
5056 * @param enabled control enable or disable radio.
5057 * {@hide}
5058 */
5059 @Override
5060 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5061 enforceModifyPermission();
5062 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063
5064 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005065 if (phone == null) {
5066 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5067 return;
5068 }
5069 try {
5070 phone.carrierActionSetRadioEnabled(enabled);
5071 } catch (Exception e) {
5072 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 } finally {
5074 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005075 }
5076 }
5077
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005078 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005079 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5080 * network status based on which carrier apps could apply actions accordingly,
5081 * enable/disable default url handler for example.
5082 *
5083 * @param subId the subscription ID that this action applies to.
5084 * @param report control start/stop reporting the default network status.
5085 * {@hide}
5086 */
5087 @Override
5088 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5089 enforceModifyPermission();
5090 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091
5092 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005093 if (phone == null) {
5094 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5095 return;
5096 }
5097 try {
5098 phone.carrierActionReportDefaultNetworkStatus(report);
5099 } catch (Exception e) {
5100 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101 } finally {
5102 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005103 }
5104 }
5105
5106 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005107 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5108 * bug report is being generated.
5109 */
5110 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005111 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005112 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5113 != PackageManager.PERMISSION_GRANTED) {
5114 writer.println("Permission Denial: can't dump Phone from pid="
5115 + Binder.getCallingPid()
5116 + ", uid=" + Binder.getCallingUid()
5117 + "without permission "
5118 + android.Manifest.permission.DUMP);
5119 return;
5120 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005121 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005122 }
Jack Yueb89b242016-06-22 13:27:47 -07005123
Brad Ebingerdac2f002018-04-03 15:17:52 -07005124 @Override
5125 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5126 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5127 throws RemoteException {
5128 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5129 }
5130
Jack Yueb89b242016-06-22 13:27:47 -07005131 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005132 * Get aggregated video call data usage since boot.
5133 *
5134 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5135 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005136 * {@hide}
5137 */
5138 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005139 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005140 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5141 null);
5142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 // NetworkStatsService keeps tracking the active network interface and identity. It
5146 // records the delta with the corresponding network identity.
5147 // We just return the total video call data usage snapshot since boot.
5148 Phone phone = getPhone(subId);
5149 if (phone != null) {
5150 return phone.getVtDataUsage(perUidStats);
5151 }
5152 return null;
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005155 }
Jack Yueb89b242016-06-22 13:27:47 -07005156 }
Jack Yu75ab2952016-07-08 14:29:33 -07005157
5158 /**
5159 * Policy control of data connection. Usually used when data limit is passed.
5160 * @param enabled True if enabling the data, otherwise disabling.
5161 * @param subId Subscription index
5162 * {@hide}
5163 */
5164 @Override
5165 public void setPolicyDataEnabled(boolean enabled, int subId) {
5166 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167
5168 final long identity = Binder.clearCallingIdentity();
5169 try {
5170 Phone phone = getPhone(subId);
5171 if (phone != null) {
5172 phone.setPolicyDataEnabled(enabled);
5173 }
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005176 }
5177 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005178
5179 /**
5180 * Get Client request stats
5181 * @return List of Client Request Stats
5182 * @hide
5183 */
5184 @Override
5185 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005187 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005188 return null;
5189 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005190 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 final long identity = Binder.clearCallingIdentity();
5193 try {
5194 if (phone != null) {
5195 return phone.getClientRequestStats();
5196 }
5197
5198 return null;
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005202 }
5203
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005204 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005205 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005206 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005207 }
Jack Yueb4124c2017-02-16 15:32:43 -08005208
5209 /**
Grace Chen70990072017-03-24 17:21:30 -07005210 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005211 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005212 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005213 * @param state State of SIM (power down, power up, pass through)
5214 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5215 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5216 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005217 *
5218 **/
5219 @Override
Grace Chen70990072017-03-24 17:21:30 -07005220 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005221 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005222 Phone phone = PhoneFactory.getPhone(slotIndex);
5223
vagdeviaf9a5b92018-08-15 16:01:53 -07005224 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 final long identity = Binder.clearCallingIdentity();
5227 try {
5228 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005229 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 }
5231 } finally {
5232 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005233 }
5234 }
Shuo Qiandd210312017-04-12 22:11:33 +00005235
Tyler Gunn65d45c22017-06-05 11:22:26 -07005236 private boolean isUssdApiAllowed(int subId) {
5237 CarrierConfigManager configManager =
5238 (CarrierConfigManager) mPhone.getContext().getSystemService(
5239 Context.CARRIER_CONFIG_SERVICE);
5240 if (configManager == null) {
5241 return false;
5242 }
5243 PersistableBundle pb = configManager.getConfigForSubId(subId);
5244 if (pb == null) {
5245 return false;
5246 }
5247 return pb.getBoolean(
5248 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5249 }
5250
Shuo Qiandd210312017-04-12 22:11:33 +00005251 /**
5252 * Check if phone is in emergency callback mode
5253 * @return true if phone is in emergency callback mode
5254 * @param subId sub id
5255 */
goneil9c5f4872017-12-05 14:07:56 -08005256 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005257 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005258 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005259 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260
5261 final long identity = Binder.clearCallingIdentity();
5262 try {
5263 if (phone != null) {
5264 return phone.isInEcm();
5265 } else {
5266 return false;
5267 }
5268 } finally {
5269 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005270 }
5271 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005272
5273 /**
5274 * Get the current signal strength information for the given subscription.
5275 * Because this information is not updated when the device is in a low power state
5276 * it should not be relied-upon to be current.
5277 * @param subId Subscription index
5278 * @return the most recent cached signal strength info from the modem
5279 */
5280 @Override
5281 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 final long identity = Binder.clearCallingIdentity();
5283 try {
5284 Phone p = getPhone(subId);
5285 if (p == null) {
5286 return null;
5287 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 return p.getSignalStrength();
5290 } finally {
5291 Binder.restoreCallingIdentity(identity);
5292 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005293 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005294
Pengquan Meng77b7f132018-08-22 14:49:57 -07005295 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005296 * Get the current modem radio state for the given slot.
5297 * @param slotIndex slot index.
5298 * @param callingPackage the name of the package making the call.
5299 * @return the current radio power state from the modem
5300 */
5301 @Override
5302 public int getRadioPowerState(int slotIndex, String callingPackage) {
5303 Phone phone = PhoneFactory.getPhone(slotIndex);
5304 if (phone != null) {
5305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5306 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5307 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5308 }
5309
5310 final long identity = Binder.clearCallingIdentity();
5311 try {
5312 return phone.getRadioPowerState();
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
5316 }
5317 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5318 }
5319
5320 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07005321 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5322 *
5323 * <p>Requires one of the following permissions:
5324 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5325 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5326 * privileges.
5327 *
5328 * @param subId subscription id
5329 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5330 * {@code false}.
5331 */
5332 @Override
5333 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005334 boolean isEnabled = false;
5335 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005336 try {
5337 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005338 null /* message */);
5339 Phone phone = getPhone(subId);
5340 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005341 } catch (Exception e) {
5342 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5343 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005344 } finally {
5345 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005346 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005347 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005348 }
5349
5350
5351 /**
5352 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5353 *
5354 * <p> Requires permission:
5355 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5356 * privileges.
5357 *
5358 * @param subId subscription id
5359 * @param isEnabled {@code true} means enable, {@code false} means disable.
5360 */
5361 @Override
5362 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005363 final long identity = Binder.clearCallingIdentity();
5364 try {
5365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5366 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005367
Pengquan Menga1bb6272018-09-06 09:59:22 -07005368 Phone phone = getPhone(subId);
5369 if (phone != null) {
5370 phone.setDataRoamingEnabled(isEnabled);
5371 }
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005374 }
5375 }
5376
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005377 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005378 public boolean isManualNetworkSelectionAllowed(int subId) {
5379 boolean isAllowed = true;
5380 final long identity = Binder.clearCallingIdentity();
5381 try {
5382 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5383 mApp, subId, "isManualNetworkSelectionAllowed");
5384 Phone phone = getPhone(subId);
5385 if (phone != null) {
5386 isAllowed = phone.isCspPlmnEnabled();
5387 }
5388 } finally {
5389 Binder.restoreCallingIdentity(identity);
5390 }
5391 return isAllowed;
5392 }
5393
5394 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005395 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005396 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 final long identity = Binder.clearCallingIdentity();
5399 try {
5400 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5401 if (slots == null) {
5402 Rlog.i(LOG_TAG, "slots is null.");
5403 return null;
5404 }
5405
5406 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5407 for (int i = 0; i < slots.length; i++) {
5408 UiccSlot slot = slots[i];
5409 if (slot == null) {
5410 continue;
5411 }
5412
5413 String cardId;
5414 UiccCard card = slot.getUiccCard();
5415 if (card != null) {
5416 cardId = card.getCardId();
5417 } else {
5418 cardId = slot.getIccId();
5419 }
5420
5421 int cardState = 0;
5422 switch (slot.getCardState()) {
5423 case CARDSTATE_ABSENT:
5424 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5425 break;
5426 case CARDSTATE_PRESENT:
5427 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5428 break;
5429 case CARDSTATE_ERROR:
5430 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5431 break;
5432 case CARDSTATE_RESTRICTED:
5433 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5434 break;
5435 default:
5436 break;
5437
5438 }
5439
5440 infos[i] = new UiccSlotInfo(
5441 slot.isActive(),
5442 slot.isEuicc(),
5443 cardId,
5444 cardState,
5445 slot.getPhoneId(),
5446 slot.isExtendedApduSupported());
5447 }
5448 return infos;
5449 } finally {
5450 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005451 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005452 }
5453
5454 @Override
5455 public boolean switchSlots(int[] physicalSlots) {
5456 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457
5458 final long identity = Binder.clearCallingIdentity();
5459 try {
5460 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005464 }
Jack Yu4c988042018-02-27 15:30:01 -08005465
5466 @Override
5467 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5468 enforceModifyPermission();
5469 final Phone phone = getPhone(subId);
5470 if (phone == null) {
5471 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5472 return;
5473 }
5474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 final long identity = Binder.clearCallingIdentity();
5476 try {
5477 phone.setRadioIndicationUpdateMode(filters, mode);
5478 } finally {
5479 Binder.restoreCallingIdentity(identity);
5480 }
Jack Yu4c988042018-02-27 15:30:01 -08005481 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005482
5483 /**
goneil47ffb6e2018-04-06 15:40:58 -07005484 * A test API to reload the UICC profile.
5485 *
5486 * <p>Requires that the calling app has permission
5487 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5488 * @hide
5489 */
5490 @Override
5491 public void refreshUiccProfile(int subId) {
5492 enforceModifyPermission();
5493
5494 final long identity = Binder.clearCallingIdentity();
5495 try {
5496 Phone phone = getPhone(subId);
5497 if (phone == null) {
5498 return;
5499 }
5500 UiccCard uiccCard = phone.getUiccCard();
5501 if (uiccCard == null) {
5502 return;
5503 }
5504 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5505 if (uiccProfile == null) {
5506 return;
5507 }
5508 uiccProfile.refresh();
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
5512 }
5513
5514 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005515 * Returns false if the mobile data is disabled by default, otherwise return true.
5516 */
5517 private boolean getDefaultDataEnabled() {
5518 return "true".equalsIgnoreCase(
5519 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5520 }
5521
5522 /**
5523 * Returns true if the data roaming is enabled by default, i.e the system property
5524 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5525 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5526 */
5527 private boolean getDefaultDataRoamingEnabled(int subId) {
5528 final CarrierConfigManager configMgr = (CarrierConfigManager)
5529 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5530 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5531 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5532 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5533 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5534 return isDataRoamingEnabled;
5535 }
5536
5537 /**
5538 * Returns the default network type for the given {@code subId}, if the default network type is
5539 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5540 */
5541 private int getDefaultNetworkType(int subId) {
5542 return Integer.parseInt(
5543 TelephonyManager.getTelephonyProperty(
5544 mSubscriptionController.getPhoneId(subId),
5545 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5546 String.valueOf(Phone.PREFERRED_NT_MODE)));
5547 }
fionaxua13278b2018-03-21 00:08:13 -07005548
5549 @Override
5550 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5551 gid1, String gid2, String plmn, String spn) {
5552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553
5554 final long identity = Binder.clearCallingIdentity();
5555 try {
5556 final Phone phone = getPhone(subId);
5557 if (phone == null) {
5558 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5559 return;
5560 }
5561 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5562 } finally {
5563 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005564 }
fionaxua13278b2018-03-21 00:08:13 -07005565 }
5566
5567 @Override
5568 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005569 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570
5571 final long identity = Binder.clearCallingIdentity();
5572 try {
5573 final Phone phone = getPhone(subId);
5574 if (phone == null) {
5575 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5576 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5577 }
5578 return phone.getCarrierIdListVersion();
5579 } finally {
5580 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005581 }
fionaxua13278b2018-03-21 00:08:13 -07005582 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005583
5584 @Override
5585 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5587 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5588 return -1;
5589 }
5590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5594 } finally {
5595 Binder.restoreCallingIdentity(identity);
5596 }
5597 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005598
5599 @Override
5600 public int getCdmaRoamingMode(int subId) {
5601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, subId, "getCdmaRoamingMode");
5603
5604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5607 } finally {
5608 Binder.restoreCallingIdentity(identity);
5609 }
5610 }
5611
5612 @Override
5613 public boolean setCdmaRoamingMode(int subId, int mode) {
5614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5615 mApp, subId, "setCdmaRoamingMode");
5616
5617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
5623 }
5624
5625 @Override
5626 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5628 mApp, subId, "setCdmaSubscriptionMode");
5629
5630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5633 } finally {
5634 Binder.restoreCallingIdentity(identity);
5635 }
5636 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005637
5638 private void ensureUserRunning(int userId) {
5639 if (!mUserManager.isUserRunning(userId)) {
5640 throw new IllegalStateException("User " + userId + " does not exist or not running");
5641 }
5642 }
5643
5644 /**
5645 * Returns a list of SMS apps on a given user.
5646 *
5647 * Only the shell user (UID 2000 or 0) can call it.
5648 * Target user must be running.
5649 */
5650 @Override
5651 public String[] getSmsApps(int userId) {
5652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5653 ensureUserRunning(userId);
5654
5655 final Collection<SmsApplicationData> apps =
5656 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5657
5658 String[] ret = new String[apps.size()];
5659 int i = 0;
5660 for (SmsApplicationData app : apps) {
5661 ret[i++] = app.mPackageName;
5662 }
5663 return ret;
5664 }
5665
5666 /**
5667 * Returns the default SMS app package name on a given user.
5668 *
5669 * Only the shell user (UID 2000 or 0) can call it.
5670 * Target user must be running.
5671 */
5672 @Override
5673 public String getDefaultSmsApp(int userId) {
5674 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5675 ensureUserRunning(userId);
5676
5677 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5678 /* updateIfNeeded= */ true, userId);
5679 return cn == null ? null : cn.getPackageName();
5680 }
5681
5682 /**
5683 * Set a package as the default SMS app on a given user.
5684 *
5685 * Only the shell user (UID 2000 or 0) can call it.
5686 * Target user must be running.
5687 */
5688 @Override
5689 public void setDefaultSmsApp(int userId, String packageName) {
5690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5691 ensureUserRunning(userId);
5692
5693 boolean found = false;
5694 for (String pkg : getSmsApps(userId)) {
5695 if (TextUtils.equals(packageName, pkg)) {
5696 found = true;
5697 break;
5698 }
5699 }
5700 if (!found) {
5701 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5702 }
5703
5704 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005706}