blob: 247963192123c5ccfe16db214b8424583f20d4a9 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800199 // Parameters of select command.
200 private static final int SELECT_COMMAND = 0xA4;
201 private static final int SELECT_P1 = 0x04;
202 private static final int SELECT_P2 = 0;
203 private static final int SELECT_P3 = 0x10;
204
Pengquan Meng85728fb2018-03-12 16:31:21 -0700205 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
206 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
207 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
208
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700209 /** The singleton instance. */
210 private static PhoneInterfaceManager sInstance;
211
Wink Saville3ab207e2014-11-20 13:07:20 -0800212 private PhoneGlobals mApp;
213 private Phone mPhone;
214 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700215 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800216 private AppOpsManager mAppOps;
217 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800218 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800219 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700220 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221
Derek Tan97ebb422014-09-05 16:55:38 -0700222 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
223 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800224 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700225
Derek Tan740e1672017-06-27 14:56:27 -0700226 // The AID of ISD-R.
227 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
228
yinxub1bed742017-04-17 11:45:04 -0700229 private NetworkScanRequestTracker mNetworkScanRequestTracker;
230
David Kelly5e06a7f2018-03-12 14:10:59 +0000231 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
232 private static final int MANUFACTURER_CODE_LENGTH = 8;
233
Derek Tan89e89d42014-07-08 17:00:10 -0700234 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700235 * A request object to use for transmitting data to an ICC.
236 */
237 private static final class IccAPDUArgument {
238 public int channel, cla, command, p1, p2, p3;
239 public String data;
240
241 public IccAPDUArgument(int channel, int cla, int command,
242 int p1, int p2, int p3, String data) {
243 this.channel = channel;
244 this.cla = cla;
245 this.command = command;
246 this.p1 = p1;
247 this.p2 = p2;
248 this.p3 = p3;
249 this.data = data;
250 }
251 }
252
253 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700254 * A request object to use for transmitting data to an ICC.
255 */
256 private static final class ManualNetworkSelectionArgument {
257 public OperatorInfo operatorInfo;
258 public boolean persistSelection;
259
260 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
261 this.operatorInfo = operatorInfo;
262 this.persistSelection = persistSelection;
263 }
264 }
265
266 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
268 * request after sending. The main thread will notify the request when it is complete.
269 */
270 private static final class MainThreadRequest {
271 /** The argument to use for the request */
272 public Object argument;
273 /** The result of the request that is run on the main thread */
274 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800275 // The subscriber id that this request applies to. Defaults to
276 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
277 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278
279 public MainThreadRequest(Object argument) {
280 this.argument = argument;
281 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800282
283 public MainThreadRequest(Object argument, Integer subId) {
284 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800285 if (subId != null) {
286 this.subId = subId;
287 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 }
290
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800291 private static final class IncomingThirdPartyCallArgs {
292 public final ComponentName component;
293 public final String callId;
294 public final String callerDisplayName;
295
296 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
297 String callerDisplayName) {
298 this.component = component;
299 this.callId = callId;
300 this.callerDisplayName = callerDisplayName;
301 }
302 }
303
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304 /**
305 * A handler that processes messages on the main thread in the phone process. Since many
306 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
307 * inbound binder threads to the main thread in the phone process. The Binder thread
308 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
309 * on, which will be notified when the operation completes and will contain the result of the
310 * request.
311 *
312 * <p>If a MainThreadRequest object is provided in the msg.obj field,
313 * note that request.result must be set to something non-null for the calling thread to
314 * unblock.
315 */
316 private final class MainThreadHandler extends Handler {
317 @Override
318 public void handleMessage(Message msg) {
319 MainThreadRequest request;
320 Message onCompleted;
321 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800322 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700323 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324
325 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700326 case CMD_HANDLE_USSD_REQUEST: {
327 request = (MainThreadRequest) msg.obj;
328 final Phone phone = getPhoneFromRequest(request);
329 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
330 String ussdRequest = ussdObject.first;
331 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700332
333 if (!isUssdApiAllowed(request.subId)) {
334 // Carrier does not support use of this API, return failure.
335 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
336 UssdResponse response = new UssdResponse(ussdRequest, null);
337 Bundle returnData = new Bundle();
338 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
339 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
340
341 request.result = true;
342 synchronized (request) {
343 request.notifyAll();
344 }
345 return;
346 }
347
Tyler Gunn52dcf772017-04-26 11:30:31 -0700348 try {
349 request.result = phone != null ?
350 phone.handleUssdRequest(ussdRequest, wrappedCallback)
351 : false;
352 } catch (CallStateException cse) {
353 request.result = false;
354 }
pkanwar32d516d2016-10-14 19:37:38 -0700355 // Wake up the requesting thread
356 synchronized (request) {
357 request.notifyAll();
358 }
359 break;
360 }
361
Yorke Lee716f67e2015-06-17 15:39:16 -0700362 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700364 final Phone phone = getPhoneFromRequest(request);
365 request.result = phone != null ?
366 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
367 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 // Wake up the requesting thread
369 synchronized (request) {
370 request.notifyAll();
371 }
372 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700376 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800377 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700378 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800379 request.result = ""; // dummy result for notifying the waiting thread
380 // Wake up the requesting thread
381 synchronized (request) {
382 request.notifyAll();
383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 break;
385
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 case CMD_END_CALL:
387 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800388 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700389 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700390 Phone phone = getPhone(end_subId);
391 if (phone == null) {
392 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
393 break;
394 }
395 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
397 // CDMA: If the user presses the Power button we treat it as
398 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700399 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
401 // GSM: End the call as per the Phone state
402 hungUp = PhoneUtils.hangup(mCM);
403 } else {
404 throw new IllegalStateException("Unexpected phone type: " + phoneType);
405 }
406 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
407 request.result = hungUp;
408 // Wake up the requesting thread
409 synchronized (request) {
410 request.notifyAll();
411 }
412 break;
413
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700415 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800417 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 if (uiccCard == null) {
419 loge("iccTransmitApduLogicalChannel: No UICC");
420 request.result = new IccIoResult(0x6F, 0, (byte[])null);
421 synchronized (request) {
422 request.notifyAll();
423 }
424 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
426 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 iccArgument.channel, iccArgument.cla, iccArgument.command,
429 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 break;
433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 ar = (AsyncResult) msg.obj;
436 request = (MainThreadRequest) ar.userObj;
437 if (ar.exception == null && ar.result != null) {
438 request.result = ar.result;
439 } else {
440 request.result = new IccIoResult(0x6F, 0, (byte[])null);
441 if (ar.result == null) {
442 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800443 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800445 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 } else {
447 loge("iccTransmitApduLogicalChannel: Unknown exception");
448 }
449 }
450 synchronized (request) {
451 request.notifyAll();
452 }
453 break;
454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
456 request = (MainThreadRequest) msg.obj;
457 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800458 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 if (uiccCard == null) {
460 loge("iccTransmitApduBasicChannel: No UICC");
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
462 synchronized (request) {
463 request.notifyAll();
464 }
465 } else {
466 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
467 request);
468 uiccCard.iccTransmitApduBasicChannel(
469 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
470 iccArgument.p3, iccArgument.data, onCompleted);
471 }
472 break;
473
474 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
475 ar = (AsyncResult) msg.obj;
476 request = (MainThreadRequest) ar.userObj;
477 if (ar.exception == null && ar.result != null) {
478 request.result = ar.result;
479 } else {
480 request.result = new IccIoResult(0x6F, 0, (byte[])null);
481 if (ar.result == null) {
482 loge("iccTransmitApduBasicChannel: Empty response");
483 } else if (ar.exception instanceof CommandException) {
484 loge("iccTransmitApduBasicChannel: CommandException: " +
485 ar.exception);
486 } else {
487 loge("iccTransmitApduBasicChannel: Unknown exception");
488 }
489 }
490 synchronized (request) {
491 request.notifyAll();
492 }
493 break;
494
495 case CMD_EXCHANGE_SIM_IO:
496 request = (MainThreadRequest) msg.obj;
497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 if (uiccCard == null) {
500 loge("iccExchangeSimIO: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
502 synchronized (request) {
503 request.notifyAll();
504 }
505 } else {
506 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
507 request);
508 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
509 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
510 iccArgument.data, onCompleted);
511 }
512 break;
513
514 case EVENT_EXCHANGE_SIM_IO_DONE:
515 ar = (AsyncResult) msg.obj;
516 request = (MainThreadRequest) ar.userObj;
517 if (ar.exception == null && ar.result != null) {
518 request.result = ar.result;
519 } else {
520 request.result = new IccIoResult(0x6f, 0, (byte[])null);
521 }
522 synchronized (request) {
523 request.notifyAll();
524 }
525 break;
526
Derek Tan4d5e5c12014-02-04 11:54:58 -0800527 case CMD_SEND_ENVELOPE:
528 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 if (uiccCard == null) {
531 loge("sendEnvelopeWithStatus: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
533 synchronized (request) {
534 request.notifyAll();
535 }
536 } else {
537 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
538 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
539 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 break;
541
542 case EVENT_SEND_ENVELOPE_DONE:
543 ar = (AsyncResult) msg.obj;
544 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700545 if (ar.exception == null && ar.result != null) {
546 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
549 if (ar.result == null) {
550 loge("sendEnvelopeWithStatus: Empty response");
551 } else if (ar.exception instanceof CommandException) {
552 loge("sendEnvelopeWithStatus: CommandException: " +
553 ar.exception);
554 } else {
555 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
556 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 }
558 synchronized (request) {
559 request.notifyAll();
560 }
561 break;
562
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 case CMD_OPEN_CHANNEL:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800566 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 if (uiccCard == null) {
568 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800569 request.result = new IccOpenLogicalChannelResponse(-1,
570 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700571 synchronized (request) {
572 request.notifyAll();
573 }
574 } else {
575 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800576 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
577 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700578 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 break;
580
581 case EVENT_OPEN_CHANNEL_DONE:
582 ar = (AsyncResult) msg.obj;
583 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 int[] result = (int[]) ar.result;
587 int channelId = result[0];
588 byte[] selectResponse = null;
589 if (result.length > 1) {
590 selectResponse = new byte[result.length - 1];
591 for (int i = 1; i < result.length; ++i) {
592 selectResponse[i - 1] = (byte) result[i];
593 }
594 }
595 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 if (ar.result == null) {
599 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 if (ar.exception != null) {
602 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
603 }
604
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700605 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700606 if (ar.exception instanceof CommandException) {
607 CommandException.Error error =
608 ((CommandException) (ar.exception)).getCommandError();
609 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700611 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700612 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 }
614 }
615 openChannelResp = new IccOpenLogicalChannelResponse(
616 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700618 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 synchronized (request) {
620 request.notifyAll();
621 }
622 break;
623
624 case CMD_CLOSE_CHANNEL:
625 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800626 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 if (uiccCard == null) {
628 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900629 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 synchronized (request) {
631 request.notifyAll();
632 }
633 } else {
634 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
635 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
636 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
639 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800640 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
641 break;
642
643 case CMD_NV_READ_ITEM:
644 request = (MainThreadRequest) msg.obj;
645 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
646 mPhone.nvReadItem((Integer) request.argument, onCompleted);
647 break;
648
649 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 ar = (AsyncResult) msg.obj;
651 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800652 if (ar.exception == null && ar.result != null) {
653 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800655 request.result = "";
656 if (ar.result == null) {
657 loge("nvReadItem: Empty response");
658 } else if (ar.exception instanceof CommandException) {
659 loge("nvReadItem: CommandException: " +
660 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800662 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 }
664 }
665 synchronized (request) {
666 request.notifyAll();
667 }
668 break;
669
Jake Hambye994d462014-02-03 13:10:13 -0800670 case CMD_NV_WRITE_ITEM:
671 request = (MainThreadRequest) msg.obj;
672 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
673 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
674 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
675 break;
676
677 case EVENT_NV_WRITE_ITEM_DONE:
678 handleNullReturnEvent(msg, "nvWriteItem");
679 break;
680
681 case CMD_NV_WRITE_CDMA_PRL:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
684 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
685 break;
686
687 case EVENT_NV_WRITE_CDMA_PRL_DONE:
688 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
689 break;
690
691 case CMD_NV_RESET_CONFIG:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
694 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
695 break;
696
697 case EVENT_NV_RESET_CONFIG_DONE:
698 handleNullReturnEvent(msg, "nvResetConfig");
699 break;
700
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 case CMD_GET_PREFERRED_NETWORK_TYPE:
702 request = (MainThreadRequest) msg.obj;
703 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700704 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800705 break;
706
707 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
708 ar = (AsyncResult) msg.obj;
709 request = (MainThreadRequest) ar.userObj;
710 if (ar.exception == null && ar.result != null) {
711 request.result = ar.result; // Integer
712 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800713 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 if (ar.result == null) {
715 loge("getPreferredNetworkType: Empty response");
716 } else if (ar.exception instanceof CommandException) {
717 loge("getPreferredNetworkType: CommandException: " +
718 ar.exception);
719 } else {
720 loge("getPreferredNetworkType: Unknown exception");
721 }
722 }
723 synchronized (request) {
724 request.notifyAll();
725 }
726 break;
727
728 case CMD_SET_PREFERRED_NETWORK_TYPE:
729 request = (MainThreadRequest) msg.obj;
730 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
731 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700732 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800733 break;
734
735 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
736 handleNullReturnEvent(msg, "setPreferredNetworkType");
737 break;
738
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000739 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
740 request = (MainThreadRequest)msg.obj;
741 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
742 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
743 break;
744
745 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
746 ar = (AsyncResult)msg.obj;
747 request = (MainThreadRequest)ar.userObj;
748 request.result = ar;
749 synchronized (request) {
750 request.notifyAll();
751 }
752 break;
753
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800754 case CMD_SET_VOICEMAIL_NUMBER:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
757 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800758 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
759 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800760 break;
761
762 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
763 handleNullReturnEvent(msg, "setVoicemailNumber");
764 break;
765
Stuart Scott54788802015-03-30 13:18:01 -0700766 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
767 request = (MainThreadRequest) msg.obj;
768 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
769 request);
770 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
771 break;
772
773 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
774 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
775 break;
776
Shishir Agrawal302c8692015-06-19 13:49:39 -0700777 case CMD_PERFORM_NETWORK_SCAN:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
780 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
781 break;
782
783 case EVENT_PERFORM_NETWORK_SCAN_DONE:
784 ar = (AsyncResult) msg.obj;
785 request = (MainThreadRequest) ar.userObj;
786 CellNetworkScanResult cellScanResult;
787 if (ar.exception == null && ar.result != null) {
788 cellScanResult = new CellNetworkScanResult(
789 CellNetworkScanResult.STATUS_SUCCESS,
790 (List<OperatorInfo>) ar.result);
791 } else {
792 if (ar.result == null) {
793 loge("getCellNetworkScanResults: Empty response");
794 }
795 if (ar.exception != null) {
796 loge("getCellNetworkScanResults: Exception: " + ar.exception);
797 }
798 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
799 if (ar.exception instanceof CommandException) {
800 CommandException.Error error =
801 ((CommandException) (ar.exception)).getCommandError();
802 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
803 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
804 } else if (error == CommandException.Error.GENERIC_FAILURE) {
805 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
806 }
807 }
808 cellScanResult = new CellNetworkScanResult(errorCode, null);
809 }
810 request.result = cellScanResult;
811 synchronized (request) {
812 request.notifyAll();
813 }
814 break;
815
816 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
817 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700818 ManualNetworkSelectionArgument selArg =
819 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700820 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
821 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700822 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
823 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 break;
825
826 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
827 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
828 break;
829
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700830 case CMD_GET_MODEM_ACTIVITY_INFO:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700833 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700834 break;
835
836 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null && ar.result != null) {
840 request.result = ar.result;
841 } else {
842 if (ar.result == null) {
843 loge("queryModemActivityInfo: Empty response");
844 } else if (ar.exception instanceof CommandException) {
845 loge("queryModemActivityInfo: CommandException: " +
846 ar.exception);
847 } else {
848 loge("queryModemActivityInfo: Unknown exception");
849 }
850 }
Amit Mahajand4766222016-01-28 15:28:28 -0800851 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
852 if (request.result == null) {
853 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
854 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 synchronized (request) {
856 request.notifyAll();
857 }
858 break;
859
Meng Wang1a7c35a2016-05-05 20:56:15 -0700860 case CMD_SET_ALLOWED_CARRIERS:
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
863 mPhone.setAllowedCarriers(
864 (List<CarrierIdentifier>) request.argument,
865 onCompleted);
866 break;
867
868 case EVENT_SET_ALLOWED_CARRIERS_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
874 if (ar.result == null) {
875 loge("setAllowedCarriers: Empty response");
876 } else if (ar.exception instanceof CommandException) {
877 loge("setAllowedCarriers: CommandException: " +
878 ar.exception);
879 } else {
880 loge("setAllowedCarriers: Unknown exception");
881 }
882 }
883 // Result cannot be null. Return -1 on error.
884 if (request.result == null) {
885 request.result = new int[]{-1};
886 }
887 synchronized (request) {
888 request.notifyAll();
889 }
890 break;
891
892 case CMD_GET_ALLOWED_CARRIERS:
893 request = (MainThreadRequest) msg.obj;
894 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
895 mPhone.getAllowedCarriers(onCompleted);
896 break;
897
898 case EVENT_GET_ALLOWED_CARRIERS_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null && ar.result != null) {
902 request.result = ar.result;
903 } else {
904 if (ar.result == null) {
905 loge("getAllowedCarriers: Empty response");
906 } else if (ar.exception instanceof CommandException) {
907 loge("getAllowedCarriers: CommandException: " +
908 ar.exception);
909 } else {
910 loge("getAllowedCarriers: Unknown exception");
911 }
912 }
913 // Result cannot be null. Return empty list of CarrierIdentifier.
914 if (request.result == null) {
915 request.result = new ArrayList<CarrierIdentifier>(0);
916 }
917 synchronized (request) {
918 request.notifyAll();
919 }
920 break;
921
Nathan Haroldb3014052017-01-25 15:57:32 -0800922 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
923 ar = (AsyncResult) msg.obj;
924 request = (MainThreadRequest) ar.userObj;
925 if (ar.exception == null && ar.result != null) {
926 request.result = ar.result;
927 } else {
928 request.result = new IllegalArgumentException(
929 "Failed to retrieve Forbidden Plmns");
930 if (ar.result == null) {
931 loge("getForbiddenPlmns: Empty response");
932 } else {
933 loge("getForbiddenPlmns: Unknown exception");
934 }
935 }
936 synchronized (request) {
937 request.notifyAll();
938 }
939 break;
940
941 case CMD_GET_FORBIDDEN_PLMNS:
942 request = (MainThreadRequest) msg.obj;
943 uiccCard = getUiccCardFromRequest(request);
944 if (uiccCard == null) {
945 loge("getForbiddenPlmns() UiccCard is null");
946 request.result = new IllegalArgumentException(
947 "getForbiddenPlmns() UiccCard is null");
948 synchronized (request) {
949 request.notifyAll();
950 }
951 break;
952 }
953 Integer appType = (Integer) request.argument;
954 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
955 if (uiccApp == null) {
956 loge("getForbiddenPlmns() no app with specified type -- "
957 + appType);
958 request.result = new IllegalArgumentException("Failed to get UICC App");
959 synchronized (request) {
960 request.notifyAll();
961 }
962 break;
963 } else {
964 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
965 + " specified type -- " + appType);
966 }
967 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
968 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
969 onCompleted);
970 break;
971
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000972 case CMD_SWITCH_SLOTS:
973 request = (MainThreadRequest) msg.obj;
974 int[] physicalSlots = (int[]) request.argument;
975 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
976 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
977 break;
978
979 case EVENT_SWITCH_SLOTS_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 request.result = (ar.exception == null);
983 synchronized (request) {
984 request.notifyAll();
985 }
986 break;
987
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700988 default:
989 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
990 break;
991 }
992 }
Jake Hambye994d462014-02-03 13:10:13 -0800993
994 private void handleNullReturnEvent(Message msg, String command) {
995 AsyncResult ar = (AsyncResult) msg.obj;
996 MainThreadRequest request = (MainThreadRequest) ar.userObj;
997 if (ar.exception == null) {
998 request.result = true;
999 } else {
1000 request.result = false;
1001 if (ar.exception instanceof CommandException) {
1002 loge(command + ": CommandException: " + ar.exception);
1003 } else {
1004 loge(command + ": Unknown exception");
1005 }
1006 }
1007 synchronized (request) {
1008 request.notifyAll();
1009 }
1010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001011 }
1012
1013 /**
1014 * Posts the specified command to be executed on the main thread,
1015 * waits for the request to complete, and returns the result.
1016 * @see #sendRequestAsync
1017 */
1018 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001019 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001020 }
1021
1022 /**
1023 * Posts the specified command to be executed on the main thread,
1024 * waits for the request to complete, and returns the result.
1025 * @see #sendRequestAsync
1026 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001027 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001028 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1029 throw new RuntimeException("This method will deadlock if called from the main thread.");
1030 }
1031
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001032 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001033 Message msg = mMainThreadHandler.obtainMessage(command, request);
1034 msg.sendToTarget();
1035
1036 // Wait for the request to complete
1037 synchronized (request) {
1038 while (request.result == null) {
1039 try {
1040 request.wait();
1041 } catch (InterruptedException e) {
1042 // Do nothing, go back and wait until the request is complete
1043 }
1044 }
1045 }
1046 return request.result;
1047 }
1048
1049 /**
1050 * Asynchronous ("fire and forget") version of sendRequest():
1051 * Posts the specified command to be executed on the main thread, and
1052 * returns immediately.
1053 * @see #sendRequest
1054 */
1055 private void sendRequestAsync(int command) {
1056 mMainThreadHandler.sendEmptyMessage(command);
1057 }
1058
1059 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001060 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1061 * @see {@link #sendRequest(int,Object)}
1062 */
1063 private void sendRequestAsync(int command, Object argument) {
1064 MainThreadRequest request = new MainThreadRequest(argument);
1065 Message msg = mMainThreadHandler.obtainMessage(command, request);
1066 msg.sendToTarget();
1067 }
1068
1069 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001070 * Initialize the singleton PhoneInterfaceManager instance.
1071 * This is only done once, at startup, from PhoneApp.onCreate().
1072 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001073 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001074 synchronized (PhoneInterfaceManager.class) {
1075 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001076 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001077 } else {
1078 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1079 }
1080 return sInstance;
1081 }
1082 }
1083
1084 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001085 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001086 mApp = app;
1087 mPhone = phone;
1088 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001089 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1091 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001092 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001093 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001094 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001095 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001096 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001097
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001098 publish();
1099 }
1100
1101 private void publish() {
1102 if (DBG) log("publish: " + this);
1103
1104 ServiceManager.addService("phone", this);
1105 }
1106
Stuart Scott584921c2015-01-15 17:10:34 -08001107 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001108 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1109 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001110 }
1111
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001112 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1113 Phone phone = getPhoneFromRequest(request);
1114 return phone == null ? null :
1115 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1116 }
1117
Wink Saville36469e72014-06-11 15:17:00 -07001118 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001119 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001120 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001121 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001122 //
1123 // Implementation of the ITelephony interface.
1124 //
1125
1126 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001127 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001128 }
1129
Wink Savilleb564aae2014-10-23 10:18:09 -07001130 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001131 if (DBG) log("dial: " + number);
1132 // No permission check needed here: This is just a wrapper around the
1133 // ACTION_DIAL intent, which is available to any app since it puts up
1134 // the UI before it does anything.
1135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001136 final long identity = Binder.clearCallingIdentity();
1137 try {
1138 String url = createTelUrl(number);
1139 if (url == null) {
1140 return;
1141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001143 // PENDING: should we just silently fail if phone is offhook or ringing?
1144 PhoneConstants.State state = mCM.getState(subId);
1145 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1146 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1147 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1148 mApp.startActivity(intent);
1149 }
1150 } finally {
1151 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001152 }
1153 }
1154
1155 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001156 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001157 }
1158
Wink Savilleb564aae2014-10-23 10:18:09 -07001159 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 if (DBG) log("call: " + number);
1161
1162 // This is just a wrapper around the ACTION_CALL intent, but we still
1163 // need to do a permission check since we're calling startActivity()
1164 // from the context of the phone app.
1165 enforceCallPermission();
1166
1167 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1168 != AppOpsManager.MODE_ALLOWED) {
1169 return;
1170 }
1171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001172 final long identity = Binder.clearCallingIdentity();
1173 try {
1174 String url = createTelUrl(number);
1175 if (url == null) {
1176 return;
1177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001179 boolean isValid = false;
1180 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1181 if (slist != null) {
1182 for (SubscriptionInfo subInfoRecord : slist) {
1183 if (subInfoRecord.getSubscriptionId() == subId) {
1184 isValid = true;
1185 break;
1186 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001187 }
Wink Saville08874612014-08-31 19:19:58 -07001188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001189 if (!isValid) {
1190 return;
1191 }
Wink Saville08874612014-08-31 19:19:58 -07001192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001193 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1194 intent.putExtra(SUBSCRIPTION_KEY, subId);
1195 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1196 mApp.startActivity(intent);
1197 } finally {
1198 Binder.restoreCallingIdentity(identity);
1199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001200 }
1201
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 /**
1203 * End a call based on call state
1204 * @return true is a call was ended
1205 */
1206 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001207 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001208 }
1209
1210 /**
1211 * End a call based on the call state of the subId
1212 * @return true is a call was ended
1213 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001214 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001215 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1216 != PackageManager.PERMISSION_GRANTED) {
1217 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1218 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1219 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1220 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001221
1222 final long identity = Binder.clearCallingIdentity();
1223 try {
1224 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1225 } finally {
1226 Binder.restoreCallingIdentity(identity);
1227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 }
1229
1230 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001231 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001232 }
1233
Wink Savilleb564aae2014-10-23 10:18:09 -07001234 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 if (DBG) log("answerRingingCall...");
1236 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1237 // but that can probably wait till the big TelephonyManager API overhaul.
1238 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1239 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001240
1241 final long identity = Binder.clearCallingIdentity();
1242 try {
1243 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1244 } finally {
1245 Binder.restoreCallingIdentity(identity);
1246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 }
1248
1249 /**
1250 * Make the actual telephony calls to implement answerRingingCall().
1251 * This should only be called from the main thread of the Phone app.
1252 * @see #answerRingingCall
1253 *
1254 * TODO: it would be nice to return true if we answered the call, or
1255 * false if there wasn't actually a ringing incoming call, or some
1256 * other error occurred. (In other words, pass back the return value
1257 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1258 * But that would require calling this method via sendRequest() rather
1259 * than sendRequestAsync(), and right now we don't actually *need* that
1260 * return value, so let's just return void for now.
1261 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001262 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001263 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001265 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1266 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 if (hasActiveCall && hasHoldingCall) {
1268 // Both lines are in use!
1269 // TODO: provide a flag to let the caller specify what
1270 // policy to use if both lines are in use. (The current
1271 // behavior is hardwired to "answer incoming, end ongoing",
1272 // which is how the CALL button is specced to behave.)
1273 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1274 return;
1275 } else {
1276 // answerCall() will automatically hold the current active
1277 // call, if there is one.
1278 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1279 return;
1280 }
1281 } else {
1282 // No call was ringing.
1283 return;
1284 }
1285 }
1286
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001287 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001288 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001289 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001290 public void silenceRinger() {
1291 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292 }
1293
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001294 @Override
1295 public boolean isOffhook(String callingPackage) {
1296 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001297 }
1298
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001299 @Override
1300 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001302 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001303 return false;
1304 }
1305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001306 final long identity = Binder.clearCallingIdentity();
1307 try {
1308 final Phone phone = getPhone(subId);
1309 if (phone != null) {
1310 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1311 } else {
1312 return false;
1313 }
1314 } finally {
1315 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 }
1318
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001319 @Override
1320 public boolean isRinging(String callingPackage) {
1321 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001322 }
1323
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001324 @Override
1325 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001327 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001328 return false;
1329 }
1330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001331 final long identity = Binder.clearCallingIdentity();
1332 try {
1333 final Phone phone = getPhone(subId);
1334 if (phone != null) {
1335 return (phone.getState() == PhoneConstants.State.RINGING);
1336 } else {
1337 return false;
1338 }
1339 } finally {
1340 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 }
1343
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001344 @Override
1345 public boolean isIdle(String callingPackage) {
1346 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001347 }
1348
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001349 @Override
1350 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001352 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001353 return false;
1354 }
1355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001356 final long identity = Binder.clearCallingIdentity();
1357 try {
1358 final Phone phone = getPhone(subId);
1359 if (phone != null) {
1360 return (phone.getState() == PhoneConstants.State.IDLE);
1361 } else {
1362 return false;
1363 }
1364 } finally {
1365 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367 }
1368
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001369 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001370 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
1372
Wink Savilleb564aae2014-10-23 10:18:09 -07001373 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001375 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1376 }
1377
1378 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001379 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001380 }
1381
Wink Savilleb564aae2014-10-23 10:18:09 -07001382 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001383 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001384 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1385 }
1386
1387 /** {@hide} */
1388 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001389 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001390 }
1391
Wink Savilleb564aae2014-10-23 10:18:09 -07001392 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001394
1395 final long identity = Binder.clearCallingIdentity();
1396 try {
1397 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1398 checkSimPin.start();
1399 return checkSimPin.unlockSim(null, pin);
1400 } finally {
1401 Binder.restoreCallingIdentity(identity);
1402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 }
1404
Wink Saville9de0f752013-10-22 19:04:03 -07001405 /** {@hide} */
1406 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001407 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001408 }
1409
Wink Savilleb564aae2014-10-23 10:18:09 -07001410 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001412
1413 final long identity = Binder.clearCallingIdentity();
1414 try {
1415 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1416 checkSimPuk.start();
1417 return checkSimPuk.unlockSim(puk, pin);
1418 } finally {
1419 Binder.restoreCallingIdentity(identity);
1420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421 }
1422
1423 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001424 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425 * a synchronous one.
1426 */
1427 private static class UnlockSim extends Thread {
1428
1429 private final IccCard mSimCard;
1430
1431 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001432 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1433 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001434
1435 // For replies from SimCard interface
1436 private Handler mHandler;
1437
1438 // For async handler to identify request type
1439 private static final int SUPPLY_PIN_COMPLETE = 100;
1440
1441 public UnlockSim(IccCard simCard) {
1442 mSimCard = simCard;
1443 }
1444
1445 @Override
1446 public void run() {
1447 Looper.prepare();
1448 synchronized (UnlockSim.this) {
1449 mHandler = new Handler() {
1450 @Override
1451 public void handleMessage(Message msg) {
1452 AsyncResult ar = (AsyncResult) msg.obj;
1453 switch (msg.what) {
1454 case SUPPLY_PIN_COMPLETE:
1455 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1456 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001457 mRetryCount = msg.arg1;
1458 if (ar.exception != null) {
1459 if (ar.exception instanceof CommandException &&
1460 ((CommandException)(ar.exception)).getCommandError()
1461 == CommandException.Error.PASSWORD_INCORRECT) {
1462 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1463 } else {
1464 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1465 }
1466 } else {
1467 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 mDone = true;
1470 UnlockSim.this.notifyAll();
1471 }
1472 break;
1473 }
1474 }
1475 };
1476 UnlockSim.this.notifyAll();
1477 }
1478 Looper.loop();
1479 }
1480
1481 /*
1482 * Use PIN or PUK to unlock SIM card
1483 *
1484 * If PUK is null, unlock SIM card with PIN
1485 *
1486 * If PUK is not null, unlock SIM card with PUK and set PIN code
1487 */
Wink Saville9de0f752013-10-22 19:04:03 -07001488 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489
1490 while (mHandler == null) {
1491 try {
1492 wait();
1493 } catch (InterruptedException e) {
1494 Thread.currentThread().interrupt();
1495 }
1496 }
1497 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1498
1499 if (puk == null) {
1500 mSimCard.supplyPin(pin, callback);
1501 } else {
1502 mSimCard.supplyPuk(puk, pin, callback);
1503 }
1504
1505 while (!mDone) {
1506 try {
1507 Log.d(LOG_TAG, "wait for done");
1508 wait();
1509 } catch (InterruptedException e) {
1510 // Restore the interrupted status
1511 Thread.currentThread().interrupt();
1512 }
1513 }
1514 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001515 int[] resultArray = new int[2];
1516 resultArray[0] = mResult;
1517 resultArray[1] = mRetryCount;
1518 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001519 }
1520 }
1521
1522 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001523 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001524
1525 }
1526
Wink Savilleb564aae2014-10-23 10:18:09 -07001527 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 // No permission check needed here: this call is harmless, and it's
1529 // needed for the ServiceState.requestStateUpdate() call (which is
1530 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001531 final long identity = Binder.clearCallingIdentity();
1532 try {
1533 final Phone phone = getPhone(subId);
1534 if (phone != null) {
1535 phone.updateServiceLocation();
1536 }
1537 } finally {
1538 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001540 }
1541
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001542 @Override
1543 public boolean isRadioOn(String callingPackage) {
1544 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001545 }
1546
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001547 @Override
1548 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001550 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001551 return false;
1552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001553
1554 final long identity = Binder.clearCallingIdentity();
1555 try {
1556 return isRadioOnForSubscriber(subId);
1557 } finally {
1558 Binder.restoreCallingIdentity(identity);
1559 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001560 }
1561
1562 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001563 final long identity = Binder.clearCallingIdentity();
1564 try {
1565 final Phone phone = getPhone(subId);
1566 if (phone != null) {
1567 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1568 } else {
1569 return false;
1570 }
1571 } finally {
1572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 }
1575
1576 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001577 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 }
Wink Saville36469e72014-06-11 15:17:00 -07001579
Wink Savilleb564aae2014-10-23 10:18:09 -07001580 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001582
1583 final long identity = Binder.clearCallingIdentity();
1584 try {
1585 final Phone phone = getPhone(subId);
1586 if (phone != null) {
1587 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1588 }
1589 } finally {
1590 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001591 }
Wink Saville36469e72014-06-11 15:17:00 -07001592 }
1593
1594 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001595 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001596 }
1597
Wink Savilleb564aae2014-10-23 10:18:09 -07001598 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001599 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001600
1601 final long identity = Binder.clearCallingIdentity();
1602 try {
1603 final Phone phone = getPhone(subId);
1604 if (phone == null) {
1605 return false;
1606 }
1607 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1608 toggleRadioOnOffForSubscriber(subId);
1609 }
1610 return true;
1611 } finally {
1612 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 }
Wink Saville36469e72014-06-11 15:17:00 -07001615
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001616 public boolean needMobileRadioShutdown() {
1617 /*
1618 * If any of the Radios are available, it will need to be
1619 * shutdown. So return true if any Radio is available.
1620 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001621 final long identity = Binder.clearCallingIdentity();
1622 try {
1623 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1624 Phone phone = PhoneFactory.getPhone(i);
1625 if (phone != null && phone.isRadioAvailable()) return true;
1626 }
1627 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1628 return false;
1629 } finally {
1630 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001632 }
1633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001634 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001635 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001636 enforceModifyPermission();
1637
1638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1641 logv("Shutting down Phone " + i);
1642 shutdownRadioUsingPhoneId(i);
1643 }
1644 } finally {
1645 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001646 }
1647 }
1648
1649 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001650 Phone phone = PhoneFactory.getPhone(phoneId);
1651 if (phone != null && phone.isRadioAvailable()) {
1652 phone.shutdownRadio();
1653 }
1654 }
1655
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001657 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001658
1659 final long identity = Binder.clearCallingIdentity();
1660 try {
1661 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1662 if (defaultPhone != null) {
1663 defaultPhone.setRadioPower(turnOn);
1664 return true;
1665 } else {
1666 loge("There's no default phone.");
1667 return false;
1668 }
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001671 }
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
Wink Savilleb564aae2014-10-23 10:18:09 -07001674 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001676
1677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 final Phone phone = getPhone(subId);
1680 if (phone != null) {
1681 phone.setRadioPower(turnOn);
1682 return true;
1683 } else {
1684 return false;
1685 }
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 }
1690
Wink Saville36469e72014-06-11 15:17:00 -07001691 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001692 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 public boolean enableDataConnectivity() {
1694 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001695
1696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 int subId = mSubscriptionController.getDefaultDataSubId();
1699 final Phone phone = getPhone(subId);
1700 if (phone != null) {
1701 phone.setUserDataEnabled(true);
1702 return true;
1703 } else {
1704 return false;
1705 }
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 }
1710
Wink Saville36469e72014-06-11 15:17:00 -07001711 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 public boolean disableDataConnectivity() {
1714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 int subId = mSubscriptionController.getDefaultDataSubId();
1719 final Phone phone = getPhone(subId);
1720 if (phone != null) {
1721 phone.setUserDataEnabled(false);
1722 return true;
1723 } else {
1724 return false;
1725 }
1726 } finally {
1727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 }
1730
Sanket Padawe356d7632015-06-22 14:03:32 -07001731 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001732 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 final Phone phone = getPhone(subId);
1736 if (phone != null) {
1737 return phone.isDataAllowed();
1738 } else {
1739 return false;
1740 }
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745
1746 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001747 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001748 }
1749
pkanwarae03a6b2016-11-06 20:37:09 -08001750 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001751 enforceCallPermission();
1752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1756 return;
1757 }
1758 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1759 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1760 } finally {
1761 Binder.restoreCallingIdentity(identity);
1762 }
pkanwar32d516d2016-10-14 19:37:38 -07001763 };
1764
Wink Savilleb564aae2014-10-23 10:18:09 -07001765 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767
1768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1771 return false;
1772 }
1773 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
1778
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001780 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001781 }
1782
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001783 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 Phone phone = PhoneFactory.getPhone(slotIndex);
1787 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1788 PhoneConstantConversions.convertCallState(phone.getState());
1789 } finally {
1790 Binder.restoreCallingIdentity(identity);
1791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
1793
Sanket Padawe356d7632015-06-22 14:03:32 -07001794 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1799 if (phone != null) {
1800 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1801 } else {
1802 return PhoneConstantConversions.convertDataState(
1803 PhoneConstants.DataState.DISCONNECTED);
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Sanket Padawe356d7632015-06-22 14:03:32 -07001810 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 final long identity = Binder.clearCallingIdentity();
1813 try {
1814 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1815 if (phone != null) {
1816 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1817 } else {
1818 return TelephonyManager.DATA_ACTIVITY_NONE;
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
1825 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001826 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001827 mPhone.getContext().getSystemService(AppOpsManager.class)
1828 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001829 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001830 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001831 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 }
1833
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001834 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 if (DBG_LOC) log("getCellLocation: is active user");
1838 Bundle data = new Bundle();
1839 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1840 if (phone == null) {
1841 return null;
1842 }
1843
1844 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1845 return data;
1846 } finally {
1847 Binder.restoreCallingIdentity(identity);
1848 }
Svetoslav64fad262015-04-14 14:35:21 -07001849 }
1850
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001852 public String getNetworkCountryIsoForPhone(int phoneId) {
1853 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1854 // registered cell info, so return a NULL country instead.
1855 final long identity = Binder.clearCallingIdentity();
1856 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001857 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1858 // Get default phone in this case.
1859 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1860 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001861 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001862 // Todo: fix this when we can get the actual cellular network info when the device
1863 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001864 if (TelephonyManager.NETWORK_TYPE_IWLAN
1865 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1866 return "";
1867 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001868 Phone phone = PhoneFactory.getPhone(phoneId);
1869 if (phone != null) {
1870 ServiceStateTracker sst = phone.getServiceStateTracker();
1871 if (sst != null) {
1872 LocaleTracker lt = sst.getLocaleTracker();
1873 if (lt != null) {
1874 return lt.getCurrentCountry();
1875 }
1876 }
1877 }
1878 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001879 } finally {
1880 Binder.restoreCallingIdentity(identity);
1881 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001882 }
1883
1884 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001886 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001887 }
1888
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001890 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 mApp.enforceCallingOrSelfPermission(
1892 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001893
1894 final long identity = Binder.clearCallingIdentity();
1895 try {
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
1898 phone.enableLocationUpdates();
1899 }
1900 } finally {
1901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905 @Override
1906 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001907 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001908 }
1909
Sanket Padawe356d7632015-06-22 14:03:32 -07001910 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001911 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 mApp.enforceCallingOrSelfPermission(
1913 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914
1915 final long identity = Binder.clearCallingIdentity();
1916 try {
1917 final Phone phone = getPhone(subId);
1918 if (phone != null) {
1919 phone.disableLocationUpdates();
1920 }
1921 } finally {
1922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 }
1925
1926 @Override
1927 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001928 public List<NeighboringCellInfo>
1929 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harolddbea45a2018-08-30 14:35:07 -07001930 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1931 throw new SecurityException(
1932 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1933 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001934
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1936 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1937 return null;
1938 }
Svetoslav64fad262015-04-14 14:35:21 -07001939
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001940 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941
Nathan Haroldf180aac2018-06-01 18:43:55 -07001942 List<CellInfo> info = getAllCellInfo(callingPackage);
1943 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944
Nathan Haroldf180aac2018-06-01 18:43:55 -07001945 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1946 for (CellInfo ci : info) {
1947 if (ci instanceof CellInfoGsm) {
1948 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1949 } else if (ci instanceof CellInfoWcdma) {
1950 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001953 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
1955
1956
1957 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001958 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001959 mPhone.getContext().getSystemService(AppOpsManager.class)
1960 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001961 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001962 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001963 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964 }
1965
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001966 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001967 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968 final long identity = Binder.clearCallingIdentity();
1969 try {
1970 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1971 for (Phone phone : PhoneFactory.getPhones()) {
1972 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1973 if (info != null) cellInfos.addAll(info);
1974 }
1975 return cellInfos;
1976 } finally {
1977 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979 }
1980
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001981 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001983 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001984 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985
1986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 mPhone.setCellInfoListRate(rateInMillis, workSource);
1989 } finally {
1990 Binder.restoreCallingIdentity(identity);
1991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 }
1993
Shishir Agrawala9f32182016-04-12 12:00:16 -07001994 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001995 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001996 Phone phone = PhoneFactory.getPhone(slotIndex);
1997 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001998 return null;
1999 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002000 int subId = phone.getSubId();
2001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2002 mApp, subId, callingPackage, "getImeiForSlot")) {
2003 return null;
2004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002005
2006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 return phone.getImei();
2009 } finally {
2010 Binder.restoreCallingIdentity(identity);
2011 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002012 }
2013
2014 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002015 public String getTypeAllocationCodeForSlot(int slotIndex) {
2016 Phone phone = PhoneFactory.getPhone(slotIndex);
2017 String tac = null;
2018 if (phone != null) {
2019 String imei = phone.getImei();
2020 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2021 }
2022 return tac;
2023 }
2024
2025 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002026 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002027 Phone phone = PhoneFactory.getPhone(slotIndex);
2028 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002029 return null;
2030 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002031 int subId = phone.getSubId();
2032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2033 mApp, subId, callingPackage, "getMeidForSlot")) {
2034 return null;
2035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036
2037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 return phone.getMeid();
2040 } finally {
2041 Binder.restoreCallingIdentity(identity);
2042 }
Jack Yu2af8d712017-03-15 17:14:14 -07002043 }
2044
2045 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002046 public String getManufacturerCodeForSlot(int slotIndex) {
2047 Phone phone = PhoneFactory.getPhone(slotIndex);
2048 String manufacturerCode = null;
2049 if (phone != null) {
2050 String meid = phone.getMeid();
2051 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2052 }
2053 return manufacturerCode;
2054 }
2055
2056 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002057 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002058 Phone phone = PhoneFactory.getPhone(slotIndex);
2059 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002060 return null;
2061 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002062 int subId = phone.getSubId();
2063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2064 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2065 return null;
2066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002067
2068 final long identity = Binder.clearCallingIdentity();
2069 try {
2070 return phone.getDeviceSvn();
2071 } finally {
2072 Binder.restoreCallingIdentity(identity);
2073 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002074 }
2075
fionaxu43304da2017-11-27 22:51:16 -08002076 @Override
2077 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 final Phone phone = getPhone(subId);
2081 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
2084 }
fionaxu43304da2017-11-27 22:51:16 -08002085 }
2086
2087 @Override
2088 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002089 final long identity = Binder.clearCallingIdentity();
2090 try {
2091 final Phone phone = getPhone(subId);
2092 return phone == null ? null : phone.getCarrierName();
2093 } finally {
2094 Binder.restoreCallingIdentity(identity);
2095 }
fionaxu43304da2017-11-27 22:51:16 -08002096 }
2097
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 //
2099 // Internal helper methods.
2100 //
2101
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002102 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2104 *
2105 * @throws SecurityException if the caller does not have the required permission
2106 */
2107 private void enforceModifyPermission() {
2108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2109 }
2110
2111 /**
2112 * Make sure the caller has the CALL_PHONE permission.
2113 *
2114 * @throws SecurityException if the caller does not have the required permission
2115 */
2116 private void enforceCallPermission() {
2117 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2118 }
2119
Stuart Scott8eef64f2015-04-08 15:13:54 -07002120 private void enforceConnectivityInternalPermission() {
2121 mApp.enforceCallingOrSelfPermission(
2122 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2123 "ConnectivityService");
2124 }
2125
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 private String createTelUrl(String number) {
2127 if (TextUtils.isEmpty(number)) {
2128 return null;
2129 }
2130
Jake Hambye994d462014-02-03 13:10:13 -08002131 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
2133
Ihab Awadf9e92732013-12-05 18:02:52 -08002134 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2136 }
2137
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002138 private static void logv(String msg) {
2139 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2140 }
2141
Ihab Awadf9e92732013-12-05 18:02:52 -08002142 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2144 }
2145
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002146 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002148 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002149 }
2150
Sanket Padawe356d7632015-06-22 14:03:32 -07002151 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002152 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 final Phone phone = PhoneFactory.getPhone(slotIndex);
2156 if (phone == null) {
2157 return PhoneConstants.PHONE_TYPE_NONE;
2158 } else {
2159 return phone.getPhoneType();
2160 }
2161 } finally {
2162 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002163 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 }
2165
2166 /**
2167 * Returns the CDMA ERI icon index to display
2168 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 @Override
2170 public int getCdmaEriIconIndex(String callingPackage) {
2171 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002172 }
2173
Sanket Padawe356d7632015-06-22 14:03:32 -07002174 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002175 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002177 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002178 return -1;
2179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180
2181 final long identity = Binder.clearCallingIdentity();
2182 try {
2183 final Phone phone = getPhone(subId);
2184 if (phone != null) {
2185 return phone.getCdmaEriIconIndex();
2186 } else {
2187 return -1;
2188 }
2189 } finally {
2190 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193
2194 /**
2195 * Returns the CDMA ERI icon mode,
2196 * 0 - ON
2197 * 1 - FLASHING
2198 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002199 @Override
2200 public int getCdmaEriIconMode(String callingPackage) {
2201 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002202 }
2203
Sanket Padawe356d7632015-06-22 14:03:32 -07002204 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002205 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002207 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002208 return -1;
2209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210
2211 final long identity = Binder.clearCallingIdentity();
2212 try {
2213 final Phone phone = getPhone(subId);
2214 if (phone != null) {
2215 return phone.getCdmaEriIconMode();
2216 } else {
2217 return -1;
2218 }
2219 } finally {
2220 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 }
2223
2224 /**
2225 * Returns the CDMA ERI text,
2226 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002227 @Override
2228 public String getCdmaEriText(String callingPackage) {
2229 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002230 }
2231
Sanket Padawe356d7632015-06-22 14:03:32 -07002232 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002235 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002236 return null;
2237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238
2239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 final Phone phone = getPhone(subId);
2242 if (phone != null) {
2243 return phone.getCdmaEriText();
2244 } else {
2245 return null;
2246 }
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
2252 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002253 * Returns the CDMA MDN.
2254 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002255 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002256 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2258 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259
2260 final long identity = Binder.clearCallingIdentity();
2261 try {
2262 final Phone phone = getPhone(subId);
2263 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2264 return phone.getLine1Number();
2265 } else {
2266 return null;
2267 }
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002270 }
2271 }
2272
2273 /**
2274 * Returns the CDMA MIN.
2275 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002277 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2279 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002280
2281 final long identity = Binder.clearCallingIdentity();
2282 try {
2283 final Phone phone = getPhone(subId);
2284 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2285 return phone.getCdmaMin();
2286 } else {
2287 return null;
2288 }
2289 } finally {
2290 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002291 }
2292 }
2293
2294 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 * Returns true if CDMA provisioning needs to run.
2296 */
2297 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 final long identity = Binder.clearCallingIdentity();
2299 try {
2300 return mPhone.needsOtaServiceProvisioning();
2301 } finally {
2302 Binder.restoreCallingIdentity(identity);
2303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 }
2305
2306 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002307 * Sets the voice mail number of a given subId.
2308 */
2309 @Override
2310 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002311 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2316 new Pair<String, String>(alphaTag, number), new Integer(subId));
2317 return success;
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
2320 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002321 }
2322
Ta-wei Yen87c49842016-05-13 21:19:52 -07002323 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002324 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2325 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2326 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2327 if (!TextUtils.equals(callingPackage, systemDialer)) {
2328 throw new SecurityException("caller must be system dialer");
2329 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
2333 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2334 if (phoneAccountHandle == null) {
2335 return null;
2336 }
2337 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002340 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002341 }
2342
2343 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002344 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002345 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002346 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002347 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002348 return null;
2349 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002351 final long identity = Binder.clearCallingIdentity();
2352 try {
2353 return RemoteVvmTaskManager
2354 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
2357 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002358 }
2359
2360 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002361 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2362 VisualVoicemailSmsFilterSettings settings) {
2363 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002364
2365 final long identity = Binder.clearCallingIdentity();
2366 try {
2367 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2368 mPhone.getContext(), callingPackage, subId, settings);
2369 } finally {
2370 Binder.restoreCallingIdentity(identity);
2371 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002372 }
2373
2374 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002375 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2376 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002377
2378 final long identity = Binder.clearCallingIdentity();
2379 try {
2380 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2381 mPhone.getContext(), callingPackage, subId);
2382 } finally {
2383 Binder.restoreCallingIdentity(identity);
2384 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002385 }
2386
2387 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002388 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2389 String callingPackage, int subId) {
2390 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002391
2392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2395 mPhone.getContext(), callingPackage, subId);
2396 } finally {
2397 Binder.restoreCallingIdentity(identity);
2398 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002399 }
2400
2401 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002402 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002403 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002404
2405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2408 mPhone.getContext(), subId);
2409 } finally {
2410 Binder.restoreCallingIdentity(identity);
2411 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002412 }
2413
2414 @Override
2415 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2416 String number, int port, String text, PendingIntent sentIntent) {
2417 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002418 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002419 enforceSendSmsPermission();
2420 // Make the calls as the phone process.
2421 final long identity = Binder.clearCallingIdentity();
2422 try {
2423 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2424 if (port == 0) {
2425 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2426 sentIntent, null, false);
2427 } else {
2428 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2429 smsManager.sendDataMessageWithSelfPermissions(number, null,
2430 (short) port, data, sentIntent, null);
2431 }
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
2434 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002435 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002436 /**
fionaxu0152e512016-11-14 13:36:14 -08002437 * Sets the voice activation state of a given subId.
2438 */
2439 @Override
2440 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2442 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443
2444 final long identity = Binder.clearCallingIdentity();
2445 try {
2446 final Phone phone = getPhone(subId);
2447 if (phone != null) {
2448 phone.setVoiceActivationState(activationState);
2449 } else {
2450 loge("setVoiceActivationState fails with invalid subId: " + subId);
2451 }
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002454 }
2455 }
2456
2457 /**
2458 * Sets the data activation state of a given subId.
2459 */
2460 @Override
2461 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2463 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 final Phone phone = getPhone(subId);
2468 if (phone != null) {
2469 phone.setDataActivationState(activationState);
2470 } else {
2471 loge("setVoiceActivationState fails with invalid subId: " + subId);
2472 }
2473 } finally {
2474 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002475 }
2476 }
2477
2478 /**
2479 * Returns the voice activation state of a given subId.
2480 */
2481 @Override
2482 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002483 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484
fionaxu0152e512016-11-14 13:36:14 -08002485 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 if (phone != null) {
2489 return phone.getVoiceActivationState();
2490 } else {
2491 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2492 }
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002495 }
2496 }
2497
2498 /**
2499 * Returns the data activation state of a given subId.
2500 */
2501 @Override
2502 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002503 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504
fionaxu0152e512016-11-14 13:36:14 -08002505 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 if (phone != null) {
2509 return phone.getDataActivationState();
2510 } else {
2511 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2512 }
2513 } finally {
2514 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002515 }
2516 }
2517
2518 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 * Returns the unread count of voicemails
2520 */
2521 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002522 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002523 }
2524
2525 /**
2526 * Returns the unread count of voicemails for a subId
2527 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002529 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 final Phone phone = getPhone(subId);
2533 if (phone != null) {
2534 return phone.getVoiceMessageCount();
2535 } else {
2536 return 0;
2537 }
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 }
2542
2543 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002544 * returns true, if the device is in a state where both voice and data
2545 * are supported simultaneously. This can change based on location or network condition.
2546 */
2547 @Override
2548 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 final Phone phone = getPhone(subId);
2552 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2553 } finally {
2554 Binder.restoreCallingIdentity(identity);
2555 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002556 }
2557
2558 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002559 * Send the dialer code if called from the current default dialer or the caller has
2560 * carrier privilege.
2561 * @param inputCode The dialer code to send
2562 */
2563 @Override
2564 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2565 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2566 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2567 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002568 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2569 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 mPhone.sendDialerSpecialCode(inputCode);
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
fionaxu235cc5e2017-03-06 22:25:57 -08002578 }
2579
2580 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002581 * Returns the data network type.
2582 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 *
2584 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2585 */
2586 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002587 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 final Phone phone = getPhone(getDefaultSubscription());
2591 if (phone != null) {
2592 return phone.getServiceState().getDataNetworkType();
2593 } else {
2594 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2595 }
2596 } finally {
2597 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002598 }
Wink Saville36469e72014-06-11 15:17:00 -07002599 }
2600
2601 /**
2602 * Returns the network type for a subId
2603 */
2604 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002605 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002607 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002608 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2609 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 final long identity = Binder.clearCallingIdentity();
2612 try {
2613 final Phone phone = getPhone(subId);
2614 if (phone != null) {
2615 return phone.getServiceState().getDataNetworkType();
2616 } else {
2617 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 }
2623
2624 /**
2625 * Returns the data network type
2626 */
2627 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 public int getDataNetworkType(String callingPackage) {
2629 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002630 }
2631
2632 /**
2633 * Returns the data network type for a subId
2634 */
2635 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002636 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002637 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002638 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002639 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2640 }
2641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 final Phone phone = getPhone(subId);
2645 if (phone != null) {
2646 return phone.getServiceState().getDataNetworkType();
2647 } else {
2648 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2649 }
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 }
2654
2655 /**
Wink Saville36469e72014-06-11 15:17:00 -07002656 * Returns the Voice network type for a subId
2657 */
2658 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002659 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002660 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002661 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002662 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2663 }
2664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 if (phone != null) {
2669 return phone.getServiceState().getVoiceNetworkType();
2670 } else {
2671 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
2678 /**
2679 * @return true if a ICC card is present
2680 */
2681 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002682 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002683 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2684 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002685 }
2686
2687 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002688 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002689 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002690 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002691 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 final long identity = Binder.clearCallingIdentity();
2693 try {
2694 final Phone phone = PhoneFactory.getPhone(slotIndex);
2695 if (phone != null) {
2696 return phone.getIccCard().hasIccCard();
2697 } else {
2698 return false;
2699 }
2700 } finally {
2701 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704
2705 /**
2706 * Return if the current radio is LTE on CDMA. This
2707 * is a tri-state return value as for a period of time
2708 * the mode may be unknown.
2709 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002710 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002711 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002712 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002714 @Override
2715 public int getLteOnCdmaMode(String callingPackage) {
2716 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002717 }
2718
Sanket Padawe356d7632015-06-22 14:03:32 -07002719 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002720 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002721 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002722 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002723 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2724 }
2725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 final Phone phone = getPhone(subId);
2729 if (phone == null) {
2730 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2731 } else {
2732 return phone.getLteOnCdmaMode();
2733 }
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002736 }
Wink Saville36469e72014-06-11 15:17:00 -07002737 }
2738
2739 public void setPhone(Phone phone) {
2740 mPhone = phone;
2741 }
2742
2743 /**
2744 * {@hide}
2745 * Returns Default subId, 0 in the case of single standby.
2746 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002747 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002748 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002749 }
2750
Shishir Agrawala9f32182016-04-12 12:00:16 -07002751 private int getSlotForDefaultSubscription() {
2752 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2753 }
2754
Wink Savilleb564aae2014-10-23 10:18:09 -07002755 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002756 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002758
2759 /**
2760 * @see android.telephony.TelephonyManager.WifiCallingChoices
2761 */
2762 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2766 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2767 getWhenToMakeWifiCallsDefaultPreference());
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
2770 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002771 }
2772
2773 /**
2774 * @see android.telephony.TelephonyManager.WifiCallingChoices
2775 */
2776 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2780 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2781 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2782 } finally {
2783 Binder.restoreCallingIdentity(identity);
2784 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002785 }
2786
Sailesh Nepald1e68152013-12-12 19:08:02 -08002787 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002788 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002789 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002790 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002791
Shishir Agrawal566b7612013-10-28 14:41:00 -07002792 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002793 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2794 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2796 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 if (TextUtils.equals(ISDR_AID, aid)) {
2802 // Only allows LPA to open logical channel to ISD-R.
2803 ComponentInfo bestComponent =
2804 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2805 if (bestComponent == null
2806 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2807 loge("The calling package is not allowed to access ISD-R.");
2808 throw new SecurityException(
2809 "The calling package is not allowed to access ISD-R.");
2810 }
Derek Tan740e1672017-06-27 14:56:27 -07002811 }
Derek Tan740e1672017-06-27 14:56:27 -07002812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 if (DBG) {
2814 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2815 }
2816 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2817 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2818 if (DBG) log("iccOpenLogicalChannel: " + response);
2819 return response;
2820 } finally {
2821 Binder.restoreCallingIdentity(identity);
2822 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002823 }
2824
2825 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002826 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2828 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2833 if (channel < 0) {
2834 return false;
2835 }
2836 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2837 if (DBG) log("iccCloseLogicalChannel: " + success);
2838 return success;
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002841 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002842 }
2843
2844 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002845 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002846 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2848 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 if (DBG) {
2853 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2854 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2855 + p3 + " data=" + data);
2856 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 if (channel < 0) {
2859 return "";
2860 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2863 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2864 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866 // Append the returned status code to the end of the response payload.
2867 String s = Integer.toHexString(
2868 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2869 if (response.payload != null) {
2870 s = IccUtils.bytesToHexString(response.payload) + s;
2871 }
2872 return s;
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002875 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002876 }
Jake Hambye994d462014-02-03 13:10:13 -08002877
Evan Charltonc66da362014-05-16 14:06:40 -07002878 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002879 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2880 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2882 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2888 && TextUtils.equals(ISDR_AID, data)) {
2889 // Only allows LPA to select ISD-R.
2890 ComponentInfo bestComponent =
2891 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2892 if (bestComponent == null
2893 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2894 loge("The calling package is not allowed to select ISD-R.");
2895 throw new SecurityException(
2896 "The calling package is not allowed to select ISD-R.");
2897 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002898 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002899
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 if (DBG) {
2901 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2902 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2903 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2906 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2907 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 // Append the returned status code to the end of the response payload.
2910 String s = Integer.toHexString(
2911 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2912 if (response.payload != null) {
2913 s = IccUtils.bytesToHexString(response.payload) + s;
2914 }
2915 return s;
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002918 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002919 }
2920
2921 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002922 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002923 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2925 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 if (DBG) {
2930 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2931 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2932 }
2933
2934 IccIoResult response =
2935 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2936 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2937 subId);
2938
2939 if (DBG) {
2940 log("Exchange SIM_IO [R]" + response);
2941 }
2942
2943 byte[] result = null;
2944 int length = 2;
2945 if (response.payload != null) {
2946 length = 2 + response.payload.length;
2947 result = new byte[length];
2948 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2949 } else {
2950 result = new byte[length];
2951 }
2952
2953 result[length - 1] = (byte) response.sw2;
2954 result[length - 2] = (byte) response.sw1;
2955 return result;
2956 } finally {
2957 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002958 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002959 }
2960
Nathan Haroldb3014052017-01-25 15:57:32 -08002961 /**
2962 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2963 * on a particular subscription
2964 */
sqianb6e41952018-03-12 14:54:01 -07002965 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2967 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2968 return null;
2969 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002970
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 if (appType != TelephonyManager.APPTYPE_USIM
2974 && appType != TelephonyManager.APPTYPE_SIM) {
2975 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2976 return null;
2977 }
2978 Object response = sendRequest(
2979 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2980 if (response instanceof String[]) {
2981 return (String[]) response;
2982 }
2983 // Response is an Exception of some kind,
2984 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08002985 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986 } finally {
2987 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002988 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002989 }
2990
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002991 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002992 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2994 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2999 if (response.payload == null) {
3000 return "";
3001 }
Evan Charltonc66da362014-05-16 14:06:40 -07003002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 // Append the returned status code to the end of the response payload.
3004 String s = Integer.toHexString(
3005 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3006 s = IccUtils.bytesToHexString(response.payload) + s;
3007 return s;
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
3010 }
Evan Charltonc66da362014-05-16 14:06:40 -07003011 }
3012
Jake Hambye994d462014-02-03 13:10:13 -08003013 /**
3014 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3015 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3016 *
3017 * @param itemID the ID of the item to read
3018 * @return the NV item as a String, or null on error.
3019 */
3020 @Override
3021 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3023 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 if (DBG) log("nvReadItem: item " + itemID);
3028 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3029 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3030 return value;
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
Jake Hambye994d462014-02-03 13:10:13 -08003034 }
3035
3036 /**
3037 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3038 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3039 *
3040 * @param itemID the ID of the item to read
3041 * @param itemValue the value to write, as a String
3042 * @return true on success; false on any failure
3043 */
3044 @Override
3045 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3047 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3052 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3053 new Pair<Integer, String>(itemID, itemValue));
3054 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3055 return success;
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
Jake Hambye994d462014-02-03 13:10:13 -08003059 }
3060
3061 /**
3062 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3063 * Used for device configuration by some CDMA operators.
3064 *
3065 * @param preferredRoamingList byte array containing the new PRL
3066 * @return true on success; false on any failure
3067 */
3068 @Override
3069 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3071 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3076 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3077 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3078 return success;
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
Jake Hambye994d462014-02-03 13:10:13 -08003082 }
3083
3084 /**
3085 * Perform the specified type of NV config reset.
3086 * Used for device configuration by some CDMA operators.
3087 *
3088 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3089 * @return true on success; false on any failure
3090 */
3091 @Override
3092 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3094 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 if (DBG) log("nvResetConfig: type " + resetType);
3099 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3100 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3101 return success;
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
Jake Hambye994d462014-02-03 13:10:13 -08003105 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003106
Svet Ganovb320e182015-04-16 12:30:10 -07003107 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003109 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003110 return new String[0];
3111 }
3112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 return mPhone.getPcscfAddress(apnType);
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
Wink Saville36469e72014-06-11 15:17:00 -07003119 }
3120
Brad Ebinger51f743a2017-01-23 13:50:20 -08003121 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003122 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3123 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003124 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003125 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003126 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 PhoneFactory.getImsResolver().enableIms(slotId);
3131 } finally {
3132 Binder.restoreCallingIdentity(identity);
3133 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003134 }
3135
3136 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003137 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3138 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003139 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003140 public void disableIms(int slotId) {
3141 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142
3143 final long identity = Binder.clearCallingIdentity();
3144 try {
3145 PhoneFactory.getImsResolver().disableIms(slotId);
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
3148 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003149 }
3150
3151 /**
3152 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3153 * feature or {@link null} if the service is not available. If the feature is available, the
3154 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3155 */
3156 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003157 IImsServiceFeatureCallback callback) {
3158 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003159
3160 final long identity = Binder.clearCallingIdentity();
3161 try {
3162 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003166 }
3167
3168 /**
3169 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3170 * feature during emergency calling or {@link null} if the service is not available. If the
3171 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3172 * listener for feature updates.
3173 */
3174 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3175 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176
3177 final long identity = Binder.clearCallingIdentity();
3178 try {
3179 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3180 } finally {
3181 Binder.restoreCallingIdentity(identity);
3182 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003183 }
3184
Brad Ebinger5f64b052017-12-14 14:26:15 -08003185 /**
3186 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3187 * specified.
3188 */
3189 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3190 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003191
3192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
3197 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003198 }
3199
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003200 /**
3201 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3202 * specified.
3203 */
3204 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206
3207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
3212 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003213 }
3214
Brad Ebinger884c07b2018-02-15 16:17:40 -08003215 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003216 * Sets the ImsService Package Name that Telephony will bind to.
3217 *
3218 * @param slotId the slot ID that the ImsService should bind for.
3219 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3220 * ImsService is the device default ImsService.
3221 * @param packageName The package name of the application that contains the ImsService to bind
3222 * to.
3223 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3224 * @hide
3225 */
3226 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003227 int[] subIds = SubscriptionManager.getSubId(slotId);
3228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3229 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3230 "setImsService");
3231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3235 isCarrierImsService, packageName);
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003239 }
3240
3241 /**
3242 * Return the ImsService configuration.
3243 *
3244 * @param slotId The slot that the ImsService is associated with.
3245 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3246 * the device default.
3247 * @return the package name of the ImsService configuration.
3248 */
3249 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003250 int[] subIds = SubscriptionManager.getSubId(slotId);
3251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3252 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3253 "getImsService");
3254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3258 isCarrierImsService);
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
3261 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003262 }
3263
Wink Saville36469e72014-06-11 15:17:00 -07003264 public void setImsRegistrationState(boolean registered) {
3265 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003266
3267 final long identity = Binder.clearCallingIdentity();
3268 try {
3269 mPhone.setImsRegistrationState(registered);
3270 } finally {
3271 Binder.restoreCallingIdentity(identity);
3272 }
Wink Saville36469e72014-06-11 15:17:00 -07003273 }
3274
3275 /**
Stuart Scott54788802015-03-30 13:18:01 -07003276 * Set the network selection mode to automatic.
3277 *
3278 */
3279 @Override
3280 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3282 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003283
3284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3287 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
Stuart Scott54788802015-03-30 13:18:01 -07003291 }
3292
3293 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003294 * Set the network selection mode to manual with the selected carrier.
3295 */
3296 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003297 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003298 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3300 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003301
3302 final long identity = Binder.clearCallingIdentity();
3303 try {
3304 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003305 /* operatorAlphaLong */ "",
3306 /* operatorAlphaShort */ "",
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307 operatorNumeric);
3308 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3309 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3310 persistSelection);
3311 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3312 } finally {
3313 Binder.restoreCallingIdentity(identity);
3314 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003315 }
3316
3317 /**
3318 * Scans for available networks.
3319 */
3320 @Override
3321 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3323 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324
3325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3328 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3329 CMD_PERFORM_NETWORK_SCAN, null, subId);
3330 return result;
3331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003334 }
3335
3336 /**
yinxub1bed742017-04-17 11:45:04 -07003337 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003338 *
yinxub1bed742017-04-17 11:45:04 -07003339 * @param subId id of the subscription
3340 * @param request contains the radio access networks with bands/channels to scan
3341 * @param messenger callback messenger for scan results or errors
3342 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003343 * @return the id of the requested scan which can be used to stop the scan.
3344 */
3345 @Override
3346 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3347 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3349 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350
3351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 return mNetworkScanRequestTracker.startNetworkScan(
3354 request, messenger, binder, getPhone(subId));
3355 } finally {
3356 Binder.restoreCallingIdentity(identity);
3357 }
yinxu504e1392017-04-12 16:03:22 -07003358 }
3359
3360 /**
3361 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003362 *
3363 * @param subId id of the subscription
3364 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003365 */
3366 @Override
3367 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3369 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003370
3371 final long identity = Binder.clearCallingIdentity();
3372 try {
3373 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3374 } finally {
3375 Binder.restoreCallingIdentity(identity);
3376 }
yinxu504e1392017-04-12 16:03:22 -07003377 }
3378
3379 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003380 * Get the calculated preferred network type.
3381 * Used for debugging incorrect network type.
3382 *
3383 * @return the preferred network type, defined in RILConstants.java.
3384 */
3385 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003386 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003388 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003389 return RILConstants.PREFERRED_NETWORK_MODE;
3390 }
3391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 // FIXME: need to get SubId from somewhere.
3395 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3396 } finally {
3397 Binder.restoreCallingIdentity(identity);
3398 }
Junda Liu84d15a22014-07-02 11:21:04 -07003399 }
3400
3401 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003402 * Get the preferred network type.
3403 * Used for device configuration by some CDMA operators.
3404 *
3405 * @return the preferred network type, defined in RILConstants.java.
3406 */
3407 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003408 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3410 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411
3412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 if (DBG) log("getPreferredNetworkType");
3415 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3416 int networkType = (result != null ? result[0] : -1);
3417 if (DBG) log("getPreferredNetworkType: " + networkType);
3418 return networkType;
3419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003422 }
3423
3424 /**
3425 * Set the preferred network type.
3426 * Used for device configuration by some CDMA operators.
3427 *
3428 * @param networkType the preferred network type, defined in RILConstants.java.
3429 * @return true on success; false on any failure.
3430 */
3431 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003432 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3434 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003435
3436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3439 Boolean success = (Boolean) sendRequest(
3440 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3441 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3442 if (success) {
3443 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3444 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3445 }
3446 return success;
3447 } finally {
3448 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003449 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003450 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003451
3452 /**
Junda Liu475951f2014-11-07 16:45:03 -08003453 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3454 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3455 * tethering.
3456 *
3457 * @return 0: Not required. 1: required. 2: Not set.
3458 * @hide
3459 */
3460 @Override
3461 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003462 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463
3464 final long identity = Binder.clearCallingIdentity();
3465 try {
3466 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3467 Settings.Global.TETHER_DUN_REQUIRED, 2);
3468 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3469 // config_tether_apndata.
3470 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3471 dunRequired = 1;
3472 }
3473 return dunRequired;
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003476 }
Junda Liu475951f2014-11-07 16:45:03 -08003477 }
3478
3479 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003480 * Set mobile data enabled
3481 * Used by the user through settings etc to turn on/off mobile data
3482 *
3483 * @param enable {@code true} turn turn data on, else {@code false}
3484 */
3485 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003486 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3488 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003489
3490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 int phoneId = mSubscriptionController.getPhoneId(subId);
3493 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3494 Phone phone = PhoneFactory.getPhone(phoneId);
3495 if (phone != null) {
3496 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3497 phone.setUserDataEnabled(enable);
3498 } else {
3499 loge("setUserDataEnabled: no phone for subId=" + subId);
3500 }
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003503 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003504 }
3505
3506 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003507 * Get the user enabled state of Mobile Data.
3508 *
3509 * TODO: remove and use isUserDataEnabled.
3510 * This can't be removed now because some vendor codes
3511 * calls through ITelephony directly while they should
3512 * use TelephonyManager.
3513 *
3514 * @return true on enabled
3515 */
3516 @Override
3517 public boolean getDataEnabled(int subId) {
3518 return isUserDataEnabled(subId);
3519 }
3520
3521 /**
3522 * Get whether mobile data is enabled per user setting.
3523 *
3524 * There are other factors deciding whether mobile data is actually enabled, but they are
3525 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003526 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003527 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003528 *
3529 * @return {@code true} if data is enabled else {@code false}
3530 */
3531 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003532 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003533 try {
3534 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3535 null);
3536 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3538 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540
3541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 int phoneId = mSubscriptionController.getPhoneId(subId);
3544 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3545 Phone phone = PhoneFactory.getPhone(phoneId);
3546 if (phone != null) {
3547 boolean retVal = phone.isUserDataEnabled();
3548 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3549 return retVal;
3550 } else {
3551 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3552 return false;
3553 }
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003556 }
3557 }
3558
3559 /**
3560 * Get whether mobile data is enabled.
3561 *
3562 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3563 * whether mobile data is actually enabled.
3564 *
3565 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3566 *
3567 * @return {@code true} if data is enabled else {@code false}
3568 */
3569 @Override
3570 public boolean isDataEnabled(int subId) {
3571 try {
3572 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3573 null);
3574 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3576 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578
3579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 int phoneId = mSubscriptionController.getPhoneId(subId);
3582 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3583 Phone phone = PhoneFactory.getPhone(phoneId);
3584 if (phone != null) {
3585 boolean retVal = phone.isDataEnabled();
3586 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3587 return retVal;
3588 } else {
3589 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3590 return false;
3591 }
3592 } finally {
3593 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003594 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003595 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003596
3597 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003598 public int getCarrierPrivilegeStatus(int subId) {
3599 final Phone phone = getPhone(subId);
3600 if (phone == null) {
3601 loge("getCarrierPrivilegeStatus: Invalid subId");
3602 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3603 }
3604 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003605 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003606 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003607 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3608 }
3609 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003610 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003611 }
Junda Liu29340342014-07-10 15:23:27 -07003612
3613 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003614 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3615 final Phone phone = getPhone(subId);
3616 if (phone == null) {
3617 loge("getCarrierPrivilegeStatus: Invalid subId");
3618 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3619 }
3620 UiccProfile profile =
3621 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3622 if (profile == null) {
3623 loge("getCarrierPrivilegeStatus: No UICC");
3624 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3625 }
3626 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3627 }
3628
3629 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003630 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003631 if (TextUtils.isEmpty(pkgName))
3632 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003633 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003634 if (card == null) {
3635 loge("checkCarrierPrivilegesForPackage: No UICC");
3636 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3637 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003638 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3639 }
3640
3641 @Override
3642 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003643 if (TextUtils.isEmpty(pkgName))
3644 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003645 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3646 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3647 UiccCard card = UiccController.getInstance().getUiccCard(i);
3648 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003649 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003650 continue;
3651 }
3652
3653 result = card.getCarrierPrivilegeStatus(
3654 mPhone.getContext().getPackageManager(), pkgName);
3655 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3656 break;
3657 }
3658 }
3659
3660 return result;
Junda Liu29340342014-07-10 15:23:27 -07003661 }
Derek Tan89e89d42014-07-08 17:00:10 -07003662
3663 @Override
Junda Liue64de782015-04-16 17:19:16 -07003664 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3665 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3666 loge("phoneId " + phoneId + " is not valid.");
3667 return null;
3668 }
3669 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003670 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003671 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003672 return null ;
3673 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003674 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003675 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003676 }
3677
Amith Yamasani6e118872016-02-19 12:53:51 -08003678 @Override
3679 public List<String> getPackagesWithCarrierPrivileges() {
3680 PackageManager pm = mPhone.getContext().getPackageManager();
3681 List<String> privilegedPackages = new ArrayList<>();
3682 List<PackageInfo> packages = null;
3683 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3684 UiccCard card = UiccController.getInstance().getUiccCard(i);
3685 if (card == null) {
3686 // No UICC in that slot.
3687 continue;
3688 }
3689 if (card.hasCarrierPrivilegeRules()) {
3690 if (packages == null) {
3691 // Only check packages in user 0 for now
3692 packages = pm.getInstalledPackagesAsUser(
3693 PackageManager.MATCH_DISABLED_COMPONENTS
3694 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3695 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3696 }
3697 for (int p = packages.size() - 1; p >= 0; p--) {
3698 PackageInfo pkgInfo = packages.get(p);
3699 if (pkgInfo != null && pkgInfo.packageName != null
3700 && card.getCarrierPrivilegeStatus(pkgInfo)
3701 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3702 privilegedPackages.add(pkgInfo.packageName);
3703 }
3704 }
3705 }
3706 }
3707 return privilegedPackages;
3708 }
3709
Wink Savilleb564aae2014-10-23 10:18:09 -07003710 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003711 final Phone phone = getPhone(subId);
3712 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003713 if (card == null) {
3714 loge("getIccId: No UICC");
3715 return null;
3716 }
3717 String iccId = card.getIccId();
3718 if (TextUtils.isEmpty(iccId)) {
3719 loge("getIccId: ICC ID is null or empty.");
3720 return null;
3721 }
3722 return iccId;
3723 }
3724
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003725 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003726 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3727 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003728 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3729 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731 final long identity = Binder.clearCallingIdentity();
3732 try {
3733 final String iccId = getIccId(subId);
3734 final Phone phone = getPhone(subId);
3735 if (phone == null) {
3736 return false;
3737 }
3738 final String subscriberId = phone.getSubscriberId();
3739
3740 if (DBG_MERGE) {
3741 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3742 + subscriberId + " to " + number);
3743 }
3744
3745 if (TextUtils.isEmpty(iccId)) {
3746 return false;
3747 }
3748
3749 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3750
3751 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3752 if (alphaTag == null) {
3753 editor.remove(alphaTagPrefKey);
3754 } else {
3755 editor.putString(alphaTagPrefKey, alphaTag);
3756 }
3757
3758 // Record both the line number and IMSI for this ICCID, since we need to
3759 // track all merged IMSIs based on line number
3760 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3761 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3762 if (number == null) {
3763 editor.remove(numberPrefKey);
3764 editor.remove(subscriberPrefKey);
3765 } else {
3766 editor.putString(numberPrefKey, number);
3767 editor.putString(subscriberPrefKey, subscriberId);
3768 }
3769
3770 editor.commit();
3771 return true;
3772 } finally {
3773 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003774 }
Derek Tan7226c842014-07-02 17:42:23 -07003775 }
3776
3777 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003778 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003779 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003781 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003782 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003783 return null;
3784 }
Derek Tan97ebb422014-09-05 16:55:38 -07003785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 String iccId = getIccId(subId);
3789 if (iccId != null) {
3790 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3791 if (DBG_MERGE) {
3792 log("getLine1NumberForDisplay returning "
3793 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3794 }
3795 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3798 return null;
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003801 }
Derek Tan7226c842014-07-02 17:42:23 -07003802 }
3803
3804 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003805 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003807 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003808 return null;
3809 }
Derek Tan97ebb422014-09-05 16:55:38 -07003810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 String iccId = getIccId(subId);
3814 if (iccId != null) {
3815 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3816 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3817 }
3818 return null;
3819 } finally {
3820 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003821 }
Derek Tan7226c842014-07-02 17:42:23 -07003822 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003823
3824 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003825 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003826 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3827 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003828 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003829 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3830 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003831 return null;
3832 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003833
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003834 final long identity = Binder.clearCallingIdentity();
3835 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836 final Context context = mPhone.getContext();
3837 final TelephonyManager tele = TelephonyManager.from(context);
3838 final SubscriptionManager sub = SubscriptionManager.from(context);
3839
3840 // Figure out what subscribers are currently active
3841 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3842 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3843 // the process, where TelephonyManager was instantiated.
3844 // Otherwise AppOps check will fail.
3845
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003846 final int[] subIds = sub.getActiveSubscriptionIdList();
3847 for (int subId : subIds) {
3848 activeSubscriberIds.add(tele.getSubscriberId(subId));
3849 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850
3851 // First pass, find a number override for an active subscriber
3852 String mergeNumber = null;
3853 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3854 for (String key : prefs.keySet()) {
3855 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3856 final String subscriberId = (String) prefs.get(key);
3857 if (activeSubscriberIds.contains(subscriberId)) {
3858 final String iccId = key.substring(
3859 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3860 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3861 mergeNumber = (String) prefs.get(numberKey);
3862 if (DBG_MERGE) {
3863 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3864 + " for active subscriber " + subscriberId);
3865 }
3866 if (!TextUtils.isEmpty(mergeNumber)) {
3867 break;
3868 }
3869 }
3870 }
3871 }
3872
3873 // Shortcut when no active merged subscribers
3874 if (TextUtils.isEmpty(mergeNumber)) {
3875 return null;
3876 }
3877
3878 // Second pass, find all subscribers under that line override
3879 final ArraySet<String> result = new ArraySet<>();
3880 for (String key : prefs.keySet()) {
3881 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3882 final String number = (String) prefs.get(key);
3883 if (mergeNumber.equals(number)) {
3884 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3885 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3886 final String subscriberId = (String) prefs.get(subscriberKey);
3887 if (!TextUtils.isEmpty(subscriberId)) {
3888 result.add(subscriberId);
3889 }
3890 }
3891 }
3892 }
3893
3894 final String[] resultArray = result.toArray(new String[result.size()]);
3895 Arrays.sort(resultArray);
3896 if (DBG_MERGE) {
3897 Slog.d(LOG_TAG,
3898 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3899 }
3900 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003901 } finally {
3902 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003903 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003904 }
3905
3906 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003907 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003908 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3909 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910
3911 final long identity = Binder.clearCallingIdentity();
3912 try {
3913 final Phone phone = getPhone(subId);
3914 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3915 } finally {
3916 Binder.restoreCallingIdentity(identity);
3917 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003918 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003919
3920 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003921 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003922 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3923 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003924 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925
3926 final long identity = Binder.clearCallingIdentity();
3927 try {
3928 final Phone phone = getPhone(subId);
3929 if (phone == null) {
3930 return false;
3931 }
3932 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3933 cdmaNonRoamingList);
3934 } finally {
3935 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003936 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003937 }
3938
3939 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003940 @Deprecated
3941 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3942 enforceModifyPermission();
3943
3944 int returnValue = 0;
3945 try {
3946 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3947 if(result.exception == null) {
3948 if (result.result != null) {
3949 byte[] responseData = (byte[])(result.result);
3950 if(responseData.length > oemResp.length) {
3951 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3952 responseData.length + "bytes. Buffer Size is " +
3953 oemResp.length + "bytes.");
3954 }
3955 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3956 returnValue = responseData.length;
3957 }
3958 } else {
3959 CommandException ex = (CommandException) result.exception;
3960 returnValue = ex.getCommandError().ordinal();
3961 if(returnValue > 0) returnValue *= -1;
3962 }
3963 } catch (RuntimeException e) {
3964 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3965 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3966 if(returnValue > 0) returnValue *= -1;
3967 }
3968
3969 return returnValue;
3970 }
3971
3972 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003973 public void setRadioCapability(RadioAccessFamily[] rafs) {
3974 try {
3975 ProxyController.getInstance().setRadioCapability(rafs);
3976 } catch (RuntimeException e) {
3977 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3978 }
3979 }
3980
3981 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003982 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003983 Phone phone = PhoneFactory.getPhone(phoneId);
3984 if (phone == null) {
3985 return RadioAccessFamily.RAF_UNKNOWN;
3986 }
3987 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003989 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003990 return RadioAccessFamily.RAF_UNKNOWN;
3991 }
3992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3996 } finally {
3997 Binder.restoreCallingIdentity(identity);
3998 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003999 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004000
4001 @Override
4002 public void enableVideoCalling(boolean enable) {
4003 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004
4005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4008 } finally {
4009 Binder.restoreCallingIdentity(identity);
4010 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004011 }
4012
4013 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004014 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4016 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4017 return false;
4018 }
Svet Ganovb320e182015-04-16 12:30:10 -07004019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 // Check the user preference and the system-level IMS setting. Even if the user has
4023 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4024 // In the long run, we may instead need to check if there exists a connection service
4025 // which can support video calling.
4026 ImsManager imsManager =
4027 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4028 return imsManager.isVtEnabledByPlatform()
4029 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4030 && imsManager.isVtEnabledByUser();
4031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004034 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004035
Andrew Leea1239f22015-03-02 17:44:07 -08004036 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004037 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4039 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4040 return false;
4041 }
4042
4043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 CarrierConfigManager configManager =
4046 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4047 return configManager.getConfigForSubId(mPhone.getSubId())
4048 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
4051 }
Andrew Leea1239f22015-03-02 17:44:07 -08004052 }
4053
4054 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055 public boolean isWorldPhone(int subId, String callingPackage) {
4056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4057 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4058 return false;
4059 }
4060
4061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 CarrierConfigManager configManager =
4064 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4065 return configManager.getConfigForSubId(mPhone.getSubId())
4066 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4067 } finally {
4068 Binder.restoreCallingIdentity(identity);
4069 }
Andrew Leea1239f22015-03-02 17:44:07 -08004070 }
4071
Andrew Lee9431b832015-03-09 18:46:45 -07004072 @Override
4073 public boolean isTtyModeSupported() {
4074 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004075 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004076 }
4077
4078 @Override
4079 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
Andrew Lee9431b832015-03-09 18:46:45 -07004086 }
4087
Hall Liu98187582018-01-22 19:15:32 -08004088 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089 final long identity = Binder.clearCallingIdentity();
4090 try {
4091 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4092 mPhone.getSubId()).getBoolean(
4093 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4094 boolean isDeviceSupported =
4095 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4096 return isCarrierSupported && isDeviceSupported;
4097 } finally {
4098 Binder.restoreCallingIdentity(identity);
4099 }
Hall Liu98187582018-01-22 19:15:32 -08004100 }
4101
Hall Liu3ad5f012018-04-06 16:23:39 -07004102 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 return isRttSupported() && Settings.Secure.getInt(
4106 mPhone.getContext().getContentResolver(),
4107 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004111 }
4112
Sanket Padawe7310cc72015-01-14 09:53:20 -08004113 /**
4114 * Returns the unique device ID of phone, for example, the IMEI for
4115 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4116 *
4117 * <p>Requires Permission:
4118 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4119 */
4120 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004121 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004122 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004123 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004124 return null;
4125 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004126 int subId = phone.getSubId();
4127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4128 mApp, subId, callingPackage, "getDeviceId")) {
4129 return null;
4130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004131
4132 final long identity = Binder.clearCallingIdentity();
4133 try {
4134 return phone.getDeviceId();
4135 } finally {
4136 Binder.restoreCallingIdentity(identity);
4137 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004138 }
4139
Ping Sunc67b7c22016-03-02 19:16:45 +08004140 /**
4141 * {@hide}
4142 * Returns the IMS Registration Status on a particular subid
4143 *
4144 * @param subId
4145 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004146 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004147 Phone phone = getPhone(subId);
4148 if (phone != null) {
4149 return phone.isImsRegistered();
4150 } else {
4151 return false;
4152 }
4153 }
4154
Santos Cordon7a1885b2015-02-03 11:15:19 -08004155 @Override
4156 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4160 } finally {
4161 Binder.restoreCallingIdentity(identity);
4162 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004163 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004164
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004165 /**
4166 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004167 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004168 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 Phone phone = getPhone(subId);
4172 if (phone != null) {
4173 return phone.isWifiCallingEnabled();
4174 } else {
4175 return false;
4176 }
4177 } finally {
4178 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004179 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004180 }
4181
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004182 /**
4183 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004184 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004185 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 Phone phone = getPhone(subId);
4189 if (phone != null) {
4190 return phone.isVolteEnabled();
4191 } else {
4192 return false;
4193 }
4194 } finally {
4195 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004196 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004197 }
Svet Ganovb320e182015-04-16 12:30:10 -07004198
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004199 /**
4200 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004201 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004202 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 Phone phone = getPhone(subId);
4206 if (phone != null) {
4207 return phone.isVideoEnabled();
4208 } else {
4209 return false;
4210 }
4211 } finally {
4212 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004213 }
4214 }
4215
4216 /**
4217 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4218 * defined in {@link ImsRegistrationImplBase}.
4219 */
4220 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221 final long identity = Binder.clearCallingIdentity();
4222 try {
4223 Phone phone = getPhone(subId);
4224 if (phone != null) {
4225 return phone.getImsRegistrationTech();
4226 } else {
4227 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4228 }
4229 } finally {
4230 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004231 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004232 }
4233
Stuart Scott8eef64f2015-04-08 15:13:54 -07004234 @Override
4235 public void factoryReset(int subId) {
4236 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004237 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4238 return;
4239 }
4240
Svet Ganovcc087f82015-05-12 20:35:54 -07004241 final long identity = Binder.clearCallingIdentity();
4242 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004243 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4244 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004245 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004246 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004247 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4248 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004249 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004250 }
4251 } finally {
4252 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004253 }
4254 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004255
4256 @Override
4257 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004258 final long identity = Binder.clearCallingIdentity();
4259 try {
4260 // We query all subscriptions instead of just the active ones, because
4261 // this might be called early on in the provisioning flow when the
4262 // subscriptions potentially aren't active yet.
4263 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4264 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004265 return null;
4266 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268 // This function may be called very early, say, from the setup wizard, at
4269 // which point we won't have a default subscription set. If that's the case
4270 // we just choose the first, which will be valid in "most cases".
4271 final int defaultSubId = getDefaultSubscription();
4272 SubscriptionInfo info = null;
4273 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4274 info = slist.get(0);
4275 } else {
4276 for (SubscriptionInfo item : slist) {
4277 if (item.getSubscriptionId() == defaultSubId) {
4278 info = item;
4279 break;
4280 }
4281 }
4282
4283 if (info == null) {
4284 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004285 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004286 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288 // Try and fetch the locale from the carrier properties or from the SIM language
4289 // preferences (EF-PL and EF-LI)...
4290 final int mcc = info.getMcc();
4291 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4292 String simLanguage = null;
4293 if (defaultPhone != null) {
4294 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4295 if (localeFromDefaultSim != null) {
4296 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4297 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4298 return localeFromDefaultSim.toLanguageTag();
4299 } else {
4300 simLanguage = localeFromDefaultSim.getLanguage();
4301 }
4302 }
4303 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 // The SIM language preferences only store a language (e.g. fr = French), not an
4306 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4307 // the SIM and carrier preferences does not include a country we add the country
4308 // determined from the SIM MCC to provide an exact locale.
4309 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4310 simLanguage);
4311 if (mccLocale != null) {
4312 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4313 return mccLocale.toLanguageTag();
4314 }
4315
4316 if (DBG) log("No locale found - returning null");
4317 return null;
4318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004321 }
4322
4323 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324 return mSubscriptionController.getAllSubInfoList(
4325 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004326 }
4327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328 /**
4329 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4330 */
4331 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4332 return mSubscriptionController.getActiveSubscriptionInfoList(
4333 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004334 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004335
Chenjie Yu1ba97252018-01-11 18:16:20 -08004336 private final ModemActivityInfo mLastModemActivityInfo =
4337 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4338
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004339 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004340 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4341 * representing the state of the modem.
4342 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004343 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4344 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004345 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004346 */
4347 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004348 public void requestModemActivityInfo(ResultReceiver result) {
4349 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350
4351 final long identity = Binder.clearCallingIdentity();
4352 try {
4353 ModemActivityInfo ret = null;
4354 synchronized (mLastModemActivityInfo) {
4355 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4356 CMD_GET_MODEM_ACTIVITY_INFO,
4357 null);
Siddharth Rayb8114062018-06-17 15:02:38 -07004358 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4360 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4361 mergedTxTimeMs[i] =
4362 info.getTxTimeMillis()[i]
4363 + mLastModemActivityInfo.getTxTimeMillis()[i];
4364 }
4365 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4366 mLastModemActivityInfo.setSleepTimeMillis(
4367 info.getSleepTimeMillis()
4368 + mLastModemActivityInfo.getSleepTimeMillis());
4369 mLastModemActivityInfo.setIdleTimeMillis(
4370 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4371 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4372 mLastModemActivityInfo.setRxTimeMillis(
4373 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4374 mLastModemActivityInfo.setEnergyUsed(
4375 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4378 mLastModemActivityInfo.getSleepTimeMillis(),
4379 mLastModemActivityInfo.getIdleTimeMillis(),
4380 mLastModemActivityInfo.getTxTimeMillis(),
4381 mLastModemActivityInfo.getRxTimeMillis(),
4382 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004383 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384 Bundle bundle = new Bundle();
4385 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4386 result.send(0, bundle);
4387 } finally {
4388 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004389 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004390 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004391
Siddharth Rayb8114062018-06-17 15:02:38 -07004392 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4393 // less than total activity duration.
4394 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4395 if (info == null) {
4396 return false;
4397 }
4398 int activityDurationMs =
4399 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4400 int totalTxTimeMs = 0;
4401 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4402 totalTxTimeMs += info.getTxTimeMillis()[i];
4403 }
4404 return (info.isValid()
4405 && (info.getSleepTimeMillis() <= activityDurationMs)
4406 && (info.getIdleTimeMillis() <= activityDurationMs)
4407 && (info.getRxTimeMillis() <= activityDurationMs)
4408 && (totalTxTimeMs <= activityDurationMs));
4409 }
4410
Jack Yu85bd38a2015-11-09 11:34:32 -08004411 /**
4412 * {@hide}
4413 * Returns the service state information on specified subscription.
4414 */
4415 @Override
4416 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004418 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004419 return null;
4420 }
4421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 final Phone phone = getPhone(subId);
4425 if (phone == null) {
4426 return null;
4427 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 return phone.getServiceState();
4430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004433 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004434
4435 /**
4436 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4437 *
4438 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4439 * voicemail ringtone.
4440 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4441 * PhoneAccount.
4442 */
4443 @Override
4444 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445 final long identity = Binder.clearCallingIdentity();
4446 try {
4447 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4448 if (phone == null) {
4449 phone = mPhone;
4450 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
4455 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004456 }
4457
4458 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004459 * Sets the per-account voicemail ringtone.
4460 *
4461 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4462 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4463 *
4464 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4465 * voicemail ringtone.
4466 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4467 * PhoneAccount.
4468 */
4469 @Override
4470 public void setVoicemailRingtoneUri(String callingPackage,
4471 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4473 if (!TextUtils.equals(callingPackage,
4474 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4476 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4477 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479
4480 final long identity = Binder.clearCallingIdentity();
4481 try {
4482 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4483 if (phone == null) {
4484 phone = mPhone;
4485 }
4486 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4487 } finally {
4488 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004489 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004490 }
4491
4492 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004493 * Returns whether vibration is set for voicemail notification in Phone settings.
4494 *
4495 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4496 * voicemail vibration setting.
4497 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4498 */
4499 @Override
4500 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501 final long identity = Binder.clearCallingIdentity();
4502 try {
4503 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4504 if (phone == null) {
4505 phone = mPhone;
4506 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4509 } finally {
4510 Binder.restoreCallingIdentity(identity);
4511 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004512 }
4513
Youhan Wange64578a2016-05-02 15:32:42 -07004514 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004515 * Sets the per-account voicemail vibration.
4516 *
4517 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4518 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4519 *
4520 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4521 * voicemail vibration setting.
4522 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4523 * specific PhoneAccount.
4524 */
4525 @Override
4526 public void setVoicemailVibrationEnabled(String callingPackage,
4527 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4529 if (!TextUtils.equals(callingPackage,
4530 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4532 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4533 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004534 }
4535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004536 final long identity = Binder.clearCallingIdentity();
4537 try {
4538 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4539 if (phone == null) {
4540 phone = mPhone;
4541 }
4542 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4543 } finally {
4544 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004545 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004546 }
4547
4548 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004549 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4550 *
4551 * @throws SecurityException if the caller does not have the required permission
4552 */
4553 private void enforceReadPrivilegedPermission() {
4554 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4555 null);
4556 }
4557
4558 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004559 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4560 * permission.
4561 *
4562 * @throws SecurityException if the caller does not have the required permission
4563 */
4564 private void enforceSendSmsPermission() {
4565 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4566 }
4567
4568 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004569 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004570 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004571 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004572 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004573 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 final long identity = Binder.clearCallingIdentity();
4575 try {
4576 ComponentName componentName =
4577 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4578 if (componentName == null) {
4579 throw new SecurityException(
4580 "Caller not current active visual voicemail package[null]");
4581 }
4582 String vvmPackage = componentName.getPackageName();
4583 if (!callingPackage.equals(vvmPackage)) {
4584 throw new SecurityException("Caller not current active visual voicemail package["
4585 + vvmPackage + "]");
4586 }
4587 } finally {
4588 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004589 }
4590 }
4591
4592 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004593 * Return the application ID for the app type.
4594 *
4595 * @param subId the subscription ID that this request applies to.
4596 * @param appType the uicc app type.
4597 * @return Application ID for specificied app type, or null if no uicc.
4598 */
4599 @Override
4600 public String getAidForAppType(int subId, int appType) {
4601 enforceReadPrivilegedPermission();
4602 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603
4604 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004605 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606 if (phone == null) {
4607 return null;
4608 }
4609 String aid = null;
4610 try {
4611 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4612 .getApplicationByType(appType).getAid();
4613 } catch (Exception e) {
4614 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4615 }
4616 return aid;
4617 } finally {
4618 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004619 }
Youhan Wange64578a2016-05-02 15:32:42 -07004620 }
4621
Youhan Wang4001d252016-05-11 10:29:41 -07004622 /**
4623 * Return the Electronic Serial Number.
4624 *
4625 * @param subId the subscription ID that this request applies to.
4626 * @return ESN or null if error.
4627 */
4628 @Override
4629 public String getEsn(int subId) {
4630 enforceReadPrivilegedPermission();
4631 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632
4633 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004634 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 if (phone == null) {
4636 return null;
4637 }
4638 String esn = null;
4639 try {
4640 esn = phone.getEsn();
4641 } catch (Exception e) {
4642 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4643 }
4644 return esn;
4645 } finally {
4646 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004647 }
Youhan Wang4001d252016-05-11 10:29:41 -07004648 }
4649
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004650 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004651 * Return the Preferred Roaming List Version.
4652 *
4653 * @param subId the subscription ID that this request applies to.
4654 * @return PRLVersion or null if error.
4655 */
4656 @Override
4657 public String getCdmaPrlVersion(int subId) {
4658 enforceReadPrivilegedPermission();
4659 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660
4661 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004662 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 if (phone == null) {
4664 return null;
4665 }
4666 String cdmaPrlVersion = null;
4667 try {
4668 cdmaPrlVersion = phone.getCdmaPrlVersion();
4669 } catch (Exception e) {
4670 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4671 }
4672 return cdmaPrlVersion;
4673 } finally {
4674 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004675 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004676 }
4677
4678 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004679 * Get snapshot of Telephony histograms
4680 * @return List of Telephony histograms
4681 * @hide
4682 */
4683 @Override
4684 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4686 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687
4688 final long identity = Binder.clearCallingIdentity();
4689 try {
4690 return RIL.getTelephonyRILTimingHistograms();
4691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004694 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004695
4696 /**
4697 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004698 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004699 * Require system privileges. In the future we may add this to carrier APIs.
4700 *
4701 * @return The number of carriers set successfully, should match length of carriers
4702 */
4703 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004704 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004705 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004706
Meng Wang9b7c4e92017-02-17 11:41:27 -08004707 if (carriers == null) {
4708 throw new NullPointerException("carriers cannot be null");
4709 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 final long identity = Binder.clearCallingIdentity();
4712 try {
4713 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4714 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4715 return retVal[0];
4716 } finally {
4717 Binder.restoreCallingIdentity(identity);
4718 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004719 }
4720
4721 /**
4722 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004723 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004724 * Require system privileges. In the future we may add this to carrier APIs.
4725 *
4726 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4727 * means all carriers are allowed.
4728 */
4729 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004730 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004731 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732
4733 final long identity = Binder.clearCallingIdentity();
4734 try {
4735 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4736 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
4739 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004740 }
4741
fionaxu59545b42016-05-25 15:53:37 -07004742 /**
4743 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4744 * @param subId the subscription ID that this action applies to.
4745 * @param enabled control enable or disable metered apns.
4746 * {@hide}
4747 */
4748 @Override
4749 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4750 enforceModifyPermission();
4751 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752
4753 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004754 if (phone == null) {
4755 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4756 return;
4757 }
4758 try {
4759 phone.carrierActionSetMeteredApnsEnabled(enabled);
4760 } catch (Exception e) {
4761 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 } finally {
4763 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004764 }
4765 }
4766
4767 /**
4768 * Action set from carrier signalling broadcast receivers to enable/disable radio
4769 * @param subId the subscription ID that this action applies to.
4770 * @param enabled control enable or disable radio.
4771 * {@hide}
4772 */
4773 @Override
4774 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4775 enforceModifyPermission();
4776 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777
4778 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004779 if (phone == null) {
4780 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4781 return;
4782 }
4783 try {
4784 phone.carrierActionSetRadioEnabled(enabled);
4785 } catch (Exception e) {
4786 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004787 } finally {
4788 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004789 }
4790 }
4791
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004792 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004793 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4794 * network status based on which carrier apps could apply actions accordingly,
4795 * enable/disable default url handler for example.
4796 *
4797 * @param subId the subscription ID that this action applies to.
4798 * @param report control start/stop reporting the default network status.
4799 * {@hide}
4800 */
4801 @Override
4802 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4803 enforceModifyPermission();
4804 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805
4806 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004807 if (phone == null) {
4808 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4809 return;
4810 }
4811 try {
4812 phone.carrierActionReportDefaultNetworkStatus(report);
4813 } catch (Exception e) {
4814 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 } finally {
4816 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004817 }
4818 }
4819
4820 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004821 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4822 * bug report is being generated.
4823 */
4824 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004825 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004826 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4827 != PackageManager.PERMISSION_GRANTED) {
4828 writer.println("Permission Denial: can't dump Phone from pid="
4829 + Binder.getCallingPid()
4830 + ", uid=" + Binder.getCallingUid()
4831 + "without permission "
4832 + android.Manifest.permission.DUMP);
4833 return;
4834 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004835 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004836 }
Jack Yueb89b242016-06-22 13:27:47 -07004837
Brad Ebingerdac2f002018-04-03 15:17:52 -07004838 @Override
4839 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4840 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4841 throws RemoteException {
4842 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4843 }
4844
Jack Yueb89b242016-06-22 13:27:47 -07004845 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004846 * Get aggregated video call data usage since boot.
4847 *
4848 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4849 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004850 * {@hide}
4851 */
4852 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004853 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004854 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4855 null);
4856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 final long identity = Binder.clearCallingIdentity();
4858 try {
4859 // NetworkStatsService keeps tracking the active network interface and identity. It
4860 // records the delta with the corresponding network identity.
4861 // We just return the total video call data usage snapshot since boot.
4862 Phone phone = getPhone(subId);
4863 if (phone != null) {
4864 return phone.getVtDataUsage(perUidStats);
4865 }
4866 return null;
4867 } finally {
4868 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004869 }
Jack Yueb89b242016-06-22 13:27:47 -07004870 }
Jack Yu75ab2952016-07-08 14:29:33 -07004871
4872 /**
4873 * Policy control of data connection. Usually used when data limit is passed.
4874 * @param enabled True if enabling the data, otherwise disabling.
4875 * @param subId Subscription index
4876 * {@hide}
4877 */
4878 @Override
4879 public void setPolicyDataEnabled(boolean enabled, int subId) {
4880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881
4882 final long identity = Binder.clearCallingIdentity();
4883 try {
4884 Phone phone = getPhone(subId);
4885 if (phone != null) {
4886 phone.setPolicyDataEnabled(enabled);
4887 }
4888 } finally {
4889 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004890 }
4891 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004892
4893 /**
4894 * Get Client request stats
4895 * @return List of Client Request Stats
4896 * @hide
4897 */
4898 @Override
4899 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004901 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004902 return null;
4903 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004904 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 if (phone != null) {
4909 return phone.getClientRequestStats();
4910 }
4911
4912 return null;
4913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004916 }
4917
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004918 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004919 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004920 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004921 }
Jack Yueb4124c2017-02-16 15:32:43 -08004922
4923 /**
Grace Chen70990072017-03-24 17:21:30 -07004924 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004925 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004926 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004927 * @param state State of SIM (power down, power up, pass through)
4928 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4929 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4930 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004931 *
4932 **/
4933 @Override
Grace Chen70990072017-03-24 17:21:30 -07004934 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004935 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004936 Phone phone = PhoneFactory.getPhone(slotIndex);
4937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 final long identity = Binder.clearCallingIdentity();
4939 try {
4940 if (phone != null) {
4941 phone.setSimPowerState(state);
4942 }
4943 } finally {
4944 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004945 }
4946 }
Shuo Qiandd210312017-04-12 22:11:33 +00004947
Tyler Gunn65d45c22017-06-05 11:22:26 -07004948 private boolean isUssdApiAllowed(int subId) {
4949 CarrierConfigManager configManager =
4950 (CarrierConfigManager) mPhone.getContext().getSystemService(
4951 Context.CARRIER_CONFIG_SERVICE);
4952 if (configManager == null) {
4953 return false;
4954 }
4955 PersistableBundle pb = configManager.getConfigForSubId(subId);
4956 if (pb == null) {
4957 return false;
4958 }
4959 return pb.getBoolean(
4960 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4961 }
4962
Shuo Qiandd210312017-04-12 22:11:33 +00004963 /**
4964 * Check if phone is in emergency callback mode
4965 * @return true if phone is in emergency callback mode
4966 * @param subId sub id
4967 */
goneil9c5f4872017-12-05 14:07:56 -08004968 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004969 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004970 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004971 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972
4973 final long identity = Binder.clearCallingIdentity();
4974 try {
4975 if (phone != null) {
4976 return phone.isInEcm();
4977 } else {
4978 return false;
4979 }
4980 } finally {
4981 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004982 }
4983 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004984
4985 /**
4986 * Get the current signal strength information for the given subscription.
4987 * Because this information is not updated when the device is in a low power state
4988 * it should not be relied-upon to be current.
4989 * @param subId Subscription index
4990 * @return the most recent cached signal strength info from the modem
4991 */
4992 @Override
4993 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 final long identity = Binder.clearCallingIdentity();
4995 try {
4996 Phone p = getPhone(subId);
4997 if (p == null) {
4998 return null;
4999 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 return p.getSignalStrength();
5002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005005 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005006
Pengquan Meng77b7f132018-08-22 14:49:57 -07005007 /**
5008 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5009 *
5010 * <p>Requires one of the following permissions:
5011 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5012 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5013 * privileges.
5014 *
5015 * @param subId subscription id
5016 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5017 * {@code false}.
5018 */
5019 @Override
5020 public boolean isDataRoamingEnabled(int subId) {
5021 try {
5022 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5023 null);
5024 } catch (Exception e) {
5025 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5026 mApp, subId, "isDataRoamingEnabled");
5027 }
5028
5029 Phone phone = getPhone(subId);
5030 return phone != null ? phone.getDataRoamingEnabled() : false;
5031 }
5032
5033
5034 /**
5035 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5036 *
5037 * <p> Requires permission:
5038 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5039 * privileges.
5040 *
5041 * @param subId subscription id
5042 * @param isEnabled {@code true} means enable, {@code false} means disable.
5043 */
5044 @Override
5045 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
5046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5047 mApp, subId, "setDataRoamingEbaled");
5048
5049 Phone phone = getPhone(subId);
5050 if (phone != null) {
5051 phone.setDataRoamingEnabled(isEnabled);
5052 }
5053 }
5054
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005055 @Override
5056 public UiccSlotInfo[] getUiccSlotsInfo() {
5057 enforceReadPrivilegedPermission();
5058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5062 if (slots == null) {
5063 Rlog.i(LOG_TAG, "slots is null.");
5064 return null;
5065 }
5066
5067 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5068 for (int i = 0; i < slots.length; i++) {
5069 UiccSlot slot = slots[i];
5070 if (slot == null) {
5071 continue;
5072 }
5073
5074 String cardId;
5075 UiccCard card = slot.getUiccCard();
5076 if (card != null) {
5077 cardId = card.getCardId();
5078 } else {
5079 cardId = slot.getIccId();
5080 }
5081
5082 int cardState = 0;
5083 switch (slot.getCardState()) {
5084 case CARDSTATE_ABSENT:
5085 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5086 break;
5087 case CARDSTATE_PRESENT:
5088 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5089 break;
5090 case CARDSTATE_ERROR:
5091 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5092 break;
5093 case CARDSTATE_RESTRICTED:
5094 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5095 break;
5096 default:
5097 break;
5098
5099 }
5100
5101 infos[i] = new UiccSlotInfo(
5102 slot.isActive(),
5103 slot.isEuicc(),
5104 cardId,
5105 cardState,
5106 slot.getPhoneId(),
5107 slot.isExtendedApduSupported());
5108 }
5109 return infos;
5110 } finally {
5111 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005112 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005113 }
5114
5115 @Override
5116 public boolean switchSlots(int[] physicalSlots) {
5117 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118
5119 final long identity = Binder.clearCallingIdentity();
5120 try {
5121 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5122 } finally {
5123 Binder.restoreCallingIdentity(identity);
5124 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005125 }
Jack Yu4c988042018-02-27 15:30:01 -08005126
5127 @Override
5128 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5129 enforceModifyPermission();
5130 final Phone phone = getPhone(subId);
5131 if (phone == null) {
5132 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5133 return;
5134 }
5135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136 final long identity = Binder.clearCallingIdentity();
5137 try {
5138 phone.setRadioIndicationUpdateMode(filters, mode);
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
Jack Yu4c988042018-02-27 15:30:01 -08005142 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005143
5144 /**
goneil47ffb6e2018-04-06 15:40:58 -07005145 * A test API to reload the UICC profile.
5146 *
5147 * <p>Requires that the calling app has permission
5148 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5149 * @hide
5150 */
5151 @Override
5152 public void refreshUiccProfile(int subId) {
5153 enforceModifyPermission();
5154
5155 final long identity = Binder.clearCallingIdentity();
5156 try {
5157 Phone phone = getPhone(subId);
5158 if (phone == null) {
5159 return;
5160 }
5161 UiccCard uiccCard = phone.getUiccCard();
5162 if (uiccCard == null) {
5163 return;
5164 }
5165 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5166 if (uiccProfile == null) {
5167 return;
5168 }
5169 uiccProfile.refresh();
5170 } finally {
5171 Binder.restoreCallingIdentity(identity);
5172 }
5173 }
5174
5175 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005176 * Returns false if the mobile data is disabled by default, otherwise return true.
5177 */
5178 private boolean getDefaultDataEnabled() {
5179 return "true".equalsIgnoreCase(
5180 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5181 }
5182
5183 /**
5184 * Returns true if the data roaming is enabled by default, i.e the system property
5185 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5186 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5187 */
5188 private boolean getDefaultDataRoamingEnabled(int subId) {
5189 final CarrierConfigManager configMgr = (CarrierConfigManager)
5190 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5191 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5192 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5193 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5194 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5195 return isDataRoamingEnabled;
5196 }
5197
5198 /**
5199 * Returns the default network type for the given {@code subId}, if the default network type is
5200 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5201 */
5202 private int getDefaultNetworkType(int subId) {
5203 return Integer.parseInt(
5204 TelephonyManager.getTelephonyProperty(
5205 mSubscriptionController.getPhoneId(subId),
5206 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5207 String.valueOf(Phone.PREFERRED_NT_MODE)));
5208 }
fionaxua13278b2018-03-21 00:08:13 -07005209
5210 @Override
5211 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5212 gid1, String gid2, String plmn, String spn) {
5213 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214
5215 final long identity = Binder.clearCallingIdentity();
5216 try {
5217 final Phone phone = getPhone(subId);
5218 if (phone == null) {
5219 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5220 return;
5221 }
5222 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005225 }
fionaxua13278b2018-03-21 00:08:13 -07005226 }
5227
5228 @Override
5229 public int getCarrierIdListVersion(int subId) {
5230 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231
5232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 final Phone phone = getPhone(subId);
5235 if (phone == null) {
5236 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5237 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5238 }
5239 return phone.getCarrierIdListVersion();
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005242 }
fionaxua13278b2018-03-21 00:08:13 -07005243 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005244
5245 @Override
5246 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5248 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5249 return -1;
5250 }
5251
5252 final long identity = Binder.clearCallingIdentity();
5253 try {
5254 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5255 } finally {
5256 Binder.restoreCallingIdentity(identity);
5257 }
5258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005259}