blob: 7bd0937c1907e7bc229716eaa231b12366095a06 [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;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070060import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070061import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080062import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070063import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080064import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070065import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070066import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070067import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080069import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070070import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080071import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080072import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070073import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070074import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000075import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070076import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070077import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080078import android.telephony.ims.aidl.IImsConfig;
79import android.telephony.ims.aidl.IImsMmTelFeature;
80import android.telephony.ims.aidl.IImsRcsFeature;
81import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080082import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080085import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080087import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080089
Andrew Lee312e8172014-10-23 17:01:36 -070090import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080091import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070092import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070093import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070094import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070095import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070096import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080099import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700100import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100101import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700102import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700103import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700105import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800106import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700107import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700108import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700110import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700111import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700112import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800113import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800114import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700115import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.uicc.IccIoResult;
117import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800118import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700119import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800120import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700121import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800122import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000123import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700124import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800125import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700126import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800127import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700128import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700129import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700131import java.io.FileDescriptor;
132import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800133import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800135import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800136import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100137import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139
140/**
141 * Implementation of the ITelephony interface.
142 */
Santos Cordon117fee72014-05-16 17:56:12 -0700143public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144 private static final String LOG_TAG = "PhoneInterfaceManager";
145 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
146 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800147 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148
149 // Message codes used with mMainThreadHandler
150 private static final int CMD_HANDLE_PIN_MMI = 1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151 private static final int CMD_ANSWER_RINGING_CALL = 4;
152 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700153 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
154 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155 private static final int CMD_OPEN_CHANNEL = 9;
156 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
157 private static final int CMD_CLOSE_CHANNEL = 11;
158 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800159 private static final int CMD_NV_READ_ITEM = 13;
160 private static final int EVENT_NV_READ_ITEM_DONE = 14;
161 private static final int CMD_NV_WRITE_ITEM = 15;
162 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
163 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
164 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
165 private static final int CMD_NV_RESET_CONFIG = 19;
166 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800167 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
168 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
169 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
170 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800171 private static final int CMD_SEND_ENVELOPE = 25;
172 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000173 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
174 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700175 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
176 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
177 private static final int CMD_EXCHANGE_SIM_IO = 31;
178 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800179 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
180 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700181 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
182 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700183 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
184 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700185 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
186 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
187 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
188 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700189 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
190 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
191 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
192 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700193 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800194 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
195 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000196 private static final int CMD_SWITCH_SLOTS = 50;
197 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700198 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
199 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
200 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
201 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
202 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
203 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
204 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
205 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800207 // Parameters of select command.
208 private static final int SELECT_COMMAND = 0xA4;
209 private static final int SELECT_P1 = 0x04;
210 private static final int SELECT_P2 = 0;
211 private static final int SELECT_P3 = 0x10;
212
Pengquan Meng85728fb2018-03-12 16:31:21 -0700213 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
214 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
215 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
216
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 /** The singleton instance. */
218 private static PhoneInterfaceManager sInstance;
219
Wink Saville3ab207e2014-11-20 13:07:20 -0800220 private PhoneGlobals mApp;
221 private Phone mPhone;
222 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700223 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800224 private AppOpsManager mAppOps;
225 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800226 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800227 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700228 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
Derek Tan97ebb422014-09-05 16:55:38 -0700230 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
231 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700233
Derek Tan740e1672017-06-27 14:56:27 -0700234 // The AID of ISD-R.
235 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
236
yinxub1bed742017-04-17 11:45:04 -0700237 private NetworkScanRequestTracker mNetworkScanRequestTracker;
238
David Kelly5e06a7f2018-03-12 14:10:59 +0000239 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
240 private static final int MANUFACTURER_CODE_LENGTH = 8;
241
Derek Tan89e89d42014-07-08 17:00:10 -0700242 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243 * A request object to use for transmitting data to an ICC.
244 */
245 private static final class IccAPDUArgument {
246 public int channel, cla, command, p1, p2, p3;
247 public String data;
248
249 public IccAPDUArgument(int channel, int cla, int command,
250 int p1, int p2, int p3, String data) {
251 this.channel = channel;
252 this.cla = cla;
253 this.command = command;
254 this.p1 = p1;
255 this.p2 = p2;
256 this.p3 = p3;
257 this.data = data;
258 }
259 }
260
261 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700262 * A request object to use for transmitting data to an ICC.
263 */
264 private static final class ManualNetworkSelectionArgument {
265 public OperatorInfo operatorInfo;
266 public boolean persistSelection;
267
268 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
269 this.operatorInfo = operatorInfo;
270 this.persistSelection = persistSelection;
271 }
272 }
273
274 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
276 * request after sending. The main thread will notify the request when it is complete.
277 */
278 private static final class MainThreadRequest {
279 /** The argument to use for the request */
280 public Object argument;
281 /** The result of the request that is run on the main thread */
282 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800283 // The subscriber id that this request applies to. Defaults to
284 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
285 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
287 public MainThreadRequest(Object argument) {
288 this.argument = argument;
289 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800290
291 public MainThreadRequest(Object argument, Integer subId) {
292 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800293 if (subId != null) {
294 this.subId = subId;
295 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 }
298
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800299 private static final class IncomingThirdPartyCallArgs {
300 public final ComponentName component;
301 public final String callId;
302 public final String callerDisplayName;
303
304 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
305 String callerDisplayName) {
306 this.component = component;
307 this.callId = callId;
308 this.callerDisplayName = callerDisplayName;
309 }
310 }
311
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312 /**
313 * A handler that processes messages on the main thread in the phone process. Since many
314 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
315 * inbound binder threads to the main thread in the phone process. The Binder thread
316 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
317 * on, which will be notified when the operation completes and will contain the result of the
318 * request.
319 *
320 * <p>If a MainThreadRequest object is provided in the msg.obj field,
321 * note that request.result must be set to something non-null for the calling thread to
322 * unblock.
323 */
324 private final class MainThreadHandler extends Handler {
325 @Override
326 public void handleMessage(Message msg) {
327 MainThreadRequest request;
328 Message onCompleted;
329 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800330 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700331 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332
333 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700334 case CMD_HANDLE_USSD_REQUEST: {
335 request = (MainThreadRequest) msg.obj;
336 final Phone phone = getPhoneFromRequest(request);
337 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
338 String ussdRequest = ussdObject.first;
339 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700340
Pengquan Menga1bb6272018-09-06 09:59:22 -0700341 if (!isUssdApiAllowed(request.subId)) {
342 // Carrier does not support use of this API, return failure.
343 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
344 UssdResponse response = new UssdResponse(ussdRequest, null);
345 Bundle returnData = new Bundle();
346 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
347 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700348
Pengquan Menga1bb6272018-09-06 09:59:22 -0700349 request.result = true;
350 notifyRequester(request);
351 return;
352 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700353
Pengquan Menga1bb6272018-09-06 09:59:22 -0700354 try {
355 request.result = phone != null
356 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
357 } catch (CallStateException cse) {
358 request.result = false;
359 }
360 // Wake up the requesting thread
361 notifyRequester(request);
362 break;
pkanwar32d516d2016-10-14 19:37:38 -0700363 }
364
Yorke Lee716f67e2015-06-17 15:39:16 -0700365 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700367 final Phone phone = getPhoneFromRequest(request);
368 request.result = phone != null ?
369 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
370 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700372 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700377 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800378 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700379 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800380 request.result = ""; // dummy result for notifying the waiting thread
381 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700382 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 break;
384
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 case CMD_END_CALL:
386 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800387 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700388 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700389 Phone phone = getPhone(end_subId);
390 if (phone == null) {
391 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
392 break;
393 }
394 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
396 // CDMA: If the user presses the Power button we treat it as
397 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700398 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
400 // GSM: End the call as per the Phone state
401 hungUp = PhoneUtils.hangup(mCM);
402 } else {
403 throw new IllegalStateException("Unexpected phone type: " + phoneType);
404 }
405 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
406 request.result = hungUp;
407 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700408 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 break;
410
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700412 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800414 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700415 if (uiccCard == null) {
416 loge("iccTransmitApduLogicalChannel: No UICC");
417 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700419 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
421 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 iccArgument.channel, iccArgument.cla, iccArgument.command,
424 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700427 break;
428
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 ar = (AsyncResult) msg.obj;
431 request = (MainThreadRequest) ar.userObj;
432 if (ar.exception == null && ar.result != null) {
433 request.result = ar.result;
434 } else {
435 request.result = new IccIoResult(0x6F, 0, (byte[])null);
436 if (ar.result == null) {
437 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800438 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700439 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800440 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700441 } else {
442 loge("iccTransmitApduLogicalChannel: Unknown exception");
443 }
444 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 break;
447
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
449 request = (MainThreadRequest) msg.obj;
450 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800451 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 if (uiccCard == null) {
453 loge("iccTransmitApduBasicChannel: No UICC");
454 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 } else {
457 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
458 request);
459 uiccCard.iccTransmitApduBasicChannel(
460 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
461 iccArgument.p3, iccArgument.data, onCompleted);
462 }
463 break;
464
465 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
466 ar = (AsyncResult) msg.obj;
467 request = (MainThreadRequest) ar.userObj;
468 if (ar.exception == null && ar.result != null) {
469 request.result = ar.result;
470 } else {
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
472 if (ar.result == null) {
473 loge("iccTransmitApduBasicChannel: Empty response");
474 } else if (ar.exception instanceof CommandException) {
475 loge("iccTransmitApduBasicChannel: CommandException: " +
476 ar.exception);
477 } else {
478 loge("iccTransmitApduBasicChannel: Unknown exception");
479 }
480 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 break;
483
484 case CMD_EXCHANGE_SIM_IO:
485 request = (MainThreadRequest) msg.obj;
486 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800487 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 if (uiccCard == null) {
489 loge("iccExchangeSimIO: No UICC");
490 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700491 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 } else {
493 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
494 request);
495 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
496 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
497 iccArgument.data, onCompleted);
498 }
499 break;
500
501 case EVENT_EXCHANGE_SIM_IO_DONE:
502 ar = (AsyncResult) msg.obj;
503 request = (MainThreadRequest) ar.userObj;
504 if (ar.exception == null && ar.result != null) {
505 request.result = ar.result;
506 } else {
507 request.result = new IccIoResult(0x6f, 0, (byte[])null);
508 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700510 break;
511
Derek Tan4d5e5c12014-02-04 11:54:58 -0800512 case CMD_SEND_ENVELOPE:
513 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800514 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700515 if (uiccCard == null) {
516 loge("sendEnvelopeWithStatus: No UICC");
517 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700519 } else {
520 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
521 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
522 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800523 break;
524
525 case EVENT_SEND_ENVELOPE_DONE:
526 ar = (AsyncResult) msg.obj;
527 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700528 if (ar.exception == null && ar.result != null) {
529 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
532 if (ar.result == null) {
533 loge("sendEnvelopeWithStatus: Empty response");
534 } else if (ar.exception instanceof CommandException) {
535 loge("sendEnvelopeWithStatus: CommandException: " +
536 ar.exception);
537 } else {
538 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
539 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800542 break;
543
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 case CMD_OPEN_CHANNEL:
545 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800546 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800547 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700548 if (uiccCard == null) {
549 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800550 request.result = new IccOpenLogicalChannelResponse(-1,
551 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 } else {
554 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800555 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
556 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 break;
559
560 case EVENT_OPEN_CHANNEL_DONE:
561 ar = (AsyncResult) msg.obj;
562 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 int[] result = (int[]) ar.result;
566 int channelId = result[0];
567 byte[] selectResponse = null;
568 if (result.length > 1) {
569 selectResponse = new byte[result.length - 1];
570 for (int i = 1; i < result.length; ++i) {
571 selectResponse[i - 1] = (byte) result[i];
572 }
573 }
574 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700575 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 if (ar.result == null) {
578 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 if (ar.exception != null) {
581 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
582 }
583
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700584 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700585 if (ar.exception instanceof CommandException) {
586 CommandException.Error error =
587 ((CommandException) (ar.exception)).getCommandError();
588 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700589 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700590 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700591 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 }
593 }
594 openChannelResp = new IccOpenLogicalChannelResponse(
595 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700597 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 break;
600
601 case CMD_CLOSE_CHANNEL:
602 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800603 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 if (uiccCard == null) {
605 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900606 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700607 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 } else {
609 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
610 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
611 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 break;
613
614 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800615 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
616 break;
617
618 case CMD_NV_READ_ITEM:
619 request = (MainThreadRequest) msg.obj;
620 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
621 mPhone.nvReadItem((Integer) request.argument, onCompleted);
622 break;
623
624 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 ar = (AsyncResult) msg.obj;
626 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800627 if (ar.exception == null && ar.result != null) {
628 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800630 request.result = "";
631 if (ar.result == null) {
632 loge("nvReadItem: Empty response");
633 } else if (ar.exception instanceof CommandException) {
634 loge("nvReadItem: CommandException: " +
635 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800637 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 }
639 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 break;
642
Jake Hambye994d462014-02-03 13:10:13 -0800643 case CMD_NV_WRITE_ITEM:
644 request = (MainThreadRequest) msg.obj;
645 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
646 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
647 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
648 break;
649
650 case EVENT_NV_WRITE_ITEM_DONE:
651 handleNullReturnEvent(msg, "nvWriteItem");
652 break;
653
654 case CMD_NV_WRITE_CDMA_PRL:
655 request = (MainThreadRequest) msg.obj;
656 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
657 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
658 break;
659
660 case EVENT_NV_WRITE_CDMA_PRL_DONE:
661 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
662 break;
663
664 case CMD_NV_RESET_CONFIG:
665 request = (MainThreadRequest) msg.obj;
666 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
667 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
668 break;
669
670 case EVENT_NV_RESET_CONFIG_DONE:
671 handleNullReturnEvent(msg, "nvResetConfig");
672 break;
673
Jake Hamby7c27be32014-03-03 13:25:59 -0800674 case CMD_GET_PREFERRED_NETWORK_TYPE:
675 request = (MainThreadRequest) msg.obj;
676 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700677 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800678 break;
679
680 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
681 ar = (AsyncResult) msg.obj;
682 request = (MainThreadRequest) ar.userObj;
683 if (ar.exception == null && ar.result != null) {
684 request.result = ar.result; // Integer
685 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800686 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 if (ar.result == null) {
688 loge("getPreferredNetworkType: Empty response");
689 } else if (ar.exception instanceof CommandException) {
690 loge("getPreferredNetworkType: CommandException: " +
691 ar.exception);
692 } else {
693 loge("getPreferredNetworkType: Unknown exception");
694 }
695 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 break;
698
699 case CMD_SET_PREFERRED_NETWORK_TYPE:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
702 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700703 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
707 handleNullReturnEvent(msg, "setPreferredNetworkType");
708 break;
709
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000710 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
711 request = (MainThreadRequest)msg.obj;
712 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
713 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
714 break;
715
716 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
717 ar = (AsyncResult)msg.obj;
718 request = (MainThreadRequest)ar.userObj;
719 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700720 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000721 break;
722
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800723 case CMD_SET_VOICEMAIL_NUMBER:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
726 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800727 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
728 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800729 break;
730
731 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
732 handleNullReturnEvent(msg, "setVoicemailNumber");
733 break;
734
Stuart Scott54788802015-03-30 13:18:01 -0700735 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
738 request);
739 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
740 break;
741
742 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
743 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
744 break;
745
Shishir Agrawal302c8692015-06-19 13:49:39 -0700746 case CMD_PERFORM_NETWORK_SCAN:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
749 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
750 break;
751
752 case EVENT_PERFORM_NETWORK_SCAN_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 CellNetworkScanResult cellScanResult;
756 if (ar.exception == null && ar.result != null) {
757 cellScanResult = new CellNetworkScanResult(
758 CellNetworkScanResult.STATUS_SUCCESS,
759 (List<OperatorInfo>) ar.result);
760 } else {
761 if (ar.result == null) {
762 loge("getCellNetworkScanResults: Empty response");
763 }
764 if (ar.exception != null) {
765 loge("getCellNetworkScanResults: Exception: " + ar.exception);
766 }
767 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
768 if (ar.exception instanceof CommandException) {
769 CommandException.Error error =
770 ((CommandException) (ar.exception)).getCommandError();
771 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
772 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
773 } else if (error == CommandException.Error.GENERIC_FAILURE) {
774 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
775 }
776 }
777 cellScanResult = new CellNetworkScanResult(errorCode, null);
778 }
779 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700780 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700781 break;
782
783 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
784 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700785 ManualNetworkSelectionArgument selArg =
786 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700787 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
788 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700789 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
790 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 break;
792
793 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
794 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
795 break;
796
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700797 case CMD_GET_MODEM_ACTIVITY_INFO:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700800 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700801 break;
802
803 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
804 ar = (AsyncResult) msg.obj;
805 request = (MainThreadRequest) ar.userObj;
806 if (ar.exception == null && ar.result != null) {
807 request.result = ar.result;
808 } else {
809 if (ar.result == null) {
810 loge("queryModemActivityInfo: Empty response");
811 } else if (ar.exception instanceof CommandException) {
812 loge("queryModemActivityInfo: CommandException: " +
813 ar.exception);
814 } else {
815 loge("queryModemActivityInfo: Unknown exception");
816 }
817 }
Amit Mahajand4766222016-01-28 15:28:28 -0800818 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
819 if (request.result == null) {
820 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
821 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700822 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700823 break;
824
Meng Wang1a7c35a2016-05-05 20:56:15 -0700825 case CMD_SET_ALLOWED_CARRIERS:
826 request = (MainThreadRequest) msg.obj;
827 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
828 mPhone.setAllowedCarriers(
829 (List<CarrierIdentifier>) request.argument,
830 onCompleted);
831 break;
832
833 case EVENT_SET_ALLOWED_CARRIERS_DONE:
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null && ar.result != null) {
837 request.result = ar.result;
838 } else {
839 if (ar.result == null) {
840 loge("setAllowedCarriers: Empty response");
841 } else if (ar.exception instanceof CommandException) {
842 loge("setAllowedCarriers: CommandException: " +
843 ar.exception);
844 } else {
845 loge("setAllowedCarriers: Unknown exception");
846 }
847 }
848 // Result cannot be null. Return -1 on error.
849 if (request.result == null) {
850 request.result = new int[]{-1};
851 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700852 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 break;
854
855 case CMD_GET_ALLOWED_CARRIERS:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
858 mPhone.getAllowedCarriers(onCompleted);
859 break;
860
861 case EVENT_GET_ALLOWED_CARRIERS_DONE:
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null && ar.result != null) {
865 request.result = ar.result;
866 } else {
867 if (ar.result == null) {
868 loge("getAllowedCarriers: Empty response");
869 } else if (ar.exception instanceof CommandException) {
870 loge("getAllowedCarriers: CommandException: " +
871 ar.exception);
872 } else {
873 loge("getAllowedCarriers: Unknown exception");
874 }
875 }
876 // Result cannot be null. Return empty list of CarrierIdentifier.
877 if (request.result == null) {
878 request.result = new ArrayList<CarrierIdentifier>(0);
879 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700880 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 break;
882
Nathan Haroldb3014052017-01-25 15:57:32 -0800883 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
889 request.result = new IllegalArgumentException(
890 "Failed to retrieve Forbidden Plmns");
891 if (ar.result == null) {
892 loge("getForbiddenPlmns: Empty response");
893 } else {
894 loge("getForbiddenPlmns: Unknown exception");
895 }
896 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700897 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800898 break;
899
900 case CMD_GET_FORBIDDEN_PLMNS:
901 request = (MainThreadRequest) msg.obj;
902 uiccCard = getUiccCardFromRequest(request);
903 if (uiccCard == null) {
904 loge("getForbiddenPlmns() UiccCard is null");
905 request.result = new IllegalArgumentException(
906 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700907 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800908 break;
909 }
910 Integer appType = (Integer) request.argument;
911 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
912 if (uiccApp == null) {
913 loge("getForbiddenPlmns() no app with specified type -- "
914 + appType);
915 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700916 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800917 break;
918 } else {
919 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
920 + " specified type -- " + appType);
921 }
922 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
923 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
924 onCompleted);
925 break;
926
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000927 case CMD_SWITCH_SLOTS:
928 request = (MainThreadRequest) msg.obj;
929 int[] physicalSlots = (int[]) request.argument;
930 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
931 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
932 break;
933
934 case EVENT_SWITCH_SLOTS_DONE:
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700938 notifyRequester(request);
939 break;
940 case CMD_GET_NETWORK_SELECTION_MODE:
941 request = (MainThreadRequest) msg.obj;
942 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
943 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
944 break;
945
946 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
947 ar = (AsyncResult) msg.obj;
948 request = (MainThreadRequest) ar.userObj;
949 if (ar.exception != null) {
950 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
951 } else {
952 int mode = ((int[]) ar.result)[0];
953 if (mode == 0) {
954 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
955 } else {
956 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
957 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000958 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700959 notifyRequester(request);
960 break;
961 case CMD_GET_CDMA_ROAMING_MODE:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
964 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
965 break;
966 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 if (ar.exception != null) {
970 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
971 } else {
972 request.result = ((int[]) ar.result)[0];
973 }
974 notifyRequester(request);
975 break;
976 case CMD_SET_CDMA_ROAMING_MODE:
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
979 int mode = (int) request.argument;
980 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
981 break;
982 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 request.result = ar.exception == null;
986 notifyRequester(request);
987 break;
988 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
991 int subscriptionMode = (int) request.argument;
992 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
993 break;
994 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 request.result = ar.exception == null;
998 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000999 break;
1000
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001001 default:
1002 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1003 break;
1004 }
1005 }
Jake Hambye994d462014-02-03 13:10:13 -08001006
Pengquan Menga1bb6272018-09-06 09:59:22 -07001007 private void notifyRequester(MainThreadRequest request) {
1008 synchronized (request) {
1009 request.notifyAll();
1010 }
1011 }
1012
Jake Hambye994d462014-02-03 13:10:13 -08001013 private void handleNullReturnEvent(Message msg, String command) {
1014 AsyncResult ar = (AsyncResult) msg.obj;
1015 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception == null) {
1017 request.result = true;
1018 } else {
1019 request.result = false;
1020 if (ar.exception instanceof CommandException) {
1021 loge(command + ": CommandException: " + ar.exception);
1022 } else {
1023 loge(command + ": Unknown exception");
1024 }
1025 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001026 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001028 }
1029
1030 /**
1031 * Posts the specified command to be executed on the main thread,
1032 * waits for the request to complete, and returns the result.
1033 * @see #sendRequestAsync
1034 */
1035 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001036 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001037 }
1038
1039 /**
1040 * Posts the specified command to be executed on the main thread,
1041 * waits for the request to complete, and returns the result.
1042 * @see #sendRequestAsync
1043 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001044 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1046 throw new RuntimeException("This method will deadlock if called from the main thread.");
1047 }
1048
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001049 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001050 Message msg = mMainThreadHandler.obtainMessage(command, request);
1051 msg.sendToTarget();
1052
1053 // Wait for the request to complete
1054 synchronized (request) {
1055 while (request.result == null) {
1056 try {
1057 request.wait();
1058 } catch (InterruptedException e) {
1059 // Do nothing, go back and wait until the request is complete
1060 }
1061 }
1062 }
1063 return request.result;
1064 }
1065
1066 /**
1067 * Asynchronous ("fire and forget") version of sendRequest():
1068 * Posts the specified command to be executed on the main thread, and
1069 * returns immediately.
1070 * @see #sendRequest
1071 */
1072 private void sendRequestAsync(int command) {
1073 mMainThreadHandler.sendEmptyMessage(command);
1074 }
1075
1076 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001077 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1078 * @see {@link #sendRequest(int,Object)}
1079 */
1080 private void sendRequestAsync(int command, Object argument) {
1081 MainThreadRequest request = new MainThreadRequest(argument);
1082 Message msg = mMainThreadHandler.obtainMessage(command, request);
1083 msg.sendToTarget();
1084 }
1085
1086 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 * Initialize the singleton PhoneInterfaceManager instance.
1088 * This is only done once, at startup, from PhoneApp.onCreate().
1089 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001090 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 synchronized (PhoneInterfaceManager.class) {
1092 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001093 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001094 } else {
1095 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1096 }
1097 return sInstance;
1098 }
1099 }
1100
1101 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001102 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 mApp = app;
1104 mPhone = phone;
1105 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001106 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001107 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1108 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001109 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001110 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001111 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001112 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001113 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001114
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001115 publish();
1116 }
1117
1118 private void publish() {
1119 if (DBG) log("publish: " + this);
1120
1121 ServiceManager.addService("phone", this);
1122 }
1123
Stuart Scott584921c2015-01-15 17:10:34 -08001124 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001125 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1126 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001127 }
1128
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001129 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1130 Phone phone = getPhoneFromRequest(request);
1131 return phone == null ? null :
1132 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1133 }
1134
Wink Saville36469e72014-06-11 15:17:00 -07001135 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001136 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001137 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 //
1140 // Implementation of the ITelephony interface.
1141 //
1142
1143 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001144 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001145 }
1146
Wink Savilleb564aae2014-10-23 10:18:09 -07001147 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 if (DBG) log("dial: " + number);
1149 // No permission check needed here: This is just a wrapper around the
1150 // ACTION_DIAL intent, which is available to any app since it puts up
1151 // the UI before it does anything.
1152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001153 final long identity = Binder.clearCallingIdentity();
1154 try {
1155 String url = createTelUrl(number);
1156 if (url == null) {
1157 return;
1158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001159
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001160 // PENDING: should we just silently fail if phone is offhook or ringing?
1161 PhoneConstants.State state = mCM.getState(subId);
1162 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1163 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1164 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1165 mApp.startActivity(intent);
1166 }
1167 } finally {
1168 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 }
1170 }
1171
1172 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001173 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001174 }
1175
Wink Savilleb564aae2014-10-23 10:18:09 -07001176 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001177 if (DBG) log("call: " + number);
1178
1179 // This is just a wrapper around the ACTION_CALL intent, but we still
1180 // need to do a permission check since we're calling startActivity()
1181 // from the context of the phone app.
1182 enforceCallPermission();
1183
1184 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1185 != AppOpsManager.MODE_ALLOWED) {
1186 return;
1187 }
1188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001189 final long identity = Binder.clearCallingIdentity();
1190 try {
1191 String url = createTelUrl(number);
1192 if (url == null) {
1193 return;
1194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001196 boolean isValid = false;
1197 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1198 if (slist != null) {
1199 for (SubscriptionInfo subInfoRecord : slist) {
1200 if (subInfoRecord.getSubscriptionId() == subId) {
1201 isValid = true;
1202 break;
1203 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001204 }
Wink Saville08874612014-08-31 19:19:58 -07001205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001206 if (!isValid) {
1207 return;
1208 }
Wink Saville08874612014-08-31 19:19:58 -07001209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001210 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1211 intent.putExtra(SUBSCRIPTION_KEY, subId);
1212 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1213 mApp.startActivity(intent);
1214 } finally {
1215 Binder.restoreCallingIdentity(identity);
1216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 }
1218
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 /**
1220 * End a call based on call state
1221 * @return true is a call was ended
1222 */
1223 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001224 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001225 }
1226
1227 /**
1228 * End a call based on the call state of the subId
1229 * @return true is a call was ended
1230 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001231 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001232 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1233 != PackageManager.PERMISSION_GRANTED) {
1234 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1235 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1236 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001238
1239 final long identity = Binder.clearCallingIdentity();
1240 try {
1241 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1242 } finally {
1243 Binder.restoreCallingIdentity(identity);
1244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 }
1246
1247 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001248 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001249 }
1250
Wink Savilleb564aae2014-10-23 10:18:09 -07001251 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 if (DBG) log("answerRingingCall...");
1253 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1254 // but that can probably wait till the big TelephonyManager API overhaul.
1255 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001257
1258 final long identity = Binder.clearCallingIdentity();
1259 try {
1260 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1261 } finally {
1262 Binder.restoreCallingIdentity(identity);
1263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 }
1265
1266 /**
1267 * Make the actual telephony calls to implement answerRingingCall().
1268 * This should only be called from the main thread of the Phone app.
1269 * @see #answerRingingCall
1270 *
1271 * TODO: it would be nice to return true if we answered the call, or
1272 * false if there wasn't actually a ringing incoming call, or some
1273 * other error occurred. (In other words, pass back the return value
1274 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1275 * But that would require calling this method via sendRequest() rather
1276 * than sendRequestAsync(), and right now we don't actually *need* that
1277 * return value, so let's just return void for now.
1278 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001279 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001280 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001282 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1283 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 if (hasActiveCall && hasHoldingCall) {
1285 // Both lines are in use!
1286 // TODO: provide a flag to let the caller specify what
1287 // policy to use if both lines are in use. (The current
1288 // behavior is hardwired to "answer incoming, end ongoing",
1289 // which is how the CALL button is specced to behave.)
1290 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1291 return;
1292 } else {
1293 // answerCall() will automatically hold the current active
1294 // call, if there is one.
1295 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1296 return;
1297 }
1298 } else {
1299 // No call was ringing.
1300 return;
1301 }
1302 }
1303
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001305 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001307 public void silenceRinger() {
1308 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 }
1310
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001311 @Override
1312 public boolean isOffhook(String callingPackage) {
1313 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001316 @Override
1317 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001318 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001319 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001320 return false;
1321 }
1322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001323 final long identity = Binder.clearCallingIdentity();
1324 try {
1325 final Phone phone = getPhone(subId);
1326 if (phone != null) {
1327 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1328 } else {
1329 return false;
1330 }
1331 } finally {
1332 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 }
1335
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001336 @Override
1337 public boolean isRinging(String callingPackage) {
1338 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001339 }
1340
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001341 @Override
1342 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001344 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001345 return false;
1346 }
1347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001348 final long identity = Binder.clearCallingIdentity();
1349 try {
1350 final Phone phone = getPhone(subId);
1351 if (phone != null) {
1352 return (phone.getState() == PhoneConstants.State.RINGING);
1353 } else {
1354 return false;
1355 }
1356 } finally {
1357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 }
1360
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001361 @Override
1362 public boolean isIdle(String callingPackage) {
1363 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001364 }
1365
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001366 @Override
1367 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001369 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001370 return false;
1371 }
1372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001373 final long identity = Binder.clearCallingIdentity();
1374 try {
1375 final Phone phone = getPhone(subId);
1376 if (phone != null) {
1377 return (phone.getState() == PhoneConstants.State.IDLE);
1378 } else {
1379 return false;
1380 }
1381 } finally {
1382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 }
1385
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001387 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001388 }
1389
Wink Savilleb564aae2014-10-23 10:18:09 -07001390 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001391 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001392 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1393 }
1394
1395 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001396 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001397 }
1398
Wink Savilleb564aae2014-10-23 10:18:09 -07001399 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001400 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001401 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1402 }
1403
1404 /** {@hide} */
1405 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001406 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001407 }
1408
Wink Savilleb564aae2014-10-23 10:18:09 -07001409 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001411
1412 final long identity = Binder.clearCallingIdentity();
1413 try {
1414 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1415 checkSimPin.start();
1416 return checkSimPin.unlockSim(null, pin);
1417 } finally {
1418 Binder.restoreCallingIdentity(identity);
1419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 }
1421
Wink Saville9de0f752013-10-22 19:04:03 -07001422 /** {@hide} */
1423 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001424 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001425 }
1426
Wink Savilleb564aae2014-10-23 10:18:09 -07001427 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001429
1430 final long identity = Binder.clearCallingIdentity();
1431 try {
1432 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1433 checkSimPuk.start();
1434 return checkSimPuk.unlockSim(puk, pin);
1435 } finally {
1436 Binder.restoreCallingIdentity(identity);
1437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438 }
1439
1440 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001441 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442 * a synchronous one.
1443 */
1444 private static class UnlockSim extends Thread {
1445
1446 private final IccCard mSimCard;
1447
1448 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001449 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1450 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451
1452 // For replies from SimCard interface
1453 private Handler mHandler;
1454
1455 // For async handler to identify request type
1456 private static final int SUPPLY_PIN_COMPLETE = 100;
1457
1458 public UnlockSim(IccCard simCard) {
1459 mSimCard = simCard;
1460 }
1461
1462 @Override
1463 public void run() {
1464 Looper.prepare();
1465 synchronized (UnlockSim.this) {
1466 mHandler = new Handler() {
1467 @Override
1468 public void handleMessage(Message msg) {
1469 AsyncResult ar = (AsyncResult) msg.obj;
1470 switch (msg.what) {
1471 case SUPPLY_PIN_COMPLETE:
1472 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1473 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001474 mRetryCount = msg.arg1;
1475 if (ar.exception != null) {
1476 if (ar.exception instanceof CommandException &&
1477 ((CommandException)(ar.exception)).getCommandError()
1478 == CommandException.Error.PASSWORD_INCORRECT) {
1479 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1480 } else {
1481 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1482 }
1483 } else {
1484 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 mDone = true;
1487 UnlockSim.this.notifyAll();
1488 }
1489 break;
1490 }
1491 }
1492 };
1493 UnlockSim.this.notifyAll();
1494 }
1495 Looper.loop();
1496 }
1497
1498 /*
1499 * Use PIN or PUK to unlock SIM card
1500 *
1501 * If PUK is null, unlock SIM card with PIN
1502 *
1503 * If PUK is not null, unlock SIM card with PUK and set PIN code
1504 */
Wink Saville9de0f752013-10-22 19:04:03 -07001505 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506
1507 while (mHandler == null) {
1508 try {
1509 wait();
1510 } catch (InterruptedException e) {
1511 Thread.currentThread().interrupt();
1512 }
1513 }
1514 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1515
1516 if (puk == null) {
1517 mSimCard.supplyPin(pin, callback);
1518 } else {
1519 mSimCard.supplyPuk(puk, pin, callback);
1520 }
1521
1522 while (!mDone) {
1523 try {
1524 Log.d(LOG_TAG, "wait for done");
1525 wait();
1526 } catch (InterruptedException e) {
1527 // Restore the interrupted status
1528 Thread.currentThread().interrupt();
1529 }
1530 }
1531 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001532 int[] resultArray = new int[2];
1533 resultArray[0] = mResult;
1534 resultArray[1] = mRetryCount;
1535 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537 }
1538
1539 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001541
1542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 // No permission check needed here: this call is harmless, and it's
1546 // needed for the ServiceState.requestStateUpdate() call (which is
1547 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001548 final long identity = Binder.clearCallingIdentity();
1549 try {
1550 final Phone phone = getPhone(subId);
1551 if (phone != null) {
1552 phone.updateServiceLocation();
1553 }
1554 } finally {
1555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001557 }
1558
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001559 @Override
1560 public boolean isRadioOn(String callingPackage) {
1561 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001562 }
1563
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001564 @Override
1565 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001567 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001568 return false;
1569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001570
1571 final long identity = Binder.clearCallingIdentity();
1572 try {
1573 return isRadioOnForSubscriber(subId);
1574 } finally {
1575 Binder.restoreCallingIdentity(identity);
1576 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001577 }
1578
1579 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001580 final long identity = Binder.clearCallingIdentity();
1581 try {
1582 final Phone phone = getPhone(subId);
1583 if (phone != null) {
1584 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1585 } else {
1586 return false;
1587 }
1588 } finally {
1589 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 }
1592
1593 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001594 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 }
Wink Saville36469e72014-06-11 15:17:00 -07001596
Wink Savilleb564aae2014-10-23 10:18:09 -07001597 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001599
1600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 final Phone phone = getPhone(subId);
1603 if (phone != null) {
1604 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1605 }
1606 } finally {
1607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 }
Wink Saville36469e72014-06-11 15:17:00 -07001609 }
1610
1611 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001612 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001613 }
1614
Wink Savilleb564aae2014-10-23 10:18:09 -07001615 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001616 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001617
1618 final long identity = Binder.clearCallingIdentity();
1619 try {
1620 final Phone phone = getPhone(subId);
1621 if (phone == null) {
1622 return false;
1623 }
1624 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1625 toggleRadioOnOffForSubscriber(subId);
1626 }
1627 return true;
1628 } finally {
1629 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 }
Wink Saville36469e72014-06-11 15:17:00 -07001632
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001633 public boolean needMobileRadioShutdown() {
1634 /*
1635 * If any of the Radios are available, it will need to be
1636 * shutdown. So return true if any Radio is available.
1637 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1641 Phone phone = PhoneFactory.getPhone(i);
1642 if (phone != null && phone.isRadioAvailable()) return true;
1643 }
1644 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1645 return false;
1646 } finally {
1647 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001648 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001649 }
1650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001651 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001652 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001653 enforceModifyPermission();
1654
1655 final long identity = Binder.clearCallingIdentity();
1656 try {
1657 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1658 logv("Shutting down Phone " + i);
1659 shutdownRadioUsingPhoneId(i);
1660 }
1661 } finally {
1662 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001663 }
1664 }
1665
1666 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001667 Phone phone = PhoneFactory.getPhone(phoneId);
1668 if (phone != null && phone.isRadioAvailable()) {
1669 phone.shutdownRadio();
1670 }
1671 }
1672
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001675
1676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1679 if (defaultPhone != null) {
1680 defaultPhone.setRadioPower(turnOn);
1681 return true;
1682 } else {
1683 loge("There's no default phone.");
1684 return false;
1685 }
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001688 }
Wink Saville36469e72014-06-11 15:17:00 -07001689 }
1690
Wink Savilleb564aae2014-10-23 10:18:09 -07001691 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001693
1694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone phone = getPhone(subId);
1697 if (phone != null) {
1698 phone.setRadioPower(turnOn);
1699 return true;
1700 } else {
1701 return false;
1702 }
1703 } finally {
1704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 }
1707
Wink Saville36469e72014-06-11 15:17:00 -07001708 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 public boolean enableDataConnectivity() {
1711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001712
1713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 int subId = mSubscriptionController.getDefaultDataSubId();
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.setUserDataEnabled(true);
1719 return true;
1720 } else {
1721 return false;
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
Wink Saville36469e72014-06-11 15:17:00 -07001728 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001729 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 public boolean disableDataConnectivity() {
1731 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001732
1733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 int subId = mSubscriptionController.getDefaultDataSubId();
1736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
1738 phone.setUserDataEnabled(false);
1739 return true;
1740 } else {
1741 return false;
1742 }
1743 } finally {
1744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
1747
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001749 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 final Phone phone = getPhone(subId);
1753 if (phone != null) {
1754 return phone.isDataAllowed();
1755 } else {
1756 return false;
1757 }
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 }
1762
1763 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001764 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001765 }
1766
pkanwarae03a6b2016-11-06 20:37:09 -08001767 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768 enforceCallPermission();
1769
1770 final long identity = Binder.clearCallingIdentity();
1771 try {
1772 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1773 return;
1774 }
1775 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1776 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1777 } finally {
1778 Binder.restoreCallingIdentity(identity);
1779 }
pkanwar32d516d2016-10-14 19:37:38 -07001780 };
1781
Wink Savilleb564aae2014-10-23 10:18:09 -07001782 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784
1785 final long identity = Binder.clearCallingIdentity();
1786 try {
1787 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1788 return false;
1789 }
1790 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1791 } finally {
1792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 }
1795
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001797 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001798 }
1799
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001800 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 final long identity = Binder.clearCallingIdentity();
1802 try {
1803 Phone phone = PhoneFactory.getPhone(slotIndex);
1804 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1805 PhoneConstantConversions.convertCallState(phone.getState());
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
1808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1816 if (phone != null) {
1817 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1818 } else {
1819 return PhoneConstantConversions.convertDataState(
1820 PhoneConstants.DataState.DISCONNECTED);
1821 }
1822 } finally {
1823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 }
1826
Sanket Padawe356d7632015-06-22 14:03:32 -07001827 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1832 if (phone != null) {
1833 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1834 } else {
1835 return TelephonyManager.DATA_ACTIVITY_NONE;
1836 }
1837 } finally {
1838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
1842 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001843 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001844 mPhone.getContext().getSystemService(AppOpsManager.class)
1845 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001846 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001847 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001848 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 }
1850
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001851 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 if (DBG_LOC) log("getCellLocation: is active user");
1855 Bundle data = new Bundle();
1856 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1857 if (phone == null) {
1858 return null;
1859 }
1860
1861 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1862 return data;
1863 } finally {
1864 Binder.restoreCallingIdentity(identity);
1865 }
Svetoslav64fad262015-04-14 14:35:21 -07001866 }
1867
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001869 public String getNetworkCountryIsoForPhone(int phoneId) {
1870 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1871 // registered cell info, so return a NULL country instead.
1872 final long identity = Binder.clearCallingIdentity();
1873 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001874 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1875 // Get default phone in this case.
1876 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1877 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001878 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001879 // Todo: fix this when we can get the actual cellular network info when the device
1880 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001881 if (TelephonyManager.NETWORK_TYPE_IWLAN
1882 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1883 return "";
1884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 Phone phone = PhoneFactory.getPhone(phoneId);
1886 if (phone != null) {
1887 ServiceStateTracker sst = phone.getServiceStateTracker();
1888 if (sst != null) {
1889 LocaleTracker lt = sst.getLocaleTracker();
1890 if (lt != null) {
1891 return lt.getCurrentCountry();
1892 }
1893 }
1894 }
1895 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001896 } finally {
1897 Binder.restoreCallingIdentity(identity);
1898 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001899 }
1900
1901 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001903 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001904 }
1905
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001907 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 mApp.enforceCallingOrSelfPermission(
1909 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001910
1911 final long identity = Binder.clearCallingIdentity();
1912 try {
1913 final Phone phone = getPhone(subId);
1914 if (phone != null) {
1915 phone.enableLocationUpdates();
1916 }
1917 } finally {
1918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
1922 @Override
1923 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001924 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001925 }
1926
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001928 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 mApp.enforceCallingOrSelfPermission(
1930 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001931
1932 final long identity = Binder.clearCallingIdentity();
1933 try {
1934 final Phone phone = getPhone(subId);
1935 if (phone != null) {
1936 phone.disableLocationUpdates();
1937 }
1938 } finally {
1939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942
1943 @Override
1944 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001945 public List<NeighboringCellInfo>
1946 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001947 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1948 throw new SecurityException(
1949 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1950 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001951
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1953 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1954 return null;
1955 }
Svetoslav64fad262015-04-14 14:35:21 -07001956
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001957 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958
Nathan Haroldf180aac2018-06-01 18:43:55 -07001959 List<CellInfo> info = getAllCellInfo(callingPackage);
1960 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961
Nathan Haroldf180aac2018-06-01 18:43:55 -07001962 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1963 for (CellInfo ci : info) {
1964 if (ci instanceof CellInfoGsm) {
1965 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1966 } else if (ci instanceof CellInfoWcdma) {
1967 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001970 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 }
1972
1973
1974 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001975 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001976 mPhone.getContext().getSystemService(AppOpsManager.class)
1977 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001978 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001979 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001980 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 }
1982
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001983 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001984 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1988 for (Phone phone : PhoneFactory.getPhones()) {
1989 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1990 if (info != null) cellInfos.addAll(info);
1991 }
1992 return cellInfos;
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 }
1996 }
1997
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001998 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002000 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002001 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002002
2003 final long identity = Binder.clearCallingIdentity();
2004 try {
2005 mPhone.setCellInfoListRate(rateInMillis, workSource);
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
2008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
Shishir Agrawala9f32182016-04-12 12:00:16 -07002011 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002012 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002013 Phone phone = PhoneFactory.getPhone(slotIndex);
2014 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002015 return null;
2016 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002017 int subId = phone.getSubId();
2018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2019 mApp, subId, callingPackage, "getImeiForSlot")) {
2020 return null;
2021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022
2023 final long identity = Binder.clearCallingIdentity();
2024 try {
2025 return phone.getImei();
2026 } finally {
2027 Binder.restoreCallingIdentity(identity);
2028 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002029 }
2030
2031 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002032 public String getTypeAllocationCodeForSlot(int slotIndex) {
2033 Phone phone = PhoneFactory.getPhone(slotIndex);
2034 String tac = null;
2035 if (phone != null) {
2036 String imei = phone.getImei();
2037 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2038 }
2039 return tac;
2040 }
2041
2042 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002043 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002044 Phone phone = PhoneFactory.getPhone(slotIndex);
2045 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002046 return null;
2047 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002048 int subId = phone.getSubId();
2049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2050 mApp, subId, callingPackage, "getMeidForSlot")) {
2051 return null;
2052 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002053
2054 final long identity = Binder.clearCallingIdentity();
2055 try {
2056 return phone.getMeid();
2057 } finally {
2058 Binder.restoreCallingIdentity(identity);
2059 }
Jack Yu2af8d712017-03-15 17:14:14 -07002060 }
2061
2062 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002063 public String getManufacturerCodeForSlot(int slotIndex) {
2064 Phone phone = PhoneFactory.getPhone(slotIndex);
2065 String manufacturerCode = null;
2066 if (phone != null) {
2067 String meid = phone.getMeid();
2068 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2069 }
2070 return manufacturerCode;
2071 }
2072
2073 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002074 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002075 Phone phone = PhoneFactory.getPhone(slotIndex);
2076 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002077 return null;
2078 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002079 int subId = phone.getSubId();
2080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2081 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2082 return null;
2083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002084
2085 final long identity = Binder.clearCallingIdentity();
2086 try {
2087 return phone.getDeviceSvn();
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
2090 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002091 }
2092
fionaxu43304da2017-11-27 22:51:16 -08002093 @Override
2094 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002095 final long identity = Binder.clearCallingIdentity();
2096 try {
2097 final Phone phone = getPhone(subId);
2098 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2099 } finally {
2100 Binder.restoreCallingIdentity(identity);
2101 }
fionaxu43304da2017-11-27 22:51:16 -08002102 }
2103
2104 @Override
2105 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002106 final long identity = Binder.clearCallingIdentity();
2107 try {
2108 final Phone phone = getPhone(subId);
2109 return phone == null ? null : phone.getCarrierName();
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
2112 }
fionaxu43304da2017-11-27 22:51:16 -08002113 }
2114
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 //
2116 // Internal helper methods.
2117 //
2118
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002119 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2121 *
2122 * @throws SecurityException if the caller does not have the required permission
2123 */
2124 private void enforceModifyPermission() {
2125 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2126 }
2127
2128 /**
2129 * Make sure the caller has the CALL_PHONE permission.
2130 *
2131 * @throws SecurityException if the caller does not have the required permission
2132 */
2133 private void enforceCallPermission() {
2134 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2135 }
2136
Stuart Scott8eef64f2015-04-08 15:13:54 -07002137 private void enforceConnectivityInternalPermission() {
2138 mApp.enforceCallingOrSelfPermission(
2139 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2140 "ConnectivityService");
2141 }
2142
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 private String createTelUrl(String number) {
2144 if (TextUtils.isEmpty(number)) {
2145 return null;
2146 }
2147
Jake Hambye994d462014-02-03 13:10:13 -08002148 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 }
2150
Ihab Awadf9e92732013-12-05 18:02:52 -08002151 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2153 }
2154
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002155 private static void logv(String msg) {
2156 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2157 }
2158
Ihab Awadf9e92732013-12-05 18:02:52 -08002159 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2161 }
2162
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002163 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002165 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
2167
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002169 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 final Phone phone = PhoneFactory.getPhone(slotIndex);
2173 if (phone == null) {
2174 return PhoneConstants.PHONE_TYPE_NONE;
2175 } else {
2176 return phone.getPhoneType();
2177 }
2178 } finally {
2179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182
2183 /**
2184 * Returns the CDMA ERI icon index to display
2185 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002186 @Override
2187 public int getCdmaEriIconIndex(String callingPackage) {
2188 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002189 }
2190
Sanket Padawe356d7632015-06-22 14:03:32 -07002191 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002192 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002193 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002194 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002195 return -1;
2196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002197
2198 final long identity = Binder.clearCallingIdentity();
2199 try {
2200 final Phone phone = getPhone(subId);
2201 if (phone != null) {
2202 return phone.getCdmaEriIconIndex();
2203 } else {
2204 return -1;
2205 }
2206 } finally {
2207 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 }
2210
2211 /**
2212 * Returns the CDMA ERI icon mode,
2213 * 0 - ON
2214 * 1 - FLASHING
2215 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002216 @Override
2217 public int getCdmaEriIconMode(String callingPackage) {
2218 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
2220
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002222 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002224 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002225 return -1;
2226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227
2228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 final Phone phone = getPhone(subId);
2231 if (phone != null) {
2232 return phone.getCdmaEriIconMode();
2233 } else {
2234 return -1;
2235 }
2236 } finally {
2237 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
2241 /**
2242 * Returns the CDMA ERI text,
2243 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002244 @Override
2245 public String getCdmaEriText(String callingPackage) {
2246 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002247 }
2248
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002250 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002252 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002253 return null;
2254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255
2256 final long identity = Binder.clearCallingIdentity();
2257 try {
2258 final Phone phone = getPhone(subId);
2259 if (phone != null) {
2260 return phone.getCdmaEriText();
2261 } else {
2262 return null;
2263 }
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
2269 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002270 * Returns the CDMA MDN.
2271 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002273 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2275 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002276
2277 final long identity = Binder.clearCallingIdentity();
2278 try {
2279 final Phone phone = getPhone(subId);
2280 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2281 return phone.getLine1Number();
2282 } else {
2283 return null;
2284 }
2285 } finally {
2286 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002287 }
2288 }
2289
2290 /**
2291 * Returns the CDMA MIN.
2292 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002293 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002294 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2296 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297
2298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 final Phone phone = getPhone(subId);
2301 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2302 return phone.getCdmaMin();
2303 } else {
2304 return null;
2305 }
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002308 }
2309 }
2310
2311 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 * Returns true if CDMA provisioning needs to run.
2313 */
2314 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002315 final long identity = Binder.clearCallingIdentity();
2316 try {
2317 return mPhone.needsOtaServiceProvisioning();
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
2320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 }
2322
2323 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002324 * Sets the voice mail number of a given subId.
2325 */
2326 @Override
2327 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002328 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002329
2330 final long identity = Binder.clearCallingIdentity();
2331 try {
2332 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2333 new Pair<String, String>(alphaTag, number), new Integer(subId));
2334 return success;
2335 } finally {
2336 Binder.restoreCallingIdentity(identity);
2337 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002338 }
2339
Ta-wei Yen87c49842016-05-13 21:19:52 -07002340 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002341 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2342 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2343 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2344 if (!TextUtils.equals(callingPackage, systemDialer)) {
2345 throw new SecurityException("caller must be system dialer");
2346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2351 if (phoneAccountHandle == null) {
2352 return null;
2353 }
2354 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002357 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002358 }
2359
2360 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002361 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002362 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002363 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002364 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002365 return null;
2366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002367
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002368 final long identity = Binder.clearCallingIdentity();
2369 try {
2370 return RemoteVvmTaskManager
2371 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
2374 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002375 }
2376
2377 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002378 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2379 VisualVoicemailSmsFilterSettings settings) {
2380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002381
2382 final long identity = Binder.clearCallingIdentity();
2383 try {
2384 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2385 mPhone.getContext(), callingPackage, subId, settings);
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002389 }
2390
2391 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002392 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002394
2395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2398 mPhone.getContext(), callingPackage, subId);
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
2401 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002402 }
2403
2404 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002405 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2406 String callingPackage, int subId) {
2407 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002408
2409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2412 mPhone.getContext(), callingPackage, subId);
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002416 }
2417
2418 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002419 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002420 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421
2422 final long identity = Binder.clearCallingIdentity();
2423 try {
2424 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2425 mPhone.getContext(), subId);
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002429 }
2430
2431 @Override
2432 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2433 String number, int port, String text, PendingIntent sentIntent) {
2434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002435 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002436 enforceSendSmsPermission();
2437 // Make the calls as the phone process.
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2441 if (port == 0) {
2442 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2443 sentIntent, null, false);
2444 } else {
2445 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2446 smsManager.sendDataMessageWithSelfPermissions(number, null,
2447 (short) port, data, sentIntent, null);
2448 }
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
2451 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002452 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002453 /**
fionaxu0152e512016-11-14 13:36:14 -08002454 * Sets the voice activation state of a given subId.
2455 */
2456 @Override
2457 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2459 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460
2461 final long identity = Binder.clearCallingIdentity();
2462 try {
2463 final Phone phone = getPhone(subId);
2464 if (phone != null) {
2465 phone.setVoiceActivationState(activationState);
2466 } else {
2467 loge("setVoiceActivationState fails with invalid subId: " + subId);
2468 }
2469 } finally {
2470 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002471 }
2472 }
2473
2474 /**
2475 * Sets the data activation state of a given subId.
2476 */
2477 @Override
2478 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2480 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481
2482 final long identity = Binder.clearCallingIdentity();
2483 try {
2484 final Phone phone = getPhone(subId);
2485 if (phone != null) {
2486 phone.setDataActivationState(activationState);
2487 } else {
2488 loge("setVoiceActivationState fails with invalid subId: " + subId);
2489 }
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002492 }
2493 }
2494
2495 /**
2496 * Returns the voice activation state of a given subId.
2497 */
2498 @Override
2499 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002500 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501
fionaxu0152e512016-11-14 13:36:14 -08002502 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 if (phone != null) {
2506 return phone.getVoiceActivationState();
2507 } else {
2508 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2509 }
2510 } finally {
2511 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002512 }
2513 }
2514
2515 /**
2516 * Returns the data activation state of a given subId.
2517 */
2518 @Override
2519 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002520 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521
fionaxu0152e512016-11-14 13:36:14 -08002522 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 final long identity = Binder.clearCallingIdentity();
2524 try {
2525 if (phone != null) {
2526 return phone.getDataActivationState();
2527 } else {
2528 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2529 }
2530 } finally {
2531 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002532 }
2533 }
2534
2535 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002536 * Returns the unread count of voicemails
2537 */
2538 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002539 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002540 }
2541
2542 /**
2543 * Returns the unread count of voicemails for a subId
2544 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002545 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002546 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547 final long identity = Binder.clearCallingIdentity();
2548 try {
2549 final Phone phone = getPhone(subId);
2550 if (phone != null) {
2551 return phone.getVoiceMessageCount();
2552 } else {
2553 return 0;
2554 }
2555 } finally {
2556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 }
2559
2560 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002561 * returns true, if the device is in a state where both voice and data
2562 * are supported simultaneously. This can change based on location or network condition.
2563 */
2564 @Override
2565 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 final Phone phone = getPhone(subId);
2569 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
2572 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002573 }
2574
2575 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002576 * Send the dialer code if called from the current default dialer or the caller has
2577 * carrier privilege.
2578 * @param inputCode The dialer code to send
2579 */
2580 @Override
2581 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2583 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2584 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002585 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2586 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002587 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588
2589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 mPhone.sendDialerSpecialCode(inputCode);
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
2594 }
fionaxu235cc5e2017-03-06 22:25:57 -08002595 }
2596
2597 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002598 * Returns the data network type.
2599 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600 *
2601 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2602 */
2603 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002604 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(getDefaultSubscription());
2608 if (phone != null) {
2609 return phone.getServiceState().getDataNetworkType();
2610 } else {
2611 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2612 }
2613 } finally {
2614 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002615 }
Wink Saville36469e72014-06-11 15:17:00 -07002616 }
2617
Pengquan Menga1bb6272018-09-06 09:59:22 -07002618 @Override
2619 public int getNetworkSelectionMode(int subId) {
2620 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2621 }
2622
Wink Saville36469e72014-06-11 15:17:00 -07002623 /**
2624 * Returns the network type for a subId
2625 */
2626 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002627 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002629 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2631 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 final Phone phone = getPhone(subId);
2636 if (phone != null) {
2637 return phone.getServiceState().getDataNetworkType();
2638 } else {
2639 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2640 }
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 }
2645
2646 /**
2647 * Returns the data network type
2648 */
2649 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002650 public int getDataNetworkType(String callingPackage) {
2651 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002652 }
2653
2654 /**
2655 * Returns the data network type for a subId
2656 */
2657 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002658 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002660 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002661 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2662 }
2663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664 final long identity = Binder.clearCallingIdentity();
2665 try {
2666 final Phone phone = getPhone(subId);
2667 if (phone != null) {
2668 return phone.getServiceState().getDataNetworkType();
2669 } else {
2670 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2671 }
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 }
2676
2677 /**
Wink Saville36469e72014-06-11 15:17:00 -07002678 * Returns the Voice network type for a subId
2679 */
2680 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002681 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002683 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002684 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2685 }
2686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 final Phone phone = getPhone(subId);
2690 if (phone != null) {
2691 return phone.getServiceState().getVoiceNetworkType();
2692 } else {
2693 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2694 }
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699
2700 /**
2701 * @return true if a ICC card is present
2702 */
2703 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002704 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002705 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2706 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002707 }
2708
2709 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002710 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002711 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002712 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002713 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 final Phone phone = PhoneFactory.getPhone(slotIndex);
2717 if (phone != null) {
2718 return phone.getIccCard().hasIccCard();
2719 } else {
2720 return false;
2721 }
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 }
2726
2727 /**
2728 * Return if the current radio is LTE on CDMA. This
2729 * is a tri-state return value as for a period of time
2730 * the mode may be unknown.
2731 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002732 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002734 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002736 @Override
2737 public int getLteOnCdmaMode(String callingPackage) {
2738 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002739 }
2740
Sanket Padawe356d7632015-06-22 14:03:32 -07002741 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002742 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002744 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002745 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2746 }
2747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 final Phone phone = getPhone(subId);
2751 if (phone == null) {
2752 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2753 } else {
2754 return phone.getLteOnCdmaMode();
2755 }
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 }
Wink Saville36469e72014-06-11 15:17:00 -07002759 }
2760
2761 public void setPhone(Phone phone) {
2762 mPhone = phone;
2763 }
2764
2765 /**
2766 * {@hide}
2767 * Returns Default subId, 0 in the case of single standby.
2768 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002769 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002770 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002771 }
2772
Shishir Agrawala9f32182016-04-12 12:00:16 -07002773 private int getSlotForDefaultSubscription() {
2774 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2775 }
2776
Wink Savilleb564aae2014-10-23 10:18:09 -07002777 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002778 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002780
2781 /**
2782 * @see android.telephony.TelephonyManager.WifiCallingChoices
2783 */
2784 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 final long identity = Binder.clearCallingIdentity();
2786 try {
2787 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2788 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2789 getWhenToMakeWifiCallsDefaultPreference());
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
2792 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002793 }
2794
2795 /**
2796 * @see android.telephony.TelephonyManager.WifiCallingChoices
2797 */
2798 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2802 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2803 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2804 } finally {
2805 Binder.restoreCallingIdentity(identity);
2806 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002807 }
2808
Sailesh Nepald1e68152013-12-12 19:08:02 -08002809 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002810 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002811 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002812 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002813
Shishir Agrawal566b7612013-10-28 14:41:00 -07002814 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002815 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2816 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2818 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 if (TextUtils.equals(ISDR_AID, aid)) {
2824 // Only allows LPA to open logical channel to ISD-R.
2825 ComponentInfo bestComponent =
2826 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2827 if (bestComponent == null
2828 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2829 loge("The calling package is not allowed to access ISD-R.");
2830 throw new SecurityException(
2831 "The calling package is not allowed to access ISD-R.");
2832 }
Derek Tan740e1672017-06-27 14:56:27 -07002833 }
Derek Tan740e1672017-06-27 14:56:27 -07002834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 if (DBG) {
2836 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2837 }
2838 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2839 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2840 if (DBG) log("iccOpenLogicalChannel: " + response);
2841 return response;
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
2844 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002845 }
2846
2847 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002848 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2850 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2855 if (channel < 0) {
2856 return false;
2857 }
2858 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2859 if (DBG) log("iccCloseLogicalChannel: " + success);
2860 return success;
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002863 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002864 }
2865
2866 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002867 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002868 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2870 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 final long identity = Binder.clearCallingIdentity();
2873 try {
2874 if (DBG) {
2875 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2876 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2877 + p3 + " data=" + data);
2878 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 if (channel < 0) {
2881 return "";
2882 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2885 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2886 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888 // Append the returned status code to the end of the response payload.
2889 String s = Integer.toHexString(
2890 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2891 if (response.payload != null) {
2892 s = IccUtils.bytesToHexString(response.payload) + s;
2893 }
2894 return s;
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002897 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002898 }
Jake Hambye994d462014-02-03 13:10:13 -08002899
Evan Charltonc66da362014-05-16 14:06:40 -07002900 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002901 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2902 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2904 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2910 && TextUtils.equals(ISDR_AID, data)) {
2911 // Only allows LPA to select ISD-R.
2912 ComponentInfo bestComponent =
2913 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2914 if (bestComponent == null
2915 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2916 loge("The calling package is not allowed to select ISD-R.");
2917 throw new SecurityException(
2918 "The calling package is not allowed to select ISD-R.");
2919 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002920 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 if (DBG) {
2923 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2924 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2925 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2928 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2929 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931 // Append the returned status code to the end of the response payload.
2932 String s = Integer.toHexString(
2933 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2934 if (response.payload != null) {
2935 s = IccUtils.bytesToHexString(response.payload) + s;
2936 }
2937 return s;
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002940 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002941 }
2942
2943 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002944 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002945 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2947 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 if (DBG) {
2952 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2953 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2954 }
2955
2956 IccIoResult response =
2957 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2958 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2959 subId);
2960
2961 if (DBG) {
2962 log("Exchange SIM_IO [R]" + response);
2963 }
2964
2965 byte[] result = null;
2966 int length = 2;
2967 if (response.payload != null) {
2968 length = 2 + response.payload.length;
2969 result = new byte[length];
2970 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2971 } else {
2972 result = new byte[length];
2973 }
2974
2975 result[length - 1] = (byte) response.sw2;
2976 result[length - 2] = (byte) response.sw1;
2977 return result;
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002980 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002981 }
2982
Nathan Haroldb3014052017-01-25 15:57:32 -08002983 /**
2984 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2985 * on a particular subscription
2986 */
sqianb6e41952018-03-12 14:54:01 -07002987 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2989 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2990 return null;
2991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002992
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 if (appType != TelephonyManager.APPTYPE_USIM
2996 && appType != TelephonyManager.APPTYPE_SIM) {
2997 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2998 return null;
2999 }
3000 Object response = sendRequest(
3001 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3002 if (response instanceof String[]) {
3003 return (String[]) response;
3004 }
3005 // Response is an Exception of some kind,
3006 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003007 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 } finally {
3009 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003010 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003011 }
3012
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003013 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003014 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3016 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3021 if (response.payload == null) {
3022 return "";
3023 }
Evan Charltonc66da362014-05-16 14:06:40 -07003024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 // Append the returned status code to the end of the response payload.
3026 String s = Integer.toHexString(
3027 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3028 s = IccUtils.bytesToHexString(response.payload) + s;
3029 return s;
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
Evan Charltonc66da362014-05-16 14:06:40 -07003033 }
3034
Jake Hambye994d462014-02-03 13:10:13 -08003035 /**
3036 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3037 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3038 *
3039 * @param itemID the ID of the item to read
3040 * @return the NV item as a String, or null on error.
3041 */
3042 @Override
3043 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3045 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046
3047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 if (DBG) log("nvReadItem: item " + itemID);
3050 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3051 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3052 return value;
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
Jake Hambye994d462014-02-03 13:10:13 -08003056 }
3057
3058 /**
3059 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3060 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3061 *
3062 * @param itemID the ID of the item to read
3063 * @param itemValue the value to write, as a String
3064 * @return true on success; false on any failure
3065 */
3066 @Override
3067 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3069 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3074 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3075 new Pair<Integer, String>(itemID, itemValue));
3076 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3077 return success;
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
Jake Hambye994d462014-02-03 13:10:13 -08003081 }
3082
3083 /**
3084 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3085 * Used for device configuration by some CDMA operators.
3086 *
3087 * @param preferredRoamingList byte array containing the new PRL
3088 * @return true on success; false on any failure
3089 */
3090 @Override
3091 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3093 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094
3095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3098 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3099 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3100 return success;
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
Jake Hambye994d462014-02-03 13:10:13 -08003104 }
3105
3106 /**
3107 * Perform the specified type of NV config reset.
3108 * Used for device configuration by some CDMA operators.
3109 *
3110 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3111 * @return true on success; false on any failure
3112 */
3113 @Override
3114 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3116 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117
3118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 if (DBG) log("nvResetConfig: type " + resetType);
3121 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3122 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3123 return success;
3124 } finally {
3125 Binder.restoreCallingIdentity(identity);
3126 }
Jake Hambye994d462014-02-03 13:10:13 -08003127 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003128
Svet Ganovb320e182015-04-16 12:30:10 -07003129 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003131 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003132 return new String[0];
3133 }
3134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 return mPhone.getPcscfAddress(apnType);
3138 } finally {
3139 Binder.restoreCallingIdentity(identity);
3140 }
Wink Saville36469e72014-06-11 15:17:00 -07003141 }
3142
Brad Ebinger51f743a2017-01-23 13:50:20 -08003143 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003144 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3145 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003146 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003147 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003148 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 PhoneFactory.getImsResolver().enableIms(slotId);
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003156 }
3157
3158 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003159 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3160 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003161 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003162 public void disableIms(int slotId) {
3163 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 PhoneFactory.getImsResolver().disableIms(slotId);
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003171 }
3172
3173 /**
3174 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3175 * feature or {@link null} if the service is not available. If the feature is available, the
3176 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3177 */
3178 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003179 IImsServiceFeatureCallback callback) {
3180 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003188 }
3189
3190 /**
3191 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3192 * feature during emergency calling or {@link null} if the service is not available. If the
3193 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3194 * listener for feature updates.
3195 */
3196 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3197 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198
3199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
3204 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003205 }
3206
Brad Ebinger5f64b052017-12-14 14:26:15 -08003207 /**
3208 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3209 * specified.
3210 */
3211 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3212 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213
3214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003220 }
3221
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003222 /**
3223 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3224 * specified.
3225 */
3226 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3227 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003235 }
3236
Brad Ebinger884c07b2018-02-15 16:17:40 -08003237 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003238 * Sets the ImsService Package Name that Telephony will bind to.
3239 *
3240 * @param slotId the slot ID that the ImsService should bind for.
3241 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3242 * ImsService is the device default ImsService.
3243 * @param packageName The package name of the application that contains the ImsService to bind
3244 * to.
3245 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3246 * @hide
3247 */
3248 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003249 int[] subIds = SubscriptionManager.getSubId(slotId);
3250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3251 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3252 "setImsService");
3253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254 final long identity = Binder.clearCallingIdentity();
3255 try {
3256 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3257 isCarrierImsService, packageName);
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003261 }
3262
3263 /**
3264 * Return the ImsService configuration.
3265 *
3266 * @param slotId The slot that the ImsService is associated with.
3267 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3268 * the device default.
3269 * @return the package name of the ImsService configuration.
3270 */
3271 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003272 int[] subIds = SubscriptionManager.getSubId(slotId);
3273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3274 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3275 "getImsService");
3276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277 final long identity = Binder.clearCallingIdentity();
3278 try {
3279 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3280 isCarrierImsService);
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
3283 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003284 }
3285
Wink Saville36469e72014-06-11 15:17:00 -07003286 public void setImsRegistrationState(boolean registered) {
3287 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288
3289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 mPhone.setImsRegistrationState(registered);
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
3294 }
Wink Saville36469e72014-06-11 15:17:00 -07003295 }
3296
3297 /**
Stuart Scott54788802015-03-30 13:18:01 -07003298 * Set the network selection mode to automatic.
3299 *
3300 */
3301 @Override
3302 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3304 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305
3306 final long identity = Binder.clearCallingIdentity();
3307 try {
3308 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3309 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
3312 }
Stuart Scott54788802015-03-30 13:18:01 -07003313 }
3314
3315 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003316 * Set the network selection mode to manual with the selected carrier.
3317 */
3318 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003319 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003320 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3322 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003323
3324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003327 /* operatorAlphaLong */ "",
3328 /* operatorAlphaShort */ "",
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 operatorNumeric);
3330 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3331 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3332 persistSelection);
3333 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
3336 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003337 }
3338
3339 /**
3340 * Scans for available networks.
3341 */
3342 @Override
3343 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3345 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346
Pengquan Menga1bb6272018-09-06 09:59:22 -07003347 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 try {
3349 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07003350 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003355 }
3356
3357 /**
yinxub1bed742017-04-17 11:45:04 -07003358 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003359 *
yinxub1bed742017-04-17 11:45:04 -07003360 * @param subId id of the subscription
3361 * @param request contains the radio access networks with bands/channels to scan
3362 * @param messenger callback messenger for scan results or errors
3363 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003364 * @return the id of the requested scan which can be used to stop the scan.
3365 */
3366 @Override
3367 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3368 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3370 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003371
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 return mNetworkScanRequestTracker.startNetworkScan(
3375 request, messenger, binder, getPhone(subId));
3376 } finally {
3377 Binder.restoreCallingIdentity(identity);
3378 }
yinxu504e1392017-04-12 16:03:22 -07003379 }
3380
3381 /**
3382 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003383 *
3384 * @param subId id of the subscription
3385 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003386 */
3387 @Override
3388 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3390 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3395 } finally {
3396 Binder.restoreCallingIdentity(identity);
3397 }
yinxu504e1392017-04-12 16:03:22 -07003398 }
3399
3400 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003401 * Get the calculated preferred network type.
3402 * Used for debugging incorrect network type.
3403 *
3404 * @return the preferred network type, defined in RILConstants.java.
3405 */
3406 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003407 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003408 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003409 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003410 return RILConstants.PREFERRED_NETWORK_MODE;
3411 }
3412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 // FIXME: need to get SubId from somewhere.
3416 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
Junda Liu84d15a22014-07-02 11:21:04 -07003420 }
3421
3422 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003423 * Get the preferred network type.
3424 * Used for device configuration by some CDMA operators.
3425 *
3426 * @return the preferred network type, defined in RILConstants.java.
3427 */
3428 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003429 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3431 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432
3433 final long identity = Binder.clearCallingIdentity();
3434 try {
3435 if (DBG) log("getPreferredNetworkType");
3436 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3437 int networkType = (result != null ? result[0] : -1);
3438 if (DBG) log("getPreferredNetworkType: " + networkType);
3439 return networkType;
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003443 }
3444
3445 /**
3446 * Set the preferred network type.
3447 * Used for device configuration by some CDMA operators.
3448 *
3449 * @param networkType the preferred network type, defined in RILConstants.java.
3450 * @return true on success; false on any failure.
3451 */
3452 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003453 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3455 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003456
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3460 Boolean success = (Boolean) sendRequest(
3461 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3462 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3463 if (success) {
3464 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3465 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3466 }
3467 return success;
3468 } finally {
3469 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003470 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003471 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003472
3473 /**
Junda Liu475951f2014-11-07 16:45:03 -08003474 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3475 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3476 * tethering.
3477 *
3478 * @return 0: Not required. 1: required. 2: Not set.
3479 * @hide
3480 */
3481 @Override
3482 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003483 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003484
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3488 Settings.Global.TETHER_DUN_REQUIRED, 2);
3489 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3490 // config_tether_apndata.
3491 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3492 dunRequired = 1;
3493 }
3494 return dunRequired;
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003497 }
Junda Liu475951f2014-11-07 16:45:03 -08003498 }
3499
3500 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003501 * Set mobile data enabled
3502 * Used by the user through settings etc to turn on/off mobile data
3503 *
3504 * @param enable {@code true} turn turn data on, else {@code false}
3505 */
3506 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003507 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3509 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003510
3511 final long identity = Binder.clearCallingIdentity();
3512 try {
3513 int phoneId = mSubscriptionController.getPhoneId(subId);
3514 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3515 Phone phone = PhoneFactory.getPhone(phoneId);
3516 if (phone != null) {
3517 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3518 phone.setUserDataEnabled(enable);
3519 } else {
3520 loge("setUserDataEnabled: no phone for subId=" + subId);
3521 }
3522 } finally {
3523 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003524 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003525 }
3526
3527 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003528 * Get the user enabled state of Mobile Data.
3529 *
3530 * TODO: remove and use isUserDataEnabled.
3531 * This can't be removed now because some vendor codes
3532 * calls through ITelephony directly while they should
3533 * use TelephonyManager.
3534 *
3535 * @return true on enabled
3536 */
3537 @Override
3538 public boolean getDataEnabled(int subId) {
3539 return isUserDataEnabled(subId);
3540 }
3541
3542 /**
3543 * Get whether mobile data is enabled per user setting.
3544 *
3545 * There are other factors deciding whether mobile data is actually enabled, but they are
3546 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003547 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003548 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003549 *
3550 * @return {@code true} if data is enabled else {@code false}
3551 */
3552 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003553 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003554 try {
3555 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3556 null);
3557 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3559 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 int phoneId = mSubscriptionController.getPhoneId(subId);
3565 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3566 Phone phone = PhoneFactory.getPhone(phoneId);
3567 if (phone != null) {
3568 boolean retVal = phone.isUserDataEnabled();
3569 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3570 return retVal;
3571 } else {
3572 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3573 return false;
3574 }
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003577 }
3578 }
3579
3580 /**
3581 * Get whether mobile data is enabled.
3582 *
3583 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3584 * whether mobile data is actually enabled.
3585 *
3586 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3587 *
3588 * @return {@code true} if data is enabled else {@code false}
3589 */
3590 @Override
3591 public boolean isDataEnabled(int subId) {
3592 try {
3593 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3594 null);
3595 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3597 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599
3600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 int phoneId = mSubscriptionController.getPhoneId(subId);
3603 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3604 Phone phone = PhoneFactory.getPhone(phoneId);
3605 if (phone != null) {
3606 boolean retVal = phone.isDataEnabled();
3607 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3608 return retVal;
3609 } else {
3610 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3611 return false;
3612 }
3613 } finally {
3614 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003615 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003616 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003617
3618 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003619 public int getCarrierPrivilegeStatus(int subId) {
3620 final Phone phone = getPhone(subId);
3621 if (phone == null) {
3622 loge("getCarrierPrivilegeStatus: Invalid subId");
3623 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3624 }
3625 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003626 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003627 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003628 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3629 }
3630 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003631 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003632 }
Junda Liu29340342014-07-10 15:23:27 -07003633
3634 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003635 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3636 final Phone phone = getPhone(subId);
3637 if (phone == null) {
3638 loge("getCarrierPrivilegeStatus: Invalid subId");
3639 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3640 }
3641 UiccProfile profile =
3642 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3643 if (profile == null) {
3644 loge("getCarrierPrivilegeStatus: No UICC");
3645 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3646 }
3647 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3648 }
3649
3650 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003651 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003652 if (TextUtils.isEmpty(pkgName))
3653 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003654 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003655 if (card == null) {
3656 loge("checkCarrierPrivilegesForPackage: No UICC");
3657 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3658 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003659 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3660 }
3661
3662 @Override
3663 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003664 if (TextUtils.isEmpty(pkgName))
3665 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003666 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3667 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3668 UiccCard card = UiccController.getInstance().getUiccCard(i);
3669 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003670 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003671 continue;
3672 }
3673
3674 result = card.getCarrierPrivilegeStatus(
3675 mPhone.getContext().getPackageManager(), pkgName);
3676 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3677 break;
3678 }
3679 }
3680
3681 return result;
Junda Liu29340342014-07-10 15:23:27 -07003682 }
Derek Tan89e89d42014-07-08 17:00:10 -07003683
3684 @Override
Junda Liue64de782015-04-16 17:19:16 -07003685 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3686 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3687 loge("phoneId " + phoneId + " is not valid.");
3688 return null;
3689 }
3690 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003691 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003692 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003693 return null ;
3694 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003695 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003696 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003697 }
3698
Amith Yamasani6e118872016-02-19 12:53:51 -08003699 @Override
3700 public List<String> getPackagesWithCarrierPrivileges() {
3701 PackageManager pm = mPhone.getContext().getPackageManager();
3702 List<String> privilegedPackages = new ArrayList<>();
3703 List<PackageInfo> packages = null;
3704 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3705 UiccCard card = UiccController.getInstance().getUiccCard(i);
3706 if (card == null) {
3707 // No UICC in that slot.
3708 continue;
3709 }
3710 if (card.hasCarrierPrivilegeRules()) {
3711 if (packages == null) {
3712 // Only check packages in user 0 for now
3713 packages = pm.getInstalledPackagesAsUser(
3714 PackageManager.MATCH_DISABLED_COMPONENTS
3715 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3716 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3717 }
3718 for (int p = packages.size() - 1; p >= 0; p--) {
3719 PackageInfo pkgInfo = packages.get(p);
3720 if (pkgInfo != null && pkgInfo.packageName != null
3721 && card.getCarrierPrivilegeStatus(pkgInfo)
3722 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3723 privilegedPackages.add(pkgInfo.packageName);
3724 }
3725 }
3726 }
3727 }
3728 return privilegedPackages;
3729 }
3730
Wink Savilleb564aae2014-10-23 10:18:09 -07003731 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003732 final Phone phone = getPhone(subId);
3733 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003734 if (card == null) {
3735 loge("getIccId: No UICC");
3736 return null;
3737 }
3738 String iccId = card.getIccId();
3739 if (TextUtils.isEmpty(iccId)) {
3740 loge("getIccId: ICC ID is null or empty.");
3741 return null;
3742 }
3743 return iccId;
3744 }
3745
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003746 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003747 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3748 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003749 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3750 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 final String iccId = getIccId(subId);
3755 final Phone phone = getPhone(subId);
3756 if (phone == null) {
3757 return false;
3758 }
3759 final String subscriberId = phone.getSubscriberId();
3760
3761 if (DBG_MERGE) {
3762 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3763 + subscriberId + " to " + number);
3764 }
3765
3766 if (TextUtils.isEmpty(iccId)) {
3767 return false;
3768 }
3769
3770 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3771
3772 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3773 if (alphaTag == null) {
3774 editor.remove(alphaTagPrefKey);
3775 } else {
3776 editor.putString(alphaTagPrefKey, alphaTag);
3777 }
3778
3779 // Record both the line number and IMSI for this ICCID, since we need to
3780 // track all merged IMSIs based on line number
3781 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3782 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3783 if (number == null) {
3784 editor.remove(numberPrefKey);
3785 editor.remove(subscriberPrefKey);
3786 } else {
3787 editor.putString(numberPrefKey, number);
3788 editor.putString(subscriberPrefKey, subscriberId);
3789 }
3790
3791 editor.commit();
3792 return true;
3793 } finally {
3794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003795 }
Derek Tan7226c842014-07-02 17:42:23 -07003796 }
3797
3798 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003799 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003800 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003802 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003803 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003804 return null;
3805 }
Derek Tan97ebb422014-09-05 16:55:38 -07003806
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 String iccId = getIccId(subId);
3810 if (iccId != null) {
3811 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3812 if (DBG_MERGE) {
3813 log("getLine1NumberForDisplay returning "
3814 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3815 }
3816 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003817 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3819 return null;
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003822 }
Derek Tan7226c842014-07-02 17:42:23 -07003823 }
3824
3825 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003826 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003828 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003829 return null;
3830 }
Derek Tan97ebb422014-09-05 16:55:38 -07003831
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 String iccId = getIccId(subId);
3835 if (iccId != null) {
3836 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3837 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3838 }
3839 return null;
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003842 }
Derek Tan7226c842014-07-02 17:42:23 -07003843 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003844
3845 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003846 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003847 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3848 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003850 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3851 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003852 return null;
3853 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003854
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003855 final long identity = Binder.clearCallingIdentity();
3856 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final Context context = mPhone.getContext();
3858 final TelephonyManager tele = TelephonyManager.from(context);
3859 final SubscriptionManager sub = SubscriptionManager.from(context);
3860
3861 // Figure out what subscribers are currently active
3862 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3863 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3864 // the process, where TelephonyManager was instantiated.
3865 // Otherwise AppOps check will fail.
3866
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003867 final int[] subIds = sub.getActiveSubscriptionIdList();
3868 for (int subId : subIds) {
3869 activeSubscriberIds.add(tele.getSubscriberId(subId));
3870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871
3872 // First pass, find a number override for an active subscriber
3873 String mergeNumber = null;
3874 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3875 for (String key : prefs.keySet()) {
3876 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3877 final String subscriberId = (String) prefs.get(key);
3878 if (activeSubscriberIds.contains(subscriberId)) {
3879 final String iccId = key.substring(
3880 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3881 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3882 mergeNumber = (String) prefs.get(numberKey);
3883 if (DBG_MERGE) {
3884 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3885 + " for active subscriber " + subscriberId);
3886 }
3887 if (!TextUtils.isEmpty(mergeNumber)) {
3888 break;
3889 }
3890 }
3891 }
3892 }
3893
3894 // Shortcut when no active merged subscribers
3895 if (TextUtils.isEmpty(mergeNumber)) {
3896 return null;
3897 }
3898
3899 // Second pass, find all subscribers under that line override
3900 final ArraySet<String> result = new ArraySet<>();
3901 for (String key : prefs.keySet()) {
3902 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3903 final String number = (String) prefs.get(key);
3904 if (mergeNumber.equals(number)) {
3905 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3906 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3907 final String subscriberId = (String) prefs.get(subscriberKey);
3908 if (!TextUtils.isEmpty(subscriberId)) {
3909 result.add(subscriberId);
3910 }
3911 }
3912 }
3913 }
3914
3915 final String[] resultArray = result.toArray(new String[result.size()]);
3916 Arrays.sort(resultArray);
3917 if (DBG_MERGE) {
3918 Slog.d(LOG_TAG,
3919 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3920 }
3921 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003922 } finally {
3923 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003924 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003925 }
3926
3927 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003928 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003929 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3930 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003931
3932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 final Phone phone = getPhone(subId);
3935 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
3938 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003939 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003940
3941 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003942 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003943 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3944 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003945 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946
3947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 final Phone phone = getPhone(subId);
3950 if (phone == null) {
3951 return false;
3952 }
3953 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3954 cdmaNonRoamingList);
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003957 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003958 }
3959
3960 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003961 @Deprecated
3962 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3963 enforceModifyPermission();
3964
3965 int returnValue = 0;
3966 try {
3967 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3968 if(result.exception == null) {
3969 if (result.result != null) {
3970 byte[] responseData = (byte[])(result.result);
3971 if(responseData.length > oemResp.length) {
3972 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3973 responseData.length + "bytes. Buffer Size is " +
3974 oemResp.length + "bytes.");
3975 }
3976 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3977 returnValue = responseData.length;
3978 }
3979 } else {
3980 CommandException ex = (CommandException) result.exception;
3981 returnValue = ex.getCommandError().ordinal();
3982 if(returnValue > 0) returnValue *= -1;
3983 }
3984 } catch (RuntimeException e) {
3985 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3986 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3987 if(returnValue > 0) returnValue *= -1;
3988 }
3989
3990 return returnValue;
3991 }
3992
3993 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003994 public void setRadioCapability(RadioAccessFamily[] rafs) {
3995 try {
3996 ProxyController.getInstance().setRadioCapability(rafs);
3997 } catch (RuntimeException e) {
3998 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3999 }
4000 }
4001
4002 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004003 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004004 Phone phone = PhoneFactory.getPhone(phoneId);
4005 if (phone == null) {
4006 return RadioAccessFamily.RAF_UNKNOWN;
4007 }
4008 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004010 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004011 return RadioAccessFamily.RAF_UNKNOWN;
4012 }
4013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004020 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004021
4022 @Override
4023 public void enableVideoCalling(boolean enable) {
4024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025
4026 final long identity = Binder.clearCallingIdentity();
4027 try {
4028 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4029 } finally {
4030 Binder.restoreCallingIdentity(identity);
4031 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004032 }
4033
4034 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004035 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4037 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4038 return false;
4039 }
Svet Ganovb320e182015-04-16 12:30:10 -07004040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 // Check the user preference and the system-level IMS setting. Even if the user has
4044 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4045 // In the long run, we may instead need to check if there exists a connection service
4046 // which can support video calling.
4047 ImsManager imsManager =
4048 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4049 return imsManager.isVtEnabledByPlatform()
4050 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4051 && imsManager.isVtEnabledByUser();
4052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004055 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004056
Andrew Leea1239f22015-03-02 17:44:07 -08004057 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4059 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4060 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4061 return false;
4062 }
4063
4064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 CarrierConfigManager configManager =
4067 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4068 return configManager.getConfigForSubId(mPhone.getSubId())
4069 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
Andrew Leea1239f22015-03-02 17:44:07 -08004073 }
4074
4075 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004076 public boolean isWorldPhone(int subId, String callingPackage) {
4077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4078 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4079 return false;
4080 }
4081
4082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 CarrierConfigManager configManager =
4085 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4086 return configManager.getConfigForSubId(mPhone.getSubId())
4087 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
Andrew Leea1239f22015-03-02 17:44:07 -08004091 }
4092
Andrew Lee9431b832015-03-09 18:46:45 -07004093 @Override
4094 public boolean isTtyModeSupported() {
4095 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004096 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004097 }
4098
4099 @Override
4100 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
Andrew Lee9431b832015-03-09 18:46:45 -07004107 }
4108
Hall Liu98187582018-01-22 19:15:32 -08004109 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4113 mPhone.getSubId()).getBoolean(
4114 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4115 boolean isDeviceSupported =
4116 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4117 return isCarrierSupported && isDeviceSupported;
4118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
Hall Liu98187582018-01-22 19:15:32 -08004121 }
4122
Hall Liu3ad5f012018-04-06 16:23:39 -07004123 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 return isRttSupported() && Settings.Secure.getInt(
4127 mPhone.getContext().getContentResolver(),
4128 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004132 }
4133
Sanket Padawe7310cc72015-01-14 09:53:20 -08004134 /**
4135 * Returns the unique device ID of phone, for example, the IMEI for
4136 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4137 *
4138 * <p>Requires Permission:
4139 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4140 */
4141 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004142 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004143 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004144 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004145 return null;
4146 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004147 int subId = phone.getSubId();
4148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4149 mApp, subId, callingPackage, "getDeviceId")) {
4150 return null;
4151 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 return phone.getDeviceId();
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
4158 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004159 }
4160
Ping Sunc67b7c22016-03-02 19:16:45 +08004161 /**
4162 * {@hide}
4163 * Returns the IMS Registration Status on a particular subid
4164 *
4165 * @param subId
4166 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004167 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004168 Phone phone = getPhone(subId);
4169 if (phone != null) {
4170 return phone.isImsRegistered();
4171 } else {
4172 return false;
4173 }
4174 }
4175
Santos Cordon7a1885b2015-02-03 11:15:19 -08004176 @Override
4177 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004184 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004185
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004186 /**
4187 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004188 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004189 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 Phone phone = getPhone(subId);
4193 if (phone != null) {
4194 return phone.isWifiCallingEnabled();
4195 } else {
4196 return false;
4197 }
4198 } finally {
4199 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004200 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004201 }
4202
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004203 /**
4204 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004205 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004206 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004207 final long identity = Binder.clearCallingIdentity();
4208 try {
4209 Phone phone = getPhone(subId);
4210 if (phone != null) {
4211 return phone.isVolteEnabled();
4212 } else {
4213 return false;
4214 }
4215 } finally {
4216 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004217 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004218 }
Svet Ganovb320e182015-04-16 12:30:10 -07004219
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004220 /**
4221 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004222 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004223 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004224 final long identity = Binder.clearCallingIdentity();
4225 try {
4226 Phone phone = getPhone(subId);
4227 if (phone != null) {
4228 return phone.isVideoEnabled();
4229 } else {
4230 return false;
4231 }
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004234 }
4235 }
4236
4237 /**
4238 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4239 * defined in {@link ImsRegistrationImplBase}.
4240 */
4241 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
4244 Phone phone = getPhone(subId);
4245 if (phone != null) {
4246 return phone.getImsRegistrationTech();
4247 } else {
4248 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4249 }
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004252 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004253 }
4254
Stuart Scott8eef64f2015-04-08 15:13:54 -07004255 @Override
4256 public void factoryReset(int subId) {
4257 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004258 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4259 return;
4260 }
4261
Svet Ganovcc087f82015-05-12 20:35:54 -07004262 final long identity = Binder.clearCallingIdentity();
4263 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004264 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4265 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004266 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004267 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004268 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4269 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004270 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004271 }
4272 } finally {
4273 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004274 }
4275 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004276
4277 @Override
4278 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 // We query all subscriptions instead of just the active ones, because
4282 // this might be called early on in the provisioning flow when the
4283 // subscriptions potentially aren't active yet.
4284 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4285 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004286 return null;
4287 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 // This function may be called very early, say, from the setup wizard, at
4290 // which point we won't have a default subscription set. If that's the case
4291 // we just choose the first, which will be valid in "most cases".
4292 final int defaultSubId = getDefaultSubscription();
4293 SubscriptionInfo info = null;
4294 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4295 info = slist.get(0);
4296 } else {
4297 for (SubscriptionInfo item : slist) {
4298 if (item.getSubscriptionId() == defaultSubId) {
4299 info = item;
4300 break;
4301 }
4302 }
4303
4304 if (info == null) {
4305 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004306 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004307 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 // Try and fetch the locale from the carrier properties or from the SIM language
4310 // preferences (EF-PL and EF-LI)...
4311 final int mcc = info.getMcc();
4312 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4313 String simLanguage = null;
4314 if (defaultPhone != null) {
4315 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4316 if (localeFromDefaultSim != null) {
4317 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4318 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4319 return localeFromDefaultSim.toLanguageTag();
4320 } else {
4321 simLanguage = localeFromDefaultSim.getLanguage();
4322 }
4323 }
4324 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 // The SIM language preferences only store a language (e.g. fr = French), not an
4327 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4328 // the SIM and carrier preferences does not include a country we add the country
4329 // determined from the SIM MCC to provide an exact locale.
4330 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4331 simLanguage);
4332 if (mccLocale != null) {
4333 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4334 return mccLocale.toLanguageTag();
4335 }
4336
4337 if (DBG) log("No locale found - returning null");
4338 return null;
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004342 }
4343
4344 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 return mSubscriptionController.getAllSubInfoList(
4346 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004347 }
4348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349 /**
4350 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4351 */
4352 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4353 return mSubscriptionController.getActiveSubscriptionInfoList(
4354 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004355 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004356
Chenjie Yu1ba97252018-01-11 18:16:20 -08004357 private final ModemActivityInfo mLastModemActivityInfo =
4358 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4359
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004360 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004361 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4362 * representing the state of the modem.
4363 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004364 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4365 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004366 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004367 */
4368 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004369 public void requestModemActivityInfo(ResultReceiver result) {
4370 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371
4372 final long identity = Binder.clearCallingIdentity();
4373 try {
4374 ModemActivityInfo ret = null;
4375 synchronized (mLastModemActivityInfo) {
4376 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4377 CMD_GET_MODEM_ACTIVITY_INFO,
4378 null);
Siddharth Rayb8114062018-06-17 15:02:38 -07004379 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4381 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4382 mergedTxTimeMs[i] =
4383 info.getTxTimeMillis()[i]
4384 + mLastModemActivityInfo.getTxTimeMillis()[i];
4385 }
4386 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4387 mLastModemActivityInfo.setSleepTimeMillis(
4388 info.getSleepTimeMillis()
4389 + mLastModemActivityInfo.getSleepTimeMillis());
4390 mLastModemActivityInfo.setIdleTimeMillis(
4391 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4392 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4393 mLastModemActivityInfo.setRxTimeMillis(
4394 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4395 mLastModemActivityInfo.setEnergyUsed(
4396 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004397 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4399 mLastModemActivityInfo.getSleepTimeMillis(),
4400 mLastModemActivityInfo.getIdleTimeMillis(),
4401 mLastModemActivityInfo.getTxTimeMillis(),
4402 mLastModemActivityInfo.getRxTimeMillis(),
4403 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004405 Bundle bundle = new Bundle();
4406 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4407 result.send(0, bundle);
4408 } finally {
4409 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004410 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004411 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004412
Siddharth Rayb8114062018-06-17 15:02:38 -07004413 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4414 // less than total activity duration.
4415 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4416 if (info == null) {
4417 return false;
4418 }
4419 int activityDurationMs =
4420 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4421 int totalTxTimeMs = 0;
4422 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4423 totalTxTimeMs += info.getTxTimeMillis()[i];
4424 }
4425 return (info.isValid()
4426 && (info.getSleepTimeMillis() <= activityDurationMs)
4427 && (info.getIdleTimeMillis() <= activityDurationMs)
4428 && (info.getRxTimeMillis() <= activityDurationMs)
4429 && (totalTxTimeMs <= activityDurationMs));
4430 }
4431
Jack Yu85bd38a2015-11-09 11:34:32 -08004432 /**
4433 * {@hide}
4434 * Returns the service state information on specified subscription.
4435 */
4436 @Override
4437 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004439 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004440 return null;
4441 }
4442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 final long identity = Binder.clearCallingIdentity();
4444 try {
4445 final Phone phone = getPhone(subId);
4446 if (phone == null) {
4447 return null;
4448 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 return phone.getServiceState();
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004454 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004455
4456 /**
4457 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4458 *
4459 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4460 * voicemail ringtone.
4461 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4462 * PhoneAccount.
4463 */
4464 @Override
4465 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004466 final long identity = Binder.clearCallingIdentity();
4467 try {
4468 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4469 if (phone == null) {
4470 phone = mPhone;
4471 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4474 } finally {
4475 Binder.restoreCallingIdentity(identity);
4476 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004477 }
4478
4479 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004480 * Sets the per-account voicemail ringtone.
4481 *
4482 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4483 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4484 *
4485 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4486 * voicemail ringtone.
4487 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4488 * PhoneAccount.
4489 */
4490 @Override
4491 public void setVoicemailRingtoneUri(String callingPackage,
4492 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4494 if (!TextUtils.equals(callingPackage,
4495 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4497 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4498 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500
4501 final long identity = Binder.clearCallingIdentity();
4502 try {
4503 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4504 if (phone == null) {
4505 phone = mPhone;
4506 }
4507 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4508 } finally {
4509 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004510 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004511 }
4512
4513 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004514 * Returns whether vibration is set for voicemail notification in Phone settings.
4515 *
4516 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4517 * voicemail vibration setting.
4518 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4519 */
4520 @Override
4521 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522 final long identity = Binder.clearCallingIdentity();
4523 try {
4524 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4525 if (phone == null) {
4526 phone = mPhone;
4527 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004533 }
4534
Youhan Wange64578a2016-05-02 15:32:42 -07004535 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004536 * Sets the per-account voicemail vibration.
4537 *
4538 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4539 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4540 *
4541 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4542 * voicemail vibration setting.
4543 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4544 * specific PhoneAccount.
4545 */
4546 @Override
4547 public void setVoicemailVibrationEnabled(String callingPackage,
4548 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4549 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4550 if (!TextUtils.equals(callingPackage,
4551 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4553 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4554 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004555 }
4556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 final long identity = Binder.clearCallingIdentity();
4558 try {
4559 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4560 if (phone == null) {
4561 phone = mPhone;
4562 }
4563 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4564 } finally {
4565 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004566 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004567 }
4568
4569 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004570 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4571 *
4572 * @throws SecurityException if the caller does not have the required permission
4573 */
4574 private void enforceReadPrivilegedPermission() {
4575 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4576 null);
4577 }
4578
4579 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004580 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4581 * permission.
4582 *
4583 * @throws SecurityException if the caller does not have the required permission
4584 */
4585 private void enforceSendSmsPermission() {
4586 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4587 }
4588
4589 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004590 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004591 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004592 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004593 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004594 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 final long identity = Binder.clearCallingIdentity();
4596 try {
4597 ComponentName componentName =
4598 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4599 if (componentName == null) {
4600 throw new SecurityException(
4601 "Caller not current active visual voicemail package[null]");
4602 }
4603 String vvmPackage = componentName.getPackageName();
4604 if (!callingPackage.equals(vvmPackage)) {
4605 throw new SecurityException("Caller not current active visual voicemail package["
4606 + vvmPackage + "]");
4607 }
4608 } finally {
4609 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004610 }
4611 }
4612
4613 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004614 * Return the application ID for the app type.
4615 *
4616 * @param subId the subscription ID that this request applies to.
4617 * @param appType the uicc app type.
4618 * @return Application ID for specificied app type, or null if no uicc.
4619 */
4620 @Override
4621 public String getAidForAppType(int subId, int appType) {
4622 enforceReadPrivilegedPermission();
4623 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624
4625 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004626 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 if (phone == null) {
4628 return null;
4629 }
4630 String aid = null;
4631 try {
4632 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4633 .getApplicationByType(appType).getAid();
4634 } catch (Exception e) {
4635 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4636 }
4637 return aid;
4638 } finally {
4639 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004640 }
Youhan Wange64578a2016-05-02 15:32:42 -07004641 }
4642
Youhan Wang4001d252016-05-11 10:29:41 -07004643 /**
4644 * Return the Electronic Serial Number.
4645 *
4646 * @param subId the subscription ID that this request applies to.
4647 * @return ESN or null if error.
4648 */
4649 @Override
4650 public String getEsn(int subId) {
4651 enforceReadPrivilegedPermission();
4652 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653
4654 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004655 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 if (phone == null) {
4657 return null;
4658 }
4659 String esn = null;
4660 try {
4661 esn = phone.getEsn();
4662 } catch (Exception e) {
4663 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4664 }
4665 return esn;
4666 } finally {
4667 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004668 }
Youhan Wang4001d252016-05-11 10:29:41 -07004669 }
4670
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004671 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004672 * Return the Preferred Roaming List Version.
4673 *
4674 * @param subId the subscription ID that this request applies to.
4675 * @return PRLVersion or null if error.
4676 */
4677 @Override
4678 public String getCdmaPrlVersion(int subId) {
4679 enforceReadPrivilegedPermission();
4680 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004681
4682 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004683 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684 if (phone == null) {
4685 return null;
4686 }
4687 String cdmaPrlVersion = null;
4688 try {
4689 cdmaPrlVersion = phone.getCdmaPrlVersion();
4690 } catch (Exception e) {
4691 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4692 }
4693 return cdmaPrlVersion;
4694 } finally {
4695 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004696 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004697 }
4698
4699 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004700 * Get snapshot of Telephony histograms
4701 * @return List of Telephony histograms
4702 * @hide
4703 */
4704 @Override
4705 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4707 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004708
4709 final long identity = Binder.clearCallingIdentity();
4710 try {
4711 return RIL.getTelephonyRILTimingHistograms();
4712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004715 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004716
4717 /**
4718 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004719 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004720 * Require system privileges. In the future we may add this to carrier APIs.
4721 *
4722 * @return The number of carriers set successfully, should match length of carriers
4723 */
4724 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004725 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004726 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004727
Meng Wang9b7c4e92017-02-17 11:41:27 -08004728 if (carriers == null) {
4729 throw new NullPointerException("carriers cannot be null");
4730 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4735 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4736 return retVal[0];
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
4739 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004740 }
4741
4742 /**
4743 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004744 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004745 * Require system privileges. In the future we may add this to carrier APIs.
4746 *
4747 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4748 * means all carriers are allowed.
4749 */
4750 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004751 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004752 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753
4754 final long identity = Binder.clearCallingIdentity();
4755 try {
4756 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4757 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4758 } finally {
4759 Binder.restoreCallingIdentity(identity);
4760 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004761 }
4762
fionaxu59545b42016-05-25 15:53:37 -07004763 /**
4764 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4765 * @param subId the subscription ID that this action applies to.
4766 * @param enabled control enable or disable metered apns.
4767 * {@hide}
4768 */
4769 @Override
4770 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4771 enforceModifyPermission();
4772 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773
4774 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004775 if (phone == null) {
4776 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4777 return;
4778 }
4779 try {
4780 phone.carrierActionSetMeteredApnsEnabled(enabled);
4781 } catch (Exception e) {
4782 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 } finally {
4784 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004785 }
4786 }
4787
4788 /**
4789 * Action set from carrier signalling broadcast receivers to enable/disable radio
4790 * @param subId the subscription ID that this action applies to.
4791 * @param enabled control enable or disable radio.
4792 * {@hide}
4793 */
4794 @Override
4795 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4796 enforceModifyPermission();
4797 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798
4799 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004800 if (phone == null) {
4801 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4802 return;
4803 }
4804 try {
4805 phone.carrierActionSetRadioEnabled(enabled);
4806 } catch (Exception e) {
4807 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004808 } finally {
4809 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004810 }
4811 }
4812
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004813 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004814 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4815 * network status based on which carrier apps could apply actions accordingly,
4816 * enable/disable default url handler for example.
4817 *
4818 * @param subId the subscription ID that this action applies to.
4819 * @param report control start/stop reporting the default network status.
4820 * {@hide}
4821 */
4822 @Override
4823 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4824 enforceModifyPermission();
4825 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826
4827 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004828 if (phone == null) {
4829 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4830 return;
4831 }
4832 try {
4833 phone.carrierActionReportDefaultNetworkStatus(report);
4834 } catch (Exception e) {
4835 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004836 } finally {
4837 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004838 }
4839 }
4840
4841 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004842 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4843 * bug report is being generated.
4844 */
4845 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004846 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004847 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4848 != PackageManager.PERMISSION_GRANTED) {
4849 writer.println("Permission Denial: can't dump Phone from pid="
4850 + Binder.getCallingPid()
4851 + ", uid=" + Binder.getCallingUid()
4852 + "without permission "
4853 + android.Manifest.permission.DUMP);
4854 return;
4855 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004856 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004857 }
Jack Yueb89b242016-06-22 13:27:47 -07004858
Brad Ebingerdac2f002018-04-03 15:17:52 -07004859 @Override
4860 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4861 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4862 throws RemoteException {
4863 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4864 }
4865
Jack Yueb89b242016-06-22 13:27:47 -07004866 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004867 * Get aggregated video call data usage since boot.
4868 *
4869 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4870 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004871 * {@hide}
4872 */
4873 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004874 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004875 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4876 null);
4877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878 final long identity = Binder.clearCallingIdentity();
4879 try {
4880 // NetworkStatsService keeps tracking the active network interface and identity. It
4881 // records the delta with the corresponding network identity.
4882 // We just return the total video call data usage snapshot since boot.
4883 Phone phone = getPhone(subId);
4884 if (phone != null) {
4885 return phone.getVtDataUsage(perUidStats);
4886 }
4887 return null;
4888 } finally {
4889 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004890 }
Jack Yueb89b242016-06-22 13:27:47 -07004891 }
Jack Yu75ab2952016-07-08 14:29:33 -07004892
4893 /**
4894 * Policy control of data connection. Usually used when data limit is passed.
4895 * @param enabled True if enabling the data, otherwise disabling.
4896 * @param subId Subscription index
4897 * {@hide}
4898 */
4899 @Override
4900 public void setPolicyDataEnabled(boolean enabled, int subId) {
4901 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902
4903 final long identity = Binder.clearCallingIdentity();
4904 try {
4905 Phone phone = getPhone(subId);
4906 if (phone != null) {
4907 phone.setPolicyDataEnabled(enabled);
4908 }
4909 } finally {
4910 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004911 }
4912 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004913
4914 /**
4915 * Get Client request stats
4916 * @return List of Client Request Stats
4917 * @hide
4918 */
4919 @Override
4920 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004922 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004923 return null;
4924 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004925 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 final long identity = Binder.clearCallingIdentity();
4928 try {
4929 if (phone != null) {
4930 return phone.getClientRequestStats();
4931 }
4932
4933 return null;
4934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004937 }
4938
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004939 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004940 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004941 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004942 }
Jack Yueb4124c2017-02-16 15:32:43 -08004943
4944 /**
Grace Chen70990072017-03-24 17:21:30 -07004945 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004946 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004947 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004948 * @param state State of SIM (power down, power up, pass through)
4949 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4950 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4951 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004952 *
4953 **/
4954 @Override
Grace Chen70990072017-03-24 17:21:30 -07004955 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004956 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004957 Phone phone = PhoneFactory.getPhone(slotIndex);
4958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 final long identity = Binder.clearCallingIdentity();
4960 try {
4961 if (phone != null) {
4962 phone.setSimPowerState(state);
4963 }
4964 } finally {
4965 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004966 }
4967 }
Shuo Qiandd210312017-04-12 22:11:33 +00004968
Tyler Gunn65d45c22017-06-05 11:22:26 -07004969 private boolean isUssdApiAllowed(int subId) {
4970 CarrierConfigManager configManager =
4971 (CarrierConfigManager) mPhone.getContext().getSystemService(
4972 Context.CARRIER_CONFIG_SERVICE);
4973 if (configManager == null) {
4974 return false;
4975 }
4976 PersistableBundle pb = configManager.getConfigForSubId(subId);
4977 if (pb == null) {
4978 return false;
4979 }
4980 return pb.getBoolean(
4981 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4982 }
4983
Shuo Qiandd210312017-04-12 22:11:33 +00004984 /**
4985 * Check if phone is in emergency callback mode
4986 * @return true if phone is in emergency callback mode
4987 * @param subId sub id
4988 */
goneil9c5f4872017-12-05 14:07:56 -08004989 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004990 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004991 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004992 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993
4994 final long identity = Binder.clearCallingIdentity();
4995 try {
4996 if (phone != null) {
4997 return phone.isInEcm();
4998 } else {
4999 return false;
5000 }
5001 } finally {
5002 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005003 }
5004 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005005
5006 /**
5007 * Get the current signal strength information for the given subscription.
5008 * Because this information is not updated when the device is in a low power state
5009 * it should not be relied-upon to be current.
5010 * @param subId Subscription index
5011 * @return the most recent cached signal strength info from the modem
5012 */
5013 @Override
5014 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015 final long identity = Binder.clearCallingIdentity();
5016 try {
5017 Phone p = getPhone(subId);
5018 if (p == null) {
5019 return null;
5020 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 return p.getSignalStrength();
5023 } finally {
5024 Binder.restoreCallingIdentity(identity);
5025 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005026 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005027
Pengquan Meng77b7f132018-08-22 14:49:57 -07005028 /**
5029 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5030 *
5031 * <p>Requires one of the following permissions:
5032 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5033 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5034 * privileges.
5035 *
5036 * @param subId subscription id
5037 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5038 * {@code false}.
5039 */
5040 @Override
5041 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005042 boolean isEnabled = false;
5043 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07005044 try {
5045 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07005046 null /* message */);
5047 Phone phone = getPhone(subId);
5048 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005049 } catch (Exception e) {
5050 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5051 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07005052 } finally {
5053 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005054 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005055 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07005056 }
5057
5058
5059 /**
5060 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5061 *
5062 * <p> Requires permission:
5063 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5064 * privileges.
5065 *
5066 * @param subId subscription id
5067 * @param isEnabled {@code true} means enable, {@code false} means disable.
5068 */
5069 @Override
5070 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07005071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5074 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07005075
Pengquan Menga1bb6272018-09-06 09:59:22 -07005076 Phone phone = getPhone(subId);
5077 if (phone != null) {
5078 phone.setDataRoamingEnabled(isEnabled);
5079 }
5080 } finally {
5081 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07005082 }
5083 }
5084
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005085 @Override
5086 public UiccSlotInfo[] getUiccSlotsInfo() {
5087 enforceReadPrivilegedPermission();
5088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5092 if (slots == null) {
5093 Rlog.i(LOG_TAG, "slots is null.");
5094 return null;
5095 }
5096
5097 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5098 for (int i = 0; i < slots.length; i++) {
5099 UiccSlot slot = slots[i];
5100 if (slot == null) {
5101 continue;
5102 }
5103
5104 String cardId;
5105 UiccCard card = slot.getUiccCard();
5106 if (card != null) {
5107 cardId = card.getCardId();
5108 } else {
5109 cardId = slot.getIccId();
5110 }
5111
5112 int cardState = 0;
5113 switch (slot.getCardState()) {
5114 case CARDSTATE_ABSENT:
5115 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5116 break;
5117 case CARDSTATE_PRESENT:
5118 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5119 break;
5120 case CARDSTATE_ERROR:
5121 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5122 break;
5123 case CARDSTATE_RESTRICTED:
5124 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5125 break;
5126 default:
5127 break;
5128
5129 }
5130
5131 infos[i] = new UiccSlotInfo(
5132 slot.isActive(),
5133 slot.isEuicc(),
5134 cardId,
5135 cardState,
5136 slot.getPhoneId(),
5137 slot.isExtendedApduSupported());
5138 }
5139 return infos;
5140 } finally {
5141 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005142 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005143 }
5144
5145 @Override
5146 public boolean switchSlots(int[] physicalSlots) {
5147 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148
5149 final long identity = Binder.clearCallingIdentity();
5150 try {
5151 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005155 }
Jack Yu4c988042018-02-27 15:30:01 -08005156
5157 @Override
5158 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5159 enforceModifyPermission();
5160 final Phone phone = getPhone(subId);
5161 if (phone == null) {
5162 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5163 return;
5164 }
5165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 final long identity = Binder.clearCallingIdentity();
5167 try {
5168 phone.setRadioIndicationUpdateMode(filters, mode);
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
5171 }
Jack Yu4c988042018-02-27 15:30:01 -08005172 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005173
5174 /**
goneil47ffb6e2018-04-06 15:40:58 -07005175 * A test API to reload the UICC profile.
5176 *
5177 * <p>Requires that the calling app has permission
5178 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5179 * @hide
5180 */
5181 @Override
5182 public void refreshUiccProfile(int subId) {
5183 enforceModifyPermission();
5184
5185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 Phone phone = getPhone(subId);
5188 if (phone == null) {
5189 return;
5190 }
5191 UiccCard uiccCard = phone.getUiccCard();
5192 if (uiccCard == null) {
5193 return;
5194 }
5195 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5196 if (uiccProfile == null) {
5197 return;
5198 }
5199 uiccProfile.refresh();
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
5203 }
5204
5205 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005206 * Returns false if the mobile data is disabled by default, otherwise return true.
5207 */
5208 private boolean getDefaultDataEnabled() {
5209 return "true".equalsIgnoreCase(
5210 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5211 }
5212
5213 /**
5214 * Returns true if the data roaming is enabled by default, i.e the system property
5215 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5216 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5217 */
5218 private boolean getDefaultDataRoamingEnabled(int subId) {
5219 final CarrierConfigManager configMgr = (CarrierConfigManager)
5220 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5221 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5222 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5223 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5224 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5225 return isDataRoamingEnabled;
5226 }
5227
5228 /**
5229 * Returns the default network type for the given {@code subId}, if the default network type is
5230 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5231 */
5232 private int getDefaultNetworkType(int subId) {
5233 return Integer.parseInt(
5234 TelephonyManager.getTelephonyProperty(
5235 mSubscriptionController.getPhoneId(subId),
5236 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5237 String.valueOf(Phone.PREFERRED_NT_MODE)));
5238 }
fionaxua13278b2018-03-21 00:08:13 -07005239
5240 @Override
5241 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5242 gid1, String gid2, String plmn, String spn) {
5243 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244
5245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 final Phone phone = getPhone(subId);
5248 if (phone == null) {
5249 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5250 return;
5251 }
5252 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005255 }
fionaxua13278b2018-03-21 00:08:13 -07005256 }
5257
5258 @Override
5259 public int getCarrierIdListVersion(int subId) {
5260 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261
5262 final long identity = Binder.clearCallingIdentity();
5263 try {
5264 final Phone phone = getPhone(subId);
5265 if (phone == null) {
5266 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5267 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5268 }
5269 return phone.getCarrierIdListVersion();
5270 } finally {
5271 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005272 }
fionaxua13278b2018-03-21 00:08:13 -07005273 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005274
5275 @Override
5276 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5278 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5279 return -1;
5280 }
5281
5282 final long identity = Binder.clearCallingIdentity();
5283 try {
5284 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
5287 }
5288 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07005289
5290 @Override
5291 public int getCdmaRoamingMode(int subId) {
5292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5293 mApp, subId, "getCdmaRoamingMode");
5294
5295 final long identity = Binder.clearCallingIdentity();
5296 try {
5297 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
5298 } finally {
5299 Binder.restoreCallingIdentity(identity);
5300 }
5301 }
5302
5303 @Override
5304 public boolean setCdmaRoamingMode(int subId, int mode) {
5305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5306 mApp, subId, "setCdmaRoamingMode");
5307
5308 final long identity = Binder.clearCallingIdentity();
5309 try {
5310 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
5314 }
5315
5316 @Override
5317 public boolean setCdmaSubscriptionMode(int subId, int mode) {
5318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5319 mApp, subId, "setCdmaSubscriptionMode");
5320
5321 final long identity = Binder.clearCallingIdentity();
5322 try {
5323 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
5324 } finally {
5325 Binder.restoreCallingIdentity(identity);
5326 }
5327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005328}