blob: 1b35e3699c8d5077dfce8c638df35f36401edcdf [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070045import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070046import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070048import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070049import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070050import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080051import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070052import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080053import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080054import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070055import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070056import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070058import android.telephony.CellInfoGsm;
59import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070060import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070061import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070062import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080063import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070064import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080065import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070066import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070067import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070068import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080070import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070071import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080072import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070074import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070075import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000076import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070077import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070078import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070079import android.telephony.cdma.CdmaCellLocation;
80import android.telephony.gsm.GsmCellLocation;
Brad Ebinger35c841c2018-10-01 10:40:55 -070081import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080082import android.telephony.ims.aidl.IImsConfig;
83import android.telephony.ims.aidl.IImsMmTelFeature;
84import android.telephony.ims.aidl.IImsRcsFeature;
85import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -070086import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080087import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080091import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080092import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080093
Brad Ebinger35c841c2018-10-01 10:40:55 -070094import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -070095import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080096import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070097import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070098import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070099import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700100import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700101import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800104import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700105import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100106import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700107import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700108import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700110import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800111import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700112import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700113import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700114import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700115import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700116import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700117import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700118import com.android.internal.telephony.SmsApplication;
119import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800120import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800121import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700122import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.uicc.IccIoResult;
124import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800125import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700126import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800127import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800129import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000130import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700131import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800132import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700133import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800134import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700135import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700136import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800137
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700138import java.io.FileDescriptor;
139import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800140import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800142import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700143import java.util.Collection;
Jake Hambye994d462014-02-03 13:10:13 -0800144import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100145import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800146import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147
148/**
149 * Implementation of the ITelephony interface.
150 */
Santos Cordon117fee72014-05-16 17:56:12 -0700151public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152 private static final String LOG_TAG = "PhoneInterfaceManager";
153 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
154 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800155 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156
157 // Message codes used with mMainThreadHandler
158 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700159 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
160 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161 private static final int CMD_OPEN_CHANNEL = 9;
162 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
163 private static final int CMD_CLOSE_CHANNEL = 11;
164 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800165 private static final int CMD_NV_READ_ITEM = 13;
166 private static final int EVENT_NV_READ_ITEM_DONE = 14;
167 private static final int CMD_NV_WRITE_ITEM = 15;
168 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
169 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
170 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
171 private static final int CMD_NV_RESET_CONFIG = 19;
172 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800173 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
174 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
175 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
176 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800177 private static final int CMD_SEND_ENVELOPE = 25;
178 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000179 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
180 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700181 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
182 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
183 private static final int CMD_EXCHANGE_SIM_IO = 31;
184 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800185 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
186 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700187 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
188 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700189 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
190 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700191 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
192 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
193 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
194 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700195 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
196 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
197 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
198 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700199 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
201 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000202 private static final int CMD_SWITCH_SLOTS = 50;
203 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700204 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
205 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
206 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
207 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
208 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
209 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
210 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
211 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700212 private static final int CMD_GET_ALL_CELL_INFO = 60;
213 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
214 private static final int CMD_GET_CELL_LOCATION = 62;
215 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800217 // Parameters of select command.
218 private static final int SELECT_COMMAND = 0xA4;
219 private static final int SELECT_P1 = 0x04;
220 private static final int SELECT_P2 = 0;
221 private static final int SELECT_P3 = 0x10;
222
Pengquan Meng85728fb2018-03-12 16:31:21 -0700223 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
224 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
225 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
226
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227 /** The singleton instance. */
228 private static PhoneInterfaceManager sInstance;
229
Wink Saville3ab207e2014-11-20 13:07:20 -0800230 private PhoneGlobals mApp;
231 private Phone mPhone;
232 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700233 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800234 private AppOpsManager mAppOps;
235 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800236 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800237 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700238 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
Derek Tan97ebb422014-09-05 16:55:38 -0700240 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
241 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800242 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700243
Derek Tan740e1672017-06-27 14:56:27 -0700244 // The AID of ISD-R.
245 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
246
yinxub1bed742017-04-17 11:45:04 -0700247 private NetworkScanRequestTracker mNetworkScanRequestTracker;
248
David Kelly5e06a7f2018-03-12 14:10:59 +0000249 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
250 private static final int MANUFACTURER_CODE_LENGTH = 8;
251
Derek Tan89e89d42014-07-08 17:00:10 -0700252 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700253 * A request object to use for transmitting data to an ICC.
254 */
255 private static final class IccAPDUArgument {
256 public int channel, cla, command, p1, p2, p3;
257 public String data;
258
259 public IccAPDUArgument(int channel, int cla, int command,
260 int p1, int p2, int p3, String data) {
261 this.channel = channel;
262 this.cla = cla;
263 this.command = command;
264 this.p1 = p1;
265 this.p2 = p2;
266 this.p3 = p3;
267 this.data = data;
268 }
269 }
270
271 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700272 * A request object to use for transmitting data to an ICC.
273 */
274 private static final class ManualNetworkSelectionArgument {
275 public OperatorInfo operatorInfo;
276 public boolean persistSelection;
277
278 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
279 this.operatorInfo = operatorInfo;
280 this.persistSelection = persistSelection;
281 }
282 }
283
284 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
286 * request after sending. The main thread will notify the request when it is complete.
287 */
288 private static final class MainThreadRequest {
289 /** The argument to use for the request */
290 public Object argument;
291 /** The result of the request that is run on the main thread */
292 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800293 // The subscriber id that this request applies to. Defaults to
294 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
295 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700296
vagdeviaf9a5b92018-08-15 16:01:53 -0700297 public WorkSource workSource;
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 public MainThreadRequest(Object argument) {
300 this.argument = argument;
301 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800302
vagdeviaf9a5b92018-08-15 16:01:53 -0700303 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800304 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800305 if (subId != null) {
306 this.subId = subId;
307 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700308 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310 }
311
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800312 private static final class IncomingThirdPartyCallArgs {
313 public final ComponentName component;
314 public final String callId;
315 public final String callerDisplayName;
316
317 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
318 String callerDisplayName) {
319 this.component = component;
320 this.callId = callId;
321 this.callerDisplayName = callerDisplayName;
322 }
323 }
324
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 /**
326 * A handler that processes messages on the main thread in the phone process. Since many
327 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
328 * inbound binder threads to the main thread in the phone process. The Binder thread
329 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
330 * on, which will be notified when the operation completes and will contain the result of the
331 * request.
332 *
333 * <p>If a MainThreadRequest object is provided in the msg.obj field,
334 * note that request.result must be set to something non-null for the calling thread to
335 * unblock.
336 */
337 private final class MainThreadHandler extends Handler {
338 @Override
339 public void handleMessage(Message msg) {
340 MainThreadRequest request;
341 Message onCompleted;
342 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800343 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700344 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
346 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700347 case CMD_HANDLE_USSD_REQUEST: {
348 request = (MainThreadRequest) msg.obj;
349 final Phone phone = getPhoneFromRequest(request);
350 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
351 String ussdRequest = ussdObject.first;
352 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700353
Pengquan Menga1bb6272018-09-06 09:59:22 -0700354 if (!isUssdApiAllowed(request.subId)) {
355 // Carrier does not support use of this API, return failure.
356 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
357 UssdResponse response = new UssdResponse(ussdRequest, null);
358 Bundle returnData = new Bundle();
359 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
360 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700361
Pengquan Menga1bb6272018-09-06 09:59:22 -0700362 request.result = true;
363 notifyRequester(request);
364 return;
365 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700366
Pengquan Menga1bb6272018-09-06 09:59:22 -0700367 try {
368 request.result = phone != null
369 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
370 } catch (CallStateException cse) {
371 request.result = false;
372 }
373 // Wake up the requesting thread
374 notifyRequester(request);
375 break;
pkanwar32d516d2016-10-14 19:37:38 -0700376 }
377
Yorke Lee716f67e2015-06-17 15:39:16 -0700378 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700380 final Phone phone = getPhoneFromRequest(request);
381 request.result = phone != null ?
382 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
383 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700385 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700389 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700390 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700391 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800392 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700393 if (uiccCard == null) {
394 loge("iccTransmitApduLogicalChannel: No UICC");
395 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700396 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700397 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700398 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
399 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700400 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 iccArgument.channel, iccArgument.cla, iccArgument.command,
402 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700403 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700404 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 break;
406
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700407 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700408 ar = (AsyncResult) msg.obj;
409 request = (MainThreadRequest) ar.userObj;
410 if (ar.exception == null && ar.result != null) {
411 request.result = ar.result;
412 } else {
413 request.result = new IccIoResult(0x6F, 0, (byte[])null);
414 if (ar.result == null) {
415 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800416 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800418 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 } else {
420 loge("iccTransmitApduLogicalChannel: Unknown exception");
421 }
422 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 break;
425
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
427 request = (MainThreadRequest) msg.obj;
428 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800429 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700430 if (uiccCard == null) {
431 loge("iccTransmitApduBasicChannel: No UICC");
432 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700433 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 } else {
435 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
436 request);
437 uiccCard.iccTransmitApduBasicChannel(
438 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
439 iccArgument.p3, iccArgument.data, onCompleted);
440 }
441 break;
442
443 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
444 ar = (AsyncResult) msg.obj;
445 request = (MainThreadRequest) ar.userObj;
446 if (ar.exception == null && ar.result != null) {
447 request.result = ar.result;
448 } else {
449 request.result = new IccIoResult(0x6F, 0, (byte[])null);
450 if (ar.result == null) {
451 loge("iccTransmitApduBasicChannel: Empty response");
452 } else if (ar.exception instanceof CommandException) {
453 loge("iccTransmitApduBasicChannel: CommandException: " +
454 ar.exception);
455 } else {
456 loge("iccTransmitApduBasicChannel: Unknown exception");
457 }
458 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 break;
461
462 case CMD_EXCHANGE_SIM_IO:
463 request = (MainThreadRequest) msg.obj;
464 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800465 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 if (uiccCard == null) {
467 loge("iccExchangeSimIO: No UICC");
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 } else {
471 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
472 request);
473 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
474 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
475 iccArgument.data, onCompleted);
476 }
477 break;
478
479 case EVENT_EXCHANGE_SIM_IO_DONE:
480 ar = (AsyncResult) msg.obj;
481 request = (MainThreadRequest) ar.userObj;
482 if (ar.exception == null && ar.result != null) {
483 request.result = ar.result;
484 } else {
485 request.result = new IccIoResult(0x6f, 0, (byte[])null);
486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 break;
489
Derek Tan4d5e5c12014-02-04 11:54:58 -0800490 case CMD_SEND_ENVELOPE:
491 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 if (uiccCard == null) {
494 loge("sendEnvelopeWithStatus: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 } else {
498 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
499 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
500 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800501 break;
502
503 case EVENT_SEND_ENVELOPE_DONE:
504 ar = (AsyncResult) msg.obj;
505 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700506 if (ar.exception == null && ar.result != null) {
507 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800508 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
510 if (ar.result == null) {
511 loge("sendEnvelopeWithStatus: Empty response");
512 } else if (ar.exception instanceof CommandException) {
513 loge("sendEnvelopeWithStatus: CommandException: " +
514 ar.exception);
515 } else {
516 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
517 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800520 break;
521
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 case CMD_OPEN_CHANNEL:
523 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800524 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800525 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 if (uiccCard == null) {
527 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800528 request.result = new IccOpenLogicalChannelResponse(-1,
529 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700531 } else {
532 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800533 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
534 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700535 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700536 break;
537
538 case EVENT_OPEN_CHANNEL_DONE:
539 ar = (AsyncResult) msg.obj;
540 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 int[] result = (int[]) ar.result;
544 int channelId = result[0];
545 byte[] selectResponse = null;
546 if (result.length > 1) {
547 selectResponse = new byte[result.length - 1];
548 for (int i = 1; i < result.length; ++i) {
549 selectResponse[i - 1] = (byte) result[i];
550 }
551 }
552 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700553 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 if (ar.result == null) {
556 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 if (ar.exception != null) {
559 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
560 }
561
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700562 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700563 if (ar.exception instanceof CommandException) {
564 CommandException.Error error =
565 ((CommandException) (ar.exception)).getCommandError();
566 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700567 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700568 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700569 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 }
571 }
572 openChannelResp = new IccOpenLogicalChannelResponse(
573 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700575 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 break;
578
579 case CMD_CLOSE_CHANNEL:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700582 if (uiccCard == null) {
583 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900584 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 } else {
587 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
588 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
592 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800593 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
594 break;
595
596 case CMD_NV_READ_ITEM:
597 request = (MainThreadRequest) msg.obj;
598 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700599 mPhone.nvReadItem((Integer) request.argument, onCompleted, request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800600 break;
601
602 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800605 if (ar.exception == null && ar.result != null) {
606 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800608 request.result = "";
609 if (ar.result == null) {
610 loge("nvReadItem: Empty response");
611 } else if (ar.exception instanceof CommandException) {
612 loge("nvReadItem: CommandException: " +
613 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800615 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 }
617 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 break;
620
Jake Hambye994d462014-02-03 13:10:13 -0800621 case CMD_NV_WRITE_ITEM:
622 request = (MainThreadRequest) msg.obj;
623 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
624 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
vagdeviaf9a5b92018-08-15 16:01:53 -0700625 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
626 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800627 break;
628
629 case EVENT_NV_WRITE_ITEM_DONE:
630 handleNullReturnEvent(msg, "nvWriteItem");
631 break;
632
633 case CMD_NV_WRITE_CDMA_PRL:
634 request = (MainThreadRequest) msg.obj;
635 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
636 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
637 break;
638
639 case EVENT_NV_WRITE_CDMA_PRL_DONE:
640 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
641 break;
642
643 case CMD_NV_RESET_CONFIG:
644 request = (MainThreadRequest) msg.obj;
645 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
646 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
647 break;
648
649 case EVENT_NV_RESET_CONFIG_DONE:
650 handleNullReturnEvent(msg, "nvResetConfig");
651 break;
652
Jake Hamby7c27be32014-03-03 13:25:59 -0800653 case CMD_GET_PREFERRED_NETWORK_TYPE:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700656 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800657 break;
658
659 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
660 ar = (AsyncResult) msg.obj;
661 request = (MainThreadRequest) ar.userObj;
662 if (ar.exception == null && ar.result != null) {
663 request.result = ar.result; // Integer
664 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800665 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800666 if (ar.result == null) {
667 loge("getPreferredNetworkType: Empty response");
668 } else if (ar.exception instanceof CommandException) {
669 loge("getPreferredNetworkType: CommandException: " +
670 ar.exception);
671 } else {
672 loge("getPreferredNetworkType: Unknown exception");
673 }
674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800676 break;
677
678 case CMD_SET_PREFERRED_NETWORK_TYPE:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
681 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700682 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800683 break;
684
685 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
686 handleNullReturnEvent(msg, "setPreferredNetworkType");
687 break;
688
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000689 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
690 request = (MainThreadRequest)msg.obj;
691 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700692 mPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000693 break;
694
695 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
696 ar = (AsyncResult)msg.obj;
697 request = (MainThreadRequest)ar.userObj;
698 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700699 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000700 break;
701
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800702 case CMD_SET_VOICEMAIL_NUMBER:
703 request = (MainThreadRequest) msg.obj;
704 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
705 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800706 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
707 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800708 break;
709
710 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
711 handleNullReturnEvent(msg, "setVoicemailNumber");
712 break;
713
Stuart Scott54788802015-03-30 13:18:01 -0700714 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
717 request);
718 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
719 break;
720
721 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
722 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
723 break;
724
Shishir Agrawal302c8692015-06-19 13:49:39 -0700725 case CMD_PERFORM_NETWORK_SCAN:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
728 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
729 break;
730
731 case EVENT_PERFORM_NETWORK_SCAN_DONE:
732 ar = (AsyncResult) msg.obj;
733 request = (MainThreadRequest) ar.userObj;
734 CellNetworkScanResult cellScanResult;
735 if (ar.exception == null && ar.result != null) {
736 cellScanResult = new CellNetworkScanResult(
737 CellNetworkScanResult.STATUS_SUCCESS,
738 (List<OperatorInfo>) ar.result);
739 } else {
740 if (ar.result == null) {
741 loge("getCellNetworkScanResults: Empty response");
742 }
743 if (ar.exception != null) {
744 loge("getCellNetworkScanResults: Exception: " + ar.exception);
745 }
746 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
747 if (ar.exception instanceof CommandException) {
748 CommandException.Error error =
749 ((CommandException) (ar.exception)).getCommandError();
750 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
751 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
752 } else if (error == CommandException.Error.GENERIC_FAILURE) {
753 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
754 }
755 }
756 cellScanResult = new CellNetworkScanResult(errorCode, null);
757 }
758 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700760 break;
761
762 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
763 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700764 ManualNetworkSelectionArgument selArg =
765 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700766 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
767 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700768 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
769 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700770 break;
771
772 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700773 ar = (AsyncResult) msg.obj;
774 request = (MainThreadRequest) ar.userObj;
775 if (ar.exception == null) {
776 request.result = true;
777 } else {
778 request.result = false;
779 loge("setNetworkSelectionModeManual " + ar.exception);
780 }
781 notifyRequester(request);
782 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700783 break;
784
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700785 case CMD_GET_MODEM_ACTIVITY_INFO:
786 request = (MainThreadRequest) msg.obj;
787 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700788 mPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700789 break;
790
791 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
792 ar = (AsyncResult) msg.obj;
793 request = (MainThreadRequest) ar.userObj;
794 if (ar.exception == null && ar.result != null) {
795 request.result = ar.result;
796 } else {
797 if (ar.result == null) {
798 loge("queryModemActivityInfo: Empty response");
799 } else if (ar.exception instanceof CommandException) {
800 loge("queryModemActivityInfo: CommandException: " +
801 ar.exception);
802 } else {
803 loge("queryModemActivityInfo: Unknown exception");
804 }
805 }
Amit Mahajand4766222016-01-28 15:28:28 -0800806 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
807 if (request.result == null) {
808 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
809 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700810 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700811 break;
812
Meng Wang1a7c35a2016-05-05 20:56:15 -0700813 case CMD_SET_ALLOWED_CARRIERS:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
816 mPhone.setAllowedCarriers(
817 (List<CarrierIdentifier>) request.argument,
vagdeviaf9a5b92018-08-15 16:01:53 -0700818 onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700819 break;
820
821 case EVENT_SET_ALLOWED_CARRIERS_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null && ar.result != null) {
825 request.result = ar.result;
826 } else {
827 if (ar.result == null) {
828 loge("setAllowedCarriers: Empty response");
829 } else if (ar.exception instanceof CommandException) {
830 loge("setAllowedCarriers: CommandException: " +
831 ar.exception);
832 } else {
833 loge("setAllowedCarriers: Unknown exception");
834 }
835 }
836 // Result cannot be null. Return -1 on error.
837 if (request.result == null) {
838 request.result = new int[]{-1};
839 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700840 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700841 break;
842
843 case CMD_GET_ALLOWED_CARRIERS:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
vagdeviaf9a5b92018-08-15 16:01:53 -0700846 mPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700847 break;
848
849 case EVENT_GET_ALLOWED_CARRIERS_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result;
854 } else {
855 if (ar.result == null) {
856 loge("getAllowedCarriers: Empty response");
857 } else if (ar.exception instanceof CommandException) {
858 loge("getAllowedCarriers: CommandException: " +
859 ar.exception);
860 } else {
861 loge("getAllowedCarriers: Unknown exception");
862 }
863 }
864 // Result cannot be null. Return empty list of CarrierIdentifier.
865 if (request.result == null) {
866 request.result = new ArrayList<CarrierIdentifier>(0);
867 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700868 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700869 break;
870
Nathan Haroldb3014052017-01-25 15:57:32 -0800871 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
872 ar = (AsyncResult) msg.obj;
873 request = (MainThreadRequest) ar.userObj;
874 if (ar.exception == null && ar.result != null) {
875 request.result = ar.result;
876 } else {
877 request.result = new IllegalArgumentException(
878 "Failed to retrieve Forbidden Plmns");
879 if (ar.result == null) {
880 loge("getForbiddenPlmns: Empty response");
881 } else {
882 loge("getForbiddenPlmns: Unknown exception");
883 }
884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700885 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800886 break;
887
888 case CMD_GET_FORBIDDEN_PLMNS:
889 request = (MainThreadRequest) msg.obj;
890 uiccCard = getUiccCardFromRequest(request);
891 if (uiccCard == null) {
892 loge("getForbiddenPlmns() UiccCard is null");
893 request.result = new IllegalArgumentException(
894 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700895 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800896 break;
897 }
898 Integer appType = (Integer) request.argument;
899 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
900 if (uiccApp == null) {
901 loge("getForbiddenPlmns() no app with specified type -- "
902 + appType);
903 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700904 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800905 break;
906 } else {
907 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
908 + " specified type -- " + appType);
909 }
910 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
911 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
912 onCompleted);
913 break;
914
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000915 case CMD_SWITCH_SLOTS:
916 request = (MainThreadRequest) msg.obj;
917 int[] physicalSlots = (int[]) request.argument;
918 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
919 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
920 break;
921
922 case EVENT_SWITCH_SLOTS_DONE:
923 ar = (AsyncResult) msg.obj;
924 request = (MainThreadRequest) ar.userObj;
925 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700926 notifyRequester(request);
927 break;
928 case CMD_GET_NETWORK_SELECTION_MODE:
929 request = (MainThreadRequest) msg.obj;
930 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
931 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
932 break;
933
934 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 if (ar.exception != null) {
938 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
939 } else {
940 int mode = ((int[]) ar.result)[0];
941 if (mode == 0) {
942 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
943 } else {
944 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
945 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000946 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700947 notifyRequester(request);
948 break;
949 case CMD_GET_CDMA_ROAMING_MODE:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
952 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
953 break;
954 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
955 ar = (AsyncResult) msg.obj;
956 request = (MainThreadRequest) ar.userObj;
957 if (ar.exception != null) {
958 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
959 } else {
960 request.result = ((int[]) ar.result)[0];
961 }
962 notifyRequester(request);
963 break;
964 case CMD_SET_CDMA_ROAMING_MODE:
965 request = (MainThreadRequest) msg.obj;
966 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
967 int mode = (int) request.argument;
968 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
969 break;
970 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
973 request.result = ar.exception == null;
974 notifyRequester(request);
975 break;
976 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
979 int subscriptionMode = (int) request.argument;
980 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
981 break;
982 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 request.result = ar.exception == null;
986 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000987 break;
988
Nathan Harold3ff88932018-08-14 10:19:49 -0700989 case CMD_GET_ALL_CELL_INFO:
990 request = (MainThreadRequest) msg.obj;
991 Pair<Phone, WorkSource> args = (Pair<Phone, WorkSource>) request.argument;
992 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
993 ((Phone) args.first).getAllCellInfo(args.second, onCompleted);
994 break;
995
996 case EVENT_GET_ALL_CELL_INFO_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -0700999 // If a timeout occurs, the response will be null
1000 request.result = (ar.exception == null && ar.result != null)
1001 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001002 synchronized (request) {
1003 request.notifyAll();
1004 }
1005 break;
1006
1007 case CMD_GET_CELL_LOCATION: {
1008 request = (MainThreadRequest) msg.obj;
1009 WorkSource ws = (WorkSource) request.argument;
1010 Phone phone = getPhoneFromRequest(request);
1011 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1012 break;
1013 }
1014
1015 case EVENT_GET_CELL_LOCATION_DONE: {
1016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception == null) {
1019 request.result = ar.result;
1020 } else {
1021 Phone phone = getPhoneFromRequest(request);
1022 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1023 ? new CdmaCellLocation() : new GsmCellLocation();
1024 }
1025
1026 synchronized (request) {
1027 request.notifyAll();
1028 }
1029 break;
1030 }
1031
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001032 default:
1033 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1034 break;
1035 }
1036 }
Jake Hambye994d462014-02-03 13:10:13 -08001037
Pengquan Menga1bb6272018-09-06 09:59:22 -07001038 private void notifyRequester(MainThreadRequest request) {
1039 synchronized (request) {
1040 request.notifyAll();
1041 }
1042 }
1043
Jake Hambye994d462014-02-03 13:10:13 -08001044 private void handleNullReturnEvent(Message msg, String command) {
1045 AsyncResult ar = (AsyncResult) msg.obj;
1046 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1047 if (ar.exception == null) {
1048 request.result = true;
1049 } else {
1050 request.result = false;
1051 if (ar.exception instanceof CommandException) {
1052 loge(command + ": CommandException: " + ar.exception);
1053 } else {
1054 loge(command + ": Unknown exception");
1055 }
1056 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001057 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001059 }
1060
1061 /**
1062 * Posts the specified command to be executed on the main thread,
1063 * waits for the request to complete, and returns the result.
1064 * @see #sendRequestAsync
1065 */
1066 private Object sendRequest(int command, Object argument) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001067 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null);
1068 }
1069
1070 /**
1071 * Posts the specified command to be executed on the main thread,
1072 * waits for the request to complete, and returns the result.
1073 * @see #sendRequestAsync
1074 */
1075 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1076 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
1077 workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001078 }
1079
1080 /**
1081 * Posts the specified command to be executed on the main thread,
1082 * waits for the request to complete, and returns the result.
1083 * @see #sendRequestAsync
1084 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001085 private Object sendRequest(int command, Object argument, Integer subId) {
vagdeviaf9a5b92018-08-15 16:01:53 -07001086 return sendRequest(command, argument, subId, null);
1087 }
1088
1089 /**
1090 * Posts the specified command to be executed on the main thread,
1091 * waits for the request to complete, and returns the result.
1092 * @see #sendRequestAsync
1093 */
1094 private Object sendRequest(int command, Object argument, Integer subId, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001095 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1096 throw new RuntimeException("This method will deadlock if called from the main thread.");
1097 }
1098
vagdeviaf9a5b92018-08-15 16:01:53 -07001099 MainThreadRequest request = new MainThreadRequest(argument, subId, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001100 Message msg = mMainThreadHandler.obtainMessage(command, request);
1101 msg.sendToTarget();
1102
1103 // Wait for the request to complete
1104 synchronized (request) {
1105 while (request.result == null) {
1106 try {
1107 request.wait();
1108 } catch (InterruptedException e) {
1109 // Do nothing, go back and wait until the request is complete
1110 }
1111 }
1112 }
1113 return request.result;
1114 }
1115
1116 /**
1117 * Asynchronous ("fire and forget") version of sendRequest():
1118 * Posts the specified command to be executed on the main thread, and
1119 * returns immediately.
1120 * @see #sendRequest
1121 */
1122 private void sendRequestAsync(int command) {
1123 mMainThreadHandler.sendEmptyMessage(command);
1124 }
1125
1126 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001127 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1128 * @see {@link #sendRequest(int,Object)}
1129 */
1130 private void sendRequestAsync(int command, Object argument) {
1131 MainThreadRequest request = new MainThreadRequest(argument);
1132 Message msg = mMainThreadHandler.obtainMessage(command, request);
1133 msg.sendToTarget();
1134 }
1135
1136 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001137 * Initialize the singleton PhoneInterfaceManager instance.
1138 * This is only done once, at startup, from PhoneApp.onCreate().
1139 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001140 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 synchronized (PhoneInterfaceManager.class) {
1142 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001143 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001144 } else {
1145 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1146 }
1147 return sInstance;
1148 }
1149 }
1150
1151 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001152 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001153 mApp = app;
1154 mPhone = phone;
1155 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001156 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001157 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1158 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001159 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001160 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001161 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001162 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001163 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001164
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 publish();
1166 }
1167
1168 private void publish() {
1169 if (DBG) log("publish: " + this);
1170
1171 ServiceManager.addService("phone", this);
1172 }
1173
Stuart Scott584921c2015-01-15 17:10:34 -08001174 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001175 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1176 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001177 }
1178
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001179 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1180 Phone phone = getPhoneFromRequest(request);
1181 return phone == null ? null :
1182 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1183 }
1184
Wink Saville36469e72014-06-11 15:17:00 -07001185 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001186 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001187 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189
1190 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001191 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001192 }
1193
Wink Savilleb564aae2014-10-23 10:18:09 -07001194 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 if (DBG) log("dial: " + number);
1196 // No permission check needed here: This is just a wrapper around the
1197 // ACTION_DIAL intent, which is available to any app since it puts up
1198 // the UI before it does anything.
1199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001200 final long identity = Binder.clearCallingIdentity();
1201 try {
1202 String url = createTelUrl(number);
1203 if (url == null) {
1204 return;
1205 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001207 // PENDING: should we just silently fail if phone is offhook or ringing?
1208 PhoneConstants.State state = mCM.getState(subId);
1209 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1210 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1211 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1212 mApp.startActivity(intent);
1213 }
1214 } finally {
1215 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 }
1217 }
1218
1219 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001220 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001221 }
1222
Wink Savilleb564aae2014-10-23 10:18:09 -07001223 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001224 if (DBG) log("call: " + number);
1225
1226 // This is just a wrapper around the ACTION_CALL intent, but we still
1227 // need to do a permission check since we're calling startActivity()
1228 // from the context of the phone app.
1229 enforceCallPermission();
1230
1231 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1232 != AppOpsManager.MODE_ALLOWED) {
1233 return;
1234 }
1235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001236 final long identity = Binder.clearCallingIdentity();
1237 try {
1238 String url = createTelUrl(number);
1239 if (url == null) {
1240 return;
1241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001243 boolean isValid = false;
1244 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1245 if (slist != null) {
1246 for (SubscriptionInfo subInfoRecord : slist) {
1247 if (subInfoRecord.getSubscriptionId() == subId) {
1248 isValid = true;
1249 break;
1250 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001251 }
Wink Saville08874612014-08-31 19:19:58 -07001252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001253 if (!isValid) {
1254 return;
1255 }
Wink Saville08874612014-08-31 19:19:58 -07001256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001257 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1258 intent.putExtra(SUBSCRIPTION_KEY, subId);
1259 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1260 mApp.startActivity(intent);
1261 } finally {
1262 Binder.restoreCallingIdentity(identity);
1263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 }
1265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001267 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001268 }
1269
Wink Savilleb564aae2014-10-23 10:18:09 -07001270 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001271 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001272 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1273 }
1274
1275 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001276 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001277 }
1278
Wink Savilleb564aae2014-10-23 10:18:09 -07001279 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001280 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001281 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1282 }
1283
1284 /** {@hide} */
1285 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001286 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001287 }
1288
Wink Savilleb564aae2014-10-23 10:18:09 -07001289 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001291
1292 final long identity = Binder.clearCallingIdentity();
1293 try {
1294 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1295 checkSimPin.start();
1296 return checkSimPin.unlockSim(null, pin);
1297 } finally {
1298 Binder.restoreCallingIdentity(identity);
1299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 }
1301
Wink Saville9de0f752013-10-22 19:04:03 -07001302 /** {@hide} */
1303 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001304 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001305 }
1306
Wink Savilleb564aae2014-10-23 10:18:09 -07001307 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001309
1310 final long identity = Binder.clearCallingIdentity();
1311 try {
1312 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1313 checkSimPuk.start();
1314 return checkSimPuk.unlockSim(puk, pin);
1315 } finally {
1316 Binder.restoreCallingIdentity(identity);
1317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 }
1319
1320 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001321 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 * a synchronous one.
1323 */
1324 private static class UnlockSim extends Thread {
1325
1326 private final IccCard mSimCard;
1327
1328 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001329 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1330 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331
1332 // For replies from SimCard interface
1333 private Handler mHandler;
1334
1335 // For async handler to identify request type
1336 private static final int SUPPLY_PIN_COMPLETE = 100;
1337
1338 public UnlockSim(IccCard simCard) {
1339 mSimCard = simCard;
1340 }
1341
1342 @Override
1343 public void run() {
1344 Looper.prepare();
1345 synchronized (UnlockSim.this) {
1346 mHandler = new Handler() {
1347 @Override
1348 public void handleMessage(Message msg) {
1349 AsyncResult ar = (AsyncResult) msg.obj;
1350 switch (msg.what) {
1351 case SUPPLY_PIN_COMPLETE:
1352 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1353 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001354 mRetryCount = msg.arg1;
1355 if (ar.exception != null) {
1356 if (ar.exception instanceof CommandException &&
1357 ((CommandException)(ar.exception)).getCommandError()
1358 == CommandException.Error.PASSWORD_INCORRECT) {
1359 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1360 } else {
1361 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1362 }
1363 } else {
1364 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366 mDone = true;
1367 UnlockSim.this.notifyAll();
1368 }
1369 break;
1370 }
1371 }
1372 };
1373 UnlockSim.this.notifyAll();
1374 }
1375 Looper.loop();
1376 }
1377
1378 /*
1379 * Use PIN or PUK to unlock SIM card
1380 *
1381 * If PUK is null, unlock SIM card with PIN
1382 *
1383 * If PUK is not null, unlock SIM card with PUK and set PIN code
1384 */
Wink Saville9de0f752013-10-22 19:04:03 -07001385 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386
1387 while (mHandler == null) {
1388 try {
1389 wait();
1390 } catch (InterruptedException e) {
1391 Thread.currentThread().interrupt();
1392 }
1393 }
1394 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1395
1396 if (puk == null) {
1397 mSimCard.supplyPin(pin, callback);
1398 } else {
1399 mSimCard.supplyPuk(puk, pin, callback);
1400 }
1401
1402 while (!mDone) {
1403 try {
1404 Log.d(LOG_TAG, "wait for done");
1405 wait();
1406 } catch (InterruptedException e) {
1407 // Restore the interrupted status
1408 Thread.currentThread().interrupt();
1409 }
1410 }
1411 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001412 int[] resultArray = new int[2];
1413 resultArray[0] = mResult;
1414 resultArray[1] = mRetryCount;
1415 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 }
1417 }
1418
1419 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001420 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001421
1422 }
1423
Wink Savilleb564aae2014-10-23 10:18:09 -07001424 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425 // No permission check needed here: this call is harmless, and it's
1426 // needed for the ServiceState.requestStateUpdate() call (which is
1427 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001428 final long identity = Binder.clearCallingIdentity();
1429 try {
1430 final Phone phone = getPhone(subId);
1431 if (phone != null) {
1432 phone.updateServiceLocation();
1433 }
1434 } finally {
1435 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001437 }
1438
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001439 @Override
1440 public boolean isRadioOn(String callingPackage) {
1441 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001442 }
1443
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001444 @Override
1445 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001447 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001448 return false;
1449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001450
1451 final long identity = Binder.clearCallingIdentity();
1452 try {
1453 return isRadioOnForSubscriber(subId);
1454 } finally {
1455 Binder.restoreCallingIdentity(identity);
1456 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001457 }
1458
1459 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001460 final long identity = Binder.clearCallingIdentity();
1461 try {
1462 final Phone phone = getPhone(subId);
1463 if (phone != null) {
1464 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1465 } else {
1466 return false;
1467 }
1468 } finally {
1469 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 }
1472
1473 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001474 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 }
Wink Saville36469e72014-06-11 15:17:00 -07001476
Wink Savilleb564aae2014-10-23 10:18:09 -07001477 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001479
1480 final long identity = Binder.clearCallingIdentity();
1481 try {
1482 final Phone phone = getPhone(subId);
1483 if (phone != null) {
1484 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1485 }
1486 } finally {
1487 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001488 }
Wink Saville36469e72014-06-11 15:17:00 -07001489 }
1490
1491 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001492 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001493 }
1494
Wink Savilleb564aae2014-10-23 10:18:09 -07001495 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001497
1498 final long identity = Binder.clearCallingIdentity();
1499 try {
1500 final Phone phone = getPhone(subId);
1501 if (phone == null) {
1502 return false;
1503 }
1504 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1505 toggleRadioOnOffForSubscriber(subId);
1506 }
1507 return true;
1508 } finally {
1509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 }
Wink Saville36469e72014-06-11 15:17:00 -07001512
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001513 public boolean needMobileRadioShutdown() {
1514 /*
1515 * If any of the Radios are available, it will need to be
1516 * shutdown. So return true if any Radio is available.
1517 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001518 final long identity = Binder.clearCallingIdentity();
1519 try {
1520 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1521 Phone phone = PhoneFactory.getPhone(i);
1522 if (phone != null && phone.isRadioAvailable()) return true;
1523 }
1524 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1525 return false;
1526 } finally {
1527 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001528 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001529 }
1530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001531 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001532 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001533 enforceModifyPermission();
1534
1535 final long identity = Binder.clearCallingIdentity();
1536 try {
1537 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1538 logv("Shutting down Phone " + i);
1539 shutdownRadioUsingPhoneId(i);
1540 }
1541 } finally {
1542 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001543 }
1544 }
1545
1546 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001547 Phone phone = PhoneFactory.getPhone(phoneId);
1548 if (phone != null && phone.isRadioAvailable()) {
1549 phone.shutdownRadio();
1550 }
1551 }
1552
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001555
1556 final long identity = Binder.clearCallingIdentity();
1557 try {
1558 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1559 if (defaultPhone != null) {
1560 defaultPhone.setRadioPower(turnOn);
1561 return true;
1562 } else {
1563 loge("There's no default phone.");
1564 return false;
1565 }
1566 } finally {
1567 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001568 }
Wink Saville36469e72014-06-11 15:17:00 -07001569 }
1570
Wink Savilleb564aae2014-10-23 10:18:09 -07001571 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001573
1574 final long identity = Binder.clearCallingIdentity();
1575 try {
1576 final Phone phone = getPhone(subId);
1577 if (phone != null) {
1578 phone.setRadioPower(turnOn);
1579 return true;
1580 } else {
1581 return false;
1582 }
1583 } finally {
1584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 }
1587
Wink Saville36469e72014-06-11 15:17:00 -07001588 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001589 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 public boolean enableDataConnectivity() {
1591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001592
1593 final long identity = Binder.clearCallingIdentity();
1594 try {
1595 int subId = mSubscriptionController.getDefaultDataSubId();
1596 final Phone phone = getPhone(subId);
1597 if (phone != null) {
1598 phone.setUserDataEnabled(true);
1599 return true;
1600 } else {
1601 return false;
1602 }
1603 } finally {
1604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 }
1607
Wink Saville36469e72014-06-11 15:17:00 -07001608 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 public boolean disableDataConnectivity() {
1611 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001612
1613 final long identity = Binder.clearCallingIdentity();
1614 try {
1615 int subId = mSubscriptionController.getDefaultDataSubId();
1616 final Phone phone = getPhone(subId);
1617 if (phone != null) {
1618 phone.setUserDataEnabled(false);
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
Sanket Padawe356d7632015-06-22 14:03:32 -07001628 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001629 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001630 final long identity = Binder.clearCallingIdentity();
1631 try {
1632 final Phone phone = getPhone(subId);
1633 if (phone != null) {
1634 return phone.isDataAllowed();
1635 } else {
1636 return false;
1637 }
1638 } finally {
1639 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 }
1642
1643 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001644 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001645 }
1646
pkanwarae03a6b2016-11-06 20:37:09 -08001647 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001648 enforceCallPermission();
1649
1650 final long identity = Binder.clearCallingIdentity();
1651 try {
1652 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1653 return;
1654 }
1655 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1656 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1657 } finally {
1658 Binder.restoreCallingIdentity(identity);
1659 }
pkanwar32d516d2016-10-14 19:37:38 -07001660 };
1661
Wink Savilleb564aae2014-10-23 10:18:09 -07001662 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001664
1665 final long identity = Binder.clearCallingIdentity();
1666 try {
1667 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1668 return false;
1669 }
1670 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1671 } finally {
1672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 }
1675
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001677 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001678 }
1679
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001680 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 Phone phone = PhoneFactory.getPhone(slotIndex);
1684 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1685 PhoneConstantConversions.convertCallState(phone.getState());
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
1688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 }
1690
Sanket Padawe356d7632015-06-22 14:03:32 -07001691 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1696 if (phone != null) {
1697 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1698 } else {
1699 return PhoneConstantConversions.convertDataState(
1700 PhoneConstants.DataState.DISCONNECTED);
1701 }
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001709 final long identity = Binder.clearCallingIdentity();
1710 try {
1711 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1712 if (phone != null) {
1713 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1714 } else {
1715 return TelephonyManager.DATA_ACTIVITY_NONE;
1716 }
1717 } finally {
1718 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 }
1721
1722 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001723 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001724 mPhone.getContext().getSystemService(AppOpsManager.class)
1725 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001726 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001727 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001728 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 }
1730
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001731 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001732 final long identity = Binder.clearCallingIdentity();
1733 try {
1734 if (DBG_LOC) log("getCellLocation: is active user");
1735 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 int subId = mSubscriptionController.getDefaultDataSubId();
1737 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1738 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001739 return data;
1740 } finally {
1741 Binder.restoreCallingIdentity(identity);
1742 }
Svetoslav64fad262015-04-14 14:35:21 -07001743 }
1744
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001746 public String getNetworkCountryIsoForPhone(int phoneId) {
1747 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1748 // registered cell info, so return a NULL country instead.
1749 final long identity = Binder.clearCallingIdentity();
1750 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001751 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1752 // Get default phone in this case.
1753 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1754 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001755 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001756 // Todo: fix this when we can get the actual cellular network info when the device
1757 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001758 if (TelephonyManager.NETWORK_TYPE_IWLAN
1759 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1760 return "";
1761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001762 Phone phone = PhoneFactory.getPhone(phoneId);
1763 if (phone != null) {
1764 ServiceStateTracker sst = phone.getServiceStateTracker();
1765 if (sst != null) {
1766 LocaleTracker lt = sst.getLocaleTracker();
1767 if (lt != null) {
1768 return lt.getCurrentCountry();
1769 }
1770 }
1771 }
1772 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001773 } finally {
1774 Binder.restoreCallingIdentity(identity);
1775 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001776 }
1777
1778 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001780 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001781 }
1782
Sanket Padawe356d7632015-06-22 14:03:32 -07001783 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001784 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 mApp.enforceCallingOrSelfPermission(
1786 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787
1788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 final Phone phone = getPhone(subId);
1791 if (phone != null) {
1792 phone.enableLocationUpdates();
1793 }
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
1799 @Override
1800 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001801 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001802 }
1803
Sanket Padawe356d7632015-06-22 14:03:32 -07001804 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001805 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 mApp.enforceCallingOrSelfPermission(
1807 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001808
1809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 final Phone phone = getPhone(subId);
1812 if (phone != null) {
1813 phone.disableLocationUpdates();
1814 }
1815 } finally {
1816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 }
1819
1820 @Override
1821 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001822 public List<NeighboringCellInfo>
1823 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001824 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1825 throw new SecurityException(
1826 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1827 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001828
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1830 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1831 return null;
1832 }
Svetoslav64fad262015-04-14 14:35:21 -07001833
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001834 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835
Nathan Haroldf180aac2018-06-01 18:43:55 -07001836 List<CellInfo> info = getAllCellInfo(callingPackage);
1837 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838
Nathan Haroldf180aac2018-06-01 18:43:55 -07001839 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1840 for (CellInfo ci : info) {
1841 if (ci instanceof CellInfoGsm) {
1842 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1843 } else if (ci instanceof CellInfoWcdma) {
1844 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001847 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
1850
1851 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001852 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001853 mPhone.getContext().getSystemService(AppOpsManager.class)
1854 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001855 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001856 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001857 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001860 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001861 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001862 final long identity = Binder.clearCallingIdentity();
1863 try {
1864 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1865 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07001866 final List<CellInfo> info = (List<CellInfo>) sendRequest(
1867 CMD_GET_ALL_CELL_INFO,
1868 new Pair<Phone, WorkSource>(phone, workSource));
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001869 if (info != null) cellInfos.addAll(info);
1870 }
1871 return cellInfos;
1872 } finally {
1873 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 }
1875 }
1876
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001877 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001879 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001880 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001881
1882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 mPhone.setCellInfoListRate(rateInMillis, workSource);
1885 } finally {
1886 Binder.restoreCallingIdentity(identity);
1887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 }
1889
Shishir Agrawala9f32182016-04-12 12:00:16 -07001890 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001891 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001892 Phone phone = PhoneFactory.getPhone(slotIndex);
1893 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001894 return null;
1895 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001896 int subId = phone.getSubId();
1897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1898 mApp, subId, callingPackage, "getImeiForSlot")) {
1899 return null;
1900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001901
1902 final long identity = Binder.clearCallingIdentity();
1903 try {
1904 return phone.getImei();
1905 } finally {
1906 Binder.restoreCallingIdentity(identity);
1907 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001908 }
1909
1910 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001911 public String getTypeAllocationCodeForSlot(int slotIndex) {
1912 Phone phone = PhoneFactory.getPhone(slotIndex);
1913 String tac = null;
1914 if (phone != null) {
1915 String imei = phone.getImei();
1916 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1917 }
1918 return tac;
1919 }
1920
1921 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001922 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001923 Phone phone = PhoneFactory.getPhone(slotIndex);
1924 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001925 return null;
1926 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001927 int subId = phone.getSubId();
1928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1929 mApp, subId, callingPackage, "getMeidForSlot")) {
1930 return null;
1931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001932
1933 final long identity = Binder.clearCallingIdentity();
1934 try {
1935 return phone.getMeid();
1936 } finally {
1937 Binder.restoreCallingIdentity(identity);
1938 }
Jack Yu2af8d712017-03-15 17:14:14 -07001939 }
1940
1941 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001942 public String getManufacturerCodeForSlot(int slotIndex) {
1943 Phone phone = PhoneFactory.getPhone(slotIndex);
1944 String manufacturerCode = null;
1945 if (phone != null) {
1946 String meid = phone.getMeid();
1947 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1948 }
1949 return manufacturerCode;
1950 }
1951
1952 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001953 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001954 Phone phone = PhoneFactory.getPhone(slotIndex);
1955 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001956 return null;
1957 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001958 int subId = phone.getSubId();
1959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1960 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1961 return null;
1962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001963
1964 final long identity = Binder.clearCallingIdentity();
1965 try {
1966 return phone.getDeviceSvn();
1967 } finally {
1968 Binder.restoreCallingIdentity(identity);
1969 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001970 }
1971
fionaxu43304da2017-11-27 22:51:16 -08001972 @Override
1973 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001974 final long identity = Binder.clearCallingIdentity();
1975 try {
1976 final Phone phone = getPhone(subId);
1977 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1978 } finally {
1979 Binder.restoreCallingIdentity(identity);
1980 }
fionaxu43304da2017-11-27 22:51:16 -08001981 }
1982
1983 @Override
1984 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 final Phone phone = getPhone(subId);
1988 return phone == null ? null : phone.getCarrierName();
1989 } finally {
1990 Binder.restoreCallingIdentity(identity);
1991 }
fionaxu43304da2017-11-27 22:51:16 -08001992 }
1993
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 //
1995 // Internal helper methods.
1996 //
1997
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001998 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2000 *
2001 * @throws SecurityException if the caller does not have the required permission
2002 */
2003 private void enforceModifyPermission() {
2004 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2005 }
2006
2007 /**
2008 * Make sure the caller has the CALL_PHONE permission.
2009 *
2010 * @throws SecurityException if the caller does not have the required permission
2011 */
2012 private void enforceCallPermission() {
2013 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2014 }
2015
Stuart Scott8eef64f2015-04-08 15:13:54 -07002016 private void enforceConnectivityInternalPermission() {
2017 mApp.enforceCallingOrSelfPermission(
2018 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2019 "ConnectivityService");
2020 }
2021
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002022 private String createTelUrl(String number) {
2023 if (TextUtils.isEmpty(number)) {
2024 return null;
2025 }
2026
Jake Hambye994d462014-02-03 13:10:13 -08002027 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 }
2029
Ihab Awadf9e92732013-12-05 18:02:52 -08002030 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2032 }
2033
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002034 private static void logv(String msg) {
2035 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2036 }
2037
Ihab Awadf9e92732013-12-05 18:02:52 -08002038 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2040 }
2041
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002042 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002044 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002045 }
2046
Sanket Padawe356d7632015-06-22 14:03:32 -07002047 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002048 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002049 final long identity = Binder.clearCallingIdentity();
2050 try {
2051 final Phone phone = PhoneFactory.getPhone(slotIndex);
2052 if (phone == null) {
2053 return PhoneConstants.PHONE_TYPE_NONE;
2054 } else {
2055 return phone.getPhoneType();
2056 }
2057 } finally {
2058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 }
2061
2062 /**
2063 * Returns the CDMA ERI icon index to display
2064 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002065 @Override
2066 public int getCdmaEriIconIndex(String callingPackage) {
2067 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002068 }
2069
Sanket Padawe356d7632015-06-22 14:03:32 -07002070 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002071 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002073 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002074 return -1;
2075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 final Phone phone = getPhone(subId);
2080 if (phone != null) {
2081 return phone.getCdmaEriIconIndex();
2082 } else {
2083 return -1;
2084 }
2085 } finally {
2086 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002087 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 }
2089
2090 /**
2091 * Returns the CDMA ERI icon mode,
2092 * 0 - ON
2093 * 1 - FLASHING
2094 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002095 @Override
2096 public int getCdmaEriIconMode(String callingPackage) {
2097 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002098 }
2099
Sanket Padawe356d7632015-06-22 14:03:32 -07002100 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002101 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002103 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002104 return -1;
2105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106
2107 final long identity = Binder.clearCallingIdentity();
2108 try {
2109 final Phone phone = getPhone(subId);
2110 if (phone != null) {
2111 return phone.getCdmaEriIconMode();
2112 } else {
2113 return -1;
2114 }
2115 } finally {
2116 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
2120 /**
2121 * Returns the CDMA ERI text,
2122 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002123 @Override
2124 public String getCdmaEriText(String callingPackage) {
2125 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002126 }
2127
Sanket Padawe356d7632015-06-22 14:03:32 -07002128 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002129 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002131 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002132 return null;
2133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002134
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final Phone phone = getPhone(subId);
2138 if (phone != null) {
2139 return phone.getCdmaEriText();
2140 } else {
2141 return null;
2142 }
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 }
2147
2148 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002149 * Returns the CDMA MDN.
2150 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002151 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002152 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2154 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002155
2156 final long identity = Binder.clearCallingIdentity();
2157 try {
2158 final Phone phone = getPhone(subId);
2159 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2160 return phone.getLine1Number();
2161 } else {
2162 return null;
2163 }
2164 } finally {
2165 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002166 }
2167 }
2168
2169 /**
2170 * Returns the CDMA MIN.
2171 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002172 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002173 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2175 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176
2177 final long identity = Binder.clearCallingIdentity();
2178 try {
2179 final Phone phone = getPhone(subId);
2180 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2181 return phone.getCdmaMin();
2182 } else {
2183 return null;
2184 }
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002187 }
2188 }
2189
2190 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 * Returns true if CDMA provisioning needs to run.
2192 */
2193 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002194 final long identity = Binder.clearCallingIdentity();
2195 try {
2196 return mPhone.needsOtaServiceProvisioning();
2197 } finally {
2198 Binder.restoreCallingIdentity(identity);
2199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
2202 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002203 * Sets the voice mail number of a given subId.
2204 */
2205 @Override
2206 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002207 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208
2209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2212 new Pair<String, String>(alphaTag, number), new Integer(subId));
2213 return success;
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
2216 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002217 }
2218
Ta-wei Yen87c49842016-05-13 21:19:52 -07002219 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002220 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2221 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2222 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2223 if (!TextUtils.equals(callingPackage, systemDialer)) {
2224 throw new SecurityException("caller must be system dialer");
2225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226
2227 final long identity = Binder.clearCallingIdentity();
2228 try {
2229 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2230 if (phoneAccountHandle == null) {
2231 return null;
2232 }
2233 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2234 } finally {
2235 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002236 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002237 }
2238
2239 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002240 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002241 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002243 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002244 return null;
2245 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002247 final long identity = Binder.clearCallingIdentity();
2248 try {
2249 return RemoteVvmTaskManager
2250 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2251 } finally {
2252 Binder.restoreCallingIdentity(identity);
2253 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002254 }
2255
2256 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002257 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2258 VisualVoicemailSmsFilterSettings settings) {
2259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260
2261 final long identity = Binder.clearCallingIdentity();
2262 try {
2263 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2264 mPhone.getContext(), callingPackage, subId, settings);
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
2267 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002268 }
2269
2270 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002271 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2272 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002273
2274 final long identity = Binder.clearCallingIdentity();
2275 try {
2276 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2277 mPhone.getContext(), callingPackage, subId);
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
2280 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002281 }
2282
2283 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002284 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2285 String callingPackage, int subId) {
2286 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287
2288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2291 mPhone.getContext(), callingPackage, subId);
2292 } finally {
2293 Binder.restoreCallingIdentity(identity);
2294 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002295 }
2296
2297 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002298 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002299 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002300
2301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2304 mPhone.getContext(), subId);
2305 } finally {
2306 Binder.restoreCallingIdentity(identity);
2307 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002308 }
2309
2310 @Override
2311 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2312 String number, int port, String text, PendingIntent sentIntent) {
2313 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002314 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002315 enforceSendSmsPermission();
2316 // Make the calls as the phone process.
2317 final long identity = Binder.clearCallingIdentity();
2318 try {
2319 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2320 if (port == 0) {
2321 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2322 sentIntent, null, false);
2323 } else {
2324 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2325 smsManager.sendDataMessageWithSelfPermissions(number, null,
2326 (short) port, data, sentIntent, null);
2327 }
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
2330 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002331 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002332 /**
fionaxu0152e512016-11-14 13:36:14 -08002333 * Sets the voice activation state of a given subId.
2334 */
2335 @Override
2336 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2338 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339
2340 final long identity = Binder.clearCallingIdentity();
2341 try {
2342 final Phone phone = getPhone(subId);
2343 if (phone != null) {
2344 phone.setVoiceActivationState(activationState);
2345 } else {
2346 loge("setVoiceActivationState fails with invalid subId: " + subId);
2347 }
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002350 }
2351 }
2352
2353 /**
2354 * Sets the data activation state of a given subId.
2355 */
2356 @Override
2357 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2359 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002360
2361 final long identity = Binder.clearCallingIdentity();
2362 try {
2363 final Phone phone = getPhone(subId);
2364 if (phone != null) {
2365 phone.setDataActivationState(activationState);
2366 } else {
2367 loge("setVoiceActivationState fails with invalid subId: " + subId);
2368 }
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002371 }
2372 }
2373
2374 /**
2375 * Returns the voice activation state of a given subId.
2376 */
2377 @Override
2378 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002379 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002380
fionaxu0152e512016-11-14 13:36:14 -08002381 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 if (phone != null) {
2385 return phone.getVoiceActivationState();
2386 } else {
2387 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2388 }
2389 } finally {
2390 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002391 }
2392 }
2393
2394 /**
2395 * Returns the data activation state of a given subId.
2396 */
2397 @Override
2398 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002399 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002400
fionaxu0152e512016-11-14 13:36:14 -08002401 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002402 final long identity = Binder.clearCallingIdentity();
2403 try {
2404 if (phone != null) {
2405 return phone.getDataActivationState();
2406 } else {
2407 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2408 }
2409 } finally {
2410 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002411 }
2412 }
2413
2414 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 * Returns the unread count of voicemails
2416 */
2417 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002418 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002419 }
2420
2421 /**
2422 * Returns the unread count of voicemails for a subId
2423 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002424 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002425 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 final Phone phone = getPhone(subId);
2429 if (phone != null) {
2430 return phone.getVoiceMessageCount();
2431 } else {
2432 return 0;
2433 }
2434 } finally {
2435 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002437 }
2438
2439 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002440 * returns true, if the device is in a state where both voice and data
2441 * are supported simultaneously. This can change based on location or network condition.
2442 */
2443 @Override
2444 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 final long identity = Binder.clearCallingIdentity();
2446 try {
2447 final Phone phone = getPhone(subId);
2448 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
2451 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002452 }
2453
2454 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002455 * Send the dialer code if called from the current default dialer or the caller has
2456 * carrier privilege.
2457 * @param inputCode The dialer code to send
2458 */
2459 @Override
2460 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2462 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2463 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002464 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2465 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002466 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467
2468 final long identity = Binder.clearCallingIdentity();
2469 try {
2470 mPhone.sendDialerSpecialCode(inputCode);
2471 } finally {
2472 Binder.restoreCallingIdentity(identity);
2473 }
fionaxu235cc5e2017-03-06 22:25:57 -08002474 }
2475
2476 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002477 * Returns the data network type.
2478 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002479 *
2480 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2481 */
2482 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002483 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 final long identity = Binder.clearCallingIdentity();
2485 try {
2486 final Phone phone = getPhone(getDefaultSubscription());
2487 if (phone != null) {
2488 return phone.getServiceState().getDataNetworkType();
2489 } else {
2490 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2491 }
2492 } finally {
2493 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002494 }
Wink Saville36469e72014-06-11 15:17:00 -07002495 }
2496
Pengquan Menga1bb6272018-09-06 09:59:22 -07002497 @Override
2498 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002499 if (!isActiveSubscription(subId)) {
2500 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2501 }
2502
Pengquan Menga1bb6272018-09-06 09:59:22 -07002503 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2504 }
2505
Brad Ebinger35c841c2018-10-01 10:40:55 -07002506 @Override
2507 public void addImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2508 String callingPackage) throws RemoteException {
2509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2510 "addImsRegistrationCallback")) {
2511 return;
2512 }
2513 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2514 final long token = Binder.clearCallingIdentity();
2515 try {
2516 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2517 .addRegistrationCallbackForSubscription(c, subId);
2518 } finally {
2519 Binder.restoreCallingIdentity(token);
2520 }
2521 }
2522
2523 @Override
2524 public void removeImsRegistrationCallback(int subId, IImsRegistrationCallback c,
2525 String callingPackage) {
2526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2527 "removeImsRegistrationCallback")) {
2528 return;
2529 }
2530 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2531 Binder.withCleanCallingIdentity(() ->
2532 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2533 .removeRegistrationCallbackForSubscription(c, subId));
2534 }
2535
2536 @Override
2537 public void addMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2538 String callingPackage) throws RemoteException {
2539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2540 "addMmTelCapabilityCallback")) {
2541 return;
2542 }
2543 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2544 final long token = Binder.clearCallingIdentity();
2545 try {
2546 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2547 .addCapabilitiesCallbackForSubscription(c, subId);
2548 } finally {
2549 Binder.restoreCallingIdentity(token);
2550 }
2551 }
2552
2553 @Override
2554 public void removeMmTelCapabilityCallback(int subId, IImsCapabilityCallback c,
2555 String callingPackage) {
2556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2557 "removeMmTelCapabilityCallback")) {
2558 return;
2559 }
2560 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2561 Binder.withCleanCallingIdentity(() ->
2562 ImsManager.getInstance(mPhone.getContext(), getSlotIndexOrException(subId))
2563 .removeCapabilitiesCallbackForSubscription(c, subId));
2564 }
2565
2566 @Override
2567 public boolean isCapable(int subId, int capability, int regTech, String callingPackage) {
2568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2569 "isCapable")) {
2570 return false;
2571 }
2572 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2573 final long token = Binder.clearCallingIdentity();
2574 try {
2575 return ImsManager.getInstance(mPhone.getContext(),
2576 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2577 } catch (ImsException e) {
2578 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2579 return false;
2580 } finally {
2581 Binder.restoreCallingIdentity(token);
2582 }
2583 }
2584
2585 @Override
2586 public boolean isAvailable(int subId, int capability, int regTech, String callingPackage) {
2587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2588 "isAvailable")) {
2589 return false;
2590 }
2591 final long token = Binder.clearCallingIdentity();
2592 try {
2593 Phone phone = getPhone(subId);
2594 if (phone == null) return false;
2595 return phone.isImsCapabilityAvailable(capability, regTech);
2596 } finally {
2597 Binder.restoreCallingIdentity(token);
2598 }
2599 }
2600
2601 @Override
2602 public boolean isAdvancedCallingSettingEnabled(int subId) {
2603 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2604 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2605 final long token = Binder.clearCallingIdentity();
2606 try {
2607 return ImsManager.getInstance(mPhone.getContext(),
2608 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2609 } finally {
2610 Binder.restoreCallingIdentity(token);
2611 }
2612 }
2613
2614 @Override
2615 public void setAdvancedCallingSetting(int subId, boolean isEnabled) {
2616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2617 "setAdvancedCallingSetting");
2618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2621 ImsManager.getInstance(mPhone.getContext(),
2622 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
2625 }
2626 }
2627
2628 @Override
2629 public boolean isVtSettingEnabled(int subId, String callingPackage) {
2630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2631 "isVtSettingEnabled")) {
2632 return false;
2633 }
2634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2637 return ImsManager.getInstance(mPhone.getContext(),
2638 getSlotIndexOrException(subId)).isVtEnabledByUser();
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
2641 }
2642 }
2643
2644 @Override
2645 public void setVtSetting(int subId, boolean isEnabled) {
2646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2647 "setVtSetting");
2648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2651 ImsManager.getInstance(mPhone.getContext(),
2652 getSlotIndexOrException(subId)).setVtSetting(isEnabled);
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
2655 }
2656 }
2657
2658 @Override
2659 public boolean isVoWiFiSettingEnabled(int subId) {
2660 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2664 return ImsManager.getInstance(mPhone.getContext(),
2665 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
2669 }
2670
2671 @Override
2672 public void setVoWiFiSetting(int subId, boolean isEnabled) {
2673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2674 "setVoWiFiSetting");
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2678 ImsManager.getInstance(mPhone.getContext(),
2679 getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
2680 } finally {
2681 Binder.restoreCallingIdentity(identity);
2682 }
2683 }
2684
2685 @Override
2686 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2687 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2691 return ImsManager.getInstance(mPhone.getContext(),
2692 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
2695 }
2696 }
2697
2698 @Override
2699 public void setVoWiFiRoamingSetting(int subId, boolean isEnabled) {
2700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2701 "setVoWiFiRoamingSetting");
2702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2705 ImsManager.getInstance(mPhone.getContext(),
2706 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
2710 }
2711
2712 @Override
2713 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2715 "setVoWiFiNonPersistent");
2716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2719 ImsManager.getInstance(mPhone.getContext(),
2720 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
2723 }
2724 }
2725
2726 @Override
2727 public int getVoWiFiModeSetting(int subId) {
2728 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
2729 final long identity = Binder.clearCallingIdentity();
2730 try {
2731 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2732 return ImsManager.getInstance(mPhone.getContext(),
2733 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
2736 }
2737 }
2738
2739 @Override
2740 public void setVoWiFiModeSetting(int subId, int mode) {
2741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2742 "setVoWiFiModeSetting");
2743 final long identity = Binder.clearCallingIdentity();
2744 try {
2745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2746 ImsManager.getInstance(mPhone.getContext(),
2747 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
2748 } finally {
2749 Binder.restoreCallingIdentity(identity);
2750 }
2751 }
2752
2753 @Override
2754 public int getVoWiFiRoamingModeSetting(int subId) {
2755 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
2756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2759 return ImsManager.getInstance(mPhone.getContext(),
2760 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
2761 } finally {
2762 Binder.restoreCallingIdentity(identity);
2763 }
2764 }
2765
2766 @Override
2767 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
2768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2769 "setVoWiFiRoamingModeSetting");
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2773 ImsManager.getInstance(mPhone.getContext(),
2774 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
2777 }
2778 }
2779
2780 @Override
2781 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
2782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2783 "setRttCapabilityEnabled");
2784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2787 ImsManager.getInstance(mPhone.getContext(),
2788 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
2791 }
2792 }
2793
2794 @Override
2795 public boolean isTtyOverVolteEnabled(int subId) {
2796 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2800 return ImsManager.getInstance(mPhone.getContext(),
2801 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
2802 } finally {
2803 Binder.restoreCallingIdentity(identity);
2804 }
2805 }
2806
2807 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
2808 int slotId = SubscriptionManager.getSlotIndex(subId);
2809 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
2810 throw new IllegalArgumentException("Invalid Subscription Id.");
2811 }
2812 return slotId;
2813 }
2814
Wink Saville36469e72014-06-11 15:17:00 -07002815 /**
2816 * Returns the network type for a subId
2817 */
2818 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002819 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002820 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002821 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002822 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2823 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 final Phone phone = getPhone(subId);
2828 if (phone != null) {
2829 return phone.getServiceState().getDataNetworkType();
2830 } else {
2831 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2832 }
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836 }
2837
2838 /**
2839 * Returns the data network type
2840 */
2841 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002842 public int getDataNetworkType(String callingPackage) {
2843 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002844 }
2845
2846 /**
2847 * Returns the data network type for a subId
2848 */
2849 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002850 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002852 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002853 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2854 }
2855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 final Phone phone = getPhone(subId);
2859 if (phone != null) {
2860 return phone.getServiceState().getDataNetworkType();
2861 } else {
2862 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2863 }
2864 } finally {
2865 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 }
2868
2869 /**
Wink Saville36469e72014-06-11 15:17:00 -07002870 * Returns the Voice network type for a subId
2871 */
2872 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002873 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002875 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002876 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2877 }
2878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 final Phone phone = getPhone(subId);
2882 if (phone != null) {
2883 return phone.getServiceState().getVoiceNetworkType();
2884 } else {
2885 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2886 }
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
2892 /**
2893 * @return true if a ICC card is present
2894 */
2895 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002896 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002897 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2898 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002899 }
2900
2901 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002902 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002903 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002904 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002905 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 final Phone phone = PhoneFactory.getPhone(slotIndex);
2909 if (phone != null) {
2910 return phone.getIccCard().hasIccCard();
2911 } else {
2912 return false;
2913 }
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002917 }
2918
2919 /**
2920 * Return if the current radio is LTE on CDMA. This
2921 * is a tri-state return value as for a period of time
2922 * the mode may be unknown.
2923 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002924 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002925 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002926 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002928 @Override
2929 public int getLteOnCdmaMode(String callingPackage) {
2930 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002931 }
2932
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002934 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002936 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002937 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2938 }
2939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 final Phone phone = getPhone(subId);
2943 if (phone == null) {
2944 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2945 } else {
2946 return phone.getLteOnCdmaMode();
2947 }
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002950 }
Wink Saville36469e72014-06-11 15:17:00 -07002951 }
2952
2953 public void setPhone(Phone phone) {
2954 mPhone = phone;
2955 }
2956
2957 /**
2958 * {@hide}
2959 * Returns Default subId, 0 in the case of single standby.
2960 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002961 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002962 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002963 }
2964
Shishir Agrawala9f32182016-04-12 12:00:16 -07002965 private int getSlotForDefaultSubscription() {
2966 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2967 }
2968
Wink Savilleb564aae2014-10-23 10:18:09 -07002969 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002970 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002972
Pengquan Menge92a50d2018-09-21 15:54:48 -07002973 private boolean isActiveSubscription(int subId) {
2974 return mSubscriptionController.isActiveSubId(subId);
2975 }
2976
Ihab Awadf2177b72013-11-25 13:33:23 -08002977 /**
2978 * @see android.telephony.TelephonyManager.WifiCallingChoices
2979 */
2980 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2984 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2985 getWhenToMakeWifiCallsDefaultPreference());
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002989 }
2990
2991 /**
2992 * @see android.telephony.TelephonyManager.WifiCallingChoices
2993 */
2994 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2998 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2999 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003003 }
3004
Sailesh Nepald1e68152013-12-12 19:08:02 -08003005 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003006 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003007 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003008 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003009
Shishir Agrawal566b7612013-10-28 14:41:00 -07003010 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003011 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3012 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3014 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 if (TextUtils.equals(ISDR_AID, aid)) {
3020 // Only allows LPA to open logical channel to ISD-R.
3021 ComponentInfo bestComponent =
3022 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3023 if (bestComponent == null
3024 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3025 loge("The calling package is not allowed to access ISD-R.");
3026 throw new SecurityException(
3027 "The calling package is not allowed to access ISD-R.");
3028 }
Derek Tan740e1672017-06-27 14:56:27 -07003029 }
Derek Tan740e1672017-06-27 14:56:27 -07003030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031 if (DBG) {
3032 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3033 }
3034 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3035 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3036 if (DBG) log("iccOpenLogicalChannel: " + response);
3037 return response;
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003041 }
3042
3043 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003044 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3046 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3051 if (channel < 0) {
3052 return false;
3053 }
3054 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3055 if (DBG) log("iccCloseLogicalChannel: " + success);
3056 return success;
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003059 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003060 }
3061
3062 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003063 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003064 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3066 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 if (DBG) {
3071 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3072 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3073 + p3 + " data=" + data);
3074 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003076 if (channel < 0) {
3077 return "";
3078 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3081 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3082 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084 // Append the returned status code to the end of the response payload.
3085 String s = Integer.toHexString(
3086 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3087 if (response.payload != null) {
3088 s = IccUtils.bytesToHexString(response.payload) + s;
3089 }
3090 return s;
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003093 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003094 }
Jake Hambye994d462014-02-03 13:10:13 -08003095
Evan Charltonc66da362014-05-16 14:06:40 -07003096 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003097 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3098 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3100 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3106 && TextUtils.equals(ISDR_AID, data)) {
3107 // Only allows LPA to select ISD-R.
3108 ComponentInfo bestComponent =
3109 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
3110 if (bestComponent == null
3111 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3112 loge("The calling package is not allowed to select ISD-R.");
3113 throw new SecurityException(
3114 "The calling package is not allowed to select ISD-R.");
3115 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003116 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 if (DBG) {
3119 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3120 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3121 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3124 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3125 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127 // Append the returned status code to the end of the response payload.
3128 String s = Integer.toHexString(
3129 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3130 if (response.payload != null) {
3131 s = IccUtils.bytesToHexString(response.payload) + s;
3132 }
3133 return s;
3134 } finally {
3135 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003136 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003137 }
3138
3139 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003140 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003141 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3143 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 if (DBG) {
3148 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3149 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3150 }
3151
3152 IccIoResult response =
3153 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3154 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3155 subId);
3156
3157 if (DBG) {
3158 log("Exchange SIM_IO [R]" + response);
3159 }
3160
3161 byte[] result = null;
3162 int length = 2;
3163 if (response.payload != null) {
3164 length = 2 + response.payload.length;
3165 result = new byte[length];
3166 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3167 } else {
3168 result = new byte[length];
3169 }
3170
3171 result[length - 1] = (byte) response.sw2;
3172 result[length - 2] = (byte) response.sw1;
3173 return result;
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003176 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003177 }
3178
Nathan Haroldb3014052017-01-25 15:57:32 -08003179 /**
3180 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3181 * on a particular subscription
3182 */
sqianb6e41952018-03-12 14:54:01 -07003183 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3185 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3186 return null;
3187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188
3189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 if (appType != TelephonyManager.APPTYPE_USIM
3192 && appType != TelephonyManager.APPTYPE_SIM) {
3193 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3194 return null;
3195 }
3196 Object response = sendRequest(
3197 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3198 if (response instanceof String[]) {
3199 return (String[]) response;
3200 }
3201 // Response is an Exception of some kind,
3202 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003203 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 } finally {
3205 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003206 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003207 }
3208
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003209 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003210 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3212 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3217 if (response.payload == null) {
3218 return "";
3219 }
Evan Charltonc66da362014-05-16 14:06:40 -07003220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 // Append the returned status code to the end of the response payload.
3222 String s = Integer.toHexString(
3223 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3224 s = IccUtils.bytesToHexString(response.payload) + s;
3225 return s;
3226 } finally {
3227 Binder.restoreCallingIdentity(identity);
3228 }
Evan Charltonc66da362014-05-16 14:06:40 -07003229 }
3230
Jake Hambye994d462014-02-03 13:10:13 -08003231 /**
3232 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3233 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3234 *
3235 * @param itemID the ID of the item to read
3236 * @return the NV item as a String, or null on error.
3237 */
3238 @Override
3239 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003240 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3242 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003243
3244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003247 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3249 return value;
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
3252 }
Jake Hambye994d462014-02-03 13:10:13 -08003253 }
3254
3255 /**
3256 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3257 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3258 *
3259 * @param itemID the ID of the item to read
3260 * @param itemValue the value to write, as a String
3261 * @return true on success; false on any failure
3262 */
3263 @Override
3264 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003265 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3267 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268
3269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3272 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003273 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3275 return success;
3276 } finally {
3277 Binder.restoreCallingIdentity(identity);
3278 }
Jake Hambye994d462014-02-03 13:10:13 -08003279 }
3280
3281 /**
3282 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3283 * Used for device configuration by some CDMA operators.
3284 *
3285 * @param preferredRoamingList byte array containing the new PRL
3286 * @return true on success; false on any failure
3287 */
3288 @Override
3289 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3296 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3297 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3298 return success;
3299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
Jake Hambye994d462014-02-03 13:10:13 -08003302 }
3303
3304 /**
3305 * Perform the specified type of NV config reset.
3306 * Used for device configuration by some CDMA operators.
3307 *
3308 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3309 * @return true on success; false on any failure
3310 */
3311 @Override
3312 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3314 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315
3316 final long identity = Binder.clearCallingIdentity();
3317 try {
3318 if (DBG) log("nvResetConfig: type " + resetType);
3319 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3320 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3321 return success;
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
Jake Hambye994d462014-02-03 13:10:13 -08003325 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003326
Svet Ganovb320e182015-04-16 12:30:10 -07003327 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003329 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003330 return new String[0];
3331 }
3332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 return mPhone.getPcscfAddress(apnType);
3336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
Wink Saville36469e72014-06-11 15:17:00 -07003339 }
3340
Brad Ebinger51f743a2017-01-23 13:50:20 -08003341 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003342 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3343 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003344 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003345 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003346 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 PhoneFactory.getImsResolver().enableIms(slotId);
3351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003354 }
3355
3356 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003357 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3358 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003359 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003360 public void disableIms(int slotId) {
3361 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362
3363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 PhoneFactory.getImsResolver().disableIms(slotId);
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003369 }
3370
3371 /**
3372 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3373 * feature or {@link null} if the service is not available. If the feature is available, the
3374 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3375 */
3376 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003377 IImsServiceFeatureCallback callback) {
3378 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379
3380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003386 }
3387
3388 /**
3389 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3390 * feature during emergency calling or {@link null} if the service is not available. If the
3391 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3392 * listener for feature updates.
3393 */
3394 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3395 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003396
3397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003403 }
3404
Brad Ebinger5f64b052017-12-14 14:26:15 -08003405 /**
3406 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3407 * specified.
3408 */
3409 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3410 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411
3412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003418 }
3419
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003420 /**
3421 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3422 * specified.
3423 */
3424 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3425 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003426
3427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003433 }
3434
Brad Ebinger884c07b2018-02-15 16:17:40 -08003435 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003436 * Sets the ImsService Package Name that Telephony will bind to.
3437 *
3438 * @param slotId the slot ID that the ImsService should bind for.
3439 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3440 * ImsService is the device default ImsService.
3441 * @param packageName The package name of the application that contains the ImsService to bind
3442 * to.
3443 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3444 * @hide
3445 */
3446 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003447 int[] subIds = SubscriptionManager.getSubId(slotId);
3448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3449 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3450 "setImsService");
3451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452 final long identity = Binder.clearCallingIdentity();
3453 try {
3454 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3455 isCarrierImsService, packageName);
3456 } finally {
3457 Binder.restoreCallingIdentity(identity);
3458 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003459 }
3460
3461 /**
3462 * Return the ImsService configuration.
3463 *
3464 * @param slotId The slot that the ImsService is associated with.
3465 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3466 * the device default.
3467 * @return the package name of the ImsService configuration.
3468 */
3469 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003470 int[] subIds = SubscriptionManager.getSubId(slotId);
3471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3472 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3473 "getImsService");
3474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003475 final long identity = Binder.clearCallingIdentity();
3476 try {
3477 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3478 isCarrierImsService);
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003482 }
3483
Wink Saville36469e72014-06-11 15:17:00 -07003484 public void setImsRegistrationState(boolean registered) {
3485 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003486
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 mPhone.setImsRegistrationState(registered);
3490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
Wink Saville36469e72014-06-11 15:17:00 -07003493 }
3494
3495 /**
Stuart Scott54788802015-03-30 13:18:01 -07003496 * Set the network selection mode to automatic.
3497 *
3498 */
3499 @Override
3500 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3502 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503
Pengquan Menge92a50d2018-09-21 15:54:48 -07003504 if (!isActiveSubscription(subId)) {
3505 return;
3506 }
3507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3511 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
Stuart Scott54788802015-03-30 13:18:01 -07003515 }
3516
Pengquan Mengea84e042018-09-20 14:57:26 -07003517 /**
3518 * Ask the radio to connect to the input network and change selection mode to manual.
3519 *
3520 * @param subId the id of the subscription.
3521 * @param operatorInfo the operator information, included the PLMN, long name and short name of
3522 * the operator to attach to.
3523 * @param persistSelection whether the selection will persist until reboot. If true, only allows
3524 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
3525 * normal network selection next time.
3526 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07003527 */
3528 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07003529 public boolean setNetworkSelectionModeManual(
3530 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3532 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07003533
3534 if (!isActiveSubscription(subId)) {
3535 return false;
3536 }
3537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538 final long identity = Binder.clearCallingIdentity();
3539 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07003540 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003541 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07003542 if (DBG) {
3543 log("setNetworkSelectionModeManual: subId: " + subId
3544 + " operator: " + operatorInfo);
3545 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
3549 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003550 }
3551
3552 /**
3553 * Scans for available networks.
3554 */
3555 @Override
3556 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3558 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559
Pengquan Menga1bb6272018-09-06 09:59:22 -07003560 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561 try {
3562 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003563 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 } finally {
3566 Binder.restoreCallingIdentity(identity);
3567 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003568 }
3569
3570 /**
yinxub1bed742017-04-17 11:45:04 -07003571 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003572 *
yinxub1bed742017-04-17 11:45:04 -07003573 * @param subId id of the subscription
3574 * @param request contains the radio access networks with bands/channels to scan
3575 * @param messenger callback messenger for scan results or errors
3576 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003577 * @return the id of the requested scan which can be used to stop the scan.
3578 */
3579 @Override
3580 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3581 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3583 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584
3585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 return mNetworkScanRequestTracker.startNetworkScan(
3588 request, messenger, binder, getPhone(subId));
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
yinxu504e1392017-04-12 16:03:22 -07003592 }
3593
3594 /**
3595 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003596 *
3597 * @param subId id of the subscription
3598 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003599 */
3600 @Override
3601 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3603 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604
3605 final long identity = Binder.clearCallingIdentity();
3606 try {
3607 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3608 } finally {
3609 Binder.restoreCallingIdentity(identity);
3610 }
yinxu504e1392017-04-12 16:03:22 -07003611 }
3612
3613 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003614 * Get the calculated preferred network type.
3615 * Used for debugging incorrect network type.
3616 *
3617 * @return the preferred network type, defined in RILConstants.java.
3618 */
3619 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003620 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003622 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003623 return RILConstants.PREFERRED_NETWORK_MODE;
3624 }
3625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 // FIXME: need to get SubId from somewhere.
3629 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
Junda Liu84d15a22014-07-02 11:21:04 -07003633 }
3634
3635 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003636 * Get the preferred network type.
3637 * Used for device configuration by some CDMA operators.
3638 *
3639 * @return the preferred network type, defined in RILConstants.java.
3640 */
3641 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003642 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3644 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645
3646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 if (DBG) log("getPreferredNetworkType");
3649 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3650 int networkType = (result != null ? result[0] : -1);
3651 if (DBG) log("getPreferredNetworkType: " + networkType);
3652 return networkType;
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003656 }
3657
3658 /**
3659 * Set the preferred network type.
3660 * Used for device configuration by some CDMA operators.
3661 *
3662 * @param networkType the preferred network type, defined in RILConstants.java.
3663 * @return true on success; false on any failure.
3664 */
3665 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003666 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3668 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3673 Boolean success = (Boolean) sendRequest(
3674 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3675 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3676 if (success) {
3677 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3678 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3679 }
3680 return success;
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003683 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003684 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003685
3686 /**
Junda Liu475951f2014-11-07 16:45:03 -08003687 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3688 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3689 * tethering.
3690 *
3691 * @return 0: Not required. 1: required. 2: Not set.
3692 * @hide
3693 */
3694 @Override
3695 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003696 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003697
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3701 Settings.Global.TETHER_DUN_REQUIRED, 2);
3702 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3703 // config_tether_apndata.
3704 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3705 dunRequired = 1;
3706 }
3707 return dunRequired;
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003710 }
Junda Liu475951f2014-11-07 16:45:03 -08003711 }
3712
3713 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003714 * Set mobile data enabled
3715 * Used by the user through settings etc to turn on/off mobile data
3716 *
3717 * @param enable {@code true} turn turn data on, else {@code false}
3718 */
3719 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003720 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3722 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 int phoneId = mSubscriptionController.getPhoneId(subId);
3727 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3728 Phone phone = PhoneFactory.getPhone(phoneId);
3729 if (phone != null) {
3730 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3731 phone.setUserDataEnabled(enable);
3732 } else {
3733 loge("setUserDataEnabled: no phone for subId=" + subId);
3734 }
3735 } finally {
3736 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003737 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003738 }
3739
3740 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003741 * Get the user enabled state of Mobile Data.
3742 *
3743 * TODO: remove and use isUserDataEnabled.
3744 * This can't be removed now because some vendor codes
3745 * calls through ITelephony directly while they should
3746 * use TelephonyManager.
3747 *
3748 * @return true on enabled
3749 */
3750 @Override
3751 public boolean getDataEnabled(int subId) {
3752 return isUserDataEnabled(subId);
3753 }
3754
3755 /**
3756 * Get whether mobile data is enabled per user setting.
3757 *
3758 * There are other factors deciding whether mobile data is actually enabled, but they are
3759 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003760 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003761 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003762 *
3763 * @return {@code true} if data is enabled else {@code false}
3764 */
3765 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003766 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003767 try {
3768 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3769 null);
3770 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3772 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774
3775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 int phoneId = mSubscriptionController.getPhoneId(subId);
3778 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3779 Phone phone = PhoneFactory.getPhone(phoneId);
3780 if (phone != null) {
3781 boolean retVal = phone.isUserDataEnabled();
3782 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3783 return retVal;
3784 } else {
3785 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3786 return false;
3787 }
3788 } finally {
3789 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003790 }
3791 }
3792
3793 /**
3794 * Get whether mobile data is enabled.
3795 *
3796 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3797 * whether mobile data is actually enabled.
3798 *
3799 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3800 *
3801 * @return {@code true} if data is enabled else {@code false}
3802 */
3803 @Override
3804 public boolean isDataEnabled(int subId) {
3805 try {
3806 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3807 null);
3808 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3810 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
3813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 int phoneId = mSubscriptionController.getPhoneId(subId);
3816 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3817 Phone phone = PhoneFactory.getPhone(phoneId);
3818 if (phone != null) {
3819 boolean retVal = phone.isDataEnabled();
3820 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3821 return retVal;
3822 } else {
3823 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3824 return false;
3825 }
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003828 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003829 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003830
3831 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003832 public int getCarrierPrivilegeStatus(int subId) {
3833 final Phone phone = getPhone(subId);
3834 if (phone == null) {
3835 loge("getCarrierPrivilegeStatus: Invalid subId");
3836 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3837 }
3838 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003839 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003840 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003841 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3842 }
3843 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003844 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003845 }
Junda Liu29340342014-07-10 15:23:27 -07003846
3847 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003848 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3849 final Phone phone = getPhone(subId);
3850 if (phone == null) {
3851 loge("getCarrierPrivilegeStatus: Invalid subId");
3852 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3853 }
3854 UiccProfile profile =
3855 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3856 if (profile == null) {
3857 loge("getCarrierPrivilegeStatus: No UICC");
3858 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3859 }
3860 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3861 }
3862
3863 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003864 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003865 if (TextUtils.isEmpty(pkgName))
3866 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003867 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003868 if (card == null) {
3869 loge("checkCarrierPrivilegesForPackage: No UICC");
3870 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3871 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003872 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3873 }
3874
3875 @Override
3876 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003877 if (TextUtils.isEmpty(pkgName))
3878 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003879 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3880 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3881 UiccCard card = UiccController.getInstance().getUiccCard(i);
3882 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003883 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003884 continue;
3885 }
3886
3887 result = card.getCarrierPrivilegeStatus(
3888 mPhone.getContext().getPackageManager(), pkgName);
3889 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3890 break;
3891 }
3892 }
3893
3894 return result;
Junda Liu29340342014-07-10 15:23:27 -07003895 }
Derek Tan89e89d42014-07-08 17:00:10 -07003896
3897 @Override
Junda Liue64de782015-04-16 17:19:16 -07003898 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3899 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3900 loge("phoneId " + phoneId + " is not valid.");
3901 return null;
3902 }
3903 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003904 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003905 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003906 return null ;
3907 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003908 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003909 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003910 }
3911
Amith Yamasani6e118872016-02-19 12:53:51 -08003912 @Override
3913 public List<String> getPackagesWithCarrierPrivileges() {
3914 PackageManager pm = mPhone.getContext().getPackageManager();
3915 List<String> privilegedPackages = new ArrayList<>();
3916 List<PackageInfo> packages = null;
3917 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3918 UiccCard card = UiccController.getInstance().getUiccCard(i);
3919 if (card == null) {
3920 // No UICC in that slot.
3921 continue;
3922 }
3923 if (card.hasCarrierPrivilegeRules()) {
3924 if (packages == null) {
3925 // Only check packages in user 0 for now
3926 packages = pm.getInstalledPackagesAsUser(
3927 PackageManager.MATCH_DISABLED_COMPONENTS
3928 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3929 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3930 }
3931 for (int p = packages.size() - 1; p >= 0; p--) {
3932 PackageInfo pkgInfo = packages.get(p);
3933 if (pkgInfo != null && pkgInfo.packageName != null
3934 && card.getCarrierPrivilegeStatus(pkgInfo)
3935 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3936 privilegedPackages.add(pkgInfo.packageName);
3937 }
3938 }
3939 }
3940 }
3941 return privilegedPackages;
3942 }
3943
Wink Savilleb564aae2014-10-23 10:18:09 -07003944 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003945 final Phone phone = getPhone(subId);
3946 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003947 if (card == null) {
3948 loge("getIccId: No UICC");
3949 return null;
3950 }
3951 String iccId = card.getIccId();
3952 if (TextUtils.isEmpty(iccId)) {
3953 loge("getIccId: ICC ID is null or empty.");
3954 return null;
3955 }
3956 return iccId;
3957 }
3958
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003959 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003960 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3961 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003962 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3963 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 final String iccId = getIccId(subId);
3968 final Phone phone = getPhone(subId);
3969 if (phone == null) {
3970 return false;
3971 }
3972 final String subscriberId = phone.getSubscriberId();
3973
3974 if (DBG_MERGE) {
3975 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3976 + subscriberId + " to " + number);
3977 }
3978
3979 if (TextUtils.isEmpty(iccId)) {
3980 return false;
3981 }
3982
3983 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3984
3985 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3986 if (alphaTag == null) {
3987 editor.remove(alphaTagPrefKey);
3988 } else {
3989 editor.putString(alphaTagPrefKey, alphaTag);
3990 }
3991
3992 // Record both the line number and IMSI for this ICCID, since we need to
3993 // track all merged IMSIs based on line number
3994 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3995 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3996 if (number == null) {
3997 editor.remove(numberPrefKey);
3998 editor.remove(subscriberPrefKey);
3999 } else {
4000 editor.putString(numberPrefKey, number);
4001 editor.putString(subscriberPrefKey, subscriberId);
4002 }
4003
4004 editor.commit();
4005 return true;
4006 } finally {
4007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004008 }
Derek Tan7226c842014-07-02 17:42:23 -07004009 }
4010
4011 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004012 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004013 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004015 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004016 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004017 return null;
4018 }
Derek Tan97ebb422014-09-05 16:55:38 -07004019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 String iccId = getIccId(subId);
4023 if (iccId != null) {
4024 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4025 if (DBG_MERGE) {
4026 log("getLine1NumberForDisplay returning "
4027 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4028 }
4029 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4032 return null;
4033 } finally {
4034 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004035 }
Derek Tan7226c842014-07-02 17:42:23 -07004036 }
4037
4038 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004039 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004041 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004042 return null;
4043 }
Derek Tan97ebb422014-09-05 16:55:38 -07004044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 String iccId = getIccId(subId);
4048 if (iccId != null) {
4049 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4050 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4051 }
4052 return null;
4053 } finally {
4054 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004055 }
Derek Tan7226c842014-07-02 17:42:23 -07004056 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004057
4058 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004059 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004060 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4061 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004063 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4064 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004065 return null;
4066 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004067
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004068 final long identity = Binder.clearCallingIdentity();
4069 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 final Context context = mPhone.getContext();
4071 final TelephonyManager tele = TelephonyManager.from(context);
4072 final SubscriptionManager sub = SubscriptionManager.from(context);
4073
4074 // Figure out what subscribers are currently active
4075 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4076 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4077 // the process, where TelephonyManager was instantiated.
4078 // Otherwise AppOps check will fail.
4079
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004080 final int[] subIds = sub.getActiveSubscriptionIdList();
4081 for (int subId : subIds) {
4082 activeSubscriberIds.add(tele.getSubscriberId(subId));
4083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084
4085 // First pass, find a number override for an active subscriber
4086 String mergeNumber = null;
4087 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4088 for (String key : prefs.keySet()) {
4089 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4090 final String subscriberId = (String) prefs.get(key);
4091 if (activeSubscriberIds.contains(subscriberId)) {
4092 final String iccId = key.substring(
4093 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4094 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4095 mergeNumber = (String) prefs.get(numberKey);
4096 if (DBG_MERGE) {
4097 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4098 + " for active subscriber " + subscriberId);
4099 }
4100 if (!TextUtils.isEmpty(mergeNumber)) {
4101 break;
4102 }
4103 }
4104 }
4105 }
4106
4107 // Shortcut when no active merged subscribers
4108 if (TextUtils.isEmpty(mergeNumber)) {
4109 return null;
4110 }
4111
4112 // Second pass, find all subscribers under that line override
4113 final ArraySet<String> result = new ArraySet<>();
4114 for (String key : prefs.keySet()) {
4115 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4116 final String number = (String) prefs.get(key);
4117 if (mergeNumber.equals(number)) {
4118 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4119 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4120 final String subscriberId = (String) prefs.get(subscriberKey);
4121 if (!TextUtils.isEmpty(subscriberId)) {
4122 result.add(subscriberId);
4123 }
4124 }
4125 }
4126 }
4127
4128 final String[] resultArray = result.toArray(new String[result.size()]);
4129 Arrays.sort(resultArray);
4130 if (DBG_MERGE) {
4131 Slog.d(LOG_TAG,
4132 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4133 }
4134 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004135 } finally {
4136 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004137 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004138 }
4139
4140 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004141 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004142 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4143 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144
4145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 final Phone phone = getPhone(subId);
4148 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
4151 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004152 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004153
4154 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004155 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004156 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4157 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004158 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004159
4160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 final Phone phone = getPhone(subId);
4163 if (phone == null) {
4164 return false;
4165 }
4166 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4167 cdmaNonRoamingList);
4168 } finally {
4169 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004170 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004171 }
4172
4173 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004174 @Deprecated
4175 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4176 enforceModifyPermission();
4177
4178 int returnValue = 0;
4179 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004180 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004181 if(result.exception == null) {
4182 if (result.result != null) {
4183 byte[] responseData = (byte[])(result.result);
4184 if(responseData.length > oemResp.length) {
4185 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4186 responseData.length + "bytes. Buffer Size is " +
4187 oemResp.length + "bytes.");
4188 }
4189 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4190 returnValue = responseData.length;
4191 }
4192 } else {
4193 CommandException ex = (CommandException) result.exception;
4194 returnValue = ex.getCommandError().ordinal();
4195 if(returnValue > 0) returnValue *= -1;
4196 }
4197 } catch (RuntimeException e) {
4198 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4199 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4200 if(returnValue > 0) returnValue *= -1;
4201 }
4202
4203 return returnValue;
4204 }
4205
4206 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004207 public void setRadioCapability(RadioAccessFamily[] rafs) {
4208 try {
4209 ProxyController.getInstance().setRadioCapability(rafs);
4210 } catch (RuntimeException e) {
4211 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4212 }
4213 }
4214
4215 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004216 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004217 Phone phone = PhoneFactory.getPhone(phoneId);
4218 if (phone == null) {
4219 return RadioAccessFamily.RAF_UNKNOWN;
4220 }
4221 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004223 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004224 return RadioAccessFamily.RAF_UNKNOWN;
4225 }
4226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227 final long identity = Binder.clearCallingIdentity();
4228 try {
4229 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4230 } finally {
4231 Binder.restoreCallingIdentity(identity);
4232 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004233 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004234
4235 @Override
4236 public void enableVideoCalling(boolean enable) {
4237 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238
4239 final long identity = Binder.clearCallingIdentity();
4240 try {
4241 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004245 }
4246
4247 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004248 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4250 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4251 return false;
4252 }
Svet Ganovb320e182015-04-16 12:30:10 -07004253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 final long identity = Binder.clearCallingIdentity();
4255 try {
4256 // Check the user preference and the system-level IMS setting. Even if the user has
4257 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4258 // In the long run, we may instead need to check if there exists a connection service
4259 // which can support video calling.
4260 ImsManager imsManager =
4261 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4262 return imsManager.isVtEnabledByPlatform()
4263 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4264 && imsManager.isVtEnabledByUser();
4265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004268 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004269
Andrew Leea1239f22015-03-02 17:44:07 -08004270 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004271 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4273 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4274 return false;
4275 }
4276
4277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 CarrierConfigManager configManager =
4280 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4281 return configManager.getConfigForSubId(mPhone.getSubId())
4282 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
Andrew Leea1239f22015-03-02 17:44:07 -08004286 }
4287
4288 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 public boolean isWorldPhone(int subId, String callingPackage) {
4290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4291 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4292 return false;
4293 }
4294
4295 final long identity = Binder.clearCallingIdentity();
4296 try {
4297 CarrierConfigManager configManager =
4298 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4299 return configManager.getConfigForSubId(mPhone.getSubId())
4300 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
Andrew Leea1239f22015-03-02 17:44:07 -08004304 }
4305
Andrew Lee9431b832015-03-09 18:46:45 -07004306 @Override
4307 public boolean isTtyModeSupported() {
4308 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004309 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004310 }
4311
4312 @Override
4313 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004314 final long identity = Binder.clearCallingIdentity();
4315 try {
4316 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
Andrew Lee9431b832015-03-09 18:46:45 -07004320 }
4321
Hall Liu98187582018-01-22 19:15:32 -08004322 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4326 mPhone.getSubId()).getBoolean(
4327 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4328 boolean isDeviceSupported =
4329 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4330 return isCarrierSupported && isDeviceSupported;
4331 } finally {
4332 Binder.restoreCallingIdentity(identity);
4333 }
Hall Liu98187582018-01-22 19:15:32 -08004334 }
4335
Hall Liu3ad5f012018-04-06 16:23:39 -07004336 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 return isRttSupported() && Settings.Secure.getInt(
4340 mPhone.getContext().getContentResolver(),
4341 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004345 }
4346
Sanket Padawe7310cc72015-01-14 09:53:20 -08004347 /**
4348 * Returns the unique device ID of phone, for example, the IMEI for
4349 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4350 *
4351 * <p>Requires Permission:
4352 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4353 */
4354 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004355 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004356 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004357 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004358 return null;
4359 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004360 int subId = phone.getSubId();
4361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4362 mApp, subId, callingPackage, "getDeviceId")) {
4363 return null;
4364 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365
4366 final long identity = Binder.clearCallingIdentity();
4367 try {
4368 return phone.getDeviceId();
4369 } finally {
4370 Binder.restoreCallingIdentity(identity);
4371 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004372 }
4373
Ping Sunc67b7c22016-03-02 19:16:45 +08004374 /**
4375 * {@hide}
4376 * Returns the IMS Registration Status on a particular subid
4377 *
4378 * @param subId
4379 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004380 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004381 Phone phone = getPhone(subId);
4382 if (phone != null) {
4383 return phone.isImsRegistered();
4384 } else {
4385 return false;
4386 }
4387 }
4388
Santos Cordon7a1885b2015-02-03 11:15:19 -08004389 @Override
4390 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004391 final long identity = Binder.clearCallingIdentity();
4392 try {
4393 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
4396 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004397 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004398
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004399 /**
4400 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004401 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004402 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 final long identity = Binder.clearCallingIdentity();
4404 try {
4405 Phone phone = getPhone(subId);
4406 if (phone != null) {
4407 return phone.isWifiCallingEnabled();
4408 } else {
4409 return false;
4410 }
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004413 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004414 }
4415
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004416 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004417 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004418 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004419 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 Phone phone = getPhone(subId);
4423 if (phone != null) {
4424 return phone.isVideoEnabled();
4425 } else {
4426 return false;
4427 }
4428 } finally {
4429 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004430 }
4431 }
4432
4433 /**
4434 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4435 * defined in {@link ImsRegistrationImplBase}.
4436 */
4437 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004438 final long identity = Binder.clearCallingIdentity();
4439 try {
4440 Phone phone = getPhone(subId);
4441 if (phone != null) {
4442 return phone.getImsRegistrationTech();
4443 } else {
4444 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4445 }
4446 } finally {
4447 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004448 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004449 }
4450
Stuart Scott8eef64f2015-04-08 15:13:54 -07004451 @Override
4452 public void factoryReset(int subId) {
4453 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004454 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4455 return;
4456 }
4457
Svet Ganovcc087f82015-05-12 20:35:54 -07004458 final long identity = Binder.clearCallingIdentity();
4459 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004460 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4461 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004462 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004463 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004464 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4465 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004466 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004467 }
4468 } finally {
4469 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004470 }
4471 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004472
4473 @Override
4474 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 // We query all subscriptions instead of just the active ones, because
4478 // this might be called early on in the provisioning flow when the
4479 // subscriptions potentially aren't active yet.
4480 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4481 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004482 return null;
4483 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004484
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 // This function may be called very early, say, from the setup wizard, at
4486 // which point we won't have a default subscription set. If that's the case
4487 // we just choose the first, which will be valid in "most cases".
4488 final int defaultSubId = getDefaultSubscription();
4489 SubscriptionInfo info = null;
4490 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4491 info = slist.get(0);
4492 } else {
4493 for (SubscriptionInfo item : slist) {
4494 if (item.getSubscriptionId() == defaultSubId) {
4495 info = item;
4496 break;
4497 }
4498 }
4499
4500 if (info == null) {
4501 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004502 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004503 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004505 // Try and fetch the locale from the carrier properties or from the SIM language
4506 // preferences (EF-PL and EF-LI)...
4507 final int mcc = info.getMcc();
4508 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4509 String simLanguage = null;
4510 if (defaultPhone != null) {
4511 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4512 if (localeFromDefaultSim != null) {
4513 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4514 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4515 return localeFromDefaultSim.toLanguageTag();
4516 } else {
4517 simLanguage = localeFromDefaultSim.getLanguage();
4518 }
4519 }
4520 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522 // The SIM language preferences only store a language (e.g. fr = French), not an
4523 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4524 // the SIM and carrier preferences does not include a country we add the country
4525 // determined from the SIM MCC to provide an exact locale.
4526 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4527 simLanguage);
4528 if (mccLocale != null) {
4529 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4530 return mccLocale.toLanguageTag();
4531 }
4532
4533 if (DBG) log("No locale found - returning null");
4534 return null;
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004538 }
4539
4540 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 return mSubscriptionController.getAllSubInfoList(
4542 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004543 }
4544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545 /**
4546 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4547 */
4548 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4549 return mSubscriptionController.getActiveSubscriptionInfoList(
4550 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004551 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004552
Chenjie Yu1ba97252018-01-11 18:16:20 -08004553 private final ModemActivityInfo mLastModemActivityInfo =
4554 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4555
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004556 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004557 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4558 * representing the state of the modem.
4559 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004560 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4561 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004562 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004563 */
4564 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004565 public void requestModemActivityInfo(ResultReceiver result) {
4566 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004567 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 ModemActivityInfo ret = null;
4572 synchronized (mLastModemActivityInfo) {
4573 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4574 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07004575 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07004576 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4578 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4579 mergedTxTimeMs[i] =
4580 info.getTxTimeMillis()[i]
4581 + mLastModemActivityInfo.getTxTimeMillis()[i];
4582 }
4583 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4584 mLastModemActivityInfo.setSleepTimeMillis(
4585 info.getSleepTimeMillis()
4586 + mLastModemActivityInfo.getSleepTimeMillis());
4587 mLastModemActivityInfo.setIdleTimeMillis(
4588 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4589 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4590 mLastModemActivityInfo.setRxTimeMillis(
4591 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4592 mLastModemActivityInfo.setEnergyUsed(
4593 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4596 mLastModemActivityInfo.getSleepTimeMillis(),
4597 mLastModemActivityInfo.getIdleTimeMillis(),
4598 mLastModemActivityInfo.getTxTimeMillis(),
4599 mLastModemActivityInfo.getRxTimeMillis(),
4600 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004602 Bundle bundle = new Bundle();
4603 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4604 result.send(0, bundle);
4605 } finally {
4606 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004607 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004608 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004609
Siddharth Rayb8114062018-06-17 15:02:38 -07004610 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4611 // less than total activity duration.
4612 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4613 if (info == null) {
4614 return false;
4615 }
4616 int activityDurationMs =
4617 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4618 int totalTxTimeMs = 0;
4619 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4620 totalTxTimeMs += info.getTxTimeMillis()[i];
4621 }
4622 return (info.isValid()
4623 && (info.getSleepTimeMillis() <= activityDurationMs)
4624 && (info.getIdleTimeMillis() <= activityDurationMs)
4625 && (info.getRxTimeMillis() <= activityDurationMs)
4626 && (totalTxTimeMs <= activityDurationMs));
4627 }
4628
Jack Yu85bd38a2015-11-09 11:34:32 -08004629 /**
4630 * {@hide}
4631 * Returns the service state information on specified subscription.
4632 */
4633 @Override
4634 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004636 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004637 return null;
4638 }
4639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 final long identity = Binder.clearCallingIdentity();
4641 try {
4642 final Phone phone = getPhone(subId);
4643 if (phone == null) {
4644 return null;
4645 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647 return phone.getServiceState();
4648 } finally {
4649 Binder.restoreCallingIdentity(identity);
4650 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004651 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004652
4653 /**
4654 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4655 *
4656 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4657 * voicemail ringtone.
4658 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4659 * PhoneAccount.
4660 */
4661 @Override
4662 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 final long identity = Binder.clearCallingIdentity();
4664 try {
4665 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4666 if (phone == null) {
4667 phone = mPhone;
4668 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4671 } finally {
4672 Binder.restoreCallingIdentity(identity);
4673 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004674 }
4675
4676 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004677 * Sets the per-account voicemail ringtone.
4678 *
4679 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4680 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4681 *
4682 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4683 * voicemail ringtone.
4684 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4685 * PhoneAccount.
4686 */
4687 @Override
4688 public void setVoicemailRingtoneUri(String callingPackage,
4689 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4690 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4691 if (!TextUtils.equals(callingPackage,
4692 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4694 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4695 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004696 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697
4698 final long identity = Binder.clearCallingIdentity();
4699 try {
4700 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4701 if (phone == null) {
4702 phone = mPhone;
4703 }
4704 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4705 } finally {
4706 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004707 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004708 }
4709
4710 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004711 * Returns whether vibration is set for voicemail notification in Phone settings.
4712 *
4713 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4714 * voicemail vibration setting.
4715 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4716 */
4717 @Override
4718 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004719 final long identity = Binder.clearCallingIdentity();
4720 try {
4721 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4722 if (phone == null) {
4723 phone = mPhone;
4724 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004730 }
4731
Youhan Wange64578a2016-05-02 15:32:42 -07004732 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004733 * Sets the per-account voicemail vibration.
4734 *
4735 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4736 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4737 *
4738 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4739 * voicemail vibration setting.
4740 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4741 * specific PhoneAccount.
4742 */
4743 @Override
4744 public void setVoicemailVibrationEnabled(String callingPackage,
4745 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4747 if (!TextUtils.equals(callingPackage,
4748 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4750 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4751 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004752 }
4753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754 final long identity = Binder.clearCallingIdentity();
4755 try {
4756 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4757 if (phone == null) {
4758 phone = mPhone;
4759 }
4760 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4761 } finally {
4762 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004763 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004764 }
4765
4766 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004767 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4768 *
4769 * @throws SecurityException if the caller does not have the required permission
4770 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07004772 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004773 message);
Youhan Wange64578a2016-05-02 15:32:42 -07004774 }
4775
4776 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004777 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4778 * permission.
4779 *
4780 * @throws SecurityException if the caller does not have the required permission
4781 */
4782 private void enforceSendSmsPermission() {
4783 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4784 }
4785
4786 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004787 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004788 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004789 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004790 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004791 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 final long identity = Binder.clearCallingIdentity();
4793 try {
4794 ComponentName componentName =
4795 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4796 if (componentName == null) {
4797 throw new SecurityException(
4798 "Caller not current active visual voicemail package[null]");
4799 }
4800 String vvmPackage = componentName.getPackageName();
4801 if (!callingPackage.equals(vvmPackage)) {
4802 throw new SecurityException("Caller not current active visual voicemail package["
4803 + vvmPackage + "]");
4804 }
4805 } finally {
4806 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004807 }
4808 }
4809
4810 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004811 * Return the application ID for the app type.
4812 *
4813 * @param subId the subscription ID that this request applies to.
4814 * @param appType the uicc app type.
4815 * @return Application ID for specificied app type, or null if no uicc.
4816 */
4817 @Override
4818 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004819 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07004820 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821
4822 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004823 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 if (phone == null) {
4825 return null;
4826 }
4827 String aid = null;
4828 try {
4829 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4830 .getApplicationByType(appType).getAid();
4831 } catch (Exception e) {
4832 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4833 }
4834 return aid;
4835 } finally {
4836 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004837 }
Youhan Wange64578a2016-05-02 15:32:42 -07004838 }
4839
Youhan Wang4001d252016-05-11 10:29:41 -07004840 /**
4841 * Return the Electronic Serial Number.
4842 *
4843 * @param subId the subscription ID that this request applies to.
4844 * @return ESN or null if error.
4845 */
4846 @Override
4847 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004848 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07004849 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850
4851 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004852 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 if (phone == null) {
4854 return null;
4855 }
4856 String esn = null;
4857 try {
4858 esn = phone.getEsn();
4859 } catch (Exception e) {
4860 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4861 }
4862 return esn;
4863 } finally {
4864 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004865 }
Youhan Wang4001d252016-05-11 10:29:41 -07004866 }
4867
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004868 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004869 * Return the Preferred Roaming List Version.
4870 *
4871 * @param subId the subscription ID that this request applies to.
4872 * @return PRLVersion or null if error.
4873 */
4874 @Override
4875 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004876 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07004877 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878
4879 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004880 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881 if (phone == null) {
4882 return null;
4883 }
4884 String cdmaPrlVersion = null;
4885 try {
4886 cdmaPrlVersion = phone.getCdmaPrlVersion();
4887 } catch (Exception e) {
4888 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4889 }
4890 return cdmaPrlVersion;
4891 } finally {
4892 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004893 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004894 }
4895
4896 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004897 * Get snapshot of Telephony histograms
4898 * @return List of Telephony histograms
4899 * @hide
4900 */
4901 @Override
4902 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4904 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905
4906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 return RIL.getTelephonyRILTimingHistograms();
4909 } finally {
4910 Binder.restoreCallingIdentity(identity);
4911 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004912 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004913
4914 /**
4915 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004916 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004917 * Require system privileges. In the future we may add this to carrier APIs.
4918 *
4919 * @return The number of carriers set successfully, should match length of carriers
4920 */
4921 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004922 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004923 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07004924 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004925
Meng Wang9b7c4e92017-02-17 11:41:27 -08004926 if (carriers == null) {
4927 throw new NullPointerException("carriers cannot be null");
4928 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930 final long identity = Binder.clearCallingIdentity();
4931 try {
4932 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004933 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId,
4934 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 return retVal[0];
4936 } finally {
4937 Binder.restoreCallingIdentity(identity);
4938 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004939 }
4940
4941 /**
4942 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004943 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004944 * Require system privileges. In the future we may add this to carrier APIs.
4945 *
4946 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4947 * means all carriers are allowed.
4948 */
4949 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004950 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004951 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07004952 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953
4954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 int subId = SubscriptionManager.getSubId(slotIndex)[0];
vagdeviaf9a5b92018-08-15 16:01:53 -07004957 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId,
4958 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004962 }
4963
fionaxu59545b42016-05-25 15:53:37 -07004964 /**
4965 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4966 * @param subId the subscription ID that this action applies to.
4967 * @param enabled control enable or disable metered apns.
4968 * {@hide}
4969 */
4970 @Override
4971 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4972 enforceModifyPermission();
4973 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974
4975 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004976 if (phone == null) {
4977 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4978 return;
4979 }
4980 try {
4981 phone.carrierActionSetMeteredApnsEnabled(enabled);
4982 } catch (Exception e) {
4983 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 } finally {
4985 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004986 }
4987 }
4988
4989 /**
4990 * Action set from carrier signalling broadcast receivers to enable/disable radio
4991 * @param subId the subscription ID that this action applies to.
4992 * @param enabled control enable or disable radio.
4993 * {@hide}
4994 */
4995 @Override
4996 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4997 enforceModifyPermission();
4998 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999
5000 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005001 if (phone == null) {
5002 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5003 return;
5004 }
5005 try {
5006 phone.carrierActionSetRadioEnabled(enabled);
5007 } catch (Exception e) {
5008 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005011 }
5012 }
5013
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005014 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005015 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5016 * network status based on which carrier apps could apply actions accordingly,
5017 * enable/disable default url handler for example.
5018 *
5019 * @param subId the subscription ID that this action applies to.
5020 * @param report control start/stop reporting the default network status.
5021 * {@hide}
5022 */
5023 @Override
5024 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5025 enforceModifyPermission();
5026 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027
5028 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005029 if (phone == null) {
5030 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5031 return;
5032 }
5033 try {
5034 phone.carrierActionReportDefaultNetworkStatus(report);
5035 } catch (Exception e) {
5036 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037 } finally {
5038 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005039 }
5040 }
5041
5042 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005043 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5044 * bug report is being generated.
5045 */
5046 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005047 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07005048 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5049 != PackageManager.PERMISSION_GRANTED) {
5050 writer.println("Permission Denial: can't dump Phone from pid="
5051 + Binder.getCallingPid()
5052 + ", uid=" + Binder.getCallingUid()
5053 + "without permission "
5054 + android.Manifest.permission.DUMP);
5055 return;
5056 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07005057 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005058 }
Jack Yueb89b242016-06-22 13:27:47 -07005059
Brad Ebingerdac2f002018-04-03 15:17:52 -07005060 @Override
5061 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5062 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5063 throws RemoteException {
5064 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5065 }
5066
Jack Yueb89b242016-06-22 13:27:47 -07005067 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005068 * Get aggregated video call data usage since boot.
5069 *
5070 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5071 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005072 * {@hide}
5073 */
5074 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005075 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005076 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5077 null);
5078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 final long identity = Binder.clearCallingIdentity();
5080 try {
5081 // NetworkStatsService keeps tracking the active network interface and identity. It
5082 // records the delta with the corresponding network identity.
5083 // We just return the total video call data usage snapshot since boot.
5084 Phone phone = getPhone(subId);
5085 if (phone != null) {
5086 return phone.getVtDataUsage(perUidStats);
5087 }
5088 return null;
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005091 }
Jack Yueb89b242016-06-22 13:27:47 -07005092 }
Jack Yu75ab2952016-07-08 14:29:33 -07005093
5094 /**
5095 * Policy control of data connection. Usually used when data limit is passed.
5096 * @param enabled True if enabling the data, otherwise disabling.
5097 * @param subId Subscription index
5098 * {@hide}
5099 */
5100 @Override
5101 public void setPolicyDataEnabled(boolean enabled, int subId) {
5102 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005103
5104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 Phone phone = getPhone(subId);
5107 if (phone != null) {
5108 phone.setPolicyDataEnabled(enabled);
5109 }
5110 } finally {
5111 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005112 }
5113 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005114
5115 /**
5116 * Get Client request stats
5117 * @return List of Client Request Stats
5118 * @hide
5119 */
5120 @Override
5121 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005123 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005124 return null;
5125 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005126 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 final long identity = Binder.clearCallingIdentity();
5129 try {
5130 if (phone != null) {
5131 return phone.getClientRequestStats();
5132 }
5133
5134 return null;
5135 } finally {
5136 Binder.restoreCallingIdentity(identity);
5137 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005138 }
5139
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005140 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005141 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005142 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005143 }
Jack Yueb4124c2017-02-16 15:32:43 -08005144
5145 /**
Grace Chen70990072017-03-24 17:21:30 -07005146 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005147 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005148 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005149 * @param state State of SIM (power down, power up, pass through)
5150 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5151 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5152 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005153 *
5154 **/
5155 @Override
Grace Chen70990072017-03-24 17:21:30 -07005156 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005157 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005158 Phone phone = PhoneFactory.getPhone(slotIndex);
5159
vagdeviaf9a5b92018-08-15 16:01:53 -07005160 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 final long identity = Binder.clearCallingIdentity();
5163 try {
5164 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005165 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 }
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005169 }
5170 }
Shuo Qiandd210312017-04-12 22:11:33 +00005171
Tyler Gunn65d45c22017-06-05 11:22:26 -07005172 private boolean isUssdApiAllowed(int subId) {
5173 CarrierConfigManager configManager =
5174 (CarrierConfigManager) mPhone.getContext().getSystemService(
5175 Context.CARRIER_CONFIG_SERVICE);
5176 if (configManager == null) {
5177 return false;
5178 }
5179 PersistableBundle pb = configManager.getConfigForSubId(subId);
5180 if (pb == null) {
5181 return false;
5182 }
5183 return pb.getBoolean(
5184 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5185 }
5186
Shuo Qiandd210312017-04-12 22:11:33 +00005187 /**
5188 * Check if phone is in emergency callback mode
5189 * @return true if phone is in emergency callback mode
5190 * @param subId sub id
5191 */
goneil9c5f4872017-12-05 14:07:56 -08005192 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005193 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005194 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005195 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196
5197 final long identity = Binder.clearCallingIdentity();
5198 try {
5199 if (phone != null) {
5200 return phone.isInEcm();
5201 } else {
5202 return false;
5203 }
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005206 }
5207 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005208
5209 /**
5210 * Get the current signal strength information for the given subscription.
5211 * Because this information is not updated when the device is in a low power state
5212 * it should not be relied-upon to be current.
5213 * @param subId Subscription index
5214 * @return the most recent cached signal strength info from the modem
5215 */
5216 @Override
5217 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 Phone p = getPhone(subId);
5221 if (p == null) {
5222 return null;
5223 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 return p.getSignalStrength();
5226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005229 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005230
Pengquan Meng77b7f132018-08-22 14:49:57 -07005231 /**
5232 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5233 *
5234 * <p>Requires one of the following permissions:
5235 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5236 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5237 * privileges.
5238 *
5239 * @param subId subscription id
5240 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5241 * {@code false}.
5242 */
5243 @Override
5244 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005245 boolean isEnabled = false;
5246 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005247 try {
5248 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005249 null /* message */);
5250 Phone phone = getPhone(subId);
5251 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005252 } catch (Exception e) {
5253 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5254 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005255 } finally {
5256 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005257 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005258 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005259 }
5260
5261
5262 /**
5263 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5264 *
5265 * <p> Requires permission:
5266 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5267 * privileges.
5268 *
5269 * @param subId subscription id
5270 * @param isEnabled {@code true} means enable, {@code false} means disable.
5271 */
5272 @Override
5273 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005274 final long identity = Binder.clearCallingIdentity();
5275 try {
5276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5277 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005278
Pengquan Menga1bb6272018-09-06 09:59:22 -07005279 Phone phone = getPhone(subId);
5280 if (phone != null) {
5281 phone.setDataRoamingEnabled(isEnabled);
5282 }
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005285 }
5286 }
5287
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005288 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07005289 public boolean isManualNetworkSelectionAllowed(int subId) {
5290 boolean isAllowed = true;
5291 final long identity = Binder.clearCallingIdentity();
5292 try {
5293 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5294 mApp, subId, "isManualNetworkSelectionAllowed");
5295 Phone phone = getPhone(subId);
5296 if (phone != null) {
5297 isAllowed = phone.isCspPlmnEnabled();
5298 }
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
5301 }
5302 return isAllowed;
5303 }
5304
5305 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005306 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005307 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 final long identity = Binder.clearCallingIdentity();
5310 try {
5311 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5312 if (slots == null) {
5313 Rlog.i(LOG_TAG, "slots is null.");
5314 return null;
5315 }
5316
5317 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5318 for (int i = 0; i < slots.length; i++) {
5319 UiccSlot slot = slots[i];
5320 if (slot == null) {
5321 continue;
5322 }
5323
5324 String cardId;
5325 UiccCard card = slot.getUiccCard();
5326 if (card != null) {
5327 cardId = card.getCardId();
5328 } else {
5329 cardId = slot.getIccId();
5330 }
5331
5332 int cardState = 0;
5333 switch (slot.getCardState()) {
5334 case CARDSTATE_ABSENT:
5335 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5336 break;
5337 case CARDSTATE_PRESENT:
5338 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5339 break;
5340 case CARDSTATE_ERROR:
5341 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5342 break;
5343 case CARDSTATE_RESTRICTED:
5344 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5345 break;
5346 default:
5347 break;
5348
5349 }
5350
5351 infos[i] = new UiccSlotInfo(
5352 slot.isActive(),
5353 slot.isEuicc(),
5354 cardId,
5355 cardState,
5356 slot.getPhoneId(),
5357 slot.isExtendedApduSupported());
5358 }
5359 return infos;
5360 } finally {
5361 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005362 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005363 }
5364
5365 @Override
5366 public boolean switchSlots(int[] physicalSlots) {
5367 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368
5369 final long identity = Binder.clearCallingIdentity();
5370 try {
5371 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005375 }
Jack Yu4c988042018-02-27 15:30:01 -08005376
5377 @Override
5378 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5379 enforceModifyPermission();
5380 final Phone phone = getPhone(subId);
5381 if (phone == null) {
5382 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5383 return;
5384 }
5385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
5388 phone.setRadioIndicationUpdateMode(filters, mode);
5389 } finally {
5390 Binder.restoreCallingIdentity(identity);
5391 }
Jack Yu4c988042018-02-27 15:30:01 -08005392 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005393
5394 /**
goneil47ffb6e2018-04-06 15:40:58 -07005395 * A test API to reload the UICC profile.
5396 *
5397 * <p>Requires that the calling app has permission
5398 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5399 * @hide
5400 */
5401 @Override
5402 public void refreshUiccProfile(int subId) {
5403 enforceModifyPermission();
5404
5405 final long identity = Binder.clearCallingIdentity();
5406 try {
5407 Phone phone = getPhone(subId);
5408 if (phone == null) {
5409 return;
5410 }
5411 UiccCard uiccCard = phone.getUiccCard();
5412 if (uiccCard == null) {
5413 return;
5414 }
5415 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5416 if (uiccProfile == null) {
5417 return;
5418 }
5419 uiccProfile.refresh();
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
5423 }
5424
5425 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005426 * Returns false if the mobile data is disabled by default, otherwise return true.
5427 */
5428 private boolean getDefaultDataEnabled() {
5429 return "true".equalsIgnoreCase(
5430 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5431 }
5432
5433 /**
5434 * Returns true if the data roaming is enabled by default, i.e the system property
5435 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5436 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5437 */
5438 private boolean getDefaultDataRoamingEnabled(int subId) {
5439 final CarrierConfigManager configMgr = (CarrierConfigManager)
5440 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5441 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5442 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5443 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5444 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5445 return isDataRoamingEnabled;
5446 }
5447
5448 /**
5449 * Returns the default network type for the given {@code subId}, if the default network type is
5450 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5451 */
5452 private int getDefaultNetworkType(int subId) {
5453 return Integer.parseInt(
5454 TelephonyManager.getTelephonyProperty(
5455 mSubscriptionController.getPhoneId(subId),
5456 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5457 String.valueOf(Phone.PREFERRED_NT_MODE)));
5458 }
fionaxua13278b2018-03-21 00:08:13 -07005459
5460 @Override
5461 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5462 gid1, String gid2, String plmn, String spn) {
5463 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 final Phone phone = getPhone(subId);
5468 if (phone == null) {
5469 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5470 return;
5471 }
5472 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5473 } finally {
5474 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005475 }
fionaxua13278b2018-03-21 00:08:13 -07005476 }
5477
5478 @Override
5479 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005480 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481
5482 final long identity = Binder.clearCallingIdentity();
5483 try {
5484 final Phone phone = getPhone(subId);
5485 if (phone == null) {
5486 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5487 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5488 }
5489 return phone.getCarrierIdListVersion();
5490 } finally {
5491 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005492 }
fionaxua13278b2018-03-21 00:08:13 -07005493 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005494
5495 @Override
5496 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5498 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5499 return -1;
5500 }
5501
5502 final long identity = Binder.clearCallingIdentity();
5503 try {
5504 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
5508 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005509
5510 @Override
5511 public int getCdmaRoamingMode(int subId) {
5512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5513 mApp, subId, "getCdmaRoamingMode");
5514
5515 final long identity = Binder.clearCallingIdentity();
5516 try {
5517 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
5520 }
5521 }
5522
5523 @Override
5524 public boolean setCdmaRoamingMode(int subId, int mode) {
5525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5526 mApp, subId, "setCdmaRoamingMode");
5527
5528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
5534 }
5535
5536 @Override
5537 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5539 mApp, subId, "setCdmaSubscriptionMode");
5540
5541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
5547 }
Makoto Onukida3bf792018-09-18 16:06:29 -07005548
5549 private void ensureUserRunning(int userId) {
5550 if (!mUserManager.isUserRunning(userId)) {
5551 throw new IllegalStateException("User " + userId + " does not exist or not running");
5552 }
5553 }
5554
5555 /**
5556 * Returns a list of SMS apps on a given user.
5557 *
5558 * Only the shell user (UID 2000 or 0) can call it.
5559 * Target user must be running.
5560 */
5561 @Override
5562 public String[] getSmsApps(int userId) {
5563 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
5564 ensureUserRunning(userId);
5565
5566 final Collection<SmsApplicationData> apps =
5567 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
5568
5569 String[] ret = new String[apps.size()];
5570 int i = 0;
5571 for (SmsApplicationData app : apps) {
5572 ret[i++] = app.mPackageName;
5573 }
5574 return ret;
5575 }
5576
5577 /**
5578 * Returns the default SMS app package name on a given user.
5579 *
5580 * Only the shell user (UID 2000 or 0) can call it.
5581 * Target user must be running.
5582 */
5583 @Override
5584 public String getDefaultSmsApp(int userId) {
5585 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
5586 ensureUserRunning(userId);
5587
5588 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
5589 /* updateIfNeeded= */ true, userId);
5590 return cn == null ? null : cn.getPackageName();
5591 }
5592
5593 /**
5594 * Set a package as the default SMS app on a given user.
5595 *
5596 * Only the shell user (UID 2000 or 0) can call it.
5597 * Target user must be running.
5598 */
5599 @Override
5600 public void setDefaultSmsApp(int userId, String packageName) {
5601 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
5602 ensureUserRunning(userId);
5603
5604 boolean found = false;
5605 for (String pkg : getSmsApps(userId)) {
5606 if (TextUtils.equals(packageName, pkg)) {
5607 found = true;
5608 break;
5609 }
5610 }
5611 if (!found) {
5612 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
5613 }
5614
5615 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
5616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005617}