blob: cbad440b42edab1a1db860f64640a64da81e675a [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 Harold54a07f92018-08-09 16:20:42 -07001930 if (targetSdk > android.os.Build.VERSION_CODES.P) return null;
Nathan Haroldb4d55612018-07-20 13:13:08 -07001931
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1933 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1934 return null;
1935 }
Svetoslav64fad262015-04-14 14:35:21 -07001936
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001937 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938
Nathan Haroldf180aac2018-06-01 18:43:55 -07001939 List<CellInfo> info = getAllCellInfo(callingPackage);
1940 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941
Nathan Haroldf180aac2018-06-01 18:43:55 -07001942 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1943 for (CellInfo ci : info) {
1944 if (ci instanceof CellInfoGsm) {
1945 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1946 } else if (ci instanceof CellInfoWcdma) {
1947 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001950 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 }
1952
1953
1954 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001955 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001956 mPhone.getContext().getSystemService(AppOpsManager.class)
1957 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001958 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001959 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001960 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 }
1962
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001963 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001964 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001965 final long identity = Binder.clearCallingIdentity();
1966 try {
1967 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1968 for (Phone phone : PhoneFactory.getPhones()) {
1969 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1970 if (info != null) cellInfos.addAll(info);
1971 }
1972 return cellInfos;
1973 } finally {
1974 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 }
1976 }
1977
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001978 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001980 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001981 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001982
1983 final long identity = Binder.clearCallingIdentity();
1984 try {
1985 mPhone.setCellInfoListRate(rateInMillis, workSource);
1986 } finally {
1987 Binder.restoreCallingIdentity(identity);
1988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
Shishir Agrawala9f32182016-04-12 12:00:16 -07001991 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001992 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001993 Phone phone = PhoneFactory.getPhone(slotIndex);
1994 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001995 return null;
1996 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001997 int subId = phone.getSubId();
1998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1999 mApp, subId, callingPackage, "getImeiForSlot")) {
2000 return null;
2001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002002
2003 final long identity = Binder.clearCallingIdentity();
2004 try {
2005 return phone.getImei();
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
2008 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002009 }
2010
2011 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002012 public String getTypeAllocationCodeForSlot(int slotIndex) {
2013 Phone phone = PhoneFactory.getPhone(slotIndex);
2014 String tac = null;
2015 if (phone != null) {
2016 String imei = phone.getImei();
2017 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2018 }
2019 return tac;
2020 }
2021
2022 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002023 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002024 Phone phone = PhoneFactory.getPhone(slotIndex);
2025 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002026 return null;
2027 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002028 int subId = phone.getSubId();
2029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2030 mApp, subId, callingPackage, "getMeidForSlot")) {
2031 return null;
2032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002033
2034 final long identity = Binder.clearCallingIdentity();
2035 try {
2036 return phone.getMeid();
2037 } finally {
2038 Binder.restoreCallingIdentity(identity);
2039 }
Jack Yu2af8d712017-03-15 17:14:14 -07002040 }
2041
2042 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002043 public String getManufacturerCodeForSlot(int slotIndex) {
2044 Phone phone = PhoneFactory.getPhone(slotIndex);
2045 String manufacturerCode = null;
2046 if (phone != null) {
2047 String meid = phone.getMeid();
2048 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2049 }
2050 return manufacturerCode;
2051 }
2052
2053 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002054 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002055 Phone phone = PhoneFactory.getPhone(slotIndex);
2056 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002057 return null;
2058 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002059 int subId = phone.getSubId();
2060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2061 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2062 return null;
2063 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002064
2065 final long identity = Binder.clearCallingIdentity();
2066 try {
2067 return phone.getDeviceSvn();
2068 } finally {
2069 Binder.restoreCallingIdentity(identity);
2070 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002071 }
2072
fionaxu43304da2017-11-27 22:51:16 -08002073 @Override
2074 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 final Phone phone = getPhone(subId);
2078 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2079 } finally {
2080 Binder.restoreCallingIdentity(identity);
2081 }
fionaxu43304da2017-11-27 22:51:16 -08002082 }
2083
2084 @Override
2085 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086 final long identity = Binder.clearCallingIdentity();
2087 try {
2088 final Phone phone = getPhone(subId);
2089 return phone == null ? null : phone.getCarrierName();
2090 } finally {
2091 Binder.restoreCallingIdentity(identity);
2092 }
fionaxu43304da2017-11-27 22:51:16 -08002093 }
2094
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 //
2096 // Internal helper methods.
2097 //
2098
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002099 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2101 *
2102 * @throws SecurityException if the caller does not have the required permission
2103 */
2104 private void enforceModifyPermission() {
2105 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2106 }
2107
2108 /**
2109 * Make sure the caller has the CALL_PHONE permission.
2110 *
2111 * @throws SecurityException if the caller does not have the required permission
2112 */
2113 private void enforceCallPermission() {
2114 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2115 }
2116
Stuart Scott8eef64f2015-04-08 15:13:54 -07002117 private void enforceConnectivityInternalPermission() {
2118 mApp.enforceCallingOrSelfPermission(
2119 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2120 "ConnectivityService");
2121 }
2122
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123 private String createTelUrl(String number) {
2124 if (TextUtils.isEmpty(number)) {
2125 return null;
2126 }
2127
Jake Hambye994d462014-02-03 13:10:13 -08002128 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
2130
Ihab Awadf9e92732013-12-05 18:02:52 -08002131 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2133 }
2134
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002135 private static void logv(String msg) {
2136 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2137 }
2138
Ihab Awadf9e92732013-12-05 18:02:52 -08002139 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2141 }
2142
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002143 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002145 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002146 }
2147
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002149 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002150 final long identity = Binder.clearCallingIdentity();
2151 try {
2152 final Phone phone = PhoneFactory.getPhone(slotIndex);
2153 if (phone == null) {
2154 return PhoneConstants.PHONE_TYPE_NONE;
2155 } else {
2156 return phone.getPhoneType();
2157 }
2158 } finally {
2159 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 }
2162
2163 /**
2164 * Returns the CDMA ERI icon index to display
2165 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002166 @Override
2167 public int getCdmaEriIconIndex(String callingPackage) {
2168 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002169 }
2170
Sanket Padawe356d7632015-06-22 14:03:32 -07002171 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002172 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002174 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002175 return -1;
2176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002177
2178 final long identity = Binder.clearCallingIdentity();
2179 try {
2180 final Phone phone = getPhone(subId);
2181 if (phone != null) {
2182 return phone.getCdmaEriIconIndex();
2183 } else {
2184 return -1;
2185 }
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 }
2190
2191 /**
2192 * Returns the CDMA ERI icon mode,
2193 * 0 - ON
2194 * 1 - FLASHING
2195 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002196 @Override
2197 public int getCdmaEriIconMode(String callingPackage) {
2198 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002199 }
2200
Sanket Padawe356d7632015-06-22 14:03:32 -07002201 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002202 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002203 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002204 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002205 return -1;
2206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207
2208 final long identity = Binder.clearCallingIdentity();
2209 try {
2210 final Phone phone = getPhone(subId);
2211 if (phone != null) {
2212 return phone.getCdmaEriIconMode();
2213 } else {
2214 return -1;
2215 }
2216 } finally {
2217 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220
2221 /**
2222 * Returns the CDMA ERI text,
2223 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002224 @Override
2225 public String getCdmaEriText(String callingPackage) {
2226 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002227 }
2228
Sanket Padawe356d7632015-06-22 14:03:32 -07002229 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002232 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 return null;
2234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235
2236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 final Phone phone = getPhone(subId);
2239 if (phone != null) {
2240 return phone.getCdmaEriText();
2241 } else {
2242 return null;
2243 }
2244 } finally {
2245 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 }
2248
2249 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002250 * Returns the CDMA MDN.
2251 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002253 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2255 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002256
2257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 final Phone phone = getPhone(subId);
2260 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2261 return phone.getLine1Number();
2262 } else {
2263 return null;
2264 }
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002267 }
2268 }
2269
2270 /**
2271 * Returns the CDMA MIN.
2272 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002273 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002274 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2276 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277
2278 final long identity = Binder.clearCallingIdentity();
2279 try {
2280 final Phone phone = getPhone(subId);
2281 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2282 return phone.getCdmaMin();
2283 } else {
2284 return null;
2285 }
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002288 }
2289 }
2290
2291 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 * Returns true if CDMA provisioning needs to run.
2293 */
2294 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 final long identity = Binder.clearCallingIdentity();
2296 try {
2297 return mPhone.needsOtaServiceProvisioning();
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
2300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002304 * Sets the voice mail number of a given subId.
2305 */
2306 @Override
2307 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002308 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002309
2310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2313 new Pair<String, String>(alphaTag, number), new Integer(subId));
2314 return success;
2315 } finally {
2316 Binder.restoreCallingIdentity(identity);
2317 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002318 }
2319
Ta-wei Yen87c49842016-05-13 21:19:52 -07002320 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002321 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2322 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2323 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2324 if (!TextUtils.equals(callingPackage, systemDialer)) {
2325 throw new SecurityException("caller must be system dialer");
2326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2331 if (phoneAccountHandle == null) {
2332 return null;
2333 }
2334 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2335 } finally {
2336 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002337 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002338 }
2339
2340 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002341 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002342 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002344 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002345 return null;
2346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 return RemoteVvmTaskManager
2351 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2352 } finally {
2353 Binder.restoreCallingIdentity(identity);
2354 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002355 }
2356
2357 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002358 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2359 VisualVoicemailSmsFilterSettings settings) {
2360 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002361
2362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2365 mPhone.getContext(), callingPackage, subId, settings);
2366 } finally {
2367 Binder.restoreCallingIdentity(identity);
2368 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002369 }
2370
2371 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002372 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002374
2375 final long identity = Binder.clearCallingIdentity();
2376 try {
2377 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2378 mPhone.getContext(), callingPackage, subId);
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
2381 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002382 }
2383
2384 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002385 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2386 String callingPackage, int subId) {
2387 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2392 mPhone.getContext(), callingPackage, subId);
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
2395 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002396 }
2397
2398 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002399 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002400 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002401
2402 final long identity = Binder.clearCallingIdentity();
2403 try {
2404 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2405 mPhone.getContext(), subId);
2406 } finally {
2407 Binder.restoreCallingIdentity(identity);
2408 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002409 }
2410
2411 @Override
2412 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2413 String number, int port, String text, PendingIntent sentIntent) {
2414 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002415 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002416 enforceSendSmsPermission();
2417 // Make the calls as the phone process.
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2421 if (port == 0) {
2422 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2423 sentIntent, null, false);
2424 } else {
2425 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2426 smsManager.sendDataMessageWithSelfPermissions(number, null,
2427 (short) port, data, sentIntent, null);
2428 }
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
2431 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002432 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002433 /**
fionaxu0152e512016-11-14 13:36:14 -08002434 * Sets the voice activation state of a given subId.
2435 */
2436 @Override
2437 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2439 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
2443 final Phone phone = getPhone(subId);
2444 if (phone != null) {
2445 phone.setVoiceActivationState(activationState);
2446 } else {
2447 loge("setVoiceActivationState fails with invalid subId: " + subId);
2448 }
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002451 }
2452 }
2453
2454 /**
2455 * Sets the data activation state of a given subId.
2456 */
2457 @Override
2458 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2460 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461
2462 final long identity = Binder.clearCallingIdentity();
2463 try {
2464 final Phone phone = getPhone(subId);
2465 if (phone != null) {
2466 phone.setDataActivationState(activationState);
2467 } else {
2468 loge("setVoiceActivationState fails with invalid subId: " + subId);
2469 }
2470 } finally {
2471 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002472 }
2473 }
2474
2475 /**
2476 * Returns the voice activation state of a given subId.
2477 */
2478 @Override
2479 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002480 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481
fionaxu0152e512016-11-14 13:36:14 -08002482 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 final long identity = Binder.clearCallingIdentity();
2484 try {
2485 if (phone != null) {
2486 return phone.getVoiceActivationState();
2487 } else {
2488 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2489 }
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002492 }
2493 }
2494
2495 /**
2496 * Returns the data activation state of a given subId.
2497 */
2498 @Override
2499 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002500 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501
fionaxu0152e512016-11-14 13:36:14 -08002502 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 if (phone != null) {
2506 return phone.getDataActivationState();
2507 } else {
2508 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2509 }
2510 } finally {
2511 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002512 }
2513 }
2514
2515 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 * Returns the unread count of voicemails
2517 */
2518 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002519 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002520 }
2521
2522 /**
2523 * Returns the unread count of voicemails for a subId
2524 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002526 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 final Phone phone = getPhone(subId);
2530 if (phone != null) {
2531 return phone.getVoiceMessageCount();
2532 } else {
2533 return 0;
2534 }
2535 } finally {
2536 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 }
2539
2540 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002541 * returns true, if the device is in a state where both voice and data
2542 * are supported simultaneously. This can change based on location or network condition.
2543 */
2544 @Override
2545 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 final Phone phone = getPhone(subId);
2549 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
2552 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002553 }
2554
2555 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002556 * Send the dialer code if called from the current default dialer or the caller has
2557 * carrier privilege.
2558 * @param inputCode The dialer code to send
2559 */
2560 @Override
2561 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2562 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2563 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2564 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002565 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2566 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002567 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 mPhone.sendDialerSpecialCode(inputCode);
2572 } finally {
2573 Binder.restoreCallingIdentity(identity);
2574 }
fionaxu235cc5e2017-03-06 22:25:57 -08002575 }
2576
2577 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002578 * Returns the data network type.
2579 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 *
2581 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2582 */
2583 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002584 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 final Phone phone = getPhone(getDefaultSubscription());
2588 if (phone != null) {
2589 return phone.getServiceState().getDataNetworkType();
2590 } else {
2591 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2592 }
2593 } finally {
2594 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002595 }
Wink Saville36469e72014-06-11 15:17:00 -07002596 }
2597
2598 /**
2599 * Returns the network type for a subId
2600 */
2601 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002602 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002604 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002605 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2606 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 final Phone phone = getPhone(subId);
2611 if (phone != null) {
2612 return phone.getServiceState().getDataNetworkType();
2613 } else {
2614 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 }
2620
2621 /**
2622 * Returns the data network type
2623 */
2624 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002625 public int getDataNetworkType(String callingPackage) {
2626 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002627 }
2628
2629 /**
2630 * Returns the data network type for a subId
2631 */
2632 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002633 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002635 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002636 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2637 }
2638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 final Phone phone = getPhone(subId);
2642 if (phone != null) {
2643 return phone.getServiceState().getDataNetworkType();
2644 } else {
2645 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2646 }
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 }
2651
2652 /**
Wink Saville36469e72014-06-11 15:17:00 -07002653 * Returns the Voice network type for a subId
2654 */
2655 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002656 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002658 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002659 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2660 }
2661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 if (phone != null) {
2666 return phone.getServiceState().getVoiceNetworkType();
2667 } else {
2668 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 }
2674
2675 /**
2676 * @return true if a ICC card is present
2677 */
2678 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002679 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002680 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2681 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002682 }
2683
2684 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002685 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002686 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002687 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002688 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 final Phone phone = PhoneFactory.getPhone(slotIndex);
2692 if (phone != null) {
2693 return phone.getIccCard().hasIccCard();
2694 } else {
2695 return false;
2696 }
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 }
2701
2702 /**
2703 * Return if the current radio is LTE on CDMA. This
2704 * is a tri-state return value as for a period of time
2705 * the mode may be unknown.
2706 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002707 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002709 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002711 @Override
2712 public int getLteOnCdmaMode(String callingPackage) {
2713 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002714 }
2715
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002717 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002719 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002720 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2721 }
2722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 final Phone phone = getPhone(subId);
2726 if (phone == null) {
2727 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2728 } else {
2729 return phone.getLteOnCdmaMode();
2730 }
2731 } finally {
2732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002733 }
Wink Saville36469e72014-06-11 15:17:00 -07002734 }
2735
2736 public void setPhone(Phone phone) {
2737 mPhone = phone;
2738 }
2739
2740 /**
2741 * {@hide}
2742 * Returns Default subId, 0 in the case of single standby.
2743 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002744 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002745 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002746 }
2747
Shishir Agrawala9f32182016-04-12 12:00:16 -07002748 private int getSlotForDefaultSubscription() {
2749 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2750 }
2751
Wink Savilleb564aae2014-10-23 10:18:09 -07002752 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002753 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002755
2756 /**
2757 * @see android.telephony.TelephonyManager.WifiCallingChoices
2758 */
2759 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2763 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2764 getWhenToMakeWifiCallsDefaultPreference());
2765 } finally {
2766 Binder.restoreCallingIdentity(identity);
2767 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002768 }
2769
2770 /**
2771 * @see android.telephony.TelephonyManager.WifiCallingChoices
2772 */
2773 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 final long identity = Binder.clearCallingIdentity();
2775 try {
2776 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2777 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2778 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
2781 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002782 }
2783
Sailesh Nepald1e68152013-12-12 19:08:02 -08002784 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002785 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002786 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002787 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002788
Shishir Agrawal566b7612013-10-28 14:41:00 -07002789 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002790 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2791 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2793 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796 final long identity = Binder.clearCallingIdentity();
2797 try {
2798 if (TextUtils.equals(ISDR_AID, aid)) {
2799 // Only allows LPA to open logical channel to ISD-R.
2800 ComponentInfo bestComponent =
2801 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2802 if (bestComponent == null
2803 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2804 loge("The calling package is not allowed to access ISD-R.");
2805 throw new SecurityException(
2806 "The calling package is not allowed to access ISD-R.");
2807 }
Derek Tan740e1672017-06-27 14:56:27 -07002808 }
Derek Tan740e1672017-06-27 14:56:27 -07002809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 if (DBG) {
2811 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2812 }
2813 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2814 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2815 if (DBG) log("iccOpenLogicalChannel: " + response);
2816 return response;
2817 } finally {
2818 Binder.restoreCallingIdentity(identity);
2819 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002820 }
2821
2822 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002823 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2825 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2830 if (channel < 0) {
2831 return false;
2832 }
2833 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2834 if (DBG) log("iccCloseLogicalChannel: " + success);
2835 return success;
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002838 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002839 }
2840
2841 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002842 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002843 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2845 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 if (DBG) {
2850 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2851 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2852 + p3 + " data=" + data);
2853 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 if (channel < 0) {
2856 return "";
2857 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2860 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2861 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863 // Append the returned status code to the end of the response payload.
2864 String s = Integer.toHexString(
2865 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2866 if (response.payload != null) {
2867 s = IccUtils.bytesToHexString(response.payload) + s;
2868 }
2869 return s;
2870 } finally {
2871 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002872 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002873 }
Jake Hambye994d462014-02-03 13:10:13 -08002874
Evan Charltonc66da362014-05-16 14:06:40 -07002875 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002876 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2877 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2879 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2885 && TextUtils.equals(ISDR_AID, data)) {
2886 // Only allows LPA to select ISD-R.
2887 ComponentInfo bestComponent =
2888 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2889 if (bestComponent == null
2890 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2891 loge("The calling package is not allowed to select ISD-R.");
2892 throw new SecurityException(
2893 "The calling package is not allowed to select ISD-R.");
2894 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002895 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897 if (DBG) {
2898 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2899 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2900 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2903 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2904 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 // Append the returned status code to the end of the response payload.
2907 String s = Integer.toHexString(
2908 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2909 if (response.payload != null) {
2910 s = IccUtils.bytesToHexString(response.payload) + s;
2911 }
2912 return s;
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002915 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002916 }
2917
2918 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002919 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002920 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2922 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 final long identity = Binder.clearCallingIdentity();
2925 try {
2926 if (DBG) {
2927 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2928 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2929 }
2930
2931 IccIoResult response =
2932 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2933 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2934 subId);
2935
2936 if (DBG) {
2937 log("Exchange SIM_IO [R]" + response);
2938 }
2939
2940 byte[] result = null;
2941 int length = 2;
2942 if (response.payload != null) {
2943 length = 2 + response.payload.length;
2944 result = new byte[length];
2945 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2946 } else {
2947 result = new byte[length];
2948 }
2949
2950 result[length - 1] = (byte) response.sw2;
2951 result[length - 2] = (byte) response.sw1;
2952 return result;
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002955 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002956 }
2957
Nathan Haroldb3014052017-01-25 15:57:32 -08002958 /**
2959 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2960 * on a particular subscription
2961 */
sqianb6e41952018-03-12 14:54:01 -07002962 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2963 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2964 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2965 return null;
2966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002967
2968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 if (appType != TelephonyManager.APPTYPE_USIM
2971 && appType != TelephonyManager.APPTYPE_SIM) {
2972 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2973 return null;
2974 }
2975 Object response = sendRequest(
2976 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2977 if (response instanceof String[]) {
2978 return (String[]) response;
2979 }
2980 // Response is an Exception of some kind,
2981 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08002982 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002985 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002986 }
2987
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002988 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002989 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2991 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993 final long identity = Binder.clearCallingIdentity();
2994 try {
2995 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2996 if (response.payload == null) {
2997 return "";
2998 }
Evan Charltonc66da362014-05-16 14:06:40 -07002999
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 // Append the returned status code to the end of the response payload.
3001 String s = Integer.toHexString(
3002 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3003 s = IccUtils.bytesToHexString(response.payload) + s;
3004 return s;
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Evan Charltonc66da362014-05-16 14:06:40 -07003008 }
3009
Jake Hambye994d462014-02-03 13:10:13 -08003010 /**
3011 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3012 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3013 *
3014 * @param itemID the ID of the item to read
3015 * @return the NV item as a String, or null on error.
3016 */
3017 @Override
3018 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3020 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 if (DBG) log("nvReadItem: item " + itemID);
3025 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3026 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3027 return value;
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
3030 }
Jake Hambye994d462014-02-03 13:10:13 -08003031 }
3032
3033 /**
3034 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3035 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3036 *
3037 * @param itemID the ID of the item to read
3038 * @param itemValue the value to write, as a String
3039 * @return true on success; false on any failure
3040 */
3041 @Override
3042 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3044 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3049 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3050 new Pair<Integer, String>(itemID, itemValue));
3051 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3052 return success;
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
Jake Hambye994d462014-02-03 13:10:13 -08003056 }
3057
3058 /**
3059 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3060 * Used for device configuration by some CDMA operators.
3061 *
3062 * @param preferredRoamingList byte array containing the new PRL
3063 * @return true on success; false on any failure
3064 */
3065 @Override
3066 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3068 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3073 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3074 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3075 return success;
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
Jake Hambye994d462014-02-03 13:10:13 -08003079 }
3080
3081 /**
3082 * Perform the specified type of NV config reset.
3083 * Used for device configuration by some CDMA operators.
3084 *
3085 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3086 * @return true on success; false on any failure
3087 */
3088 @Override
3089 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3091 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092
3093 final long identity = Binder.clearCallingIdentity();
3094 try {
3095 if (DBG) log("nvResetConfig: type " + resetType);
3096 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3097 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3098 return success;
3099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
Jake Hambye994d462014-02-03 13:10:13 -08003102 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003103
Svet Ganovb320e182015-04-16 12:30:10 -07003104 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003106 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003107 return new String[0];
3108 }
3109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 return mPhone.getPcscfAddress(apnType);
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
3115 }
Wink Saville36469e72014-06-11 15:17:00 -07003116 }
3117
Brad Ebinger51f743a2017-01-23 13:50:20 -08003118 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003119 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3120 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003121 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003122 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003123 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 PhoneFactory.getImsResolver().enableIms(slotId);
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003131 }
3132
3133 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003134 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3135 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003136 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003137 public void disableIms(int slotId) {
3138 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139
3140 final long identity = Binder.clearCallingIdentity();
3141 try {
3142 PhoneFactory.getImsResolver().disableIms(slotId);
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003146 }
3147
3148 /**
3149 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3150 * feature or {@link null} if the service is not available. If the feature is available, the
3151 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3152 */
3153 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003154 IImsServiceFeatureCallback callback) {
3155 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156
3157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
3162 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003163 }
3164
3165 /**
3166 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3167 * feature during emergency calling or {@link null} if the service is not available. If the
3168 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3169 * listener for feature updates.
3170 */
3171 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3172 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173
3174 final long identity = Binder.clearCallingIdentity();
3175 try {
3176 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3177 } finally {
3178 Binder.restoreCallingIdentity(identity);
3179 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003180 }
3181
Brad Ebinger5f64b052017-12-14 14:26:15 -08003182 /**
3183 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3184 * specified.
3185 */
3186 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3187 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188
3189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003195 }
3196
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003197 /**
3198 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3199 * specified.
3200 */
3201 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3202 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203
3204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003210 }
3211
Brad Ebinger884c07b2018-02-15 16:17:40 -08003212 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07003213 * Sets the ImsService Package Name that Telephony will bind to.
3214 *
3215 * @param slotId the slot ID that the ImsService should bind for.
3216 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3217 * ImsService is the device default ImsService.
3218 * @param packageName The package name of the application that contains the ImsService to bind
3219 * to.
3220 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3221 * @hide
3222 */
3223 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003224 int[] subIds = SubscriptionManager.getSubId(slotId);
3225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3226 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3227 "setImsService");
3228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3232 isCarrierImsService, packageName);
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003236 }
3237
3238 /**
3239 * Return the ImsService configuration.
3240 *
3241 * @param slotId The slot that the ImsService is associated with.
3242 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3243 * the device default.
3244 * @return the package name of the ImsService configuration.
3245 */
3246 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003247 int[] subIds = SubscriptionManager.getSubId(slotId);
3248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3249 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3250 "getImsService");
3251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3255 isCarrierImsService);
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003259 }
3260
Wink Saville36469e72014-06-11 15:17:00 -07003261 public void setImsRegistrationState(boolean registered) {
3262 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263
3264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 mPhone.setImsRegistrationState(registered);
3267 } finally {
3268 Binder.restoreCallingIdentity(identity);
3269 }
Wink Saville36469e72014-06-11 15:17:00 -07003270 }
3271
3272 /**
Stuart Scott54788802015-03-30 13:18:01 -07003273 * Set the network selection mode to automatic.
3274 *
3275 */
3276 @Override
3277 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3279 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
3281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3284 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
Stuart Scott54788802015-03-30 13:18:01 -07003288 }
3289
3290 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003291 * Set the network selection mode to manual with the selected carrier.
3292 */
3293 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003294 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003295 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3297 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003298
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003302 /* operatorAlphaLong */ "",
3303 /* operatorAlphaShort */ "",
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304 operatorNumeric);
3305 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3306 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3307 persistSelection);
3308 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003312 }
3313
3314 /**
3315 * Scans for available networks.
3316 */
3317 @Override
3318 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3320 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003321
3322 final long identity = Binder.clearCallingIdentity();
3323 try {
3324 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3325 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3326 CMD_PERFORM_NETWORK_SCAN, null, subId);
3327 return result;
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
3330 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003331 }
3332
3333 /**
yinxub1bed742017-04-17 11:45:04 -07003334 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003335 *
yinxub1bed742017-04-17 11:45:04 -07003336 * @param subId id of the subscription
3337 * @param request contains the radio access networks with bands/channels to scan
3338 * @param messenger callback messenger for scan results or errors
3339 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003340 * @return the id of the requested scan which can be used to stop the scan.
3341 */
3342 @Override
3343 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3344 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3346 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 return mNetworkScanRequestTracker.startNetworkScan(
3351 request, messenger, binder, getPhone(subId));
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
yinxu504e1392017-04-12 16:03:22 -07003355 }
3356
3357 /**
3358 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003359 *
3360 * @param subId id of the subscription
3361 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003362 */
3363 @Override
3364 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3366 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367
3368 final long identity = Binder.clearCallingIdentity();
3369 try {
3370 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
3373 }
yinxu504e1392017-04-12 16:03:22 -07003374 }
3375
3376 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003377 * Get the calculated preferred network type.
3378 * Used for debugging incorrect network type.
3379 *
3380 * @return the preferred network type, defined in RILConstants.java.
3381 */
3382 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003383 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003385 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003386 return RILConstants.PREFERRED_NETWORK_MODE;
3387 }
3388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 // FIXME: need to get SubId from somewhere.
3392 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
Junda Liu84d15a22014-07-02 11:21:04 -07003396 }
3397
3398 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003399 * Get the preferred network type.
3400 * Used for device configuration by some CDMA operators.
3401 *
3402 * @return the preferred network type, defined in RILConstants.java.
3403 */
3404 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003405 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3407 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 if (DBG) log("getPreferredNetworkType");
3412 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3413 int networkType = (result != null ? result[0] : -1);
3414 if (DBG) log("getPreferredNetworkType: " + networkType);
3415 return networkType;
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
3418 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003419 }
3420
3421 /**
3422 * Set the preferred network type.
3423 * Used for device configuration by some CDMA operators.
3424 *
3425 * @param networkType the preferred network type, defined in RILConstants.java.
3426 * @return true on success; false on any failure.
3427 */
3428 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003429 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3431 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432
3433 final long identity = Binder.clearCallingIdentity();
3434 try {
3435 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3436 Boolean success = (Boolean) sendRequest(
3437 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3438 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3439 if (success) {
3440 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3441 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3442 }
3443 return success;
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003446 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003447 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003448
3449 /**
Junda Liu475951f2014-11-07 16:45:03 -08003450 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3451 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3452 * tethering.
3453 *
3454 * @return 0: Not required. 1: required. 2: Not set.
3455 * @hide
3456 */
3457 @Override
3458 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003459 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003460
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3464 Settings.Global.TETHER_DUN_REQUIRED, 2);
3465 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3466 // config_tether_apndata.
3467 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3468 dunRequired = 1;
3469 }
3470 return dunRequired;
3471 } finally {
3472 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003473 }
Junda Liu475951f2014-11-07 16:45:03 -08003474 }
3475
3476 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003477 * Set mobile data enabled
3478 * Used by the user through settings etc to turn on/off mobile data
3479 *
3480 * @param enable {@code true} turn turn data on, else {@code false}
3481 */
3482 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003483 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3485 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003486
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 int phoneId = mSubscriptionController.getPhoneId(subId);
3490 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3491 Phone phone = PhoneFactory.getPhone(phoneId);
3492 if (phone != null) {
3493 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3494 phone.setUserDataEnabled(enable);
3495 } else {
3496 loge("setUserDataEnabled: no phone for subId=" + subId);
3497 }
3498 } finally {
3499 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003500 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003501 }
3502
3503 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003504 * Get the user enabled state of Mobile Data.
3505 *
3506 * TODO: remove and use isUserDataEnabled.
3507 * This can't be removed now because some vendor codes
3508 * calls through ITelephony directly while they should
3509 * use TelephonyManager.
3510 *
3511 * @return true on enabled
3512 */
3513 @Override
3514 public boolean getDataEnabled(int subId) {
3515 return isUserDataEnabled(subId);
3516 }
3517
3518 /**
3519 * Get whether mobile data is enabled per user setting.
3520 *
3521 * There are other factors deciding whether mobile data is actually enabled, but they are
3522 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003523 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003524 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003525 *
3526 * @return {@code true} if data is enabled else {@code false}
3527 */
3528 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003529 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003530 try {
3531 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3532 null);
3533 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3535 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537
3538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 int phoneId = mSubscriptionController.getPhoneId(subId);
3541 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3542 Phone phone = PhoneFactory.getPhone(phoneId);
3543 if (phone != null) {
3544 boolean retVal = phone.isUserDataEnabled();
3545 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3546 return retVal;
3547 } else {
3548 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3549 return false;
3550 }
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003553 }
3554 }
3555
3556 /**
3557 * Get whether mobile data is enabled.
3558 *
3559 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3560 * whether mobile data is actually enabled.
3561 *
3562 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3563 *
3564 * @return {@code true} if data is enabled else {@code false}
3565 */
3566 @Override
3567 public boolean isDataEnabled(int subId) {
3568 try {
3569 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3570 null);
3571 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3573 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575
3576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 int phoneId = mSubscriptionController.getPhoneId(subId);
3579 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3580 Phone phone = PhoneFactory.getPhone(phoneId);
3581 if (phone != null) {
3582 boolean retVal = phone.isDataEnabled();
3583 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3584 return retVal;
3585 } else {
3586 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3587 return false;
3588 }
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003591 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003592 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003593
3594 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003595 public int getCarrierPrivilegeStatus(int subId) {
3596 final Phone phone = getPhone(subId);
3597 if (phone == null) {
3598 loge("getCarrierPrivilegeStatus: Invalid subId");
3599 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3600 }
3601 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003602 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003603 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003604 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3605 }
3606 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003607 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003608 }
Junda Liu29340342014-07-10 15:23:27 -07003609
3610 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003611 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3612 final Phone phone = getPhone(subId);
3613 if (phone == null) {
3614 loge("getCarrierPrivilegeStatus: Invalid subId");
3615 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3616 }
3617 UiccProfile profile =
3618 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3619 if (profile == null) {
3620 loge("getCarrierPrivilegeStatus: No UICC");
3621 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3622 }
3623 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3624 }
3625
3626 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003627 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003628 if (TextUtils.isEmpty(pkgName))
3629 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003630 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003631 if (card == null) {
3632 loge("checkCarrierPrivilegesForPackage: No UICC");
3633 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3634 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003635 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3636 }
3637
3638 @Override
3639 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003640 if (TextUtils.isEmpty(pkgName))
3641 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003642 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3643 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3644 UiccCard card = UiccController.getInstance().getUiccCard(i);
3645 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003646 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003647 continue;
3648 }
3649
3650 result = card.getCarrierPrivilegeStatus(
3651 mPhone.getContext().getPackageManager(), pkgName);
3652 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3653 break;
3654 }
3655 }
3656
3657 return result;
Junda Liu29340342014-07-10 15:23:27 -07003658 }
Derek Tan89e89d42014-07-08 17:00:10 -07003659
3660 @Override
Junda Liue64de782015-04-16 17:19:16 -07003661 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3662 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3663 loge("phoneId " + phoneId + " is not valid.");
3664 return null;
3665 }
3666 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003667 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003668 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003669 return null ;
3670 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003671 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003672 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003673 }
3674
Amith Yamasani6e118872016-02-19 12:53:51 -08003675 @Override
3676 public List<String> getPackagesWithCarrierPrivileges() {
3677 PackageManager pm = mPhone.getContext().getPackageManager();
3678 List<String> privilegedPackages = new ArrayList<>();
3679 List<PackageInfo> packages = null;
3680 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3681 UiccCard card = UiccController.getInstance().getUiccCard(i);
3682 if (card == null) {
3683 // No UICC in that slot.
3684 continue;
3685 }
3686 if (card.hasCarrierPrivilegeRules()) {
3687 if (packages == null) {
3688 // Only check packages in user 0 for now
3689 packages = pm.getInstalledPackagesAsUser(
3690 PackageManager.MATCH_DISABLED_COMPONENTS
3691 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3692 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3693 }
3694 for (int p = packages.size() - 1; p >= 0; p--) {
3695 PackageInfo pkgInfo = packages.get(p);
3696 if (pkgInfo != null && pkgInfo.packageName != null
3697 && card.getCarrierPrivilegeStatus(pkgInfo)
3698 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3699 privilegedPackages.add(pkgInfo.packageName);
3700 }
3701 }
3702 }
3703 }
3704 return privilegedPackages;
3705 }
3706
Wink Savilleb564aae2014-10-23 10:18:09 -07003707 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003708 final Phone phone = getPhone(subId);
3709 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003710 if (card == null) {
3711 loge("getIccId: No UICC");
3712 return null;
3713 }
3714 String iccId = card.getIccId();
3715 if (TextUtils.isEmpty(iccId)) {
3716 loge("getIccId: ICC ID is null or empty.");
3717 return null;
3718 }
3719 return iccId;
3720 }
3721
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003722 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003723 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3724 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003725 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3726 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728 final long identity = Binder.clearCallingIdentity();
3729 try {
3730 final String iccId = getIccId(subId);
3731 final Phone phone = getPhone(subId);
3732 if (phone == null) {
3733 return false;
3734 }
3735 final String subscriberId = phone.getSubscriberId();
3736
3737 if (DBG_MERGE) {
3738 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3739 + subscriberId + " to " + number);
3740 }
3741
3742 if (TextUtils.isEmpty(iccId)) {
3743 return false;
3744 }
3745
3746 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3747
3748 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3749 if (alphaTag == null) {
3750 editor.remove(alphaTagPrefKey);
3751 } else {
3752 editor.putString(alphaTagPrefKey, alphaTag);
3753 }
3754
3755 // Record both the line number and IMSI for this ICCID, since we need to
3756 // track all merged IMSIs based on line number
3757 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3758 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3759 if (number == null) {
3760 editor.remove(numberPrefKey);
3761 editor.remove(subscriberPrefKey);
3762 } else {
3763 editor.putString(numberPrefKey, number);
3764 editor.putString(subscriberPrefKey, subscriberId);
3765 }
3766
3767 editor.commit();
3768 return true;
3769 } finally {
3770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003771 }
Derek Tan7226c842014-07-02 17:42:23 -07003772 }
3773
3774 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003775 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003776 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003778 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003779 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003780 return null;
3781 }
Derek Tan97ebb422014-09-05 16:55:38 -07003782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783 final long identity = Binder.clearCallingIdentity();
3784 try {
3785 String iccId = getIccId(subId);
3786 if (iccId != null) {
3787 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3788 if (DBG_MERGE) {
3789 log("getLine1NumberForDisplay returning "
3790 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3791 }
3792 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3795 return null;
3796 } finally {
3797 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003798 }
Derek Tan7226c842014-07-02 17:42:23 -07003799 }
3800
3801 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003802 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003804 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003805 return null;
3806 }
Derek Tan97ebb422014-09-05 16:55:38 -07003807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808 final long identity = Binder.clearCallingIdentity();
3809 try {
3810 String iccId = getIccId(subId);
3811 if (iccId != null) {
3812 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3813 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3814 }
3815 return null;
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003818 }
Derek Tan7226c842014-07-02 17:42:23 -07003819 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003820
3821 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003822 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003823 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3824 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003826 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3827 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003828 return null;
3829 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003830
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003831 final long identity = Binder.clearCallingIdentity();
3832 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003833 final Context context = mPhone.getContext();
3834 final TelephonyManager tele = TelephonyManager.from(context);
3835 final SubscriptionManager sub = SubscriptionManager.from(context);
3836
3837 // Figure out what subscribers are currently active
3838 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3839 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3840 // the process, where TelephonyManager was instantiated.
3841 // Otherwise AppOps check will fail.
3842
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003843 final int[] subIds = sub.getActiveSubscriptionIdList();
3844 for (int subId : subIds) {
3845 activeSubscriberIds.add(tele.getSubscriberId(subId));
3846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847
3848 // First pass, find a number override for an active subscriber
3849 String mergeNumber = null;
3850 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3851 for (String key : prefs.keySet()) {
3852 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3853 final String subscriberId = (String) prefs.get(key);
3854 if (activeSubscriberIds.contains(subscriberId)) {
3855 final String iccId = key.substring(
3856 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3857 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3858 mergeNumber = (String) prefs.get(numberKey);
3859 if (DBG_MERGE) {
3860 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3861 + " for active subscriber " + subscriberId);
3862 }
3863 if (!TextUtils.isEmpty(mergeNumber)) {
3864 break;
3865 }
3866 }
3867 }
3868 }
3869
3870 // Shortcut when no active merged subscribers
3871 if (TextUtils.isEmpty(mergeNumber)) {
3872 return null;
3873 }
3874
3875 // Second pass, find all subscribers under that line override
3876 final ArraySet<String> result = new ArraySet<>();
3877 for (String key : prefs.keySet()) {
3878 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3879 final String number = (String) prefs.get(key);
3880 if (mergeNumber.equals(number)) {
3881 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3882 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3883 final String subscriberId = (String) prefs.get(subscriberKey);
3884 if (!TextUtils.isEmpty(subscriberId)) {
3885 result.add(subscriberId);
3886 }
3887 }
3888 }
3889 }
3890
3891 final String[] resultArray = result.toArray(new String[result.size()]);
3892 Arrays.sort(resultArray);
3893 if (DBG_MERGE) {
3894 Slog.d(LOG_TAG,
3895 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3896 }
3897 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003898 } finally {
3899 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003900 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003901 }
3902
3903 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003904 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003905 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3906 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003907
3908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 final Phone phone = getPhone(subId);
3911 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
3914 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003915 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003916
3917 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003918 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003919 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3920 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003921 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003922
3923 final long identity = Binder.clearCallingIdentity();
3924 try {
3925 final Phone phone = getPhone(subId);
3926 if (phone == null) {
3927 return false;
3928 }
3929 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3930 cdmaNonRoamingList);
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003933 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003934 }
3935
3936 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003937 @Deprecated
3938 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3939 enforceModifyPermission();
3940
3941 int returnValue = 0;
3942 try {
3943 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3944 if(result.exception == null) {
3945 if (result.result != null) {
3946 byte[] responseData = (byte[])(result.result);
3947 if(responseData.length > oemResp.length) {
3948 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3949 responseData.length + "bytes. Buffer Size is " +
3950 oemResp.length + "bytes.");
3951 }
3952 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3953 returnValue = responseData.length;
3954 }
3955 } else {
3956 CommandException ex = (CommandException) result.exception;
3957 returnValue = ex.getCommandError().ordinal();
3958 if(returnValue > 0) returnValue *= -1;
3959 }
3960 } catch (RuntimeException e) {
3961 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3962 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3963 if(returnValue > 0) returnValue *= -1;
3964 }
3965
3966 return returnValue;
3967 }
3968
3969 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003970 public void setRadioCapability(RadioAccessFamily[] rafs) {
3971 try {
3972 ProxyController.getInstance().setRadioCapability(rafs);
3973 } catch (RuntimeException e) {
3974 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3975 }
3976 }
3977
3978 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003979 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003980 Phone phone = PhoneFactory.getPhone(phoneId);
3981 if (phone == null) {
3982 return RadioAccessFamily.RAF_UNKNOWN;
3983 }
3984 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003986 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003987 return RadioAccessFamily.RAF_UNKNOWN;
3988 }
3989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3993 } finally {
3994 Binder.restoreCallingIdentity(identity);
3995 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003996 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003997
3998 @Override
3999 public void enableVideoCalling(boolean enable) {
4000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001
4002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004008 }
4009
4010 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004011 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4013 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4014 return false;
4015 }
Svet Ganovb320e182015-04-16 12:30:10 -07004016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 // Check the user preference and the system-level IMS setting. Even if the user has
4020 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4021 // In the long run, we may instead need to check if there exists a connection service
4022 // which can support video calling.
4023 ImsManager imsManager =
4024 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4025 return imsManager.isVtEnabledByPlatform()
4026 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4027 && imsManager.isVtEnabledByUser();
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004031 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004032
Andrew Leea1239f22015-03-02 17:44:07 -08004033 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004034 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4036 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4037 return false;
4038 }
4039
4040 final long identity = Binder.clearCallingIdentity();
4041 try {
4042 CarrierConfigManager configManager =
4043 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4044 return configManager.getConfigForSubId(mPhone.getSubId())
4045 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4046 } finally {
4047 Binder.restoreCallingIdentity(identity);
4048 }
Andrew Leea1239f22015-03-02 17:44:07 -08004049 }
4050
4051 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 public boolean isWorldPhone(int subId, String callingPackage) {
4053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4054 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4055 return false;
4056 }
4057
4058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 CarrierConfigManager configManager =
4061 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4062 return configManager.getConfigForSubId(mPhone.getSubId())
4063 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
4066 }
Andrew Leea1239f22015-03-02 17:44:07 -08004067 }
4068
Andrew Lee9431b832015-03-09 18:46:45 -07004069 @Override
4070 public boolean isTtyModeSupported() {
4071 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004072 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004073 }
4074
4075 @Override
4076 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
Andrew Lee9431b832015-03-09 18:46:45 -07004083 }
4084
Hall Liu98187582018-01-22 19:15:32 -08004085 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4089 mPhone.getSubId()).getBoolean(
4090 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4091 boolean isDeviceSupported =
4092 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4093 return isCarrierSupported && isDeviceSupported;
4094 } finally {
4095 Binder.restoreCallingIdentity(identity);
4096 }
Hall Liu98187582018-01-22 19:15:32 -08004097 }
4098
Hall Liu3ad5f012018-04-06 16:23:39 -07004099 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 return isRttSupported() && Settings.Secure.getInt(
4103 mPhone.getContext().getContentResolver(),
4104 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4105 } finally {
4106 Binder.restoreCallingIdentity(identity);
4107 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004108 }
4109
Sanket Padawe7310cc72015-01-14 09:53:20 -08004110 /**
4111 * Returns the unique device ID of phone, for example, the IMEI for
4112 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4113 *
4114 * <p>Requires Permission:
4115 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4116 */
4117 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004118 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004119 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004120 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004121 return null;
4122 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004123 int subId = phone.getSubId();
4124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4125 mApp, subId, callingPackage, "getDeviceId")) {
4126 return null;
4127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128
4129 final long identity = Binder.clearCallingIdentity();
4130 try {
4131 return phone.getDeviceId();
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004135 }
4136
Ping Sunc67b7c22016-03-02 19:16:45 +08004137 /**
4138 * {@hide}
4139 * Returns the IMS Registration Status on a particular subid
4140 *
4141 * @param subId
4142 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004143 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004144 Phone phone = getPhone(subId);
4145 if (phone != null) {
4146 return phone.isImsRegistered();
4147 } else {
4148 return false;
4149 }
4150 }
4151
Santos Cordon7a1885b2015-02-03 11:15:19 -08004152 @Override
4153 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004154 final long identity = Binder.clearCallingIdentity();
4155 try {
4156 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004160 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004161
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004162 /**
4163 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004164 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004165 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 Phone phone = getPhone(subId);
4169 if (phone != null) {
4170 return phone.isWifiCallingEnabled();
4171 } else {
4172 return false;
4173 }
4174 } finally {
4175 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004176 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004177 }
4178
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004179 /**
4180 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004181 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004182 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 final long identity = Binder.clearCallingIdentity();
4184 try {
4185 Phone phone = getPhone(subId);
4186 if (phone != null) {
4187 return phone.isVolteEnabled();
4188 } else {
4189 return false;
4190 }
4191 } finally {
4192 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004193 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004194 }
Svet Ganovb320e182015-04-16 12:30:10 -07004195
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004196 /**
4197 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004198 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004199 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 final long identity = Binder.clearCallingIdentity();
4201 try {
4202 Phone phone = getPhone(subId);
4203 if (phone != null) {
4204 return phone.isVideoEnabled();
4205 } else {
4206 return false;
4207 }
4208 } finally {
4209 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004210 }
4211 }
4212
4213 /**
4214 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4215 * defined in {@link ImsRegistrationImplBase}.
4216 */
4217 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 final long identity = Binder.clearCallingIdentity();
4219 try {
4220 Phone phone = getPhone(subId);
4221 if (phone != null) {
4222 return phone.getImsRegistrationTech();
4223 } else {
4224 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4225 }
4226 } finally {
4227 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004228 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004229 }
4230
Stuart Scott8eef64f2015-04-08 15:13:54 -07004231 @Override
4232 public void factoryReset(int subId) {
4233 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004234 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4235 return;
4236 }
4237
Svet Ganovcc087f82015-05-12 20:35:54 -07004238 final long identity = Binder.clearCallingIdentity();
4239 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004240 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4241 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004242 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004243 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004244 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4245 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004246 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004247 }
4248 } finally {
4249 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004250 }
4251 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004252
4253 @Override
4254 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255 final long identity = Binder.clearCallingIdentity();
4256 try {
4257 // We query all subscriptions instead of just the active ones, because
4258 // this might be called early on in the provisioning flow when the
4259 // subscriptions potentially aren't active yet.
4260 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4261 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004262 return null;
4263 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004265 // This function may be called very early, say, from the setup wizard, at
4266 // which point we won't have a default subscription set. If that's the case
4267 // we just choose the first, which will be valid in "most cases".
4268 final int defaultSubId = getDefaultSubscription();
4269 SubscriptionInfo info = null;
4270 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4271 info = slist.get(0);
4272 } else {
4273 for (SubscriptionInfo item : slist) {
4274 if (item.getSubscriptionId() == defaultSubId) {
4275 info = item;
4276 break;
4277 }
4278 }
4279
4280 if (info == null) {
4281 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004282 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004283 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004285 // Try and fetch the locale from the carrier properties or from the SIM language
4286 // preferences (EF-PL and EF-LI)...
4287 final int mcc = info.getMcc();
4288 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4289 String simLanguage = null;
4290 if (defaultPhone != null) {
4291 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4292 if (localeFromDefaultSim != null) {
4293 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4294 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4295 return localeFromDefaultSim.toLanguageTag();
4296 } else {
4297 simLanguage = localeFromDefaultSim.getLanguage();
4298 }
4299 }
4300 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004302 // The SIM language preferences only store a language (e.g. fr = French), not an
4303 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4304 // the SIM and carrier preferences does not include a country we add the country
4305 // determined from the SIM MCC to provide an exact locale.
4306 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4307 simLanguage);
4308 if (mccLocale != null) {
4309 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4310 return mccLocale.toLanguageTag();
4311 }
4312
4313 if (DBG) log("No locale found - returning null");
4314 return null;
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004318 }
4319
4320 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321 return mSubscriptionController.getAllSubInfoList(
4322 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004323 }
4324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004325 /**
4326 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4327 */
4328 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4329 return mSubscriptionController.getActiveSubscriptionInfoList(
4330 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004331 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004332
Chenjie Yu1ba97252018-01-11 18:16:20 -08004333 private final ModemActivityInfo mLastModemActivityInfo =
4334 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4335
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004336 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004337 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4338 * representing the state of the modem.
4339 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004340 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4341 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004342 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004343 */
4344 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004345 public void requestModemActivityInfo(ResultReceiver result) {
4346 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347
4348 final long identity = Binder.clearCallingIdentity();
4349 try {
4350 ModemActivityInfo ret = null;
4351 synchronized (mLastModemActivityInfo) {
4352 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4353 CMD_GET_MODEM_ACTIVITY_INFO,
4354 null);
Siddharth Rayb8114062018-06-17 15:02:38 -07004355 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004356 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4357 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4358 mergedTxTimeMs[i] =
4359 info.getTxTimeMillis()[i]
4360 + mLastModemActivityInfo.getTxTimeMillis()[i];
4361 }
4362 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4363 mLastModemActivityInfo.setSleepTimeMillis(
4364 info.getSleepTimeMillis()
4365 + mLastModemActivityInfo.getSleepTimeMillis());
4366 mLastModemActivityInfo.setIdleTimeMillis(
4367 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4368 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4369 mLastModemActivityInfo.setRxTimeMillis(
4370 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4371 mLastModemActivityInfo.setEnergyUsed(
4372 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4375 mLastModemActivityInfo.getSleepTimeMillis(),
4376 mLastModemActivityInfo.getIdleTimeMillis(),
4377 mLastModemActivityInfo.getTxTimeMillis(),
4378 mLastModemActivityInfo.getRxTimeMillis(),
4379 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381 Bundle bundle = new Bundle();
4382 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4383 result.send(0, bundle);
4384 } finally {
4385 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004386 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004387 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004388
Siddharth Rayb8114062018-06-17 15:02:38 -07004389 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
4390 // less than total activity duration.
4391 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
4392 if (info == null) {
4393 return false;
4394 }
4395 int activityDurationMs =
4396 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
4397 int totalTxTimeMs = 0;
4398 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
4399 totalTxTimeMs += info.getTxTimeMillis()[i];
4400 }
4401 return (info.isValid()
4402 && (info.getSleepTimeMillis() <= activityDurationMs)
4403 && (info.getIdleTimeMillis() <= activityDurationMs)
4404 && (info.getRxTimeMillis() <= activityDurationMs)
4405 && (totalTxTimeMs <= activityDurationMs));
4406 }
4407
Jack Yu85bd38a2015-11-09 11:34:32 -08004408 /**
4409 * {@hide}
4410 * Returns the service state information on specified subscription.
4411 */
4412 @Override
4413 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004415 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004416 return null;
4417 }
4418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 final Phone phone = getPhone(subId);
4422 if (phone == null) {
4423 return null;
4424 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 return phone.getServiceState();
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004430 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004431
4432 /**
4433 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4434 *
4435 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4436 * voicemail ringtone.
4437 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4438 * PhoneAccount.
4439 */
4440 @Override
4441 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 final long identity = Binder.clearCallingIdentity();
4443 try {
4444 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4445 if (phone == null) {
4446 phone = mPhone;
4447 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004453 }
4454
4455 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004456 * Sets the per-account voicemail ringtone.
4457 *
4458 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4459 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4460 *
4461 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4462 * voicemail ringtone.
4463 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4464 * PhoneAccount.
4465 */
4466 @Override
4467 public void setVoicemailRingtoneUri(String callingPackage,
4468 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4469 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4470 if (!TextUtils.equals(callingPackage,
4471 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4473 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4474 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476
4477 final long identity = Binder.clearCallingIdentity();
4478 try {
4479 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4480 if (phone == null) {
4481 phone = mPhone;
4482 }
4483 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4484 } finally {
4485 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004486 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004487 }
4488
4489 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004490 * Returns whether vibration is set for voicemail notification in Phone settings.
4491 *
4492 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4493 * voicemail vibration setting.
4494 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4495 */
4496 @Override
4497 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 final long identity = Binder.clearCallingIdentity();
4499 try {
4500 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4501 if (phone == null) {
4502 phone = mPhone;
4503 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004505 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004509 }
4510
Youhan Wange64578a2016-05-02 15:32:42 -07004511 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004512 * Sets the per-account voicemail vibration.
4513 *
4514 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4515 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4516 *
4517 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4518 * voicemail vibration setting.
4519 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4520 * specific PhoneAccount.
4521 */
4522 @Override
4523 public void setVoicemailVibrationEnabled(String callingPackage,
4524 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4525 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4526 if (!TextUtils.equals(callingPackage,
4527 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4529 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4530 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004531 }
4532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 final long identity = Binder.clearCallingIdentity();
4534 try {
4535 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4536 if (phone == null) {
4537 phone = mPhone;
4538 }
4539 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4540 } finally {
4541 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004542 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004543 }
4544
4545 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004546 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4547 *
4548 * @throws SecurityException if the caller does not have the required permission
4549 */
4550 private void enforceReadPrivilegedPermission() {
4551 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4552 null);
4553 }
4554
4555 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004556 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4557 * permission.
4558 *
4559 * @throws SecurityException if the caller does not have the required permission
4560 */
4561 private void enforceSendSmsPermission() {
4562 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4563 }
4564
4565 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004566 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004567 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004568 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004569 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004570 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 final long identity = Binder.clearCallingIdentity();
4572 try {
4573 ComponentName componentName =
4574 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4575 if (componentName == null) {
4576 throw new SecurityException(
4577 "Caller not current active visual voicemail package[null]");
4578 }
4579 String vvmPackage = componentName.getPackageName();
4580 if (!callingPackage.equals(vvmPackage)) {
4581 throw new SecurityException("Caller not current active visual voicemail package["
4582 + vvmPackage + "]");
4583 }
4584 } finally {
4585 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004586 }
4587 }
4588
4589 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004590 * Return the application ID for the app type.
4591 *
4592 * @param subId the subscription ID that this request applies to.
4593 * @param appType the uicc app type.
4594 * @return Application ID for specificied app type, or null if no uicc.
4595 */
4596 @Override
4597 public String getAidForAppType(int subId, int appType) {
4598 enforceReadPrivilegedPermission();
4599 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004600
4601 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004602 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603 if (phone == null) {
4604 return null;
4605 }
4606 String aid = null;
4607 try {
4608 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4609 .getApplicationByType(appType).getAid();
4610 } catch (Exception e) {
4611 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4612 }
4613 return aid;
4614 } finally {
4615 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004616 }
Youhan Wange64578a2016-05-02 15:32:42 -07004617 }
4618
Youhan Wang4001d252016-05-11 10:29:41 -07004619 /**
4620 * Return the Electronic Serial Number.
4621 *
4622 * @param subId the subscription ID that this request applies to.
4623 * @return ESN or null if error.
4624 */
4625 @Override
4626 public String getEsn(int subId) {
4627 enforceReadPrivilegedPermission();
4628 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629
4630 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004631 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 if (phone == null) {
4633 return null;
4634 }
4635 String esn = null;
4636 try {
4637 esn = phone.getEsn();
4638 } catch (Exception e) {
4639 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4640 }
4641 return esn;
4642 } finally {
4643 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004644 }
Youhan Wang4001d252016-05-11 10:29:41 -07004645 }
4646
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004647 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004648 * Return the Preferred Roaming List Version.
4649 *
4650 * @param subId the subscription ID that this request applies to.
4651 * @return PRLVersion or null if error.
4652 */
4653 @Override
4654 public String getCdmaPrlVersion(int subId) {
4655 enforceReadPrivilegedPermission();
4656 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004657
4658 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004659 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 if (phone == null) {
4661 return null;
4662 }
4663 String cdmaPrlVersion = null;
4664 try {
4665 cdmaPrlVersion = phone.getCdmaPrlVersion();
4666 } catch (Exception e) {
4667 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4668 }
4669 return cdmaPrlVersion;
4670 } finally {
4671 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004672 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004673 }
4674
4675 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004676 * Get snapshot of Telephony histograms
4677 * @return List of Telephony histograms
4678 * @hide
4679 */
4680 @Override
4681 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4683 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004684
4685 final long identity = Binder.clearCallingIdentity();
4686 try {
4687 return RIL.getTelephonyRILTimingHistograms();
4688 } finally {
4689 Binder.restoreCallingIdentity(identity);
4690 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004691 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004692
4693 /**
4694 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004695 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004696 * Require system privileges. In the future we may add this to carrier APIs.
4697 *
4698 * @return The number of carriers set successfully, should match length of carriers
4699 */
4700 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004701 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004702 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004703
Meng Wang9b7c4e92017-02-17 11:41:27 -08004704 if (carriers == null) {
4705 throw new NullPointerException("carriers cannot be null");
4706 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004708 final long identity = Binder.clearCallingIdentity();
4709 try {
4710 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4711 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4712 return retVal[0];
4713 } finally {
4714 Binder.restoreCallingIdentity(identity);
4715 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004716 }
4717
4718 /**
4719 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004720 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004721 * Require system privileges. In the future we may add this to carrier APIs.
4722 *
4723 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4724 * means all carriers are allowed.
4725 */
4726 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004727 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004728 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729
4730 final long identity = Binder.clearCallingIdentity();
4731 try {
4732 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4733 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004737 }
4738
fionaxu59545b42016-05-25 15:53:37 -07004739 /**
4740 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4741 * @param subId the subscription ID that this action applies to.
4742 * @param enabled control enable or disable metered apns.
4743 * {@hide}
4744 */
4745 @Override
4746 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4747 enforceModifyPermission();
4748 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749
4750 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004751 if (phone == null) {
4752 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4753 return;
4754 }
4755 try {
4756 phone.carrierActionSetMeteredApnsEnabled(enabled);
4757 } catch (Exception e) {
4758 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 } finally {
4760 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004761 }
4762 }
4763
4764 /**
4765 * Action set from carrier signalling broadcast receivers to enable/disable radio
4766 * @param subId the subscription ID that this action applies to.
4767 * @param enabled control enable or disable radio.
4768 * {@hide}
4769 */
4770 @Override
4771 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4772 enforceModifyPermission();
4773 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774
4775 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004776 if (phone == null) {
4777 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4778 return;
4779 }
4780 try {
4781 phone.carrierActionSetRadioEnabled(enabled);
4782 } catch (Exception e) {
4783 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 } finally {
4785 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004786 }
4787 }
4788
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004789 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004790 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4791 * network status based on which carrier apps could apply actions accordingly,
4792 * enable/disable default url handler for example.
4793 *
4794 * @param subId the subscription ID that this action applies to.
4795 * @param report control start/stop reporting the default network status.
4796 * {@hide}
4797 */
4798 @Override
4799 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4800 enforceModifyPermission();
4801 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004802
4803 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004804 if (phone == null) {
4805 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4806 return;
4807 }
4808 try {
4809 phone.carrierActionReportDefaultNetworkStatus(report);
4810 } catch (Exception e) {
4811 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812 } finally {
4813 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004814 }
4815 }
4816
4817 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004818 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4819 * bug report is being generated.
4820 */
4821 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004822 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004823 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4824 != PackageManager.PERMISSION_GRANTED) {
4825 writer.println("Permission Denial: can't dump Phone from pid="
4826 + Binder.getCallingPid()
4827 + ", uid=" + Binder.getCallingUid()
4828 + "without permission "
4829 + android.Manifest.permission.DUMP);
4830 return;
4831 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004832 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004833 }
Jack Yueb89b242016-06-22 13:27:47 -07004834
Brad Ebingerdac2f002018-04-03 15:17:52 -07004835 @Override
4836 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4837 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4838 throws RemoteException {
4839 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4840 }
4841
Jack Yueb89b242016-06-22 13:27:47 -07004842 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004843 * Get aggregated video call data usage since boot.
4844 *
4845 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4846 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004847 * {@hide}
4848 */
4849 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004850 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004851 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4852 null);
4853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 // NetworkStatsService keeps tracking the active network interface and identity. It
4857 // records the delta with the corresponding network identity.
4858 // We just return the total video call data usage snapshot since boot.
4859 Phone phone = getPhone(subId);
4860 if (phone != null) {
4861 return phone.getVtDataUsage(perUidStats);
4862 }
4863 return null;
4864 } finally {
4865 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004866 }
Jack Yueb89b242016-06-22 13:27:47 -07004867 }
Jack Yu75ab2952016-07-08 14:29:33 -07004868
4869 /**
4870 * Policy control of data connection. Usually used when data limit is passed.
4871 * @param enabled True if enabling the data, otherwise disabling.
4872 * @param subId Subscription index
4873 * {@hide}
4874 */
4875 @Override
4876 public void setPolicyDataEnabled(boolean enabled, int subId) {
4877 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878
4879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 Phone phone = getPhone(subId);
4882 if (phone != null) {
4883 phone.setPolicyDataEnabled(enabled);
4884 }
4885 } finally {
4886 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004887 }
4888 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004889
4890 /**
4891 * Get Client request stats
4892 * @return List of Client Request Stats
4893 * @hide
4894 */
4895 @Override
4896 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004898 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004899 return null;
4900 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004901 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 final long identity = Binder.clearCallingIdentity();
4904 try {
4905 if (phone != null) {
4906 return phone.getClientRequestStats();
4907 }
4908
4909 return null;
4910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004913 }
4914
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004915 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004916 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004917 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004918 }
Jack Yueb4124c2017-02-16 15:32:43 -08004919
4920 /**
Grace Chen70990072017-03-24 17:21:30 -07004921 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004922 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004923 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004924 * @param state State of SIM (power down, power up, pass through)
4925 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4926 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4927 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004928 *
4929 **/
4930 @Override
Grace Chen70990072017-03-24 17:21:30 -07004931 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004932 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004933 Phone phone = PhoneFactory.getPhone(slotIndex);
4934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 final long identity = Binder.clearCallingIdentity();
4936 try {
4937 if (phone != null) {
4938 phone.setSimPowerState(state);
4939 }
4940 } finally {
4941 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004942 }
4943 }
Shuo Qiandd210312017-04-12 22:11:33 +00004944
Tyler Gunn65d45c22017-06-05 11:22:26 -07004945 private boolean isUssdApiAllowed(int subId) {
4946 CarrierConfigManager configManager =
4947 (CarrierConfigManager) mPhone.getContext().getSystemService(
4948 Context.CARRIER_CONFIG_SERVICE);
4949 if (configManager == null) {
4950 return false;
4951 }
4952 PersistableBundle pb = configManager.getConfigForSubId(subId);
4953 if (pb == null) {
4954 return false;
4955 }
4956 return pb.getBoolean(
4957 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4958 }
4959
Shuo Qiandd210312017-04-12 22:11:33 +00004960 /**
4961 * Check if phone is in emergency callback mode
4962 * @return true if phone is in emergency callback mode
4963 * @param subId sub id
4964 */
goneil9c5f4872017-12-05 14:07:56 -08004965 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004966 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004967 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004968 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969
4970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 if (phone != null) {
4973 return phone.isInEcm();
4974 } else {
4975 return false;
4976 }
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004979 }
4980 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004981
4982 /**
4983 * Get the current signal strength information for the given subscription.
4984 * Because this information is not updated when the device is in a low power state
4985 * it should not be relied-upon to be current.
4986 * @param subId Subscription index
4987 * @return the most recent cached signal strength info from the modem
4988 */
4989 @Override
4990 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 Phone p = getPhone(subId);
4994 if (p == null) {
4995 return null;
4996 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 return p.getSignalStrength();
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005002 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005003
5004 @Override
5005 public UiccSlotInfo[] getUiccSlotsInfo() {
5006 enforceReadPrivilegedPermission();
5007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 final long identity = Binder.clearCallingIdentity();
5009 try {
5010 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5011 if (slots == null) {
5012 Rlog.i(LOG_TAG, "slots is null.");
5013 return null;
5014 }
5015
5016 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5017 for (int i = 0; i < slots.length; i++) {
5018 UiccSlot slot = slots[i];
5019 if (slot == null) {
5020 continue;
5021 }
5022
5023 String cardId;
5024 UiccCard card = slot.getUiccCard();
5025 if (card != null) {
5026 cardId = card.getCardId();
5027 } else {
5028 cardId = slot.getIccId();
5029 }
5030
5031 int cardState = 0;
5032 switch (slot.getCardState()) {
5033 case CARDSTATE_ABSENT:
5034 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5035 break;
5036 case CARDSTATE_PRESENT:
5037 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5038 break;
5039 case CARDSTATE_ERROR:
5040 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5041 break;
5042 case CARDSTATE_RESTRICTED:
5043 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5044 break;
5045 default:
5046 break;
5047
5048 }
5049
5050 infos[i] = new UiccSlotInfo(
5051 slot.isActive(),
5052 slot.isEuicc(),
5053 cardId,
5054 cardState,
5055 slot.getPhoneId(),
5056 slot.isExtendedApduSupported());
5057 }
5058 return infos;
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005061 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005062 }
5063
5064 @Override
5065 public boolean switchSlots(int[] physicalSlots) {
5066 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067
5068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5071 } finally {
5072 Binder.restoreCallingIdentity(identity);
5073 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005074 }
Jack Yu4c988042018-02-27 15:30:01 -08005075
5076 @Override
5077 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5078 enforceModifyPermission();
5079 final Phone phone = getPhone(subId);
5080 if (phone == null) {
5081 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5082 return;
5083 }
5084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 final long identity = Binder.clearCallingIdentity();
5086 try {
5087 phone.setRadioIndicationUpdateMode(filters, mode);
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
5090 }
Jack Yu4c988042018-02-27 15:30:01 -08005091 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005092
5093 /**
goneil47ffb6e2018-04-06 15:40:58 -07005094 * A test API to reload the UICC profile.
5095 *
5096 * <p>Requires that the calling app has permission
5097 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5098 * @hide
5099 */
5100 @Override
5101 public void refreshUiccProfile(int subId) {
5102 enforceModifyPermission();
5103
5104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 Phone phone = getPhone(subId);
5107 if (phone == null) {
5108 return;
5109 }
5110 UiccCard uiccCard = phone.getUiccCard();
5111 if (uiccCard == null) {
5112 return;
5113 }
5114 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5115 if (uiccProfile == null) {
5116 return;
5117 }
5118 uiccProfile.refresh();
5119 } finally {
5120 Binder.restoreCallingIdentity(identity);
5121 }
5122 }
5123
5124 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005125 * Returns false if the mobile data is disabled by default, otherwise return true.
5126 */
5127 private boolean getDefaultDataEnabled() {
5128 return "true".equalsIgnoreCase(
5129 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5130 }
5131
5132 /**
5133 * Returns true if the data roaming is enabled by default, i.e the system property
5134 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5135 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5136 */
5137 private boolean getDefaultDataRoamingEnabled(int subId) {
5138 final CarrierConfigManager configMgr = (CarrierConfigManager)
5139 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5140 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5141 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5142 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5143 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5144 return isDataRoamingEnabled;
5145 }
5146
5147 /**
5148 * Returns the default network type for the given {@code subId}, if the default network type is
5149 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5150 */
5151 private int getDefaultNetworkType(int subId) {
5152 return Integer.parseInt(
5153 TelephonyManager.getTelephonyProperty(
5154 mSubscriptionController.getPhoneId(subId),
5155 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5156 String.valueOf(Phone.PREFERRED_NT_MODE)));
5157 }
fionaxua13278b2018-03-21 00:08:13 -07005158
5159 @Override
5160 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5161 gid1, String gid2, String plmn, String spn) {
5162 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163
5164 final long identity = Binder.clearCallingIdentity();
5165 try {
5166 final Phone phone = getPhone(subId);
5167 if (phone == null) {
5168 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5169 return;
5170 }
5171 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5172 } finally {
5173 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005174 }
fionaxua13278b2018-03-21 00:08:13 -07005175 }
5176
5177 @Override
5178 public int getCarrierIdListVersion(int subId) {
5179 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180
5181 final long identity = Binder.clearCallingIdentity();
5182 try {
5183 final Phone phone = getPhone(subId);
5184 if (phone == null) {
5185 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5186 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5187 }
5188 return phone.getCarrierIdListVersion();
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005191 }
fionaxua13278b2018-03-21 00:08:13 -07005192 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07005193
5194 @Override
5195 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5197 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5198 return -1;
5199 }
5200
5201 final long identity = Binder.clearCallingIdentity();
5202 try {
5203 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
5206 }
5207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005208}