blob: a97c4b31cffa5a5703ab820bd859220854519f06 [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 Chenf144d942018-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 Chenf144d942018-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 Chenf144d942018-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 Chenaabec062018-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 Chenaabec062018-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 Chenaabec062018-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 Chenaabec062018-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 Chenaabec062018-02-28 15:00:40 -08001189 if (!isValid) {
1190 return;
1191 }
Wink Saville08874612014-08-31 19:19:58 -07001192
Malcolm Chenaabec062018-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 Chenaabec062018-02-28 15:00:40 -08001221 final long identity = Binder.clearCallingIdentity();
1222 try {
1223 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1224 } finally {
1225 Binder.restoreCallingIdentity(identity);
1226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001227 }
1228
1229 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001230 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001231 }
1232
Wink Savilleb564aae2014-10-23 10:18:09 -07001233 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 if (DBG) log("answerRingingCall...");
1235 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1236 // but that can probably wait till the big TelephonyManager API overhaul.
1237 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1238 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001239
1240 final long identity = Binder.clearCallingIdentity();
1241 try {
1242 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1243 } finally {
1244 Binder.restoreCallingIdentity(identity);
1245 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 }
1247
1248 /**
1249 * Make the actual telephony calls to implement answerRingingCall().
1250 * This should only be called from the main thread of the Phone app.
1251 * @see #answerRingingCall
1252 *
1253 * TODO: it would be nice to return true if we answered the call, or
1254 * false if there wasn't actually a ringing incoming call, or some
1255 * other error occurred. (In other words, pass back the return value
1256 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1257 * But that would require calling this method via sendRequest() rather
1258 * than sendRequestAsync(), and right now we don't actually *need* that
1259 * return value, so let's just return void for now.
1260 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001261 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001262 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001264 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1265 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 if (hasActiveCall && hasHoldingCall) {
1267 // Both lines are in use!
1268 // TODO: provide a flag to let the caller specify what
1269 // policy to use if both lines are in use. (The current
1270 // behavior is hardwired to "answer incoming, end ongoing",
1271 // which is how the CALL button is specced to behave.)
1272 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1273 return;
1274 } else {
1275 // answerCall() will automatically hold the current active
1276 // call, if there is one.
1277 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1278 return;
1279 }
1280 } else {
1281 // No call was ringing.
1282 return;
1283 }
1284 }
1285
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001287 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001289 public void silenceRinger() {
1290 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001291 }
1292
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001293 @Override
1294 public boolean isOffhook(String callingPackage) {
1295 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001296 }
1297
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001298 @Override
1299 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001301 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001302 return false;
1303 }
1304
Malcolm Chenaabec062018-02-28 15:00:40 -08001305 final long identity = Binder.clearCallingIdentity();
1306 try {
1307 final Phone phone = getPhone(subId);
1308 if (phone != null) {
1309 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1310 } else {
1311 return false;
1312 }
1313 } finally {
1314 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 }
1317
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001318 @Override
1319 public boolean isRinging(String callingPackage) {
1320 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001321 }
1322
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001323 @Override
1324 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001326 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001327 return false;
1328 }
1329
Malcolm Chenaabec062018-02-28 15:00:40 -08001330 final long identity = Binder.clearCallingIdentity();
1331 try {
1332 final Phone phone = getPhone(subId);
1333 if (phone != null) {
1334 return (phone.getState() == PhoneConstants.State.RINGING);
1335 } else {
1336 return false;
1337 }
1338 } finally {
1339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341 }
1342
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001343 @Override
1344 public boolean isIdle(String callingPackage) {
1345 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001346 }
1347
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001348 @Override
1349 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001350 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001351 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001352 return false;
1353 }
1354
Malcolm Chenaabec062018-02-28 15:00:40 -08001355 final long identity = Binder.clearCallingIdentity();
1356 try {
1357 final Phone phone = getPhone(subId);
1358 if (phone != null) {
1359 return (phone.getState() == PhoneConstants.State.IDLE);
1360 } else {
1361 return false;
1362 }
1363 } finally {
1364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366 }
1367
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001369 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001370 }
1371
Wink Savilleb564aae2014-10-23 10:18:09 -07001372 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001373 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001374 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1375 }
1376
1377 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001378 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001379 }
1380
Wink Savilleb564aae2014-10-23 10:18:09 -07001381 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001382 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001383 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1384 }
1385
1386 /** {@hide} */
1387 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001388 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001389 }
1390
Wink Savilleb564aae2014-10-23 10:18:09 -07001391 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001393
1394 final long identity = Binder.clearCallingIdentity();
1395 try {
1396 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1397 checkSimPin.start();
1398 return checkSimPin.unlockSim(null, pin);
1399 } finally {
1400 Binder.restoreCallingIdentity(identity);
1401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 }
1403
Wink Saville9de0f752013-10-22 19:04:03 -07001404 /** {@hide} */
1405 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001406 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001407 }
1408
Wink Savilleb564aae2014-10-23 10:18:09 -07001409 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001411
1412 final long identity = Binder.clearCallingIdentity();
1413 try {
1414 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1415 checkSimPuk.start();
1416 return checkSimPuk.unlockSim(puk, pin);
1417 } finally {
1418 Binder.restoreCallingIdentity(identity);
1419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420 }
1421
1422 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001423 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424 * a synchronous one.
1425 */
1426 private static class UnlockSim extends Thread {
1427
1428 private final IccCard mSimCard;
1429
1430 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001431 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1432 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433
1434 // For replies from SimCard interface
1435 private Handler mHandler;
1436
1437 // For async handler to identify request type
1438 private static final int SUPPLY_PIN_COMPLETE = 100;
1439
1440 public UnlockSim(IccCard simCard) {
1441 mSimCard = simCard;
1442 }
1443
1444 @Override
1445 public void run() {
1446 Looper.prepare();
1447 synchronized (UnlockSim.this) {
1448 mHandler = new Handler() {
1449 @Override
1450 public void handleMessage(Message msg) {
1451 AsyncResult ar = (AsyncResult) msg.obj;
1452 switch (msg.what) {
1453 case SUPPLY_PIN_COMPLETE:
1454 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1455 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001456 mRetryCount = msg.arg1;
1457 if (ar.exception != null) {
1458 if (ar.exception instanceof CommandException &&
1459 ((CommandException)(ar.exception)).getCommandError()
1460 == CommandException.Error.PASSWORD_INCORRECT) {
1461 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1462 } else {
1463 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1464 }
1465 } else {
1466 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 mDone = true;
1469 UnlockSim.this.notifyAll();
1470 }
1471 break;
1472 }
1473 }
1474 };
1475 UnlockSim.this.notifyAll();
1476 }
1477 Looper.loop();
1478 }
1479
1480 /*
1481 * Use PIN or PUK to unlock SIM card
1482 *
1483 * If PUK is null, unlock SIM card with PIN
1484 *
1485 * If PUK is not null, unlock SIM card with PUK and set PIN code
1486 */
Wink Saville9de0f752013-10-22 19:04:03 -07001487 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488
1489 while (mHandler == null) {
1490 try {
1491 wait();
1492 } catch (InterruptedException e) {
1493 Thread.currentThread().interrupt();
1494 }
1495 }
1496 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1497
1498 if (puk == null) {
1499 mSimCard.supplyPin(pin, callback);
1500 } else {
1501 mSimCard.supplyPuk(puk, pin, callback);
1502 }
1503
1504 while (!mDone) {
1505 try {
1506 Log.d(LOG_TAG, "wait for done");
1507 wait();
1508 } catch (InterruptedException e) {
1509 // Restore the interrupted status
1510 Thread.currentThread().interrupt();
1511 }
1512 }
1513 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001514 int[] resultArray = new int[2];
1515 resultArray[0] = mResult;
1516 resultArray[1] = mRetryCount;
1517 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001518 }
1519 }
1520
1521 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001522 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001523
1524 }
1525
Wink Savilleb564aae2014-10-23 10:18:09 -07001526 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 // No permission check needed here: this call is harmless, and it's
1528 // needed for the ServiceState.requestStateUpdate() call (which is
1529 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001530 final long identity = Binder.clearCallingIdentity();
1531 try {
1532 final Phone phone = getPhone(subId);
1533 if (phone != null) {
1534 phone.updateServiceLocation();
1535 }
1536 } finally {
1537 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001539 }
1540
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001541 @Override
1542 public boolean isRadioOn(String callingPackage) {
1543 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001544 }
1545
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001546 @Override
1547 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001549 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001550 return false;
1551 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001552
1553 final long identity = Binder.clearCallingIdentity();
1554 try {
1555 return isRadioOnForSubscriber(subId);
1556 } finally {
1557 Binder.restoreCallingIdentity(identity);
1558 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001559 }
1560
1561 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001562 final long identity = Binder.clearCallingIdentity();
1563 try {
1564 final Phone phone = getPhone(subId);
1565 if (phone != null) {
1566 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1567 } else {
1568 return false;
1569 }
1570 } finally {
1571 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 }
1574
1575 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001576 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
Wink Saville36469e72014-06-11 15:17:00 -07001578
Wink Savilleb564aae2014-10-23 10:18:09 -07001579 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001581
1582 final long identity = Binder.clearCallingIdentity();
1583 try {
1584 final Phone phone = getPhone(subId);
1585 if (phone != null) {
1586 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1587 }
1588 } finally {
1589 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 }
Wink Saville36469e72014-06-11 15:17:00 -07001591 }
1592
1593 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001594 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001595 }
1596
Wink Savilleb564aae2014-10-23 10:18:09 -07001597 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001598 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001599
1600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 final Phone phone = getPhone(subId);
1603 if (phone == null) {
1604 return false;
1605 }
1606 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1607 toggleRadioOnOffForSubscriber(subId);
1608 }
1609 return true;
1610 } finally {
1611 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 }
Wink Saville36469e72014-06-11 15:17:00 -07001614
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001615 public boolean needMobileRadioShutdown() {
1616 /*
1617 * If any of the Radios are available, it will need to be
1618 * shutdown. So return true if any Radio is available.
1619 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001620 final long identity = Binder.clearCallingIdentity();
1621 try {
1622 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1623 Phone phone = PhoneFactory.getPhone(i);
1624 if (phone != null && phone.isRadioAvailable()) return true;
1625 }
1626 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1627 return false;
1628 } finally {
1629 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001630 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 }
1632
Malcolm Chenaabec062018-02-28 15:00:40 -08001633 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001634 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001635 enforceModifyPermission();
1636
1637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1640 logv("Shutting down Phone " + i);
1641 shutdownRadioUsingPhoneId(i);
1642 }
1643 } finally {
1644 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001645 }
1646 }
1647
1648 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001649 Phone phone = PhoneFactory.getPhone(phoneId);
1650 if (phone != null && phone.isRadioAvailable()) {
1651 phone.shutdownRadio();
1652 }
1653 }
1654
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001656 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001657
1658 final long identity = Binder.clearCallingIdentity();
1659 try {
1660 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1661 if (defaultPhone != null) {
1662 defaultPhone.setRadioPower(turnOn);
1663 return true;
1664 } else {
1665 loge("There's no default phone.");
1666 return false;
1667 }
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001670 }
Wink Saville36469e72014-06-11 15:17:00 -07001671 }
1672
Wink Savilleb564aae2014-10-23 10:18:09 -07001673 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001675
1676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 final Phone phone = getPhone(subId);
1679 if (phone != null) {
1680 phone.setRadioPower(turnOn);
1681 return true;
1682 } else {
1683 return false;
1684 }
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 }
1689
Wink Saville36469e72014-06-11 15:17:00 -07001690 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001691 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 public boolean enableDataConnectivity() {
1693 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001694
1695 final long identity = Binder.clearCallingIdentity();
1696 try {
1697 int subId = mSubscriptionController.getDefaultDataSubId();
1698 final Phone phone = getPhone(subId);
1699 if (phone != null) {
1700 phone.setUserDataEnabled(true);
1701 return true;
1702 } else {
1703 return false;
1704 }
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 }
1709
Wink Saville36469e72014-06-11 15:17:00 -07001710 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001711 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 public boolean disableDataConnectivity() {
1713 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001714
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 int subId = mSubscriptionController.getDefaultDataSubId();
1718 final Phone phone = getPhone(subId);
1719 if (phone != null) {
1720 phone.setUserDataEnabled(false);
1721 return true;
1722 } else {
1723 return false;
1724 }
1725 } finally {
1726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 }
1729
Sanket Padawe356d7632015-06-22 14:03:32 -07001730 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001731 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001732 final long identity = Binder.clearCallingIdentity();
1733 try {
1734 final Phone phone = getPhone(subId);
1735 if (phone != null) {
1736 return phone.isDataAllowed();
1737 } else {
1738 return false;
1739 }
1740 } finally {
1741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
1744
1745 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001746 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001747 }
1748
pkanwarae03a6b2016-11-06 20:37:09 -08001749 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001750 enforceCallPermission();
1751
1752 final long identity = Binder.clearCallingIdentity();
1753 try {
1754 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1755 return;
1756 }
1757 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1758 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1759 } finally {
1760 Binder.restoreCallingIdentity(identity);
1761 }
pkanwar32d516d2016-10-14 19:37:38 -07001762 };
1763
Wink Savilleb564aae2014-10-23 10:18:09 -07001764 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001766
1767 final long identity = Binder.clearCallingIdentity();
1768 try {
1769 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1770 return false;
1771 }
1772 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1773 } finally {
1774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 }
1777
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001779 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001780 }
1781
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001782 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001783 final long identity = Binder.clearCallingIdentity();
1784 try {
1785 Phone phone = PhoneFactory.getPhone(slotIndex);
1786 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1787 PhoneConstantConversions.convertCallState(phone.getState());
1788 } finally {
1789 Binder.restoreCallingIdentity(identity);
1790 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 }
1792
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001795 final long identity = Binder.clearCallingIdentity();
1796 try {
1797 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1798 if (phone != null) {
1799 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1800 } else {
1801 return PhoneConstantConversions.convertDataState(
1802 PhoneConstants.DataState.DISCONNECTED);
1803 }
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001806 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
1808
Sanket Padawe356d7632015-06-22 14:03:32 -07001809 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001811 final long identity = Binder.clearCallingIdentity();
1812 try {
1813 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1814 if (phone != null) {
1815 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1816 } else {
1817 return TelephonyManager.DATA_ACTIVITY_NONE;
1818 }
1819 } finally {
1820 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 }
1823
1824 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001825 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001826 mPhone.getContext().getSystemService(AppOpsManager.class)
1827 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001828 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001829 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001830 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
1832
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001833 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 if (DBG_LOC) log("getCellLocation: is active user");
1837 Bundle data = new Bundle();
1838 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1839 if (phone == null) {
1840 return null;
1841 }
1842
1843 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1844 return data;
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
1847 }
Svetoslav64fad262015-04-14 14:35:21 -07001848 }
1849
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001851 public String getNetworkCountryIsoForPhone(int phoneId) {
1852 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1853 // registered cell info, so return a NULL country instead.
1854 final long identity = Binder.clearCallingIdentity();
1855 try {
1856 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001857 // Todo: fix this when we can get the actual cellular network info when the device
1858 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001859 if (TelephonyManager.NETWORK_TYPE_IWLAN
1860 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1861 return "";
1862 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001863 Phone phone = PhoneFactory.getPhone(phoneId);
1864 if (phone != null) {
1865 ServiceStateTracker sst = phone.getServiceStateTracker();
1866 if (sst != null) {
1867 LocaleTracker lt = sst.getLocaleTracker();
1868 if (lt != null) {
1869 return lt.getCurrentCountry();
1870 }
1871 }
1872 }
1873 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001874 } finally {
1875 Binder.restoreCallingIdentity(identity);
1876 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001877 }
1878
1879 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001881 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001882 }
1883
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001885 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 mApp.enforceCallingOrSelfPermission(
1887 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001888
1889 final long identity = Binder.clearCallingIdentity();
1890 try {
1891 final Phone phone = getPhone(subId);
1892 if (phone != null) {
1893 phone.enableLocationUpdates();
1894 }
1895 } finally {
1896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 }
1899
1900 @Override
1901 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001902 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001903 }
1904
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001906 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 mApp.enforceCallingOrSelfPermission(
1908 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001909
1910 final long identity = Binder.clearCallingIdentity();
1911 try {
1912 final Phone phone = getPhone(subId);
1913 if (phone != null) {
1914 phone.disableLocationUpdates();
1915 }
1916 } finally {
1917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 }
1920
1921 @Override
1922 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001923 public List<NeighboringCellInfo>
1924 getNeighboringCellInfo(String callingPackage, int targetSdk) {
Nathan Harold54a07f92018-08-09 16:20:42 -07001925 if (targetSdk > android.os.Build.VERSION_CODES.P) return null;
Nathan Haroldb4d55612018-07-20 13:13:08 -07001926
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1928 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1929 return null;
1930 }
Svetoslav64fad262015-04-14 14:35:21 -07001931
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001932 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933
Nathan Haroldf180aac2018-06-01 18:43:55 -07001934 List<CellInfo> info = getAllCellInfo(callingPackage);
1935 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936
Nathan Haroldf180aac2018-06-01 18:43:55 -07001937 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1938 for (CellInfo ci : info) {
1939 if (ci instanceof CellInfoGsm) {
1940 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1941 } else if (ci instanceof CellInfoWcdma) {
1942 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001945 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
1948
1949 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001950 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001951 mPhone.getContext().getSystemService(AppOpsManager.class)
1952 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001953 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001954 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001955 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 }
1957
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001958 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001959 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001960 final long identity = Binder.clearCallingIdentity();
1961 try {
1962 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1963 for (Phone phone : PhoneFactory.getPhones()) {
1964 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1965 if (info != null) cellInfos.addAll(info);
1966 }
1967 return cellInfos;
1968 } finally {
1969 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971 }
1972
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001973 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001975 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001977
1978 final long identity = Binder.clearCallingIdentity();
1979 try {
1980 mPhone.setCellInfoListRate(rateInMillis, workSource);
1981 } finally {
1982 Binder.restoreCallingIdentity(identity);
1983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985
Shishir Agrawala9f32182016-04-12 12:00:16 -07001986 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001987 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001988 Phone phone = PhoneFactory.getPhone(slotIndex);
1989 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001990 return null;
1991 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001992 int subId = phone.getSubId();
1993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1994 mApp, subId, callingPackage, "getImeiForSlot")) {
1995 return null;
1996 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001997
1998 final long identity = Binder.clearCallingIdentity();
1999 try {
2000 return phone.getImei();
2001 } finally {
2002 Binder.restoreCallingIdentity(identity);
2003 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002004 }
2005
2006 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002007 public String getTypeAllocationCodeForSlot(int slotIndex) {
2008 Phone phone = PhoneFactory.getPhone(slotIndex);
2009 String tac = null;
2010 if (phone != null) {
2011 String imei = phone.getImei();
2012 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2013 }
2014 return tac;
2015 }
2016
2017 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002018 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002019 Phone phone = PhoneFactory.getPhone(slotIndex);
2020 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002021 return null;
2022 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002023 int subId = phone.getSubId();
2024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2025 mApp, subId, callingPackage, "getMeidForSlot")) {
2026 return null;
2027 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002028
2029 final long identity = Binder.clearCallingIdentity();
2030 try {
2031 return phone.getMeid();
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
2034 }
Jack Yu2af8d712017-03-15 17:14:14 -07002035 }
2036
2037 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002038 public String getManufacturerCodeForSlot(int slotIndex) {
2039 Phone phone = PhoneFactory.getPhone(slotIndex);
2040 String manufacturerCode = null;
2041 if (phone != null) {
2042 String meid = phone.getMeid();
2043 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2044 }
2045 return manufacturerCode;
2046 }
2047
2048 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002049 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002050 Phone phone = PhoneFactory.getPhone(slotIndex);
2051 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002052 return null;
2053 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002054 int subId = phone.getSubId();
2055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2056 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2057 return null;
2058 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002059
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
2062 return phone.getDeviceSvn();
2063 } finally {
2064 Binder.restoreCallingIdentity(identity);
2065 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002066 }
2067
fionaxu43304da2017-11-27 22:51:16 -08002068 @Override
2069 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002070 final long identity = Binder.clearCallingIdentity();
2071 try {
2072 final Phone phone = getPhone(subId);
2073 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2074 } finally {
2075 Binder.restoreCallingIdentity(identity);
2076 }
fionaxu43304da2017-11-27 22:51:16 -08002077 }
2078
2079 @Override
2080 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 final Phone phone = getPhone(subId);
2084 return phone == null ? null : phone.getCarrierName();
2085 } finally {
2086 Binder.restoreCallingIdentity(identity);
2087 }
fionaxu43304da2017-11-27 22:51:16 -08002088 }
2089
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 //
2091 // Internal helper methods.
2092 //
2093
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002094 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2096 *
2097 * @throws SecurityException if the caller does not have the required permission
2098 */
2099 private void enforceModifyPermission() {
2100 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2101 }
2102
2103 /**
2104 * Make sure the caller has the CALL_PHONE permission.
2105 *
2106 * @throws SecurityException if the caller does not have the required permission
2107 */
2108 private void enforceCallPermission() {
2109 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2110 }
2111
Stuart Scott8eef64f2015-04-08 15:13:54 -07002112 private void enforceConnectivityInternalPermission() {
2113 mApp.enforceCallingOrSelfPermission(
2114 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2115 "ConnectivityService");
2116 }
2117
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 private String createTelUrl(String number) {
2119 if (TextUtils.isEmpty(number)) {
2120 return null;
2121 }
2122
Jake Hambye994d462014-02-03 13:10:13 -08002123 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 }
2125
Ihab Awadf9e92732013-12-05 18:02:52 -08002126 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2128 }
2129
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002130 private static void logv(String msg) {
2131 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2132 }
2133
Ihab Awadf9e92732013-12-05 18:02:52 -08002134 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2136 }
2137
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002138 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002140 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002141 }
2142
Sanket Padawe356d7632015-06-22 14:03:32 -07002143 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002144 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002145 final long identity = Binder.clearCallingIdentity();
2146 try {
2147 final Phone phone = PhoneFactory.getPhone(slotIndex);
2148 if (phone == null) {
2149 return PhoneConstants.PHONE_TYPE_NONE;
2150 } else {
2151 return phone.getPhoneType();
2152 }
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 }
2157
2158 /**
2159 * Returns the CDMA ERI icon index to display
2160 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002161 @Override
2162 public int getCdmaEriIconIndex(String callingPackage) {
2163 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002164 }
2165
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002167 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002169 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002170 return -1;
2171 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 final Phone phone = getPhone(subId);
2176 if (phone != null) {
2177 return phone.getCdmaEriIconIndex();
2178 } else {
2179 return -1;
2180 }
2181 } finally {
2182 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 }
2185
2186 /**
2187 * Returns the CDMA ERI icon mode,
2188 * 0 - ON
2189 * 1 - FLASHING
2190 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002191 @Override
2192 public int getCdmaEriIconMode(String callingPackage) {
2193 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002197 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002199 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002200 return -1;
2201 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002202
2203 final long identity = Binder.clearCallingIdentity();
2204 try {
2205 final Phone phone = getPhone(subId);
2206 if (phone != null) {
2207 return phone.getCdmaEriIconMode();
2208 } else {
2209 return -1;
2210 }
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 }
2215
2216 /**
2217 * Returns the CDMA ERI text,
2218 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002219 @Override
2220 public String getCdmaEriText(String callingPackage) {
2221 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002222 }
2223
Sanket Padawe356d7632015-06-22 14:03:32 -07002224 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002225 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002226 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002227 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002228 return null;
2229 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002230
2231 final long identity = Binder.clearCallingIdentity();
2232 try {
2233 final Phone phone = getPhone(subId);
2234 if (phone != null) {
2235 return phone.getCdmaEriText();
2236 } else {
2237 return null;
2238 }
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 }
2243
2244 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002245 * Returns the CDMA MDN.
2246 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002248 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2250 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002251
2252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 final Phone phone = getPhone(subId);
2255 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2256 return phone.getLine1Number();
2257 } else {
2258 return null;
2259 }
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002262 }
2263 }
2264
2265 /**
2266 * Returns the CDMA MIN.
2267 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002268 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002269 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2271 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002272
2273 final long identity = Binder.clearCallingIdentity();
2274 try {
2275 final Phone phone = getPhone(subId);
2276 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2277 return phone.getCdmaMin();
2278 } else {
2279 return null;
2280 }
2281 } finally {
2282 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002283 }
2284 }
2285
2286 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 * Returns true if CDMA provisioning needs to run.
2288 */
2289 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 return mPhone.needsOtaServiceProvisioning();
2293 } finally {
2294 Binder.restoreCallingIdentity(identity);
2295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 }
2297
2298 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002299 * Sets the voice mail number of a given subId.
2300 */
2301 @Override
2302 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002303 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002304
2305 final long identity = Binder.clearCallingIdentity();
2306 try {
2307 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2308 new Pair<String, String>(alphaTag, number), new Integer(subId));
2309 return success;
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
2312 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002313 }
2314
Ta-wei Yen87c49842016-05-13 21:19:52 -07002315 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002316 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2317 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2318 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2319 if (!TextUtils.equals(callingPackage, systemDialer)) {
2320 throw new SecurityException("caller must be system dialer");
2321 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002322
2323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2326 if (phoneAccountHandle == null) {
2327 return null;
2328 }
2329 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002332 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002333 }
2334
2335 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002336 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002339 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002340 return null;
2341 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002342
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 return RemoteVvmTaskManager
2346 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
2349 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002350 }
2351
2352 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002353 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2354 VisualVoicemailSmsFilterSettings settings) {
2355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2360 mPhone.getContext(), callingPackage, subId, settings);
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
2363 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002364 }
2365
2366 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002367 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002369
2370 final long identity = Binder.clearCallingIdentity();
2371 try {
2372 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2373 mPhone.getContext(), callingPackage, subId);
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
2376 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002377 }
2378
2379 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002380 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2381 String callingPackage, int subId) {
2382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002383
2384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2387 mPhone.getContext(), callingPackage, subId);
2388 } finally {
2389 Binder.restoreCallingIdentity(identity);
2390 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002391 }
2392
2393 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002394 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002395 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002396
2397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2400 mPhone.getContext(), subId);
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002404 }
2405
2406 @Override
2407 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2408 String number, int port, String text, PendingIntent sentIntent) {
2409 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002410 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002411 enforceSendSmsPermission();
2412 // Make the calls as the phone process.
2413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2416 if (port == 0) {
2417 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2418 sentIntent, null, false);
2419 } else {
2420 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2421 smsManager.sendDataMessageWithSelfPermissions(number, null,
2422 (short) port, data, sentIntent, null);
2423 }
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002427 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002428 /**
fionaxu0152e512016-11-14 13:36:14 -08002429 * Sets the voice activation state of a given subId.
2430 */
2431 @Override
2432 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2434 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002435
2436 final long identity = Binder.clearCallingIdentity();
2437 try {
2438 final Phone phone = getPhone(subId);
2439 if (phone != null) {
2440 phone.setVoiceActivationState(activationState);
2441 } else {
2442 loge("setVoiceActivationState fails with invalid subId: " + subId);
2443 }
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002446 }
2447 }
2448
2449 /**
2450 * Sets the data activation state of a given subId.
2451 */
2452 @Override
2453 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2455 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002456
2457 final long identity = Binder.clearCallingIdentity();
2458 try {
2459 final Phone phone = getPhone(subId);
2460 if (phone != null) {
2461 phone.setDataActivationState(activationState);
2462 } else {
2463 loge("setVoiceActivationState fails with invalid subId: " + subId);
2464 }
2465 } finally {
2466 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002467 }
2468 }
2469
2470 /**
2471 * Returns the voice activation state of a given subId.
2472 */
2473 @Override
2474 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002475 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002476
fionaxu0152e512016-11-14 13:36:14 -08002477 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 if (phone != null) {
2481 return phone.getVoiceActivationState();
2482 } else {
2483 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2484 }
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002487 }
2488 }
2489
2490 /**
2491 * Returns the data activation state of a given subId.
2492 */
2493 @Override
2494 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002495 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002496
fionaxu0152e512016-11-14 13:36:14 -08002497 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 if (phone != null) {
2501 return phone.getDataActivationState();
2502 } else {
2503 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2504 }
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002507 }
2508 }
2509
2510 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 * Returns the unread count of voicemails
2512 */
2513 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002514 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002515 }
2516
2517 /**
2518 * Returns the unread count of voicemails for a subId
2519 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002520 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002521 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 final Phone phone = getPhone(subId);
2525 if (phone != null) {
2526 return phone.getVoiceMessageCount();
2527 } else {
2528 return 0;
2529 }
2530 } finally {
2531 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 }
2534
2535 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002536 * returns true, if the device is in a state where both voice and data
2537 * are supported simultaneously. This can change based on location or network condition.
2538 */
2539 @Override
2540 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002541 final long identity = Binder.clearCallingIdentity();
2542 try {
2543 final Phone phone = getPhone(subId);
2544 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002548 }
2549
2550 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002551 * Send the dialer code if called from the current default dialer or the caller has
2552 * carrier privilege.
2553 * @param inputCode The dialer code to send
2554 */
2555 @Override
2556 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2557 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2558 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2559 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002560 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2561 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002562 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002563
2564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 mPhone.sendDialerSpecialCode(inputCode);
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
2569 }
fionaxu235cc5e2017-03-06 22:25:57 -08002570 }
2571
2572 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002573 * Returns the data network type.
2574 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 *
2576 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2577 */
2578 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002579 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002580 final long identity = Binder.clearCallingIdentity();
2581 try {
2582 final Phone phone = getPhone(getDefaultSubscription());
2583 if (phone != null) {
2584 return phone.getServiceState().getDataNetworkType();
2585 } else {
2586 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2587 }
2588 } finally {
2589 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002590 }
Wink Saville36469e72014-06-11 15:17:00 -07002591 }
2592
2593 /**
2594 * Returns the network type for a subId
2595 */
2596 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002597 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002599 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002600 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2601 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002602
Malcolm Chenaabec062018-02-28 15:00:40 -08002603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 final Phone phone = getPhone(subId);
2606 if (phone != null) {
2607 return phone.getServiceState().getDataNetworkType();
2608 } else {
2609 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2610 }
2611 } finally {
2612 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 }
2615
2616 /**
2617 * Returns the data network type
2618 */
2619 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002620 public int getDataNetworkType(String callingPackage) {
2621 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002622 }
2623
2624 /**
2625 * Returns the data network type for a subId
2626 */
2627 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002628 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002630 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002631 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2632 }
2633
Malcolm Chenaabec062018-02-28 15:00:40 -08002634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 final Phone phone = getPhone(subId);
2637 if (phone != null) {
2638 return phone.getServiceState().getDataNetworkType();
2639 } else {
2640 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2641 }
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 }
2646
2647 /**
Wink Saville36469e72014-06-11 15:17:00 -07002648 * Returns the Voice network type for a subId
2649 */
2650 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002651 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002652 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002653 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002654 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2655 }
2656
Malcolm Chenaabec062018-02-28 15:00:40 -08002657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 if (phone != null) {
2661 return phone.getServiceState().getVoiceNetworkType();
2662 } else {
2663 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2664 }
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002667 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 }
2669
2670 /**
2671 * @return true if a ICC card is present
2672 */
2673 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002674 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002675 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2676 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002677 }
2678
2679 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002680 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002681 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002682 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002683 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 final Phone phone = PhoneFactory.getPhone(slotIndex);
2687 if (phone != null) {
2688 return phone.getIccCard().hasIccCard();
2689 } else {
2690 return false;
2691 }
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696
2697 /**
2698 * Return if the current radio is LTE on CDMA. This
2699 * is a tri-state return value as for a period of time
2700 * the mode may be unknown.
2701 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002702 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002704 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002706 @Override
2707 public int getLteOnCdmaMode(String callingPackage) {
2708 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002709 }
2710
Sanket Padawe356d7632015-06-22 14:03:32 -07002711 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002712 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002714 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002715 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2716 }
2717
Malcolm Chenaabec062018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 final Phone phone = getPhone(subId);
2721 if (phone == null) {
2722 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2723 } else {
2724 return phone.getLteOnCdmaMode();
2725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002728 }
Wink Saville36469e72014-06-11 15:17:00 -07002729 }
2730
2731 public void setPhone(Phone phone) {
2732 mPhone = phone;
2733 }
2734
2735 /**
2736 * {@hide}
2737 * Returns Default subId, 0 in the case of single standby.
2738 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002739 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002740 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002741 }
2742
Shishir Agrawala9f32182016-04-12 12:00:16 -07002743 private int getSlotForDefaultSubscription() {
2744 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2745 }
2746
Wink Savilleb564aae2014-10-23 10:18:09 -07002747 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002748 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002749 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002750
2751 /**
2752 * @see android.telephony.TelephonyManager.WifiCallingChoices
2753 */
2754 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2758 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2759 getWhenToMakeWifiCallsDefaultPreference());
2760 } finally {
2761 Binder.restoreCallingIdentity(identity);
2762 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002763 }
2764
2765 /**
2766 * @see android.telephony.TelephonyManager.WifiCallingChoices
2767 */
2768 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2772 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2773 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
2776 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002777 }
2778
Sailesh Nepald1e68152013-12-12 19:08:02 -08002779 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002780 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002781 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002782 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002783
Shishir Agrawal566b7612013-10-28 14:41:00 -07002784 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002785 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2786 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2788 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002789 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002790
Malcolm Chenaabec062018-02-28 15:00:40 -08002791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 if (TextUtils.equals(ISDR_AID, aid)) {
2794 // Only allows LPA to open logical channel to ISD-R.
2795 ComponentInfo bestComponent =
2796 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2797 if (bestComponent == null
2798 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2799 loge("The calling package is not allowed to access ISD-R.");
2800 throw new SecurityException(
2801 "The calling package is not allowed to access ISD-R.");
2802 }
Derek Tan740e1672017-06-27 14:56:27 -07002803 }
Derek Tan740e1672017-06-27 14:56:27 -07002804
Malcolm Chenaabec062018-02-28 15:00:40 -08002805 if (DBG) {
2806 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2807 }
2808 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2809 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2810 if (DBG) log("iccOpenLogicalChannel: " + response);
2811 return response;
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
2814 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002815 }
2816
2817 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002818 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2820 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002821
Malcolm Chenaabec062018-02-28 15:00:40 -08002822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2825 if (channel < 0) {
2826 return false;
2827 }
2828 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2829 if (DBG) log("iccCloseLogicalChannel: " + success);
2830 return success;
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002833 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002834 }
2835
2836 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002837 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002838 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2840 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002841
Malcolm Chenaabec062018-02-28 15:00:40 -08002842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 if (DBG) {
2845 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2846 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2847 + p3 + " data=" + data);
2848 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002849
Malcolm Chenaabec062018-02-28 15:00:40 -08002850 if (channel < 0) {
2851 return "";
2852 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002853
Malcolm Chenaabec062018-02-28 15:00:40 -08002854 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2855 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2856 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002857
Malcolm Chenaabec062018-02-28 15:00:40 -08002858 // Append the returned status code to the end of the response payload.
2859 String s = Integer.toHexString(
2860 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2861 if (response.payload != null) {
2862 s = IccUtils.bytesToHexString(response.payload) + s;
2863 }
2864 return s;
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002867 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002868 }
Jake Hambye994d462014-02-03 13:10:13 -08002869
Evan Charltonc66da362014-05-16 14:06:40 -07002870 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002871 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2872 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2874 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002875 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002876
Malcolm Chenaabec062018-02-28 15:00:40 -08002877 final long identity = Binder.clearCallingIdentity();
2878 try {
2879 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2880 && TextUtils.equals(ISDR_AID, data)) {
2881 // Only allows LPA to select ISD-R.
2882 ComponentInfo bestComponent =
2883 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2884 if (bestComponent == null
2885 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2886 loge("The calling package is not allowed to select ISD-R.");
2887 throw new SecurityException(
2888 "The calling package is not allowed to select ISD-R.");
2889 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002890 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002891
Malcolm Chenaabec062018-02-28 15:00:40 -08002892 if (DBG) {
2893 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2894 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2895 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002896
Malcolm Chenaabec062018-02-28 15:00:40 -08002897 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2898 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2899 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002900
Malcolm Chenaabec062018-02-28 15:00:40 -08002901 // Append the returned status code to the end of the response payload.
2902 String s = Integer.toHexString(
2903 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2904 if (response.payload != null) {
2905 s = IccUtils.bytesToHexString(response.payload) + s;
2906 }
2907 return s;
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002910 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002911 }
2912
2913 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002914 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002915 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2917 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002918
Malcolm Chenaabec062018-02-28 15:00:40 -08002919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 if (DBG) {
2922 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2923 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2924 }
2925
2926 IccIoResult response =
2927 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2928 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2929 subId);
2930
2931 if (DBG) {
2932 log("Exchange SIM_IO [R]" + response);
2933 }
2934
2935 byte[] result = null;
2936 int length = 2;
2937 if (response.payload != null) {
2938 length = 2 + response.payload.length;
2939 result = new byte[length];
2940 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2941 } else {
2942 result = new byte[length];
2943 }
2944
2945 result[length - 1] = (byte) response.sw2;
2946 result[length - 2] = (byte) response.sw1;
2947 return result;
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002950 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002951 }
2952
Nathan Haroldb3014052017-01-25 15:57:32 -08002953 /**
2954 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2955 * on a particular subscription
2956 */
sqianb6e41952018-03-12 14:54:01 -07002957 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2958 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2959 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2960 return null;
2961 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002962 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2963 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2964 return null;
2965 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002966
2967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2970 if (response instanceof String[]) {
2971 return (String[]) response;
2972 }
2973 // Response is an Exception of some kind,
2974 // which is signalled to the user as a NULL retval
2975 return null;
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002978 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002979 }
2980
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002981 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002982 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2984 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002985
Malcolm Chenaabec062018-02-28 15:00:40 -08002986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2989 if (response.payload == null) {
2990 return "";
2991 }
Evan Charltonc66da362014-05-16 14:06:40 -07002992
Malcolm Chenaabec062018-02-28 15:00:40 -08002993 // Append the returned status code to the end of the response payload.
2994 String s = Integer.toHexString(
2995 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2996 s = IccUtils.bytesToHexString(response.payload) + s;
2997 return s;
2998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
Evan Charltonc66da362014-05-16 14:06:40 -07003001 }
3002
Jake Hambye994d462014-02-03 13:10:13 -08003003 /**
3004 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3005 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3006 *
3007 * @param itemID the ID of the item to read
3008 * @return the NV item as a String, or null on error.
3009 */
3010 @Override
3011 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3013 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003014
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 if (DBG) log("nvReadItem: item " + itemID);
3018 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3019 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3020 return value;
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
Jake Hambye994d462014-02-03 13:10:13 -08003024 }
3025
3026 /**
3027 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3028 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3029 *
3030 * @param itemID the ID of the item to read
3031 * @param itemValue the value to write, as a String
3032 * @return true on success; false on any failure
3033 */
3034 @Override
3035 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3037 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003038
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3042 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3043 new Pair<Integer, String>(itemID, itemValue));
3044 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3045 return success;
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
Jake Hambye994d462014-02-03 13:10:13 -08003049 }
3050
3051 /**
3052 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3053 * Used for device configuration by some CDMA operators.
3054 *
3055 * @param preferredRoamingList byte array containing the new PRL
3056 * @return true on success; false on any failure
3057 */
3058 @Override
3059 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3061 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003062
3063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3066 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3067 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3068 return success;
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Jake Hambye994d462014-02-03 13:10:13 -08003072 }
3073
3074 /**
3075 * Perform the specified type of NV config reset.
3076 * Used for device configuration by some CDMA operators.
3077 *
3078 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3079 * @return true on success; false on any failure
3080 */
3081 @Override
3082 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3084 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003085
3086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 if (DBG) log("nvResetConfig: type " + resetType);
3089 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3090 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3091 return success;
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
Jake Hambye994d462014-02-03 13:10:13 -08003095 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003096
Svet Ganovb320e182015-04-16 12:30:10 -07003097 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003099 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003100 return new String[0];
3101 }
3102
Malcolm Chenaabec062018-02-28 15:00:40 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 return mPhone.getPcscfAddress(apnType);
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
Wink Saville36469e72014-06-11 15:17:00 -07003109 }
3110
Brad Ebinger51f743a2017-01-23 13:50:20 -08003111 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003112 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3113 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003114 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003115 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003116 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003117
3118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 PhoneFactory.getImsResolver().enableIms(slotId);
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
3123 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003124 }
3125
3126 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003127 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3128 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003129 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003130 public void disableIms(int slotId) {
3131 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003132
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 PhoneFactory.getImsResolver().disableIms(slotId);
3136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003139 }
3140
3141 /**
3142 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3143 * feature or {@link null} if the service is not available. If the feature is available, the
3144 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3145 */
3146 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003147 IImsServiceFeatureCallback callback) {
3148 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003149
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003156 }
3157
3158 /**
3159 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3160 * feature during emergency calling or {@link null} if the service is not available. If the
3161 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3162 * listener for feature updates.
3163 */
3164 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3165 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003166
3167 final long identity = Binder.clearCallingIdentity();
3168 try {
3169 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
3172 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003173 }
3174
Brad Ebinger5f64b052017-12-14 14:26:15 -08003175 /**
3176 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3177 * specified.
3178 */
3179 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3180 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003181
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003188 }
3189
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003190 /**
3191 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3192 * specified.
3193 */
3194 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3195 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003196
3197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
3202 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003203 }
3204
Brad Ebinger884c07b2018-02-15 16:17:40 -08003205 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003206 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3207 * available, false if the IMS resolver is idle.
3208 */
3209 public boolean isResolvingImsBinding() {
3210 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003211
3212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 return PhoneFactory.getImsResolver().isResolvingBinding();
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
Brad Ebinger67801702018-03-02 13:43:36 -08003218 }
3219
Brad Ebingerdac2f002018-04-03 15:17:52 -07003220 /**
3221 * Sets the ImsService Package Name that Telephony will bind to.
3222 *
3223 * @param slotId the slot ID that the ImsService should bind for.
3224 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3225 * ImsService is the device default ImsService.
3226 * @param packageName The package name of the application that contains the ImsService to bind
3227 * to.
3228 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3229 * @hide
3230 */
3231 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003232 int[] subIds = SubscriptionManager.getSubId(slotId);
3233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3234 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3235 "setImsService");
3236
Malcolm Chenaabec062018-02-28 15:00:40 -08003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3240 isCarrierImsService, packageName);
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003244 }
3245
3246 /**
3247 * Return the ImsService configuration.
3248 *
3249 * @param slotId The slot that the ImsService is associated with.
3250 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3251 * the device default.
3252 * @return the package name of the ImsService configuration.
3253 */
3254 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003255 int[] subIds = SubscriptionManager.getSubId(slotId);
3256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3257 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3258 "getImsService");
3259
Malcolm Chenaabec062018-02-28 15:00:40 -08003260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3263 isCarrierImsService);
3264 } finally {
3265 Binder.restoreCallingIdentity(identity);
3266 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003267 }
3268
Wink Saville36469e72014-06-11 15:17:00 -07003269 public void setImsRegistrationState(boolean registered) {
3270 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003271
3272 final long identity = Binder.clearCallingIdentity();
3273 try {
3274 mPhone.setImsRegistrationState(registered);
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
Wink Saville36469e72014-06-11 15:17:00 -07003278 }
3279
3280 /**
Stuart Scott54788802015-03-30 13:18:01 -07003281 * Set the network selection mode to automatic.
3282 *
3283 */
3284 @Override
3285 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3287 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003288
3289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3292 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3293 } finally {
3294 Binder.restoreCallingIdentity(identity);
3295 }
Stuart Scott54788802015-03-30 13:18:01 -07003296 }
3297
3298 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003299 * Set the network selection mode to manual with the selected carrier.
3300 */
3301 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003302 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003303 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3305 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaabec062018-02-28 15:00:40 -08003306
3307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003310 /* operatorAlphaLong */ "",
3311 /* operatorAlphaShort */ "",
Malcolm Chenaabec062018-02-28 15:00:40 -08003312 operatorNumeric);
3313 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3314 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3315 persistSelection);
3316 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3317 } finally {
3318 Binder.restoreCallingIdentity(identity);
3319 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003320 }
3321
3322 /**
3323 * Scans for available networks.
3324 */
3325 @Override
3326 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3328 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003329
3330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3333 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3334 CMD_PERFORM_NETWORK_SCAN, null, subId);
3335 return result;
3336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003339 }
3340
3341 /**
yinxub1bed742017-04-17 11:45:04 -07003342 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003343 *
yinxub1bed742017-04-17 11:45:04 -07003344 * @param subId id of the subscription
3345 * @param request contains the radio access networks with bands/channels to scan
3346 * @param messenger callback messenger for scan results or errors
3347 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003348 * @return the id of the requested scan which can be used to stop the scan.
3349 */
3350 @Override
3351 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3352 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3354 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003355
3356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 return mNetworkScanRequestTracker.startNetworkScan(
3359 request, messenger, binder, getPhone(subId));
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
3362 }
yinxu504e1392017-04-12 16:03:22 -07003363 }
3364
3365 /**
3366 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003367 *
3368 * @param subId id of the subscription
3369 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003370 */
3371 @Override
3372 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3374 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003375
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
yinxu504e1392017-04-12 16:03:22 -07003382 }
3383
3384 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003385 * Get the calculated preferred network type.
3386 * Used for debugging incorrect network type.
3387 *
3388 * @return the preferred network type, defined in RILConstants.java.
3389 */
3390 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003391 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003392 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003393 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003394 return RILConstants.PREFERRED_NETWORK_MODE;
3395 }
3396
Malcolm Chenaabec062018-02-28 15:00:40 -08003397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 // FIXME: need to get SubId from somewhere.
3400 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3401 } finally {
3402 Binder.restoreCallingIdentity(identity);
3403 }
Junda Liu84d15a22014-07-02 11:21:04 -07003404 }
3405
3406 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003407 * Get the preferred network type.
3408 * Used for device configuration by some CDMA operators.
3409 *
3410 * @return the preferred network type, defined in RILConstants.java.
3411 */
3412 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003413 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3415 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003416
3417 final long identity = Binder.clearCallingIdentity();
3418 try {
3419 if (DBG) log("getPreferredNetworkType");
3420 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3421 int networkType = (result != null ? result[0] : -1);
3422 if (DBG) log("getPreferredNetworkType: " + networkType);
3423 return networkType;
3424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003427 }
3428
3429 /**
3430 * Set the preferred network type.
3431 * Used for device configuration by some CDMA operators.
3432 *
3433 * @param networkType the preferred network type, defined in RILConstants.java.
3434 * @return true on success; false on any failure.
3435 */
3436 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003437 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3439 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3444 Boolean success = (Boolean) sendRequest(
3445 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3446 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3447 if (success) {
3448 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3449 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3450 }
3451 return success;
3452 } finally {
3453 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003454 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003455 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003456
3457 /**
Junda Liu475951f2014-11-07 16:45:03 -08003458 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3459 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3460 * tethering.
3461 *
3462 * @return 0: Not required. 1: required. 2: Not set.
3463 * @hide
3464 */
3465 @Override
3466 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003467 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003468
3469 final long identity = Binder.clearCallingIdentity();
3470 try {
3471 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3472 Settings.Global.TETHER_DUN_REQUIRED, 2);
3473 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3474 // config_tether_apndata.
3475 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3476 dunRequired = 1;
3477 }
3478 return dunRequired;
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003481 }
Junda Liu475951f2014-11-07 16:45:03 -08003482 }
3483
3484 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003485 * Set mobile data enabled
3486 * Used by the user through settings etc to turn on/off mobile data
3487 *
3488 * @param enable {@code true} turn turn data on, else {@code false}
3489 */
3490 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003491 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3493 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003494
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 int phoneId = mSubscriptionController.getPhoneId(subId);
3498 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3499 Phone phone = PhoneFactory.getPhone(phoneId);
3500 if (phone != null) {
3501 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3502 phone.setUserDataEnabled(enable);
3503 } else {
3504 loge("setUserDataEnabled: no phone for subId=" + subId);
3505 }
3506 } finally {
3507 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003508 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003509 }
3510
3511 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003512 * Get the user enabled state of Mobile Data.
3513 *
3514 * TODO: remove and use isUserDataEnabled.
3515 * This can't be removed now because some vendor codes
3516 * calls through ITelephony directly while they should
3517 * use TelephonyManager.
3518 *
3519 * @return true on enabled
3520 */
3521 @Override
3522 public boolean getDataEnabled(int subId) {
3523 return isUserDataEnabled(subId);
3524 }
3525
3526 /**
3527 * Get whether mobile data is enabled per user setting.
3528 *
3529 * There are other factors deciding whether mobile data is actually enabled, but they are
3530 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003531 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003532 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003533 *
3534 * @return {@code true} if data is enabled else {@code false}
3535 */
3536 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003537 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003538 try {
3539 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3540 null);
3541 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3543 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003544 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 int phoneId = mSubscriptionController.getPhoneId(subId);
3549 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3550 Phone phone = PhoneFactory.getPhone(phoneId);
3551 if (phone != null) {
3552 boolean retVal = phone.isUserDataEnabled();
3553 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3554 return retVal;
3555 } else {
3556 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3557 return false;
3558 }
3559 } finally {
3560 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003561 }
3562 }
3563
3564 /**
3565 * Get whether mobile data is enabled.
3566 *
3567 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3568 * whether mobile data is actually enabled.
3569 *
3570 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3571 *
3572 * @return {@code true} if data is enabled else {@code false}
3573 */
3574 @Override
3575 public boolean isDataEnabled(int subId) {
3576 try {
3577 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3578 null);
3579 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3581 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003582 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003583
3584 final long identity = Binder.clearCallingIdentity();
3585 try {
3586 int phoneId = mSubscriptionController.getPhoneId(subId);
3587 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3588 Phone phone = PhoneFactory.getPhone(phoneId);
3589 if (phone != null) {
3590 boolean retVal = phone.isDataEnabled();
3591 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3592 return retVal;
3593 } else {
3594 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3595 return false;
3596 }
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003599 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003600 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003601
3602 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003603 public int getCarrierPrivilegeStatus(int subId) {
3604 final Phone phone = getPhone(subId);
3605 if (phone == null) {
3606 loge("getCarrierPrivilegeStatus: Invalid subId");
3607 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3608 }
3609 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003610 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003611 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003612 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3613 }
3614 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003615 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003616 }
Junda Liu29340342014-07-10 15:23:27 -07003617
3618 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003619 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3620 final Phone phone = getPhone(subId);
3621 if (phone == null) {
3622 loge("getCarrierPrivilegeStatus: Invalid subId");
3623 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3624 }
3625 UiccProfile profile =
3626 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3627 if (profile == null) {
3628 loge("getCarrierPrivilegeStatus: No UICC");
3629 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3630 }
3631 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3632 }
3633
3634 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003635 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003636 if (TextUtils.isEmpty(pkgName))
3637 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003638 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003639 if (card == null) {
3640 loge("checkCarrierPrivilegesForPackage: No UICC");
3641 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3642 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003643 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3644 }
3645
3646 @Override
3647 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003648 if (TextUtils.isEmpty(pkgName))
3649 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003650 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3651 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3652 UiccCard card = UiccController.getInstance().getUiccCard(i);
3653 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003654 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003655 continue;
3656 }
3657
3658 result = card.getCarrierPrivilegeStatus(
3659 mPhone.getContext().getPackageManager(), pkgName);
3660 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3661 break;
3662 }
3663 }
3664
3665 return result;
Junda Liu29340342014-07-10 15:23:27 -07003666 }
Derek Tan89e89d42014-07-08 17:00:10 -07003667
3668 @Override
Junda Liue64de782015-04-16 17:19:16 -07003669 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3670 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3671 loge("phoneId " + phoneId + " is not valid.");
3672 return null;
3673 }
3674 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003675 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003676 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003677 return null ;
3678 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003679 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003680 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003681 }
3682
Amith Yamasani6e118872016-02-19 12:53:51 -08003683 @Override
3684 public List<String> getPackagesWithCarrierPrivileges() {
3685 PackageManager pm = mPhone.getContext().getPackageManager();
3686 List<String> privilegedPackages = new ArrayList<>();
3687 List<PackageInfo> packages = null;
3688 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3689 UiccCard card = UiccController.getInstance().getUiccCard(i);
3690 if (card == null) {
3691 // No UICC in that slot.
3692 continue;
3693 }
3694 if (card.hasCarrierPrivilegeRules()) {
3695 if (packages == null) {
3696 // Only check packages in user 0 for now
3697 packages = pm.getInstalledPackagesAsUser(
3698 PackageManager.MATCH_DISABLED_COMPONENTS
3699 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3700 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3701 }
3702 for (int p = packages.size() - 1; p >= 0; p--) {
3703 PackageInfo pkgInfo = packages.get(p);
3704 if (pkgInfo != null && pkgInfo.packageName != null
3705 && card.getCarrierPrivilegeStatus(pkgInfo)
3706 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3707 privilegedPackages.add(pkgInfo.packageName);
3708 }
3709 }
3710 }
3711 }
3712 return privilegedPackages;
3713 }
3714
Wink Savilleb564aae2014-10-23 10:18:09 -07003715 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003716 final Phone phone = getPhone(subId);
3717 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003718 if (card == null) {
3719 loge("getIccId: No UICC");
3720 return null;
3721 }
3722 String iccId = card.getIccId();
3723 if (TextUtils.isEmpty(iccId)) {
3724 loge("getIccId: ICC ID is null or empty.");
3725 return null;
3726 }
3727 return iccId;
3728 }
3729
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003730 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003731 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3732 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003733 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3734 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003735
Malcolm Chenaabec062018-02-28 15:00:40 -08003736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 final String iccId = getIccId(subId);
3739 final Phone phone = getPhone(subId);
3740 if (phone == null) {
3741 return false;
3742 }
3743 final String subscriberId = phone.getSubscriberId();
3744
3745 if (DBG_MERGE) {
3746 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3747 + subscriberId + " to " + number);
3748 }
3749
3750 if (TextUtils.isEmpty(iccId)) {
3751 return false;
3752 }
3753
3754 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3755
3756 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3757 if (alphaTag == null) {
3758 editor.remove(alphaTagPrefKey);
3759 } else {
3760 editor.putString(alphaTagPrefKey, alphaTag);
3761 }
3762
3763 // Record both the line number and IMSI for this ICCID, since we need to
3764 // track all merged IMSIs based on line number
3765 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3766 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3767 if (number == null) {
3768 editor.remove(numberPrefKey);
3769 editor.remove(subscriberPrefKey);
3770 } else {
3771 editor.putString(numberPrefKey, number);
3772 editor.putString(subscriberPrefKey, subscriberId);
3773 }
3774
3775 editor.commit();
3776 return true;
3777 } finally {
3778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003779 }
Derek Tan7226c842014-07-02 17:42:23 -07003780 }
3781
3782 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003783 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003784 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003786 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003787 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003788 return null;
3789 }
Derek Tan97ebb422014-09-05 16:55:38 -07003790
Malcolm Chenaabec062018-02-28 15:00:40 -08003791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 String iccId = getIccId(subId);
3794 if (iccId != null) {
3795 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3796 if (DBG_MERGE) {
3797 log("getLine1NumberForDisplay returning "
3798 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3799 }
3800 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003801 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003802 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3803 return null;
3804 } finally {
3805 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003806 }
Derek Tan7226c842014-07-02 17:42:23 -07003807 }
3808
3809 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003810 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003812 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003813 return null;
3814 }
Derek Tan97ebb422014-09-05 16:55:38 -07003815
Malcolm Chenaabec062018-02-28 15:00:40 -08003816 final long identity = Binder.clearCallingIdentity();
3817 try {
3818 String iccId = getIccId(subId);
3819 if (iccId != null) {
3820 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3821 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3822 }
3823 return null;
3824 } finally {
3825 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003826 }
Derek Tan7226c842014-07-02 17:42:23 -07003827 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003828
3829 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003830 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003831 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3832 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003834 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3835 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003836 return null;
3837 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003838
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003839 final long identity = Binder.clearCallingIdentity();
3840 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003841 final Context context = mPhone.getContext();
3842 final TelephonyManager tele = TelephonyManager.from(context);
3843 final SubscriptionManager sub = SubscriptionManager.from(context);
3844
3845 // Figure out what subscribers are currently active
3846 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3847 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3848 // the process, where TelephonyManager was instantiated.
3849 // Otherwise AppOps check will fail.
3850
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003851 final int[] subIds = sub.getActiveSubscriptionIdList();
3852 for (int subId : subIds) {
3853 activeSubscriberIds.add(tele.getSubscriberId(subId));
3854 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003855
3856 // First pass, find a number override for an active subscriber
3857 String mergeNumber = null;
3858 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3859 for (String key : prefs.keySet()) {
3860 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3861 final String subscriberId = (String) prefs.get(key);
3862 if (activeSubscriberIds.contains(subscriberId)) {
3863 final String iccId = key.substring(
3864 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3865 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3866 mergeNumber = (String) prefs.get(numberKey);
3867 if (DBG_MERGE) {
3868 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3869 + " for active subscriber " + subscriberId);
3870 }
3871 if (!TextUtils.isEmpty(mergeNumber)) {
3872 break;
3873 }
3874 }
3875 }
3876 }
3877
3878 // Shortcut when no active merged subscribers
3879 if (TextUtils.isEmpty(mergeNumber)) {
3880 return null;
3881 }
3882
3883 // Second pass, find all subscribers under that line override
3884 final ArraySet<String> result = new ArraySet<>();
3885 for (String key : prefs.keySet()) {
3886 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3887 final String number = (String) prefs.get(key);
3888 if (mergeNumber.equals(number)) {
3889 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3890 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3891 final String subscriberId = (String) prefs.get(subscriberKey);
3892 if (!TextUtils.isEmpty(subscriberId)) {
3893 result.add(subscriberId);
3894 }
3895 }
3896 }
3897 }
3898
3899 final String[] resultArray = result.toArray(new String[result.size()]);
3900 Arrays.sort(resultArray);
3901 if (DBG_MERGE) {
3902 Slog.d(LOG_TAG,
3903 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3904 }
3905 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003906 } finally {
3907 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003908 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003909 }
3910
3911 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003912 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003913 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3914 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003915
3916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 final Phone phone = getPhone(subId);
3919 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3920 } finally {
3921 Binder.restoreCallingIdentity(identity);
3922 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003923 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003924
3925 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003926 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003927 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3928 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003929 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003930
3931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 final Phone phone = getPhone(subId);
3934 if (phone == null) {
3935 return false;
3936 }
3937 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3938 cdmaNonRoamingList);
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003941 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003942 }
3943
3944 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003945 @Deprecated
3946 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3947 enforceModifyPermission();
3948
3949 int returnValue = 0;
3950 try {
3951 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3952 if(result.exception == null) {
3953 if (result.result != null) {
3954 byte[] responseData = (byte[])(result.result);
3955 if(responseData.length > oemResp.length) {
3956 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3957 responseData.length + "bytes. Buffer Size is " +
3958 oemResp.length + "bytes.");
3959 }
3960 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3961 returnValue = responseData.length;
3962 }
3963 } else {
3964 CommandException ex = (CommandException) result.exception;
3965 returnValue = ex.getCommandError().ordinal();
3966 if(returnValue > 0) returnValue *= -1;
3967 }
3968 } catch (RuntimeException e) {
3969 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3970 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3971 if(returnValue > 0) returnValue *= -1;
3972 }
3973
3974 return returnValue;
3975 }
3976
3977 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003978 public void setRadioCapability(RadioAccessFamily[] rafs) {
3979 try {
3980 ProxyController.getInstance().setRadioCapability(rafs);
3981 } catch (RuntimeException e) {
3982 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3983 }
3984 }
3985
3986 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003987 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003988 Phone phone = PhoneFactory.getPhone(phoneId);
3989 if (phone == null) {
3990 return RadioAccessFamily.RAF_UNKNOWN;
3991 }
3992 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003994 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003995 return RadioAccessFamily.RAF_UNKNOWN;
3996 }
3997
Malcolm Chenaabec062018-02-28 15:00:40 -08003998 final long identity = Binder.clearCallingIdentity();
3999 try {
4000 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4001 } finally {
4002 Binder.restoreCallingIdentity(identity);
4003 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004004 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004005
4006 @Override
4007 public void enableVideoCalling(boolean enable) {
4008 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004009
4010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4013 } finally {
4014 Binder.restoreCallingIdentity(identity);
4015 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004016 }
4017
4018 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004019 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4021 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4022 return false;
4023 }
Svet Ganovb320e182015-04-16 12:30:10 -07004024
Malcolm Chenaabec062018-02-28 15:00:40 -08004025 final long identity = Binder.clearCallingIdentity();
4026 try {
4027 // Check the user preference and the system-level IMS setting. Even if the user has
4028 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4029 // In the long run, we may instead need to check if there exists a connection service
4030 // which can support video calling.
4031 ImsManager imsManager =
4032 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4033 return imsManager.isVtEnabledByPlatform()
4034 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4035 && imsManager.isVtEnabledByUser();
4036 } finally {
4037 Binder.restoreCallingIdentity(identity);
4038 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004039 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004040
Andrew Leea1239f22015-03-02 17:44:07 -08004041 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004042 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4043 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4044 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4045 return false;
4046 }
4047
4048 final long identity = Binder.clearCallingIdentity();
4049 try {
4050 CarrierConfigManager configManager =
4051 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4052 return configManager.getConfigForSubId(mPhone.getSubId())
4053 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4054 } finally {
4055 Binder.restoreCallingIdentity(identity);
4056 }
Andrew Leea1239f22015-03-02 17:44:07 -08004057 }
4058
4059 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004060 public boolean isWorldPhone(int subId, String callingPackage) {
4061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4062 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4063 return false;
4064 }
4065
4066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 CarrierConfigManager configManager =
4069 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4070 return configManager.getConfigForSubId(mPhone.getSubId())
4071 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
Andrew Leea1239f22015-03-02 17:44:07 -08004075 }
4076
Andrew Lee9431b832015-03-09 18:46:45 -07004077 @Override
4078 public boolean isTtyModeSupported() {
4079 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004080 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004081 }
4082
4083 @Override
4084 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
Andrew Lee9431b832015-03-09 18:46:45 -07004091 }
4092
Hall Liu98187582018-01-22 19:15:32 -08004093 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4097 mPhone.getSubId()).getBoolean(
4098 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4099 boolean isDeviceSupported =
4100 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4101 return isCarrierSupported && isDeviceSupported;
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
4104 }
Hall Liu98187582018-01-22 19:15:32 -08004105 }
4106
Hall Liu3ad5f012018-04-06 16:23:39 -07004107 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 return isRttSupported() && Settings.Secure.getInt(
4111 mPhone.getContext().getContentResolver(),
4112 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004116 }
4117
Sanket Padawe7310cc72015-01-14 09:53:20 -08004118 /**
4119 * Returns the unique device ID of phone, for example, the IMEI for
4120 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4121 *
4122 * <p>Requires Permission:
4123 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4124 */
4125 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004126 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004127 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004128 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004129 return null;
4130 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004131 int subId = phone.getSubId();
4132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4133 mApp, subId, callingPackage, "getDeviceId")) {
4134 return null;
4135 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004136
4137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 return phone.getDeviceId();
4140 } finally {
4141 Binder.restoreCallingIdentity(identity);
4142 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004143 }
4144
Ping Sunc67b7c22016-03-02 19:16:45 +08004145 /**
4146 * {@hide}
4147 * Returns the IMS Registration Status on a particular subid
4148 *
4149 * @param subId
4150 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004151 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004152 Phone phone = getPhone(subId);
4153 if (phone != null) {
4154 return phone.isImsRegistered();
4155 } else {
4156 return false;
4157 }
4158 }
4159
Santos Cordon7a1885b2015-02-03 11:15:19 -08004160 @Override
4161 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004168 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004169
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004170 /**
4171 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004172 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004173 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 Phone phone = getPhone(subId);
4177 if (phone != null) {
4178 return phone.isWifiCallingEnabled();
4179 } else {
4180 return false;
4181 }
4182 } finally {
4183 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004184 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004185 }
4186
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004187 /**
4188 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004189 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004190 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004191 final long identity = Binder.clearCallingIdentity();
4192 try {
4193 Phone phone = getPhone(subId);
4194 if (phone != null) {
4195 return phone.isVolteEnabled();
4196 } else {
4197 return false;
4198 }
4199 } finally {
4200 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004201 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004202 }
Svet Ganovb320e182015-04-16 12:30:10 -07004203
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004204 /**
4205 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004206 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004207 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004208 final long identity = Binder.clearCallingIdentity();
4209 try {
4210 Phone phone = getPhone(subId);
4211 if (phone != null) {
4212 return phone.isVideoEnabled();
4213 } else {
4214 return false;
4215 }
4216 } finally {
4217 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004218 }
4219 }
4220
4221 /**
4222 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4223 * defined in {@link ImsRegistrationImplBase}.
4224 */
4225 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004226 final long identity = Binder.clearCallingIdentity();
4227 try {
4228 Phone phone = getPhone(subId);
4229 if (phone != null) {
4230 return phone.getImsRegistrationTech();
4231 } else {
4232 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4233 }
4234 } finally {
4235 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004236 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004237 }
4238
Stuart Scott8eef64f2015-04-08 15:13:54 -07004239 @Override
4240 public void factoryReset(int subId) {
4241 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004242 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4243 return;
4244 }
4245
Svet Ganovcc087f82015-05-12 20:35:54 -07004246 final long identity = Binder.clearCallingIdentity();
4247 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004248 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4249 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004250 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004251 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004252 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4253 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004254 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004255 }
4256 } finally {
4257 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004258 }
4259 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004260
4261 @Override
4262 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 // We query all subscriptions instead of just the active ones, because
4266 // this might be called early on in the provisioning flow when the
4267 // subscriptions potentially aren't active yet.
4268 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4269 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004270 return null;
4271 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004272
Malcolm Chenaabec062018-02-28 15:00:40 -08004273 // This function may be called very early, say, from the setup wizard, at
4274 // which point we won't have a default subscription set. If that's the case
4275 // we just choose the first, which will be valid in "most cases".
4276 final int defaultSubId = getDefaultSubscription();
4277 SubscriptionInfo info = null;
4278 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4279 info = slist.get(0);
4280 } else {
4281 for (SubscriptionInfo item : slist) {
4282 if (item.getSubscriptionId() == defaultSubId) {
4283 info = item;
4284 break;
4285 }
4286 }
4287
4288 if (info == null) {
4289 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004290 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004291 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004292
Malcolm Chenaabec062018-02-28 15:00:40 -08004293 // Try and fetch the locale from the carrier properties or from the SIM language
4294 // preferences (EF-PL and EF-LI)...
4295 final int mcc = info.getMcc();
4296 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4297 String simLanguage = null;
4298 if (defaultPhone != null) {
4299 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4300 if (localeFromDefaultSim != null) {
4301 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4302 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4303 return localeFromDefaultSim.toLanguageTag();
4304 } else {
4305 simLanguage = localeFromDefaultSim.getLanguage();
4306 }
4307 }
4308 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004309
Malcolm Chenaabec062018-02-28 15:00:40 -08004310 // The SIM language preferences only store a language (e.g. fr = French), not an
4311 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4312 // the SIM and carrier preferences does not include a country we add the country
4313 // determined from the SIM MCC to provide an exact locale.
4314 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4315 simLanguage);
4316 if (mccLocale != null) {
4317 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4318 return mccLocale.toLanguageTag();
4319 }
4320
4321 if (DBG) log("No locale found - returning null");
4322 return null;
4323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004326 }
4327
4328 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004329 return mSubscriptionController.getAllSubInfoList(
4330 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004331 }
4332
Malcolm Chenaabec062018-02-28 15:00:40 -08004333 /**
4334 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4335 */
4336 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4337 return mSubscriptionController.getActiveSubscriptionInfoList(
4338 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004339 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004340
Chenjie Yu1ba97252018-01-11 18:16:20 -08004341 private final ModemActivityInfo mLastModemActivityInfo =
4342 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4343
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004344 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004345 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4346 * representing the state of the modem.
4347 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004348 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4349 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004350 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004351 */
4352 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004353 public void requestModemActivityInfo(ResultReceiver result) {
4354 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08004355 ModemActivityInfo ret = null;
Adam Lesinski903a54c2016-04-11 14:49:52 -07004356
Malcolm Chenaabec062018-02-28 15:00:40 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004359 synchronized (mLastModemActivityInfo) {
4360 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
4361 null);
4362 if (info != null) {
4363 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4364 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4365 mergedTxTimeMs[i] =
4366 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
4367 }
4368 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4369 mLastModemActivityInfo.setSleepTimeMillis(
4370 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
4371 mLastModemActivityInfo.setIdleTimeMillis(
4372 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4373 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4374 mLastModemActivityInfo.setRxTimeMillis(
4375 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4376 mLastModemActivityInfo.setEnergyUsed(
4377 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004378 }
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004379 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4380 mLastModemActivityInfo.getSleepTimeMillis(),
4381 mLastModemActivityInfo.getIdleTimeMillis(),
4382 mLastModemActivityInfo.getTxTimeMillis(),
4383 mLastModemActivityInfo.getRxTimeMillis(),
4384 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004385 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004386 Bundle bundle = new Bundle();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07004387 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Malcolm Chenaabec062018-02-28 15:00:40 -08004388 result.send(0, bundle);
4389 } finally {
4390 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004391 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004392 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004393
4394 /**
4395 * {@hide}
4396 * Returns the service state information on specified subscription.
4397 */
4398 @Override
4399 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004401 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004402 return null;
4403 }
4404
Malcolm Chenaabec062018-02-28 15:00:40 -08004405 final long identity = Binder.clearCallingIdentity();
4406 try {
4407 final Phone phone = getPhone(subId);
4408 if (phone == null) {
4409 return null;
4410 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004411
Malcolm Chenaabec062018-02-28 15:00:40 -08004412 return phone.getServiceState();
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
4415 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004416 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004417
4418 /**
4419 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4420 *
4421 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4422 * voicemail ringtone.
4423 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4424 * PhoneAccount.
4425 */
4426 @Override
4427 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004428 final long identity = Binder.clearCallingIdentity();
4429 try {
4430 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4431 if (phone == null) {
4432 phone = mPhone;
4433 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004434
Malcolm Chenaabec062018-02-28 15:00:40 -08004435 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4436 } finally {
4437 Binder.restoreCallingIdentity(identity);
4438 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004439 }
4440
4441 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004442 * Sets the per-account voicemail ringtone.
4443 *
4444 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4445 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4446 *
4447 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4448 * voicemail ringtone.
4449 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4450 * PhoneAccount.
4451 */
4452 @Override
4453 public void setVoicemailRingtoneUri(String callingPackage,
4454 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4456 if (!TextUtils.equals(callingPackage,
4457 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4459 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4460 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004461 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004462
4463 final long identity = Binder.clearCallingIdentity();
4464 try {
4465 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4466 if (phone == null) {
4467 phone = mPhone;
4468 }
4469 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4470 } finally {
4471 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004472 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004473 }
4474
4475 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004476 * Returns whether vibration is set for voicemail notification in Phone settings.
4477 *
4478 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4479 * voicemail vibration setting.
4480 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4481 */
4482 @Override
4483 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004484 final long identity = Binder.clearCallingIdentity();
4485 try {
4486 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4487 if (phone == null) {
4488 phone = mPhone;
4489 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004490
Malcolm Chenaabec062018-02-28 15:00:40 -08004491 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004495 }
4496
Youhan Wange64578a2016-05-02 15:32:42 -07004497 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004498 * Sets the per-account voicemail vibration.
4499 *
4500 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4501 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4502 *
4503 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4504 * voicemail vibration setting.
4505 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4506 * specific PhoneAccount.
4507 */
4508 @Override
4509 public void setVoicemailVibrationEnabled(String callingPackage,
4510 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4511 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4512 if (!TextUtils.equals(callingPackage,
4513 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4515 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4516 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004517 }
4518
Malcolm Chenaabec062018-02-28 15:00:40 -08004519 final long identity = Binder.clearCallingIdentity();
4520 try {
4521 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4522 if (phone == null) {
4523 phone = mPhone;
4524 }
4525 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4526 } finally {
4527 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004528 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004529 }
4530
4531 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004532 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4533 *
4534 * @throws SecurityException if the caller does not have the required permission
4535 */
4536 private void enforceReadPrivilegedPermission() {
4537 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4538 null);
4539 }
4540
4541 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004542 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4543 * permission.
4544 *
4545 * @throws SecurityException if the caller does not have the required permission
4546 */
4547 private void enforceSendSmsPermission() {
4548 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4549 }
4550
4551 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004552 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004553 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004554 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004555 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004556 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004557 final long identity = Binder.clearCallingIdentity();
4558 try {
4559 ComponentName componentName =
4560 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4561 if (componentName == null) {
4562 throw new SecurityException(
4563 "Caller not current active visual voicemail package[null]");
4564 }
4565 String vvmPackage = componentName.getPackageName();
4566 if (!callingPackage.equals(vvmPackage)) {
4567 throw new SecurityException("Caller not current active visual voicemail package["
4568 + vvmPackage + "]");
4569 }
4570 } finally {
4571 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004572 }
4573 }
4574
4575 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004576 * Return the application ID for the app type.
4577 *
4578 * @param subId the subscription ID that this request applies to.
4579 * @param appType the uicc app type.
4580 * @return Application ID for specificied app type, or null if no uicc.
4581 */
4582 @Override
4583 public String getAidForAppType(int subId, int appType) {
4584 enforceReadPrivilegedPermission();
4585 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004586
4587 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004588 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004589 if (phone == null) {
4590 return null;
4591 }
4592 String aid = null;
4593 try {
4594 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4595 .getApplicationByType(appType).getAid();
4596 } catch (Exception e) {
4597 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4598 }
4599 return aid;
4600 } finally {
4601 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004602 }
Youhan Wange64578a2016-05-02 15:32:42 -07004603 }
4604
Youhan Wang4001d252016-05-11 10:29:41 -07004605 /**
4606 * Return the Electronic Serial Number.
4607 *
4608 * @param subId the subscription ID that this request applies to.
4609 * @return ESN or null if error.
4610 */
4611 @Override
4612 public String getEsn(int subId) {
4613 enforceReadPrivilegedPermission();
4614 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004615
4616 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004617 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004618 if (phone == null) {
4619 return null;
4620 }
4621 String esn = null;
4622 try {
4623 esn = phone.getEsn();
4624 } catch (Exception e) {
4625 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4626 }
4627 return esn;
4628 } finally {
4629 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004630 }
Youhan Wang4001d252016-05-11 10:29:41 -07004631 }
4632
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004633 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004634 * Return the Preferred Roaming List Version.
4635 *
4636 * @param subId the subscription ID that this request applies to.
4637 * @return PRLVersion or null if error.
4638 */
4639 @Override
4640 public String getCdmaPrlVersion(int subId) {
4641 enforceReadPrivilegedPermission();
4642 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004643
4644 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004645 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004646 if (phone == null) {
4647 return null;
4648 }
4649 String cdmaPrlVersion = null;
4650 try {
4651 cdmaPrlVersion = phone.getCdmaPrlVersion();
4652 } catch (Exception e) {
4653 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4654 }
4655 return cdmaPrlVersion;
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004658 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004659 }
4660
4661 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004662 * Get snapshot of Telephony histograms
4663 * @return List of Telephony histograms
4664 * @hide
4665 */
4666 @Override
4667 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4669 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004670
4671 final long identity = Binder.clearCallingIdentity();
4672 try {
4673 return RIL.getTelephonyRILTimingHistograms();
4674 } finally {
4675 Binder.restoreCallingIdentity(identity);
4676 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004677 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004678
4679 /**
4680 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004681 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004682 * Require system privileges. In the future we may add this to carrier APIs.
4683 *
4684 * @return The number of carriers set successfully, should match length of carriers
4685 */
4686 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004687 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004688 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004689
Meng Wang9b7c4e92017-02-17 11:41:27 -08004690 if (carriers == null) {
4691 throw new NullPointerException("carriers cannot be null");
4692 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004693
Malcolm Chenaabec062018-02-28 15:00:40 -08004694 final long identity = Binder.clearCallingIdentity();
4695 try {
4696 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4697 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4698 return retVal[0];
4699 } finally {
4700 Binder.restoreCallingIdentity(identity);
4701 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004702 }
4703
4704 /**
4705 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004706 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004707 * Require system privileges. In the future we may add this to carrier APIs.
4708 *
4709 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4710 * means all carriers are allowed.
4711 */
4712 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004713 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004714 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004715
4716 final long identity = Binder.clearCallingIdentity();
4717 try {
4718 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4719 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004723 }
4724
fionaxu59545b42016-05-25 15:53:37 -07004725 /**
4726 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4727 * @param subId the subscription ID that this action applies to.
4728 * @param enabled control enable or disable metered apns.
4729 * {@hide}
4730 */
4731 @Override
4732 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4733 enforceModifyPermission();
4734 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004735
4736 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004737 if (phone == null) {
4738 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4739 return;
4740 }
4741 try {
4742 phone.carrierActionSetMeteredApnsEnabled(enabled);
4743 } catch (Exception e) {
4744 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004745 } finally {
4746 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004747 }
4748 }
4749
4750 /**
4751 * Action set from carrier signalling broadcast receivers to enable/disable radio
4752 * @param subId the subscription ID that this action applies to.
4753 * @param enabled control enable or disable radio.
4754 * {@hide}
4755 */
4756 @Override
4757 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4758 enforceModifyPermission();
4759 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004760
4761 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004762 if (phone == null) {
4763 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4764 return;
4765 }
4766 try {
4767 phone.carrierActionSetRadioEnabled(enabled);
4768 } catch (Exception e) {
4769 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004770 } finally {
4771 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004772 }
4773 }
4774
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004775 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004776 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4777 * network status based on which carrier apps could apply actions accordingly,
4778 * enable/disable default url handler for example.
4779 *
4780 * @param subId the subscription ID that this action applies to.
4781 * @param report control start/stop reporting the default network status.
4782 * {@hide}
4783 */
4784 @Override
4785 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4786 enforceModifyPermission();
4787 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004788
4789 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004790 if (phone == null) {
4791 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4792 return;
4793 }
4794 try {
4795 phone.carrierActionReportDefaultNetworkStatus(report);
4796 } catch (Exception e) {
4797 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004798 } finally {
4799 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004800 }
4801 }
4802
4803 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004804 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4805 * bug report is being generated.
4806 */
4807 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004808 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004809 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4810 != PackageManager.PERMISSION_GRANTED) {
4811 writer.println("Permission Denial: can't dump Phone from pid="
4812 + Binder.getCallingPid()
4813 + ", uid=" + Binder.getCallingUid()
4814 + "without permission "
4815 + android.Manifest.permission.DUMP);
4816 return;
4817 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004818 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004819 }
Jack Yueb89b242016-06-22 13:27:47 -07004820
Brad Ebingerdac2f002018-04-03 15:17:52 -07004821 @Override
4822 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4823 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4824 throws RemoteException {
4825 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4826 }
4827
Jack Yueb89b242016-06-22 13:27:47 -07004828 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004829 * Get aggregated video call data usage since boot.
4830 *
4831 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4832 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004833 * {@hide}
4834 */
4835 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004836 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004837 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4838 null);
4839
Malcolm Chenaabec062018-02-28 15:00:40 -08004840 final long identity = Binder.clearCallingIdentity();
4841 try {
4842 // NetworkStatsService keeps tracking the active network interface and identity. It
4843 // records the delta with the corresponding network identity.
4844 // We just return the total video call data usage snapshot since boot.
4845 Phone phone = getPhone(subId);
4846 if (phone != null) {
4847 return phone.getVtDataUsage(perUidStats);
4848 }
4849 return null;
4850 } finally {
4851 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004852 }
Jack Yueb89b242016-06-22 13:27:47 -07004853 }
Jack Yu75ab2952016-07-08 14:29:33 -07004854
4855 /**
4856 * Policy control of data connection. Usually used when data limit is passed.
4857 * @param enabled True if enabling the data, otherwise disabling.
4858 * @param subId Subscription index
4859 * {@hide}
4860 */
4861 @Override
4862 public void setPolicyDataEnabled(boolean enabled, int subId) {
4863 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004864
4865 final long identity = Binder.clearCallingIdentity();
4866 try {
4867 Phone phone = getPhone(subId);
4868 if (phone != null) {
4869 phone.setPolicyDataEnabled(enabled);
4870 }
4871 } finally {
4872 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004873 }
4874 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004875
4876 /**
4877 * Get Client request stats
4878 * @return List of Client Request Stats
4879 * @hide
4880 */
4881 @Override
4882 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004884 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004885 return null;
4886 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004887 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004888
Malcolm Chenaabec062018-02-28 15:00:40 -08004889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 if (phone != null) {
4892 return phone.getClientRequestStats();
4893 }
4894
4895 return null;
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
4898 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004899 }
4900
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004901 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004902 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004903 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004904 }
Jack Yueb4124c2017-02-16 15:32:43 -08004905
4906 /**
Grace Chen70990072017-03-24 17:21:30 -07004907 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004908 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004909 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004910 * @param state State of SIM (power down, power up, pass through)
4911 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4912 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4913 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004914 *
4915 **/
4916 @Override
Grace Chen70990072017-03-24 17:21:30 -07004917 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004918 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004919 Phone phone = PhoneFactory.getPhone(slotIndex);
4920
Malcolm Chenaabec062018-02-28 15:00:40 -08004921 final long identity = Binder.clearCallingIdentity();
4922 try {
4923 if (phone != null) {
4924 phone.setSimPowerState(state);
4925 }
4926 } finally {
4927 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004928 }
4929 }
Shuo Qiandd210312017-04-12 22:11:33 +00004930
Tyler Gunn65d45c22017-06-05 11:22:26 -07004931 private boolean isUssdApiAllowed(int subId) {
4932 CarrierConfigManager configManager =
4933 (CarrierConfigManager) mPhone.getContext().getSystemService(
4934 Context.CARRIER_CONFIG_SERVICE);
4935 if (configManager == null) {
4936 return false;
4937 }
4938 PersistableBundle pb = configManager.getConfigForSubId(subId);
4939 if (pb == null) {
4940 return false;
4941 }
4942 return pb.getBoolean(
4943 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4944 }
4945
Shuo Qiandd210312017-04-12 22:11:33 +00004946 /**
4947 * Check if phone is in emergency callback mode
4948 * @return true if phone is in emergency callback mode
4949 * @param subId sub id
4950 */
goneil9c5f4872017-12-05 14:07:56 -08004951 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004952 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004953 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004954 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004955
4956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 if (phone != null) {
4959 return phone.isInEcm();
4960 } else {
4961 return false;
4962 }
4963 } finally {
4964 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004965 }
4966 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004967
4968 /**
4969 * Get the current signal strength information for the given subscription.
4970 * Because this information is not updated when the device is in a low power state
4971 * it should not be relied-upon to be current.
4972 * @param subId Subscription index
4973 * @return the most recent cached signal strength info from the modem
4974 */
4975 @Override
4976 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 Phone p = getPhone(subId);
4980 if (p == null) {
4981 return null;
4982 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004983
Malcolm Chenaabec062018-02-28 15:00:40 -08004984 return p.getSignalStrength();
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004988 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004989
Pengquan Meng9140aec2018-08-22 14:49:57 -07004990 /**
4991 * Checks if data roaming is enabled on the subscription with id {@code subId}.
4992 *
4993 * <p>Requires one of the following permissions:
4994 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
4995 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
4996 * privileges.
4997 *
4998 * @param subId subscription id
4999 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
5000 * {@code false}.
5001 */
5002 @Override
5003 public boolean isDataRoamingEnabled(int subId) {
5004 try {
5005 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5006 null);
5007 } catch (Exception e) {
5008 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
5009 mApp, subId, "isDataRoamingEnabled");
5010 }
5011
5012 Phone phone = getPhone(subId);
5013 return phone != null ? phone.getDataRoamingEnabled() : false;
5014 }
5015
5016
5017 /**
5018 * Enables/Disables the data roaming on the subscription with id {@code subId}.
5019 *
5020 * <p> Requires permission:
5021 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
5022 * privileges.
5023 *
5024 * @param subId subscription id
5025 * @param isEnabled {@code true} means enable, {@code false} means disable.
5026 */
5027 @Override
5028 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
5029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5030 mApp, subId, "setDataRoamingEbaled");
5031
5032 Phone phone = getPhone(subId);
5033 if (phone != null) {
5034 phone.setDataRoamingEnabled(isEnabled);
5035 }
5036 }
5037
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005038 @Override
5039 public UiccSlotInfo[] getUiccSlotsInfo() {
5040 enforceReadPrivilegedPermission();
5041
Malcolm Chenaabec062018-02-28 15:00:40 -08005042 final long identity = Binder.clearCallingIdentity();
5043 try {
5044 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005045 if (slots == null) {
5046 Rlog.i(LOG_TAG, "slots is null.");
5047 return null;
5048 }
5049
Malcolm Chenaabec062018-02-28 15:00:40 -08005050 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5051 for (int i = 0; i < slots.length; i++) {
5052 UiccSlot slot = slots[i];
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005053 if (slot == null) {
5054 continue;
5055 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005056
Malcolm Chen1cc36b62018-07-30 14:42:47 -07005057 String cardId;
5058 UiccCard card = slot.getUiccCard();
5059 if (card != null) {
5060 cardId = card.getCardId();
5061 } else {
5062 cardId = slot.getIccId();
5063 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005064
Malcolm Chenaabec062018-02-28 15:00:40 -08005065 int cardState = 0;
5066 switch (slot.getCardState()) {
5067 case CARDSTATE_ABSENT:
5068 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5069 break;
5070 case CARDSTATE_PRESENT:
5071 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5072 break;
5073 case CARDSTATE_ERROR:
5074 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5075 break;
5076 case CARDSTATE_RESTRICTED:
5077 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5078 break;
5079 default:
5080 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005081
Malcolm Chenaabec062018-02-28 15:00:40 -08005082 }
5083
5084 infos[i] = new UiccSlotInfo(
5085 slot.isActive(),
5086 slot.isEuicc(),
5087 cardId,
5088 cardState,
5089 slot.getPhoneId(),
5090 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005091 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005092 return infos;
5093 } finally {
5094 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005095 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005096 }
5097
5098 @Override
5099 public boolean switchSlots(int[] physicalSlots) {
5100 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005101
5102 final long identity = Binder.clearCallingIdentity();
5103 try {
5104 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5105 } finally {
5106 Binder.restoreCallingIdentity(identity);
5107 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005108 }
Jack Yu4c988042018-02-27 15:30:01 -08005109
5110 @Override
5111 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5112 enforceModifyPermission();
5113 final Phone phone = getPhone(subId);
5114 if (phone == null) {
5115 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5116 return;
5117 }
5118
Malcolm Chenaabec062018-02-28 15:00:40 -08005119 final long identity = Binder.clearCallingIdentity();
5120 try {
5121 phone.setRadioIndicationUpdateMode(filters, mode);
5122 } finally {
5123 Binder.restoreCallingIdentity(identity);
5124 }
Jack Yu4c988042018-02-27 15:30:01 -08005125 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005126
5127 /**
goneil47ffb6e2018-04-06 15:40:58 -07005128 * A test API to reload the UICC profile.
5129 *
5130 * <p>Requires that the calling app has permission
5131 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5132 * @hide
5133 */
5134 @Override
5135 public void refreshUiccProfile(int subId) {
5136 enforceModifyPermission();
5137
5138 final long identity = Binder.clearCallingIdentity();
5139 try {
5140 Phone phone = getPhone(subId);
5141 if (phone == null) {
5142 return;
5143 }
5144 UiccCard uiccCard = phone.getUiccCard();
5145 if (uiccCard == null) {
5146 return;
5147 }
5148 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5149 if (uiccProfile == null) {
5150 return;
5151 }
5152 uiccProfile.refresh();
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
5156 }
5157
5158 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005159 * Returns false if the mobile data is disabled by default, otherwise return true.
5160 */
5161 private boolean getDefaultDataEnabled() {
5162 return "true".equalsIgnoreCase(
5163 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5164 }
5165
5166 /**
5167 * Returns true if the data roaming is enabled by default, i.e the system property
5168 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5169 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5170 */
5171 private boolean getDefaultDataRoamingEnabled(int subId) {
5172 final CarrierConfigManager configMgr = (CarrierConfigManager)
5173 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5174 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5175 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5176 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5177 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5178 return isDataRoamingEnabled;
5179 }
5180
5181 /**
5182 * Returns the default network type for the given {@code subId}, if the default network type is
5183 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5184 */
5185 private int getDefaultNetworkType(int subId) {
5186 return Integer.parseInt(
5187 TelephonyManager.getTelephonyProperty(
5188 mSubscriptionController.getPhoneId(subId),
5189 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5190 String.valueOf(Phone.PREFERRED_NT_MODE)));
5191 }
fionaxua13278b2018-03-21 00:08:13 -07005192
5193 @Override
5194 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5195 gid1, String gid2, String plmn, String spn) {
5196 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005197
5198 final long identity = Binder.clearCallingIdentity();
5199 try {
5200 final Phone phone = getPhone(subId);
5201 if (phone == null) {
5202 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5203 return;
5204 }
5205 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005208 }
fionaxua13278b2018-03-21 00:08:13 -07005209 }
5210
5211 @Override
5212 public int getCarrierIdListVersion(int subId) {
5213 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005214
5215 final long identity = Binder.clearCallingIdentity();
5216 try {
5217 final Phone phone = getPhone(subId);
5218 if (phone == null) {
5219 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5220 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5221 }
5222 return phone.getCarrierIdListVersion();
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005225 }
fionaxua13278b2018-03-21 00:08:13 -07005226 }
Malcolm Chenf144d942018-08-14 16:00:53 -07005227
5228 @Override
5229 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
5230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5231 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
5232 return -1;
5233 }
5234
5235 final long identity = Binder.clearCallingIdentity();
5236 try {
5237 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
5240 }
5241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005242}