blob: 7e344f1b0611b89f6e4ec63b7d878ead68bc5d7e [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;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070059import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080060import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070061import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080062import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070063import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070064import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070065import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080067import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070068import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080069import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080070import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070071import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000073import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070074import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070075import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080076import android.telephony.ims.aidl.IImsConfig;
77import android.telephony.ims.aidl.IImsMmTelFeature;
78import android.telephony.ims.aidl.IImsRcsFeature;
79import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080080import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080082import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080083import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080086import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080087
Andrew Lee312e8172014-10-23 17:01:36 -070088import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080089import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070091import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070092import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070093import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070094import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080097import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -070098import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +010099import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700100import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700101import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800103import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700105import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700106import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700107import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700108import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700109import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800110import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800111import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700112import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700113import com.android.internal.telephony.uicc.IccIoResult;
114import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800115import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700116import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800117import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800119import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000120import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700121import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800122import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700123import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800124import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700125import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700126import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800127
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700128import java.io.FileDescriptor;
129import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800133import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100134import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800135import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136
137/**
138 * Implementation of the ITelephony interface.
139 */
Santos Cordon117fee72014-05-16 17:56:12 -0700140public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141 private static final String LOG_TAG = "PhoneInterfaceManager";
142 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
143 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800144 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145
146 // Message codes used with mMainThreadHandler
147 private static final int CMD_HANDLE_PIN_MMI = 1;
148 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
149 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
150 private static final int CMD_ANSWER_RINGING_CALL = 4;
151 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700152 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
153 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154 private static final int CMD_OPEN_CHANNEL = 9;
155 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
156 private static final int CMD_CLOSE_CHANNEL = 11;
157 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800158 private static final int CMD_NV_READ_ITEM = 13;
159 private static final int EVENT_NV_READ_ITEM_DONE = 14;
160 private static final int CMD_NV_WRITE_ITEM = 15;
161 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
162 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
163 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
164 private static final int CMD_NV_RESET_CONFIG = 19;
165 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800166 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
167 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
168 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
169 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800170 private static final int CMD_SEND_ENVELOPE = 25;
171 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000172 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
173 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700174 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
175 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
176 private static final int CMD_EXCHANGE_SIM_IO = 31;
177 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800178 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
179 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700180 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
181 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700182 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
183 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700184 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
185 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
186 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
187 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700188 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
189 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
190 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
191 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700192 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800193 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
194 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000195 private static final int CMD_SWITCH_SLOTS = 50;
196 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800198 // Parameters of select command.
199 private static final int SELECT_COMMAND = 0xA4;
200 private static final int SELECT_P1 = 0x04;
201 private static final int SELECT_P2 = 0;
202 private static final int SELECT_P3 = 0x10;
203
Pengquan Meng85728fb2018-03-12 16:31:21 -0700204 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
205 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
206 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
207
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208 /** The singleton instance. */
209 private static PhoneInterfaceManager sInstance;
210
Wink Saville3ab207e2014-11-20 13:07:20 -0800211 private PhoneGlobals mApp;
212 private Phone mPhone;
213 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700214 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800215 private AppOpsManager mAppOps;
216 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800217 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800218 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219
Derek Tan97ebb422014-09-05 16:55:38 -0700220 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
221 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700223
Derek Tan740e1672017-06-27 14:56:27 -0700224 // The AID of ISD-R.
225 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
226
yinxub1bed742017-04-17 11:45:04 -0700227 private NetworkScanRequestTracker mNetworkScanRequestTracker;
228
Derek Tan89e89d42014-07-08 17:00:10 -0700229 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700230 * A request object to use for transmitting data to an ICC.
231 */
232 private static final class IccAPDUArgument {
233 public int channel, cla, command, p1, p2, p3;
234 public String data;
235
236 public IccAPDUArgument(int channel, int cla, int command,
237 int p1, int p2, int p3, String data) {
238 this.channel = channel;
239 this.cla = cla;
240 this.command = command;
241 this.p1 = p1;
242 this.p2 = p2;
243 this.p3 = p3;
244 this.data = data;
245 }
246 }
247
248 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700249 * A request object to use for transmitting data to an ICC.
250 */
251 private static final class ManualNetworkSelectionArgument {
252 public OperatorInfo operatorInfo;
253 public boolean persistSelection;
254
255 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
256 this.operatorInfo = operatorInfo;
257 this.persistSelection = persistSelection;
258 }
259 }
260
261 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
263 * request after sending. The main thread will notify the request when it is complete.
264 */
265 private static final class MainThreadRequest {
266 /** The argument to use for the request */
267 public Object argument;
268 /** The result of the request that is run on the main thread */
269 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800270 // The subscriber id that this request applies to. Defaults to
271 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
272 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273
274 public MainThreadRequest(Object argument) {
275 this.argument = argument;
276 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800277
278 public MainThreadRequest(Object argument, Integer subId) {
279 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800280 if (subId != null) {
281 this.subId = subId;
282 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284 }
285
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800286 private static final class IncomingThirdPartyCallArgs {
287 public final ComponentName component;
288 public final String callId;
289 public final String callerDisplayName;
290
291 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
292 String callerDisplayName) {
293 this.component = component;
294 this.callId = callId;
295 this.callerDisplayName = callerDisplayName;
296 }
297 }
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /**
300 * A handler that processes messages on the main thread in the phone process. Since many
301 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
302 * inbound binder threads to the main thread in the phone process. The Binder thread
303 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
304 * on, which will be notified when the operation completes and will contain the result of the
305 * request.
306 *
307 * <p>If a MainThreadRequest object is provided in the msg.obj field,
308 * note that request.result must be set to something non-null for the calling thread to
309 * unblock.
310 */
311 private final class MainThreadHandler extends Handler {
312 @Override
313 public void handleMessage(Message msg) {
314 MainThreadRequest request;
315 Message onCompleted;
316 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800317 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700318 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319
320 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700321 case CMD_HANDLE_USSD_REQUEST: {
322 request = (MainThreadRequest) msg.obj;
323 final Phone phone = getPhoneFromRequest(request);
324 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
325 String ussdRequest = ussdObject.first;
326 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700327
328 if (!isUssdApiAllowed(request.subId)) {
329 // Carrier does not support use of this API, return failure.
330 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
331 UssdResponse response = new UssdResponse(ussdRequest, null);
332 Bundle returnData = new Bundle();
333 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
334 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
335
336 request.result = true;
337 synchronized (request) {
338 request.notifyAll();
339 }
340 return;
341 }
342
Tyler Gunn52dcf772017-04-26 11:30:31 -0700343 try {
344 request.result = phone != null ?
345 phone.handleUssdRequest(ussdRequest, wrappedCallback)
346 : false;
347 } catch (CallStateException cse) {
348 request.result = false;
349 }
pkanwar32d516d2016-10-14 19:37:38 -0700350 // Wake up the requesting thread
351 synchronized (request) {
352 request.notifyAll();
353 }
354 break;
355 }
356
Yorke Lee716f67e2015-06-17 15:39:16 -0700357 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700359 final Phone phone = getPhoneFromRequest(request);
360 request.result = phone != null ?
361 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
362 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 // Wake up the requesting thread
364 synchronized (request) {
365 request.notifyAll();
366 }
367 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
370 case CMD_HANDLE_NEIGHBORING_CELL:
371 request = (MainThreadRequest) msg.obj;
372 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
373 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700374 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 break;
376
377 case EVENT_NEIGHBORING_CELL_DONE:
378 ar = (AsyncResult) msg.obj;
379 request = (MainThreadRequest) ar.userObj;
380 if (ar.exception == null && ar.result != null) {
381 request.result = ar.result;
382 } else {
383 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800384 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 }
386 // Wake up the requesting thread
387 synchronized (request) {
388 request.notifyAll();
389 }
390 break;
391
392 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700393 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800394 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700395 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800396 request.result = ""; // dummy result for notifying the waiting thread
397 // Wake up the requesting thread
398 synchronized (request) {
399 request.notifyAll();
400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 break;
402
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 case CMD_END_CALL:
404 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800405 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700406 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700407 Phone phone = getPhone(end_subId);
408 if (phone == null) {
409 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
410 break;
411 }
412 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
414 // CDMA: If the user presses the Power button we treat it as
415 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700416 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
418 // GSM: End the call as per the Phone state
419 hungUp = PhoneUtils.hangup(mCM);
420 } else {
421 throw new IllegalStateException("Unexpected phone type: " + phoneType);
422 }
423 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
424 request.result = hungUp;
425 // Wake up the requesting thread
426 synchronized (request) {
427 request.notifyAll();
428 }
429 break;
430
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800434 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700435 if (uiccCard == null) {
436 loge("iccTransmitApduLogicalChannel: No UICC");
437 request.result = new IccIoResult(0x6F, 0, (byte[])null);
438 synchronized (request) {
439 request.notifyAll();
440 }
441 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
443 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700444 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 iccArgument.channel, iccArgument.cla, iccArgument.command,
446 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700448 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 break;
450
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 ar = (AsyncResult) msg.obj;
453 request = (MainThreadRequest) ar.userObj;
454 if (ar.exception == null && ar.result != null) {
455 request.result = ar.result;
456 } else {
457 request.result = new IccIoResult(0x6F, 0, (byte[])null);
458 if (ar.result == null) {
459 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800460 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800462 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 } else {
464 loge("iccTransmitApduLogicalChannel: Unknown exception");
465 }
466 }
467 synchronized (request) {
468 request.notifyAll();
469 }
470 break;
471
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
473 request = (MainThreadRequest) msg.obj;
474 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800475 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 if (uiccCard == null) {
477 loge("iccTransmitApduBasicChannel: No UICC");
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
479 synchronized (request) {
480 request.notifyAll();
481 }
482 } else {
483 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
484 request);
485 uiccCard.iccTransmitApduBasicChannel(
486 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
487 iccArgument.p3, iccArgument.data, onCompleted);
488 }
489 break;
490
491 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
492 ar = (AsyncResult) msg.obj;
493 request = (MainThreadRequest) ar.userObj;
494 if (ar.exception == null && ar.result != null) {
495 request.result = ar.result;
496 } else {
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
498 if (ar.result == null) {
499 loge("iccTransmitApduBasicChannel: Empty response");
500 } else if (ar.exception instanceof CommandException) {
501 loge("iccTransmitApduBasicChannel: CommandException: " +
502 ar.exception);
503 } else {
504 loge("iccTransmitApduBasicChannel: Unknown exception");
505 }
506 }
507 synchronized (request) {
508 request.notifyAll();
509 }
510 break;
511
512 case CMD_EXCHANGE_SIM_IO:
513 request = (MainThreadRequest) msg.obj;
514 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800515 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 if (uiccCard == null) {
517 loge("iccExchangeSimIO: No UICC");
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 synchronized (request) {
520 request.notifyAll();
521 }
522 } else {
523 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
524 request);
525 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
526 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
527 iccArgument.data, onCompleted);
528 }
529 break;
530
531 case EVENT_EXCHANGE_SIM_IO_DONE:
532 ar = (AsyncResult) msg.obj;
533 request = (MainThreadRequest) ar.userObj;
534 if (ar.exception == null && ar.result != null) {
535 request.result = ar.result;
536 } else {
537 request.result = new IccIoResult(0x6f, 0, (byte[])null);
538 }
539 synchronized (request) {
540 request.notifyAll();
541 }
542 break;
543
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 case CMD_SEND_ENVELOPE:
545 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800546 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 if (uiccCard == null) {
548 loge("sendEnvelopeWithStatus: No UICC");
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 synchronized (request) {
551 request.notifyAll();
552 }
553 } else {
554 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
555 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
556 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 break;
558
559 case EVENT_SEND_ENVELOPE_DONE:
560 ar = (AsyncResult) msg.obj;
561 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700562 if (ar.exception == null && ar.result != null) {
563 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
566 if (ar.result == null) {
567 loge("sendEnvelopeWithStatus: Empty response");
568 } else if (ar.exception instanceof CommandException) {
569 loge("sendEnvelopeWithStatus: CommandException: " +
570 ar.exception);
571 } else {
572 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
573 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800574 }
575 synchronized (request) {
576 request.notifyAll();
577 }
578 break;
579
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 case CMD_OPEN_CHANNEL:
581 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800582 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800583 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 if (uiccCard == null) {
585 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800586 request.result = new IccOpenLogicalChannelResponse(-1,
587 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 synchronized (request) {
589 request.notifyAll();
590 }
591 } else {
592 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800593 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
594 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 break;
597
598 case EVENT_OPEN_CHANNEL_DONE:
599 ar = (AsyncResult) msg.obj;
600 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 int[] result = (int[]) ar.result;
604 int channelId = result[0];
605 byte[] selectResponse = null;
606 if (result.length > 1) {
607 selectResponse = new byte[result.length - 1];
608 for (int i = 1; i < result.length; ++i) {
609 selectResponse[i - 1] = (byte) result[i];
610 }
611 }
612 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.result == null) {
616 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 if (ar.exception != null) {
619 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
620 }
621
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700623 if (ar.exception instanceof CommandException) {
624 CommandException.Error error =
625 ((CommandException) (ar.exception)).getCommandError();
626 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700627 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700628 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700629 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 }
631 }
632 openChannelResp = new IccOpenLogicalChannelResponse(
633 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700635 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 synchronized (request) {
637 request.notifyAll();
638 }
639 break;
640
641 case CMD_CLOSE_CHANNEL:
642 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800643 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 if (uiccCard == null) {
645 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900646 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 synchronized (request) {
648 request.notifyAll();
649 }
650 } else {
651 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
652 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 break;
655
656 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800657 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
658 break;
659
660 case CMD_NV_READ_ITEM:
661 request = (MainThreadRequest) msg.obj;
662 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
663 mPhone.nvReadItem((Integer) request.argument, onCompleted);
664 break;
665
666 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 ar = (AsyncResult) msg.obj;
668 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800669 if (ar.exception == null && ar.result != null) {
670 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800672 request.result = "";
673 if (ar.result == null) {
674 loge("nvReadItem: Empty response");
675 } else if (ar.exception instanceof CommandException) {
676 loge("nvReadItem: CommandException: " +
677 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800679 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 }
681 }
682 synchronized (request) {
683 request.notifyAll();
684 }
685 break;
686
Jake Hambye994d462014-02-03 13:10:13 -0800687 case CMD_NV_WRITE_ITEM:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
690 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
691 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
692 break;
693
694 case EVENT_NV_WRITE_ITEM_DONE:
695 handleNullReturnEvent(msg, "nvWriteItem");
696 break;
697
698 case CMD_NV_WRITE_CDMA_PRL:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
701 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
702 break;
703
704 case EVENT_NV_WRITE_CDMA_PRL_DONE:
705 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
706 break;
707
708 case CMD_NV_RESET_CONFIG:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
711 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
712 break;
713
714 case EVENT_NV_RESET_CONFIG_DONE:
715 handleNullReturnEvent(msg, "nvResetConfig");
716 break;
717
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 case CMD_GET_PREFERRED_NETWORK_TYPE:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700721 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 break;
723
724 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
727 if (ar.exception == null && ar.result != null) {
728 request.result = ar.result; // Integer
729 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800730 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 if (ar.result == null) {
732 loge("getPreferredNetworkType: Empty response");
733 } else if (ar.exception instanceof CommandException) {
734 loge("getPreferredNetworkType: CommandException: " +
735 ar.exception);
736 } else {
737 loge("getPreferredNetworkType: Unknown exception");
738 }
739 }
740 synchronized (request) {
741 request.notifyAll();
742 }
743 break;
744
745 case CMD_SET_PREFERRED_NETWORK_TYPE:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
748 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700749 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
753 handleNullReturnEvent(msg, "setPreferredNetworkType");
754 break;
755
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000756 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
757 request = (MainThreadRequest)msg.obj;
758 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
759 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
760 break;
761
762 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
763 ar = (AsyncResult)msg.obj;
764 request = (MainThreadRequest)ar.userObj;
765 request.result = ar;
766 synchronized (request) {
767 request.notifyAll();
768 }
769 break;
770
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800771 case CMD_SET_VOICEMAIL_NUMBER:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
774 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800775 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
776 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800777 break;
778
779 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
780 handleNullReturnEvent(msg, "setVoicemailNumber");
781 break;
782
Stuart Scott54788802015-03-30 13:18:01 -0700783 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
784 request = (MainThreadRequest) msg.obj;
785 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
786 request);
787 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
788 break;
789
790 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
791 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
792 break;
793
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 case CMD_PERFORM_NETWORK_SCAN:
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
797 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
798 break;
799
800 case EVENT_PERFORM_NETWORK_SCAN_DONE:
801 ar = (AsyncResult) msg.obj;
802 request = (MainThreadRequest) ar.userObj;
803 CellNetworkScanResult cellScanResult;
804 if (ar.exception == null && ar.result != null) {
805 cellScanResult = new CellNetworkScanResult(
806 CellNetworkScanResult.STATUS_SUCCESS,
807 (List<OperatorInfo>) ar.result);
808 } else {
809 if (ar.result == null) {
810 loge("getCellNetworkScanResults: Empty response");
811 }
812 if (ar.exception != null) {
813 loge("getCellNetworkScanResults: Exception: " + ar.exception);
814 }
815 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
816 if (ar.exception instanceof CommandException) {
817 CommandException.Error error =
818 ((CommandException) (ar.exception)).getCommandError();
819 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
820 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
821 } else if (error == CommandException.Error.GENERIC_FAILURE) {
822 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
823 }
824 }
825 cellScanResult = new CellNetworkScanResult(errorCode, null);
826 }
827 request.result = cellScanResult;
828 synchronized (request) {
829 request.notifyAll();
830 }
831 break;
832
833 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
834 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700835 ManualNetworkSelectionArgument selArg =
836 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
838 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700839 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
840 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
843 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
844 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
845 break;
846
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700847 case CMD_GET_MODEM_ACTIVITY_INFO:
848 request = (MainThreadRequest) msg.obj;
849 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700850 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700851 break;
852
853 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result;
858 } else {
859 if (ar.result == null) {
860 loge("queryModemActivityInfo: Empty response");
861 } else if (ar.exception instanceof CommandException) {
862 loge("queryModemActivityInfo: CommandException: " +
863 ar.exception);
864 } else {
865 loge("queryModemActivityInfo: Unknown exception");
866 }
867 }
Amit Mahajand4766222016-01-28 15:28:28 -0800868 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
869 if (request.result == null) {
870 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
871 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700872 synchronized (request) {
873 request.notifyAll();
874 }
875 break;
876
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 case CMD_SET_ALLOWED_CARRIERS:
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
880 mPhone.setAllowedCarriers(
881 (List<CarrierIdentifier>) request.argument,
882 onCompleted);
883 break;
884
885 case EVENT_SET_ALLOWED_CARRIERS_DONE:
886 ar = (AsyncResult) msg.obj;
887 request = (MainThreadRequest) ar.userObj;
888 if (ar.exception == null && ar.result != null) {
889 request.result = ar.result;
890 } else {
891 if (ar.result == null) {
892 loge("setAllowedCarriers: Empty response");
893 } else if (ar.exception instanceof CommandException) {
894 loge("setAllowedCarriers: CommandException: " +
895 ar.exception);
896 } else {
897 loge("setAllowedCarriers: Unknown exception");
898 }
899 }
900 // Result cannot be null. Return -1 on error.
901 if (request.result == null) {
902 request.result = new int[]{-1};
903 }
904 synchronized (request) {
905 request.notifyAll();
906 }
907 break;
908
909 case CMD_GET_ALLOWED_CARRIERS:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
912 mPhone.getAllowedCarriers(onCompleted);
913 break;
914
915 case EVENT_GET_ALLOWED_CARRIERS_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null && ar.result != null) {
919 request.result = ar.result;
920 } else {
921 if (ar.result == null) {
922 loge("getAllowedCarriers: Empty response");
923 } else if (ar.exception instanceof CommandException) {
924 loge("getAllowedCarriers: CommandException: " +
925 ar.exception);
926 } else {
927 loge("getAllowedCarriers: Unknown exception");
928 }
929 }
930 // Result cannot be null. Return empty list of CarrierIdentifier.
931 if (request.result == null) {
932 request.result = new ArrayList<CarrierIdentifier>(0);
933 }
934 synchronized (request) {
935 request.notifyAll();
936 }
937 break;
938
Nathan Haroldb3014052017-01-25 15:57:32 -0800939 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
940 ar = (AsyncResult) msg.obj;
941 request = (MainThreadRequest) ar.userObj;
942 if (ar.exception == null && ar.result != null) {
943 request.result = ar.result;
944 } else {
945 request.result = new IllegalArgumentException(
946 "Failed to retrieve Forbidden Plmns");
947 if (ar.result == null) {
948 loge("getForbiddenPlmns: Empty response");
949 } else {
950 loge("getForbiddenPlmns: Unknown exception");
951 }
952 }
953 synchronized (request) {
954 request.notifyAll();
955 }
956 break;
957
958 case CMD_GET_FORBIDDEN_PLMNS:
959 request = (MainThreadRequest) msg.obj;
960 uiccCard = getUiccCardFromRequest(request);
961 if (uiccCard == null) {
962 loge("getForbiddenPlmns() UiccCard is null");
963 request.result = new IllegalArgumentException(
964 "getForbiddenPlmns() UiccCard is null");
965 synchronized (request) {
966 request.notifyAll();
967 }
968 break;
969 }
970 Integer appType = (Integer) request.argument;
971 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
972 if (uiccApp == null) {
973 loge("getForbiddenPlmns() no app with specified type -- "
974 + appType);
975 request.result = new IllegalArgumentException("Failed to get UICC App");
976 synchronized (request) {
977 request.notifyAll();
978 }
979 break;
980 } else {
981 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
982 + " specified type -- " + appType);
983 }
984 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
985 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
986 onCompleted);
987 break;
988
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000989 case CMD_SWITCH_SLOTS:
990 request = (MainThreadRequest) msg.obj;
991 int[] physicalSlots = (int[]) request.argument;
992 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
993 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
994 break;
995
996 case EVENT_SWITCH_SLOTS_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 request.result = (ar.exception == null);
1000 synchronized (request) {
1001 request.notifyAll();
1002 }
1003 break;
1004
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001005 default:
1006 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1007 break;
1008 }
1009 }
Jake Hambye994d462014-02-03 13:10:13 -08001010
1011 private void handleNullReturnEvent(Message msg, String command) {
1012 AsyncResult ar = (AsyncResult) msg.obj;
1013 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1014 if (ar.exception == null) {
1015 request.result = true;
1016 } else {
1017 request.result = false;
1018 if (ar.exception instanceof CommandException) {
1019 loge(command + ": CommandException: " + ar.exception);
1020 } else {
1021 loge(command + ": Unknown exception");
1022 }
1023 }
1024 synchronized (request) {
1025 request.notifyAll();
1026 }
1027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001028 }
1029
1030 /**
1031 * Posts the specified command to be executed on the main thread,
1032 * waits for the request to complete, and returns the result.
1033 * @see #sendRequestAsync
1034 */
1035 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001036 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001037 }
1038
1039 /**
1040 * Posts the specified command to be executed on the main thread,
1041 * waits for the request to complete, and returns the result.
1042 * @see #sendRequestAsync
1043 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001044 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1046 throw new RuntimeException("This method will deadlock if called from the main thread.");
1047 }
1048
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001049 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001050 Message msg = mMainThreadHandler.obtainMessage(command, request);
1051 msg.sendToTarget();
1052
1053 // Wait for the request to complete
1054 synchronized (request) {
1055 while (request.result == null) {
1056 try {
1057 request.wait();
1058 } catch (InterruptedException e) {
1059 // Do nothing, go back and wait until the request is complete
1060 }
1061 }
1062 }
1063 return request.result;
1064 }
1065
1066 /**
1067 * Asynchronous ("fire and forget") version of sendRequest():
1068 * Posts the specified command to be executed on the main thread, and
1069 * returns immediately.
1070 * @see #sendRequest
1071 */
1072 private void sendRequestAsync(int command) {
1073 mMainThreadHandler.sendEmptyMessage(command);
1074 }
1075
1076 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001077 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1078 * @see {@link #sendRequest(int,Object)}
1079 */
1080 private void sendRequestAsync(int command, Object argument) {
1081 MainThreadRequest request = new MainThreadRequest(argument);
1082 Message msg = mMainThreadHandler.obtainMessage(command, request);
1083 msg.sendToTarget();
1084 }
1085
1086 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 * Initialize the singleton PhoneInterfaceManager instance.
1088 * This is only done once, at startup, from PhoneApp.onCreate().
1089 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001090 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 synchronized (PhoneInterfaceManager.class) {
1092 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001093 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001094 } else {
1095 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1096 }
1097 return sInstance;
1098 }
1099 }
1100
1101 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001102 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 mApp = app;
1104 mPhone = phone;
1105 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001106 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001107 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1108 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001109 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001110 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001111 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001112 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001113
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 publish();
1115 }
1116
1117 private void publish() {
1118 if (DBG) log("publish: " + this);
1119
1120 ServiceManager.addService("phone", this);
1121 }
1122
Stuart Scott584921c2015-01-15 17:10:34 -08001123 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001124 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1125 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001126 }
1127
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001128 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1129 Phone phone = getPhoneFromRequest(request);
1130 return phone == null ? null :
1131 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1132 }
1133
Wink Saville36469e72014-06-11 15:17:00 -07001134 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001135 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001136 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 //
1139 // Implementation of the ITelephony interface.
1140 //
1141
1142 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001143 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001144 }
1145
Wink Savilleb564aae2014-10-23 10:18:09 -07001146 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001147 if (DBG) log("dial: " + number);
1148 // No permission check needed here: This is just a wrapper around the
1149 // ACTION_DIAL intent, which is available to any app since it puts up
1150 // the UI before it does anything.
1151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001152 final long identity = Binder.clearCallingIdentity();
1153 try {
1154 String url = createTelUrl(number);
1155 if (url == null) {
1156 return;
1157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001159 // PENDING: should we just silently fail if phone is offhook or ringing?
1160 PhoneConstants.State state = mCM.getState(subId);
1161 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1162 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1163 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1164 mApp.startActivity(intent);
1165 }
1166 } finally {
1167 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 }
1169 }
1170
1171 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001172 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001173 }
1174
Wink Savilleb564aae2014-10-23 10:18:09 -07001175 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001176 if (DBG) log("call: " + number);
1177
1178 // This is just a wrapper around the ACTION_CALL intent, but we still
1179 // need to do a permission check since we're calling startActivity()
1180 // from the context of the phone app.
1181 enforceCallPermission();
1182
1183 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1184 != AppOpsManager.MODE_ALLOWED) {
1185 return;
1186 }
1187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001188 final long identity = Binder.clearCallingIdentity();
1189 try {
1190 String url = createTelUrl(number);
1191 if (url == null) {
1192 return;
1193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001195 boolean isValid = false;
1196 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1197 if (slist != null) {
1198 for (SubscriptionInfo subInfoRecord : slist) {
1199 if (subInfoRecord.getSubscriptionId() == subId) {
1200 isValid = true;
1201 break;
1202 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001203 }
Wink Saville08874612014-08-31 19:19:58 -07001204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001205 if (!isValid) {
1206 return;
1207 }
Wink Saville08874612014-08-31 19:19:58 -07001208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001209 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1210 intent.putExtra(SUBSCRIPTION_KEY, subId);
1211 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1212 mApp.startActivity(intent);
1213 } finally {
1214 Binder.restoreCallingIdentity(identity);
1215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 }
1217
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 /**
1219 * End a call based on call state
1220 * @return true is a call was ended
1221 */
1222 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001223 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001224 }
1225
1226 /**
1227 * End a call based on the call state of the subId
1228 * @return true is a call was ended
1229 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001230 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001231 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1232 != PackageManager.PERMISSION_GRANTED) {
1233 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1234 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1235 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001237
1238 final long identity = Binder.clearCallingIdentity();
1239 try {
1240 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1241 } finally {
1242 Binder.restoreCallingIdentity(identity);
1243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 }
1245
1246 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001247 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001248 }
1249
Wink Savilleb564aae2014-10-23 10:18:09 -07001250 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 if (DBG) log("answerRingingCall...");
1252 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1253 // but that can probably wait till the big TelephonyManager API overhaul.
1254 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1255 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001256
1257 final long identity = Binder.clearCallingIdentity();
1258 try {
1259 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1260 } finally {
1261 Binder.restoreCallingIdentity(identity);
1262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 }
1264
1265 /**
1266 * Make the actual telephony calls to implement answerRingingCall().
1267 * This should only be called from the main thread of the Phone app.
1268 * @see #answerRingingCall
1269 *
1270 * TODO: it would be nice to return true if we answered the call, or
1271 * false if there wasn't actually a ringing incoming call, or some
1272 * other error occurred. (In other words, pass back the return value
1273 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1274 * But that would require calling this method via sendRequest() rather
1275 * than sendRequestAsync(), and right now we don't actually *need* that
1276 * return value, so let's just return void for now.
1277 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001278 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001279 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001281 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1282 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 if (hasActiveCall && hasHoldingCall) {
1284 // Both lines are in use!
1285 // TODO: provide a flag to let the caller specify what
1286 // policy to use if both lines are in use. (The current
1287 // behavior is hardwired to "answer incoming, end ongoing",
1288 // which is how the CALL button is specced to behave.)
1289 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1290 return;
1291 } else {
1292 // answerCall() will automatically hold the current active
1293 // call, if there is one.
1294 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1295 return;
1296 }
1297 } else {
1298 // No call was ringing.
1299 return;
1300 }
1301 }
1302
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001304 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001306 public void silenceRinger() {
1307 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 }
1309
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001310 @Override
1311 public boolean isOffhook(String callingPackage) {
1312 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001313 }
1314
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001315 @Override
1316 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001318 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001319 return false;
1320 }
1321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001322 final long identity = Binder.clearCallingIdentity();
1323 try {
1324 final Phone phone = getPhone(subId);
1325 if (phone != null) {
1326 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1327 } else {
1328 return false;
1329 }
1330 } finally {
1331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 }
1334
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001335 @Override
1336 public boolean isRinging(String callingPackage) {
1337 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001338 }
1339
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001340 @Override
1341 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001343 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001344 return false;
1345 }
1346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001347 final long identity = Binder.clearCallingIdentity();
1348 try {
1349 final Phone phone = getPhone(subId);
1350 if (phone != null) {
1351 return (phone.getState() == PhoneConstants.State.RINGING);
1352 } else {
1353 return false;
1354 }
1355 } finally {
1356 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358 }
1359
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001360 @Override
1361 public boolean isIdle(String callingPackage) {
1362 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001363 }
1364
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001365 @Override
1366 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001368 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001369 return false;
1370 }
1371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001372 final long identity = Binder.clearCallingIdentity();
1373 try {
1374 final Phone phone = getPhone(subId);
1375 if (phone != null) {
1376 return (phone.getState() == PhoneConstants.State.IDLE);
1377 } else {
1378 return false;
1379 }
1380 } finally {
1381 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 }
1384
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001386 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001387 }
1388
Wink Savilleb564aae2014-10-23 10:18:09 -07001389 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001390 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001391 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1392 }
1393
1394 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001395 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001396 }
1397
Wink Savilleb564aae2014-10-23 10:18:09 -07001398 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001400 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1401 }
1402
1403 /** {@hide} */
1404 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001405 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001406 }
1407
Wink Savilleb564aae2014-10-23 10:18:09 -07001408 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001410
1411 final long identity = Binder.clearCallingIdentity();
1412 try {
1413 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1414 checkSimPin.start();
1415 return checkSimPin.unlockSim(null, pin);
1416 } finally {
1417 Binder.restoreCallingIdentity(identity);
1418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 }
1420
Wink Saville9de0f752013-10-22 19:04:03 -07001421 /** {@hide} */
1422 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001423 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
1425
Wink Savilleb564aae2014-10-23 10:18:09 -07001426 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001428
1429 final long identity = Binder.clearCallingIdentity();
1430 try {
1431 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1432 checkSimPuk.start();
1433 return checkSimPuk.unlockSim(puk, pin);
1434 } finally {
1435 Binder.restoreCallingIdentity(identity);
1436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001437 }
1438
1439 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001440 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441 * a synchronous one.
1442 */
1443 private static class UnlockSim extends Thread {
1444
1445 private final IccCard mSimCard;
1446
1447 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001448 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1449 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450
1451 // For replies from SimCard interface
1452 private Handler mHandler;
1453
1454 // For async handler to identify request type
1455 private static final int SUPPLY_PIN_COMPLETE = 100;
1456
1457 public UnlockSim(IccCard simCard) {
1458 mSimCard = simCard;
1459 }
1460
1461 @Override
1462 public void run() {
1463 Looper.prepare();
1464 synchronized (UnlockSim.this) {
1465 mHandler = new Handler() {
1466 @Override
1467 public void handleMessage(Message msg) {
1468 AsyncResult ar = (AsyncResult) msg.obj;
1469 switch (msg.what) {
1470 case SUPPLY_PIN_COMPLETE:
1471 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1472 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001473 mRetryCount = msg.arg1;
1474 if (ar.exception != null) {
1475 if (ar.exception instanceof CommandException &&
1476 ((CommandException)(ar.exception)).getCommandError()
1477 == CommandException.Error.PASSWORD_INCORRECT) {
1478 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1479 } else {
1480 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1481 }
1482 } else {
1483 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485 mDone = true;
1486 UnlockSim.this.notifyAll();
1487 }
1488 break;
1489 }
1490 }
1491 };
1492 UnlockSim.this.notifyAll();
1493 }
1494 Looper.loop();
1495 }
1496
1497 /*
1498 * Use PIN or PUK to unlock SIM card
1499 *
1500 * If PUK is null, unlock SIM card with PIN
1501 *
1502 * If PUK is not null, unlock SIM card with PUK and set PIN code
1503 */
Wink Saville9de0f752013-10-22 19:04:03 -07001504 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505
1506 while (mHandler == null) {
1507 try {
1508 wait();
1509 } catch (InterruptedException e) {
1510 Thread.currentThread().interrupt();
1511 }
1512 }
1513 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1514
1515 if (puk == null) {
1516 mSimCard.supplyPin(pin, callback);
1517 } else {
1518 mSimCard.supplyPuk(puk, pin, callback);
1519 }
1520
1521 while (!mDone) {
1522 try {
1523 Log.d(LOG_TAG, "wait for done");
1524 wait();
1525 } catch (InterruptedException e) {
1526 // Restore the interrupted status
1527 Thread.currentThread().interrupt();
1528 }
1529 }
1530 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001531 int[] resultArray = new int[2];
1532 resultArray[0] = mResult;
1533 resultArray[1] = mRetryCount;
1534 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 }
1536 }
1537
1538 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001539 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001540
1541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 // No permission check needed here: this call is harmless, and it's
1545 // needed for the ServiceState.requestStateUpdate() call (which is
1546 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001547 final long identity = Binder.clearCallingIdentity();
1548 try {
1549 final Phone phone = getPhone(subId);
1550 if (phone != null) {
1551 phone.updateServiceLocation();
1552 }
1553 } finally {
1554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001558 @Override
1559 public boolean isRadioOn(String callingPackage) {
1560 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001561 }
1562
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001563 @Override
1564 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001566 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001567 return false;
1568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001569
1570 final long identity = Binder.clearCallingIdentity();
1571 try {
1572 return isRadioOnForSubscriber(subId);
1573 } finally {
1574 Binder.restoreCallingIdentity(identity);
1575 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001576 }
1577
1578 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001579 final long identity = Binder.clearCallingIdentity();
1580 try {
1581 final Phone phone = getPhone(subId);
1582 if (phone != null) {
1583 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1584 } else {
1585 return false;
1586 }
1587 } finally {
1588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 }
1591
1592 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001593 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 }
Wink Saville36469e72014-06-11 15:17:00 -07001595
Wink Savilleb564aae2014-10-23 10:18:09 -07001596 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001598
1599 final long identity = Binder.clearCallingIdentity();
1600 try {
1601 final Phone phone = getPhone(subId);
1602 if (phone != null) {
1603 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1604 }
1605 } finally {
1606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 }
Wink Saville36469e72014-06-11 15:17:00 -07001608 }
1609
1610 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001611 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001612 }
1613
Wink Savilleb564aae2014-10-23 10:18:09 -07001614 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001615 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001616
1617 final long identity = Binder.clearCallingIdentity();
1618 try {
1619 final Phone phone = getPhone(subId);
1620 if (phone == null) {
1621 return false;
1622 }
1623 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1624 toggleRadioOnOffForSubscriber(subId);
1625 }
1626 return true;
1627 } finally {
1628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 }
Wink Saville36469e72014-06-11 15:17:00 -07001631
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001632 public boolean needMobileRadioShutdown() {
1633 /*
1634 * If any of the Radios are available, it will need to be
1635 * shutdown. So return true if any Radio is available.
1636 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001637 final long identity = Binder.clearCallingIdentity();
1638 try {
1639 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1640 Phone phone = PhoneFactory.getPhone(i);
1641 if (phone != null && phone.isRadioAvailable()) return true;
1642 }
1643 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1644 return false;
1645 } finally {
1646 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001647 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001648 }
1649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001650 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001651 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001652 enforceModifyPermission();
1653
1654 final long identity = Binder.clearCallingIdentity();
1655 try {
1656 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1657 logv("Shutting down Phone " + i);
1658 shutdownRadioUsingPhoneId(i);
1659 }
1660 } finally {
1661 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001662 }
1663 }
1664
1665 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001666 Phone phone = PhoneFactory.getPhone(phoneId);
1667 if (phone != null && phone.isRadioAvailable()) {
1668 phone.shutdownRadio();
1669 }
1670 }
1671
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001673 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001674
1675 final long identity = Binder.clearCallingIdentity();
1676 try {
1677 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1678 if (defaultPhone != null) {
1679 defaultPhone.setRadioPower(turnOn);
1680 return true;
1681 } else {
1682 loge("There's no default phone.");
1683 return false;
1684 }
1685 } finally {
1686 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001687 }
Wink Saville36469e72014-06-11 15:17:00 -07001688 }
1689
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001692
1693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
1697 phone.setRadioPower(turnOn);
1698 return true;
1699 } else {
1700 return false;
1701 }
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
Wink Saville36469e72014-06-11 15:17:00 -07001707 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 public boolean enableDataConnectivity() {
1710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001711
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 int subId = mSubscriptionController.getDefaultDataSubId();
1715 final Phone phone = getPhone(subId);
1716 if (phone != null) {
1717 phone.setUserDataEnabled(true);
1718 return true;
1719 } else {
1720 return false;
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
Wink Saville36469e72014-06-11 15:17:00 -07001727 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 public boolean disableDataConnectivity() {
1730 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001731
1732 final long identity = Binder.clearCallingIdentity();
1733 try {
1734 int subId = mSubscriptionController.getDefaultDataSubId();
1735 final Phone phone = getPhone(subId);
1736 if (phone != null) {
1737 phone.setUserDataEnabled(false);
1738 return true;
1739 } else {
1740 return false;
1741 }
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001748 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 final Phone phone = getPhone(subId);
1752 if (phone != null) {
1753 return phone.isDataAllowed();
1754 } else {
1755 return false;
1756 }
1757 } finally {
1758 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001759 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 }
1761
1762 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001763 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001764 }
1765
pkanwarae03a6b2016-11-06 20:37:09 -08001766 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 enforceCallPermission();
1768
1769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1772 return;
1773 }
1774 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1775 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1776 } finally {
1777 Binder.restoreCallingIdentity(identity);
1778 }
pkanwar32d516d2016-10-14 19:37:38 -07001779 };
1780
Wink Savilleb564aae2014-10-23 10:18:09 -07001781 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001783
1784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1787 return false;
1788 }
1789 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001796 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001797 }
1798
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001799 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001800 final long identity = Binder.clearCallingIdentity();
1801 try {
1802 Phone phone = PhoneFactory.getPhone(slotIndex);
1803 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1804 PhoneConstantConversions.convertCallState(phone.getState());
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
1807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Sanket Padawe356d7632015-06-22 14:03:32 -07001810 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 final long identity = Binder.clearCallingIdentity();
1813 try {
1814 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1815 if (phone != null) {
1816 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1817 } else {
1818 return PhoneConstantConversions.convertDataState(
1819 PhoneConstants.DataState.DISCONNECTED);
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
Sanket Padawe356d7632015-06-22 14:03:32 -07001826 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001828 final long identity = Binder.clearCallingIdentity();
1829 try {
1830 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1831 if (phone != null) {
1832 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1833 } else {
1834 return TelephonyManager.DATA_ACTIVITY_NONE;
1835 }
1836 } finally {
1837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 }
1840
1841 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001842 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001843 mPhone.getContext().getSystemService(AppOpsManager.class)
1844 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001845 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001846 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001847 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001850 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001851 final long identity = Binder.clearCallingIdentity();
1852 try {
1853 if (DBG_LOC) log("getCellLocation: is active user");
1854 Bundle data = new Bundle();
1855 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1856 if (phone == null) {
1857 return null;
1858 }
1859
1860 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1861 return data;
1862 } finally {
1863 Binder.restoreCallingIdentity(identity);
1864 }
Svetoslav64fad262015-04-14 14:35:21 -07001865 }
1866
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001868 public String getNetworkCountryIsoForPhone(int phoneId) {
1869 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1870 // registered cell info, so return a NULL country instead.
1871 final long identity = Binder.clearCallingIdentity();
1872 try {
1873 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001874 // Todo: fix this when we can get the actual cellular network info when the device
1875 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001876 if (TelephonyManager.NETWORK_TYPE_IWLAN
1877 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1878 return "";
1879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 Phone phone = PhoneFactory.getPhone(phoneId);
1881 if (phone != null) {
1882 ServiceStateTracker sst = phone.getServiceStateTracker();
1883 if (sst != null) {
1884 LocaleTracker lt = sst.getLocaleTracker();
1885 if (lt != null) {
1886 return lt.getCurrentCountry();
1887 }
1888 }
1889 }
1890 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001891 } finally {
1892 Binder.restoreCallingIdentity(identity);
1893 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001894 }
1895
1896 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001898 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001902 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 mApp.enforceCallingOrSelfPermission(
1904 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001905
1906 final long identity = Binder.clearCallingIdentity();
1907 try {
1908 final Phone phone = getPhone(subId);
1909 if (phone != null) {
1910 phone.enableLocationUpdates();
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917 @Override
1918 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001919 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001920 }
1921
Sanket Padawe356d7632015-06-22 14:03:32 -07001922 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001923 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 mApp.enforceCallingOrSelfPermission(
1925 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001926
1927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 final Phone phone = getPhone(subId);
1930 if (phone != null) {
1931 phone.disableLocationUpdates();
1932 }
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
1938 @Override
1939 @SuppressWarnings("unchecked")
1940 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001941 mPhone.getContext().getSystemService(AppOpsManager.class)
1942 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001943 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001944 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001945 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
1948 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1949 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1950 return null;
1951 }
Svetoslav64fad262015-04-14 14:35:21 -07001952
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001953 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001955 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001957 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958
1959 final long identity = Binder.clearCallingIdentity();
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001960 try {
1961 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1962 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1963 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1964 } catch (RuntimeException e) {
1965 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001966 } finally {
1967 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001969 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971
1972
1973 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001974 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001975 mPhone.getContext().getSystemService(AppOpsManager.class)
1976 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001977 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001978 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001979 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 }
1981
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001982 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001983 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001984 final long identity = Binder.clearCallingIdentity();
1985 try {
1986 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1987 for (Phone phone : PhoneFactory.getPhones()) {
1988 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1989 if (info != null) cellInfos.addAll(info);
1990 }
1991 return cellInfos;
1992 } finally {
1993 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 }
1995 }
1996
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001997 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001999 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001
2002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 mPhone.setCellInfoListRate(rateInMillis, workSource);
2005 } finally {
2006 Binder.restoreCallingIdentity(identity);
2007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 }
2009
Shishir Agrawala9f32182016-04-12 12:00:16 -07002010 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002011 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002012 Phone phone = PhoneFactory.getPhone(slotIndex);
2013 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002014 return null;
2015 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002016 int subId = phone.getSubId();
2017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2018 mApp, subId, callingPackage, "getImeiForSlot")) {
2019 return null;
2020 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021
2022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 return phone.getImei();
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
2027 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002028 }
2029
2030 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002031 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002032 Phone phone = PhoneFactory.getPhone(slotIndex);
2033 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002034 return null;
2035 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002036 int subId = phone.getSubId();
2037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2038 mApp, subId, callingPackage, "getMeidForSlot")) {
2039 return null;
2040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 return phone.getMeid();
2045 } finally {
2046 Binder.restoreCallingIdentity(identity);
2047 }
Jack Yu2af8d712017-03-15 17:14:14 -07002048 }
2049
2050 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002051 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002052 Phone phone = PhoneFactory.getPhone(slotIndex);
2053 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002054 return null;
2055 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002056 int subId = phone.getSubId();
2057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2058 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2059 return null;
2060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061
2062 final long identity = Binder.clearCallingIdentity();
2063 try {
2064 return phone.getDeviceSvn();
2065 } finally {
2066 Binder.restoreCallingIdentity(identity);
2067 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002068 }
2069
fionaxu43304da2017-11-27 22:51:16 -08002070 @Override
2071 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 final long identity = Binder.clearCallingIdentity();
2073 try {
2074 final Phone phone = getPhone(subId);
2075 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2076 } finally {
2077 Binder.restoreCallingIdentity(identity);
2078 }
fionaxu43304da2017-11-27 22:51:16 -08002079 }
2080
2081 @Override
2082 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002083 final long identity = Binder.clearCallingIdentity();
2084 try {
2085 final Phone phone = getPhone(subId);
2086 return phone == null ? null : phone.getCarrierName();
2087 } finally {
2088 Binder.restoreCallingIdentity(identity);
2089 }
fionaxu43304da2017-11-27 22:51:16 -08002090 }
2091
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002092 //
2093 // Internal helper methods.
2094 //
2095
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002096 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2098 *
2099 * @throws SecurityException if the caller does not have the required permission
2100 */
2101 private void enforceModifyPermission() {
2102 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2103 }
2104
2105 /**
2106 * Make sure the caller has the CALL_PHONE permission.
2107 *
2108 * @throws SecurityException if the caller does not have the required permission
2109 */
2110 private void enforceCallPermission() {
2111 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2112 }
2113
Stuart Scott8eef64f2015-04-08 15:13:54 -07002114 private void enforceConnectivityInternalPermission() {
2115 mApp.enforceCallingOrSelfPermission(
2116 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2117 "ConnectivityService");
2118 }
2119
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 private String createTelUrl(String number) {
2121 if (TextUtils.isEmpty(number)) {
2122 return null;
2123 }
2124
Jake Hambye994d462014-02-03 13:10:13 -08002125 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 }
2127
Ihab Awadf9e92732013-12-05 18:02:52 -08002128 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2130 }
2131
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002132 private static void logv(String msg) {
2133 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2134 }
2135
Ihab Awadf9e92732013-12-05 18:02:52 -08002136 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2138 }
2139
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002140 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002142 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002143 }
2144
Sanket Padawe356d7632015-06-22 14:03:32 -07002145 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002146 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147 final long identity = Binder.clearCallingIdentity();
2148 try {
2149 final Phone phone = PhoneFactory.getPhone(slotIndex);
2150 if (phone == null) {
2151 return PhoneConstants.PHONE_TYPE_NONE;
2152 } else {
2153 return phone.getPhoneType();
2154 }
2155 } finally {
2156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 }
2159
2160 /**
2161 * Returns the CDMA ERI icon index to display
2162 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002163 @Override
2164 public int getCdmaEriIconIndex(String callingPackage) {
2165 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
2167
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002171 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002172 return -1;
2173 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174
2175 final long identity = Binder.clearCallingIdentity();
2176 try {
2177 final Phone phone = getPhone(subId);
2178 if (phone != null) {
2179 return phone.getCdmaEriIconIndex();
2180 } else {
2181 return -1;
2182 }
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 }
2187
2188 /**
2189 * Returns the CDMA ERI icon mode,
2190 * 0 - ON
2191 * 1 - FLASHING
2192 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002193 @Override
2194 public int getCdmaEriIconMode(String callingPackage) {
2195 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002196 }
2197
Sanket Padawe356d7632015-06-22 14:03:32 -07002198 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002199 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002201 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002202 return -1;
2203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002204
2205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 final Phone phone = getPhone(subId);
2208 if (phone != null) {
2209 return phone.getCdmaEriIconMode();
2210 } else {
2211 return -1;
2212 }
2213 } finally {
2214 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 }
2217
2218 /**
2219 * Returns the CDMA ERI text,
2220 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002221 @Override
2222 public String getCdmaEriText(String callingPackage) {
2223 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002224 }
2225
Sanket Padawe356d7632015-06-22 14:03:32 -07002226 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002227 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002229 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 return null;
2231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232
2233 final long identity = Binder.clearCallingIdentity();
2234 try {
2235 final Phone phone = getPhone(subId);
2236 if (phone != null) {
2237 return phone.getCdmaEriText();
2238 } else {
2239 return null;
2240 }
2241 } finally {
2242 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 }
2245
2246 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002247 * Returns the CDMA MDN.
2248 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002250 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2252 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253
2254 final long identity = Binder.clearCallingIdentity();
2255 try {
2256 final Phone phone = getPhone(subId);
2257 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2258 return phone.getLine1Number();
2259 } else {
2260 return null;
2261 }
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002264 }
2265 }
2266
2267 /**
2268 * Returns the CDMA MIN.
2269 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002271 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2273 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002274
2275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 final Phone phone = getPhone(subId);
2278 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2279 return phone.getCdmaMin();
2280 } else {
2281 return null;
2282 }
2283 } finally {
2284 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002285 }
2286 }
2287
2288 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 * Returns true if CDMA provisioning needs to run.
2290 */
2291 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292 final long identity = Binder.clearCallingIdentity();
2293 try {
2294 return mPhone.needsOtaServiceProvisioning();
2295 } finally {
2296 Binder.restoreCallingIdentity(identity);
2297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
2300 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002301 * Sets the voice mail number of a given subId.
2302 */
2303 @Override
2304 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002305 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306
2307 final long identity = Binder.clearCallingIdentity();
2308 try {
2309 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2310 new Pair<String, String>(alphaTag, number), new Integer(subId));
2311 return success;
2312 } finally {
2313 Binder.restoreCallingIdentity(identity);
2314 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002315 }
2316
Ta-wei Yen87c49842016-05-13 21:19:52 -07002317 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002318 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2320 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2321 if (!TextUtils.equals(callingPackage, systemDialer)) {
2322 throw new SecurityException("caller must be system dialer");
2323 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
2327 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2328 if (phoneAccountHandle == null) {
2329 return null;
2330 }
2331 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002334 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002335 }
2336
2337 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002338 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002339 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002341 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002342 return null;
2343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 return RemoteVvmTaskManager
2348 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
2351 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002352 }
2353
2354 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002355 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2356 VisualVoicemailSmsFilterSettings settings) {
2357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002358
2359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2362 mPhone.getContext(), callingPackage, subId, settings);
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
2365 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002366 }
2367
2368 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002369 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2370 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371
2372 final long identity = Binder.clearCallingIdentity();
2373 try {
2374 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2375 mPhone.getContext(), callingPackage, subId);
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
2378 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002379 }
2380
2381 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002382 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2383 String callingPackage, int subId) {
2384 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002385
2386 final long identity = Binder.clearCallingIdentity();
2387 try {
2388 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2389 mPhone.getContext(), callingPackage, subId);
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
2392 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002393 }
2394
2395 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002396 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002397 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398
2399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2402 mPhone.getContext(), subId);
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
2405 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002406 }
2407
2408 @Override
2409 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2410 String number, int port, String text, PendingIntent sentIntent) {
2411 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002412 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002413 enforceSendSmsPermission();
2414 // Make the calls as the phone process.
2415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2418 if (port == 0) {
2419 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2420 sentIntent, null, false);
2421 } else {
2422 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2423 smsManager.sendDataMessageWithSelfPermissions(number, null,
2424 (short) port, data, sentIntent, null);
2425 }
2426 } finally {
2427 Binder.restoreCallingIdentity(identity);
2428 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002429 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002430 /**
fionaxu0152e512016-11-14 13:36:14 -08002431 * Sets the voice activation state of a given subId.
2432 */
2433 @Override
2434 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2436 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 final Phone phone = getPhone(subId);
2441 if (phone != null) {
2442 phone.setVoiceActivationState(activationState);
2443 } else {
2444 loge("setVoiceActivationState fails with invalid subId: " + subId);
2445 }
2446 } finally {
2447 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002448 }
2449 }
2450
2451 /**
2452 * Sets the data activation state of a given subId.
2453 */
2454 @Override
2455 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2457 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002458
2459 final long identity = Binder.clearCallingIdentity();
2460 try {
2461 final Phone phone = getPhone(subId);
2462 if (phone != null) {
2463 phone.setDataActivationState(activationState);
2464 } else {
2465 loge("setVoiceActivationState fails with invalid subId: " + subId);
2466 }
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002469 }
2470 }
2471
2472 /**
2473 * Returns the voice activation state of a given subId.
2474 */
2475 @Override
2476 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002477 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
fionaxu0152e512016-11-14 13:36:14 -08002479 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 if (phone != null) {
2483 return phone.getVoiceActivationState();
2484 } else {
2485 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2486 }
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002489 }
2490 }
2491
2492 /**
2493 * Returns the data activation state of a given subId.
2494 */
2495 @Override
2496 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002497 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498
fionaxu0152e512016-11-14 13:36:14 -08002499 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 if (phone != null) {
2503 return phone.getDataActivationState();
2504 } else {
2505 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002509 }
2510 }
2511
2512 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 * Returns the unread count of voicemails
2514 */
2515 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002516 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002517 }
2518
2519 /**
2520 * Returns the unread count of voicemails for a subId
2521 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002522 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002523 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 final Phone phone = getPhone(subId);
2527 if (phone != null) {
2528 return phone.getVoiceMessageCount();
2529 } else {
2530 return 0;
2531 }
2532 } finally {
2533 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 }
2536
2537 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002538 * returns true, if the device is in a state where both voice and data
2539 * are supported simultaneously. This can change based on location or network condition.
2540 */
2541 @Override
2542 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543 final long identity = Binder.clearCallingIdentity();
2544 try {
2545 final Phone phone = getPhone(subId);
2546 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
2549 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002550 }
2551
2552 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002553 * Send the dialer code if called from the current default dialer or the caller has
2554 * carrier privilege.
2555 * @param inputCode The dialer code to send
2556 */
2557 @Override
2558 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2560 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2561 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002562 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2563 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 mPhone.sendDialerSpecialCode(inputCode);
2569 } finally {
2570 Binder.restoreCallingIdentity(identity);
2571 }
fionaxu235cc5e2017-03-06 22:25:57 -08002572 }
2573
2574 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002575 * Returns the data network type.
2576 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 *
2578 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2579 */
2580 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002581 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 final Phone phone = getPhone(getDefaultSubscription());
2585 if (phone != null) {
2586 return phone.getServiceState().getDataNetworkType();
2587 } else {
2588 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2589 }
2590 } finally {
2591 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002592 }
Wink Saville36469e72014-06-11 15:17:00 -07002593 }
2594
2595 /**
2596 * Returns the network type for a subId
2597 */
2598 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002599 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002600 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002601 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002602 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2603 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(subId);
2608 if (phone != null) {
2609 return phone.getServiceState().getDataNetworkType();
2610 } else {
2611 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2612 }
2613 } finally {
2614 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 }
2617
2618 /**
2619 * Returns the data network type
2620 */
2621 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002622 public int getDataNetworkType(String callingPackage) {
2623 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002624 }
2625
2626 /**
2627 * Returns the data network type for a subId
2628 */
2629 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002632 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002633 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2634 }
2635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 final Phone phone = getPhone(subId);
2639 if (phone != null) {
2640 return phone.getServiceState().getDataNetworkType();
2641 } else {
2642 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2643 }
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648
2649 /**
Wink Saville36469e72014-06-11 15:17:00 -07002650 * Returns the Voice network type for a subId
2651 */
2652 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002653 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002654 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002655 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002656 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2657 }
2658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 final Phone phone = getPhone(subId);
2662 if (phone != null) {
2663 return phone.getServiceState().getVoiceNetworkType();
2664 } else {
2665 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2666 }
2667 } finally {
2668 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 }
2671
2672 /**
2673 * @return true if a ICC card is present
2674 */
2675 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002676 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002677 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2678 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002679 }
2680
2681 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002682 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002683 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002684 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002685 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 final Phone phone = PhoneFactory.getPhone(slotIndex);
2689 if (phone != null) {
2690 return phone.getIccCard().hasIccCard();
2691 } else {
2692 return false;
2693 }
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
2698
2699 /**
2700 * Return if the current radio is LTE on CDMA. This
2701 * is a tri-state return value as for a period of time
2702 * the mode may be unknown.
2703 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002704 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002706 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002708 @Override
2709 public int getLteOnCdmaMode(String callingPackage) {
2710 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002711 }
2712
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002714 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002716 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002717 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2718 }
2719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 final Phone phone = getPhone(subId);
2723 if (phone == null) {
2724 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2725 } else {
2726 return phone.getLteOnCdmaMode();
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002730 }
Wink Saville36469e72014-06-11 15:17:00 -07002731 }
2732
2733 public void setPhone(Phone phone) {
2734 mPhone = phone;
2735 }
2736
2737 /**
2738 * {@hide}
2739 * Returns Default subId, 0 in the case of single standby.
2740 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002741 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002742 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002743 }
2744
Shishir Agrawala9f32182016-04-12 12:00:16 -07002745 private int getSlotForDefaultSubscription() {
2746 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2747 }
2748
Wink Savilleb564aae2014-10-23 10:18:09 -07002749 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002750 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002752
2753 /**
2754 * @see android.telephony.TelephonyManager.WifiCallingChoices
2755 */
2756 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2760 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2761 getWhenToMakeWifiCallsDefaultPreference());
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
2764 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002765 }
2766
2767 /**
2768 * @see android.telephony.TelephonyManager.WifiCallingChoices
2769 */
2770 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2774 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2775 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
2778 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002779 }
2780
Sailesh Nepald1e68152013-12-12 19:08:02 -08002781 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002782 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002783 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002784 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002785
Shishir Agrawal566b7612013-10-28 14:41:00 -07002786 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002787 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2788 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2790 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 final long identity = Binder.clearCallingIdentity();
2794 try {
2795 if (TextUtils.equals(ISDR_AID, aid)) {
2796 // Only allows LPA to open logical channel to ISD-R.
2797 ComponentInfo bestComponent =
2798 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2799 if (bestComponent == null
2800 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2801 loge("The calling package is not allowed to access ISD-R.");
2802 throw new SecurityException(
2803 "The calling package is not allowed to access ISD-R.");
2804 }
Derek Tan740e1672017-06-27 14:56:27 -07002805 }
Derek Tan740e1672017-06-27 14:56:27 -07002806
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 if (DBG) {
2808 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2809 }
2810 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2811 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2812 if (DBG) log("iccOpenLogicalChannel: " + response);
2813 return response;
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002817 }
2818
2819 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002820 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2822 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2827 if (channel < 0) {
2828 return false;
2829 }
2830 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2831 if (DBG) log("iccCloseLogicalChannel: " + success);
2832 return success;
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002835 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002836 }
2837
2838 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002839 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002840 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2842 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 if (DBG) {
2847 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2848 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2849 + p3 + " data=" + data);
2850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 if (channel < 0) {
2853 return "";
2854 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002855
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2857 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2858 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860 // Append the returned status code to the end of the response payload.
2861 String s = Integer.toHexString(
2862 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2863 if (response.payload != null) {
2864 s = IccUtils.bytesToHexString(response.payload) + s;
2865 }
2866 return s;
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002870 }
Jake Hambye994d462014-02-03 13:10:13 -08002871
Evan Charltonc66da362014-05-16 14:06:40 -07002872 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002873 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2874 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002875 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2876 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2882 && TextUtils.equals(ISDR_AID, data)) {
2883 // Only allows LPA to select ISD-R.
2884 ComponentInfo bestComponent =
2885 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2886 if (bestComponent == null
2887 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2888 loge("The calling package is not allowed to select ISD-R.");
2889 throw new SecurityException(
2890 "The calling package is not allowed to select ISD-R.");
2891 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002892 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 if (DBG) {
2895 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2896 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2897 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2900 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2901 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 // Append the returned status code to the end of the response payload.
2904 String s = Integer.toHexString(
2905 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2906 if (response.payload != null) {
2907 s = IccUtils.bytesToHexString(response.payload) + s;
2908 }
2909 return s;
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002912 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002913 }
2914
2915 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002916 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002917 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2919 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 if (DBG) {
2924 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2925 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2926 }
2927
2928 IccIoResult response =
2929 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2930 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2931 subId);
2932
2933 if (DBG) {
2934 log("Exchange SIM_IO [R]" + response);
2935 }
2936
2937 byte[] result = null;
2938 int length = 2;
2939 if (response.payload != null) {
2940 length = 2 + response.payload.length;
2941 result = new byte[length];
2942 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2943 } else {
2944 result = new byte[length];
2945 }
2946
2947 result[length - 1] = (byte) response.sw2;
2948 result[length - 2] = (byte) response.sw1;
2949 return result;
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002952 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002953 }
2954
Nathan Haroldb3014052017-01-25 15:57:32 -08002955 /**
2956 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2957 * on a particular subscription
2958 */
sqianb6e41952018-03-12 14:54:01 -07002959 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2961 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2962 return null;
2963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 if (appType != TelephonyManager.APPTYPE_USIM
2968 && appType != TelephonyManager.APPTYPE_SIM) {
2969 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2970 return null;
2971 }
2972 Object response = sendRequest(
2973 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2974 if (response instanceof String[]) {
2975 return (String[]) response;
2976 }
2977 // Response is an Exception of some kind,
2978 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08002979 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 } finally {
2981 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002982 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002983 }
2984
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002985 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002986 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2988 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002989
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 final long identity = Binder.clearCallingIdentity();
2991 try {
2992 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2993 if (response.payload == null) {
2994 return "";
2995 }
Evan Charltonc66da362014-05-16 14:06:40 -07002996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997 // Append the returned status code to the end of the response payload.
2998 String s = Integer.toHexString(
2999 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3000 s = IccUtils.bytesToHexString(response.payload) + s;
3001 return s;
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
Evan Charltonc66da362014-05-16 14:06:40 -07003005 }
3006
Jake Hambye994d462014-02-03 13:10:13 -08003007 /**
3008 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3009 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3010 *
3011 * @param itemID the ID of the item to read
3012 * @return the NV item as a String, or null on error.
3013 */
3014 @Override
3015 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3017 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 if (DBG) log("nvReadItem: item " + itemID);
3022 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3023 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3024 return value;
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
Jake Hambye994d462014-02-03 13:10:13 -08003028 }
3029
3030 /**
3031 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3032 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3033 *
3034 * @param itemID the ID of the item to read
3035 * @param itemValue the value to write, as a String
3036 * @return true on success; false on any failure
3037 */
3038 @Override
3039 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3041 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3046 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3047 new Pair<Integer, String>(itemID, itemValue));
3048 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3049 return success;
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
Jake Hambye994d462014-02-03 13:10:13 -08003053 }
3054
3055 /**
3056 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3057 * Used for device configuration by some CDMA operators.
3058 *
3059 * @param preferredRoamingList byte array containing the new PRL
3060 * @return true on success; false on any failure
3061 */
3062 @Override
3063 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3065 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3070 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3071 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3072 return success;
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
Jake Hambye994d462014-02-03 13:10:13 -08003076 }
3077
3078 /**
3079 * Perform the specified type of NV config reset.
3080 * Used for device configuration by some CDMA operators.
3081 *
3082 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3083 * @return true on success; false on any failure
3084 */
3085 @Override
3086 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3088 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 if (DBG) log("nvResetConfig: type " + resetType);
3093 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3094 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3095 return success;
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
Jake Hambye994d462014-02-03 13:10:13 -08003099 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003100
Svet Ganovb320e182015-04-16 12:30:10 -07003101 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003103 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003104 return new String[0];
3105 }
3106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 return mPhone.getPcscfAddress(apnType);
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
Wink Saville36469e72014-06-11 15:17:00 -07003113 }
3114
Brad Ebinger51f743a2017-01-23 13:50:20 -08003115 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003116 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3117 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003118 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003119 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121
3122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 PhoneFactory.getImsResolver().enableIms(slotId);
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003128 }
3129
3130 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003131 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3132 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003133 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003134 public void disableIms(int slotId) {
3135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136
3137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 PhoneFactory.getImsResolver().disableIms(slotId);
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003143 }
3144
3145 /**
3146 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3147 * feature or {@link null} if the service is not available. If the feature is available, the
3148 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3149 */
3150 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003151 IImsServiceFeatureCallback callback) {
3152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003160 }
3161
3162 /**
3163 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3164 * feature during emergency calling or {@link null} if the service is not available. If the
3165 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3166 * listener for feature updates.
3167 */
3168 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3169 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003177 }
3178
Brad Ebinger5f64b052017-12-14 14:26:15 -08003179 /**
3180 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3181 * specified.
3182 */
3183 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3184 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08003192 }
3193
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003194 /**
3195 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3196 * specified.
3197 */
3198 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3199 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200
3201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08003207 }
3208
Brad Ebinger884c07b2018-02-15 16:17:40 -08003209 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003210 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3211 * available, false if the IMS resolver is idle.
3212 */
3213 public boolean isResolvingImsBinding() {
3214 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 return PhoneFactory.getImsResolver().isResolvingBinding();
3219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
Brad Ebinger67801702018-03-02 13:43:36 -08003222 }
3223
Brad Ebingerdac2f002018-04-03 15:17:52 -07003224 /**
3225 * Sets the ImsService Package Name that Telephony will bind to.
3226 *
3227 * @param slotId the slot ID that the ImsService should bind for.
3228 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3229 * ImsService is the device default ImsService.
3230 * @param packageName The package name of the application that contains the ImsService to bind
3231 * to.
3232 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3233 * @hide
3234 */
3235 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003236 int[] subIds = SubscriptionManager.getSubId(slotId);
3237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3238 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3239 "setImsService");
3240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3244 isCarrierImsService, packageName);
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003248 }
3249
3250 /**
3251 * Return the ImsService configuration.
3252 *
3253 * @param slotId The slot that the ImsService is associated with.
3254 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3255 * the device default.
3256 * @return the package name of the ImsService configuration.
3257 */
3258 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07003259 int[] subIds = SubscriptionManager.getSubId(slotId);
3260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3261 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3262 "getImsService");
3263
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3267 isCarrierImsService);
3268 } finally {
3269 Binder.restoreCallingIdentity(identity);
3270 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07003271 }
3272
Wink Saville36469e72014-06-11 15:17:00 -07003273 public void setImsRegistrationState(boolean registered) {
3274 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275
3276 final long identity = Binder.clearCallingIdentity();
3277 try {
3278 mPhone.setImsRegistrationState(registered);
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
Wink Saville36469e72014-06-11 15:17:00 -07003282 }
3283
3284 /**
Stuart Scott54788802015-03-30 13:18:01 -07003285 * Set the network selection mode to automatic.
3286 *
3287 */
3288 @Override
3289 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3296 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3297 } finally {
3298 Binder.restoreCallingIdentity(identity);
3299 }
Stuart Scott54788802015-03-30 13:18:01 -07003300 }
3301
3302 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003303 * Set the network selection mode to manual with the selected carrier.
3304 */
3305 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003306 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003307 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3309 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003314 /* operatorAlphaLong */ "",
3315 /* operatorAlphaShort */ "",
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316 operatorNumeric);
3317 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3318 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3319 persistSelection);
3320 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003324 }
3325
3326 /**
3327 * Scans for available networks.
3328 */
3329 @Override
3330 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3332 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333
3334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3337 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3338 CMD_PERFORM_NETWORK_SCAN, null, subId);
3339 return result;
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003343 }
3344
3345 /**
yinxub1bed742017-04-17 11:45:04 -07003346 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003347 *
yinxub1bed742017-04-17 11:45:04 -07003348 * @param subId id of the subscription
3349 * @param request contains the radio access networks with bands/channels to scan
3350 * @param messenger callback messenger for scan results or errors
3351 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003352 * @return the id of the requested scan which can be used to stop the scan.
3353 */
3354 @Override
3355 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3356 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3358 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003359
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 return mNetworkScanRequestTracker.startNetworkScan(
3363 request, messenger, binder, getPhone(subId));
3364 } finally {
3365 Binder.restoreCallingIdentity(identity);
3366 }
yinxu504e1392017-04-12 16:03:22 -07003367 }
3368
3369 /**
3370 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003371 *
3372 * @param subId id of the subscription
3373 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003374 */
3375 @Override
3376 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3378 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003379
3380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
yinxu504e1392017-04-12 16:03:22 -07003386 }
3387
3388 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003389 * Get the calculated preferred network type.
3390 * Used for debugging incorrect network type.
3391 *
3392 * @return the preferred network type, defined in RILConstants.java.
3393 */
3394 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003395 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003397 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003398 return RILConstants.PREFERRED_NETWORK_MODE;
3399 }
3400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 // FIXME: need to get SubId from somewhere.
3404 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3405 } finally {
3406 Binder.restoreCallingIdentity(identity);
3407 }
Junda Liu84d15a22014-07-02 11:21:04 -07003408 }
3409
3410 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003411 * Get the preferred network type.
3412 * Used for device configuration by some CDMA operators.
3413 *
3414 * @return the preferred network type, defined in RILConstants.java.
3415 */
3416 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003417 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3419 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 if (DBG) log("getPreferredNetworkType");
3424 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3425 int networkType = (result != null ? result[0] : -1);
3426 if (DBG) log("getPreferredNetworkType: " + networkType);
3427 return networkType;
3428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003431 }
3432
3433 /**
3434 * Set the preferred network type.
3435 * Used for device configuration by some CDMA operators.
3436 *
3437 * @param networkType the preferred network type, defined in RILConstants.java.
3438 * @return true on success; false on any failure.
3439 */
3440 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003441 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3443 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3448 Boolean success = (Boolean) sendRequest(
3449 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3450 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3451 if (success) {
3452 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3453 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3454 }
3455 return success;
3456 } finally {
3457 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003458 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003459 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003460
3461 /**
Junda Liu475951f2014-11-07 16:45:03 -08003462 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3463 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3464 * tethering.
3465 *
3466 * @return 0: Not required. 1: required. 2: Not set.
3467 * @hide
3468 */
3469 @Override
3470 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003471 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472
3473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3476 Settings.Global.TETHER_DUN_REQUIRED, 2);
3477 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3478 // config_tether_apndata.
3479 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3480 dunRequired = 1;
3481 }
3482 return dunRequired;
3483 } finally {
3484 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003485 }
Junda Liu475951f2014-11-07 16:45:03 -08003486 }
3487
3488 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003489 * Set mobile data enabled
3490 * Used by the user through settings etc to turn on/off mobile data
3491 *
3492 * @param enable {@code true} turn turn data on, else {@code false}
3493 */
3494 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003495 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3497 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 int phoneId = mSubscriptionController.getPhoneId(subId);
3502 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3503 Phone phone = PhoneFactory.getPhone(phoneId);
3504 if (phone != null) {
3505 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3506 phone.setUserDataEnabled(enable);
3507 } else {
3508 loge("setUserDataEnabled: no phone for subId=" + subId);
3509 }
3510 } finally {
3511 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003512 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003513 }
3514
3515 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08003516 * Get the user enabled state of Mobile Data.
3517 *
3518 * TODO: remove and use isUserDataEnabled.
3519 * This can't be removed now because some vendor codes
3520 * calls through ITelephony directly while they should
3521 * use TelephonyManager.
3522 *
3523 * @return true on enabled
3524 */
3525 @Override
3526 public boolean getDataEnabled(int subId) {
3527 return isUserDataEnabled(subId);
3528 }
3529
3530 /**
3531 * Get whether mobile data is enabled per user setting.
3532 *
3533 * There are other factors deciding whether mobile data is actually enabled, but they are
3534 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003535 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003536 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003537 *
3538 * @return {@code true} if data is enabled else {@code false}
3539 */
3540 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08003541 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003542 try {
3543 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3544 null);
3545 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3547 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 int phoneId = mSubscriptionController.getPhoneId(subId);
3553 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3554 Phone phone = PhoneFactory.getPhone(phoneId);
3555 if (phone != null) {
3556 boolean retVal = phone.isUserDataEnabled();
3557 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3558 return retVal;
3559 } else {
3560 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3561 return false;
3562 }
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08003565 }
3566 }
3567
3568 /**
3569 * Get whether mobile data is enabled.
3570 *
3571 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3572 * whether mobile data is actually enabled.
3573 *
3574 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3575 *
3576 * @return {@code true} if data is enabled else {@code false}
3577 */
3578 @Override
3579 public boolean isDataEnabled(int subId) {
3580 try {
3581 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3582 null);
3583 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3585 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08003586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 int phoneId = mSubscriptionController.getPhoneId(subId);
3591 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3592 Phone phone = PhoneFactory.getPhone(phoneId);
3593 if (phone != null) {
3594 boolean retVal = phone.isDataEnabled();
3595 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3596 return retVal;
3597 } else {
3598 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3599 return false;
3600 }
3601 } finally {
3602 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003603 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003604 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003605
3606 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003607 public int getCarrierPrivilegeStatus(int subId) {
3608 final Phone phone = getPhone(subId);
3609 if (phone == null) {
3610 loge("getCarrierPrivilegeStatus: Invalid subId");
3611 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3612 }
3613 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003614 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003615 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003616 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3617 }
3618 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003619 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003620 }
Junda Liu29340342014-07-10 15:23:27 -07003621
3622 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003623 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3624 final Phone phone = getPhone(subId);
3625 if (phone == null) {
3626 loge("getCarrierPrivilegeStatus: Invalid subId");
3627 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3628 }
3629 UiccProfile profile =
3630 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3631 if (profile == null) {
3632 loge("getCarrierPrivilegeStatus: No UICC");
3633 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3634 }
3635 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3636 }
3637
3638 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003639 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003640 if (TextUtils.isEmpty(pkgName))
3641 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003642 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003643 if (card == null) {
3644 loge("checkCarrierPrivilegesForPackage: No UICC");
3645 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3646 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003647 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3648 }
3649
3650 @Override
3651 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003652 if (TextUtils.isEmpty(pkgName))
3653 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003654 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3655 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3656 UiccCard card = UiccController.getInstance().getUiccCard(i);
3657 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003658 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003659 continue;
3660 }
3661
3662 result = card.getCarrierPrivilegeStatus(
3663 mPhone.getContext().getPackageManager(), pkgName);
3664 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3665 break;
3666 }
3667 }
3668
3669 return result;
Junda Liu29340342014-07-10 15:23:27 -07003670 }
Derek Tan89e89d42014-07-08 17:00:10 -07003671
3672 @Override
Junda Liue64de782015-04-16 17:19:16 -07003673 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3674 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3675 loge("phoneId " + phoneId + " is not valid.");
3676 return null;
3677 }
3678 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003679 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003680 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003681 return null ;
3682 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003683 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003684 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003685 }
3686
Amith Yamasani6e118872016-02-19 12:53:51 -08003687 @Override
3688 public List<String> getPackagesWithCarrierPrivileges() {
3689 PackageManager pm = mPhone.getContext().getPackageManager();
3690 List<String> privilegedPackages = new ArrayList<>();
3691 List<PackageInfo> packages = null;
3692 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3693 UiccCard card = UiccController.getInstance().getUiccCard(i);
3694 if (card == null) {
3695 // No UICC in that slot.
3696 continue;
3697 }
3698 if (card.hasCarrierPrivilegeRules()) {
3699 if (packages == null) {
3700 // Only check packages in user 0 for now
3701 packages = pm.getInstalledPackagesAsUser(
3702 PackageManager.MATCH_DISABLED_COMPONENTS
3703 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3704 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3705 }
3706 for (int p = packages.size() - 1; p >= 0; p--) {
3707 PackageInfo pkgInfo = packages.get(p);
3708 if (pkgInfo != null && pkgInfo.packageName != null
3709 && card.getCarrierPrivilegeStatus(pkgInfo)
3710 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3711 privilegedPackages.add(pkgInfo.packageName);
3712 }
3713 }
3714 }
3715 }
3716 return privilegedPackages;
3717 }
3718
Wink Savilleb564aae2014-10-23 10:18:09 -07003719 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003720 final Phone phone = getPhone(subId);
3721 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003722 if (card == null) {
3723 loge("getIccId: No UICC");
3724 return null;
3725 }
3726 String iccId = card.getIccId();
3727 if (TextUtils.isEmpty(iccId)) {
3728 loge("getIccId: ICC ID is null or empty.");
3729 return null;
3730 }
3731 return iccId;
3732 }
3733
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003734 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003735 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3736 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003737 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3738 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 final String iccId = getIccId(subId);
3743 final Phone phone = getPhone(subId);
3744 if (phone == null) {
3745 return false;
3746 }
3747 final String subscriberId = phone.getSubscriberId();
3748
3749 if (DBG_MERGE) {
3750 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3751 + subscriberId + " to " + number);
3752 }
3753
3754 if (TextUtils.isEmpty(iccId)) {
3755 return false;
3756 }
3757
3758 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3759
3760 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3761 if (alphaTag == null) {
3762 editor.remove(alphaTagPrefKey);
3763 } else {
3764 editor.putString(alphaTagPrefKey, alphaTag);
3765 }
3766
3767 // Record both the line number and IMSI for this ICCID, since we need to
3768 // track all merged IMSIs based on line number
3769 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3770 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3771 if (number == null) {
3772 editor.remove(numberPrefKey);
3773 editor.remove(subscriberPrefKey);
3774 } else {
3775 editor.putString(numberPrefKey, number);
3776 editor.putString(subscriberPrefKey, subscriberId);
3777 }
3778
3779 editor.commit();
3780 return true;
3781 } finally {
3782 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003783 }
Derek Tan7226c842014-07-02 17:42:23 -07003784 }
3785
3786 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003787 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003788 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003790 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003791 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003792 return null;
3793 }
Derek Tan97ebb422014-09-05 16:55:38 -07003794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 String iccId = getIccId(subId);
3798 if (iccId != null) {
3799 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3800 if (DBG_MERGE) {
3801 log("getLine1NumberForDisplay returning "
3802 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3803 }
3804 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3807 return null;
3808 } finally {
3809 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003810 }
Derek Tan7226c842014-07-02 17:42:23 -07003811 }
3812
3813 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003814 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003816 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003817 return null;
3818 }
Derek Tan97ebb422014-09-05 16:55:38 -07003819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 String iccId = getIccId(subId);
3823 if (iccId != null) {
3824 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3825 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3826 }
3827 return null;
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003830 }
Derek Tan7226c842014-07-02 17:42:23 -07003831 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003832
3833 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003834 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003835 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3836 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003838 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3839 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003840 return null;
3841 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003842
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003843 final long identity = Binder.clearCallingIdentity();
3844 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003845 final Context context = mPhone.getContext();
3846 final TelephonyManager tele = TelephonyManager.from(context);
3847 final SubscriptionManager sub = SubscriptionManager.from(context);
3848
3849 // Figure out what subscribers are currently active
3850 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3851 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3852 // the process, where TelephonyManager was instantiated.
3853 // Otherwise AppOps check will fail.
3854
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003855 final int[] subIds = sub.getActiveSubscriptionIdList();
3856 for (int subId : subIds) {
3857 activeSubscriberIds.add(tele.getSubscriberId(subId));
3858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003859
3860 // First pass, find a number override for an active subscriber
3861 String mergeNumber = null;
3862 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3863 for (String key : prefs.keySet()) {
3864 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3865 final String subscriberId = (String) prefs.get(key);
3866 if (activeSubscriberIds.contains(subscriberId)) {
3867 final String iccId = key.substring(
3868 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3869 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3870 mergeNumber = (String) prefs.get(numberKey);
3871 if (DBG_MERGE) {
3872 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3873 + " for active subscriber " + subscriberId);
3874 }
3875 if (!TextUtils.isEmpty(mergeNumber)) {
3876 break;
3877 }
3878 }
3879 }
3880 }
3881
3882 // Shortcut when no active merged subscribers
3883 if (TextUtils.isEmpty(mergeNumber)) {
3884 return null;
3885 }
3886
3887 // Second pass, find all subscribers under that line override
3888 final ArraySet<String> result = new ArraySet<>();
3889 for (String key : prefs.keySet()) {
3890 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3891 final String number = (String) prefs.get(key);
3892 if (mergeNumber.equals(number)) {
3893 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3894 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3895 final String subscriberId = (String) prefs.get(subscriberKey);
3896 if (!TextUtils.isEmpty(subscriberId)) {
3897 result.add(subscriberId);
3898 }
3899 }
3900 }
3901 }
3902
3903 final String[] resultArray = result.toArray(new String[result.size()]);
3904 Arrays.sort(resultArray);
3905 if (DBG_MERGE) {
3906 Slog.d(LOG_TAG,
3907 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3908 }
3909 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003910 } finally {
3911 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003912 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003913 }
3914
3915 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003916 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003917 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3918 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003919
3920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 final Phone phone = getPhone(subId);
3923 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
3926 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003927 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003928
3929 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003930 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003931 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3932 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003933 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003934
3935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 final Phone phone = getPhone(subId);
3938 if (phone == null) {
3939 return false;
3940 }
3941 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3942 cdmaNonRoamingList);
3943 } finally {
3944 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003945 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003946 }
3947
3948 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003949 @Deprecated
3950 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3951 enforceModifyPermission();
3952
3953 int returnValue = 0;
3954 try {
3955 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3956 if(result.exception == null) {
3957 if (result.result != null) {
3958 byte[] responseData = (byte[])(result.result);
3959 if(responseData.length > oemResp.length) {
3960 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3961 responseData.length + "bytes. Buffer Size is " +
3962 oemResp.length + "bytes.");
3963 }
3964 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3965 returnValue = responseData.length;
3966 }
3967 } else {
3968 CommandException ex = (CommandException) result.exception;
3969 returnValue = ex.getCommandError().ordinal();
3970 if(returnValue > 0) returnValue *= -1;
3971 }
3972 } catch (RuntimeException e) {
3973 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3974 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3975 if(returnValue > 0) returnValue *= -1;
3976 }
3977
3978 return returnValue;
3979 }
3980
3981 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003982 public void setRadioCapability(RadioAccessFamily[] rafs) {
3983 try {
3984 ProxyController.getInstance().setRadioCapability(rafs);
3985 } catch (RuntimeException e) {
3986 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3987 }
3988 }
3989
3990 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003991 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003992 Phone phone = PhoneFactory.getPhone(phoneId);
3993 if (phone == null) {
3994 return RadioAccessFamily.RAF_UNKNOWN;
3995 }
3996 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003997 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003998 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003999 return RadioAccessFamily.RAF_UNKNOWN;
4000 }
4001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004008 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004009
4010 @Override
4011 public void enableVideoCalling(boolean enable) {
4012 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013
4014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004020 }
4021
4022 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004023 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4025 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
4026 return false;
4027 }
Svet Ganovb320e182015-04-16 12:30:10 -07004028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029 final long identity = Binder.clearCallingIdentity();
4030 try {
4031 // Check the user preference and the system-level IMS setting. Even if the user has
4032 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4033 // In the long run, we may instead need to check if there exists a connection service
4034 // which can support video calling.
4035 ImsManager imsManager =
4036 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4037 return imsManager.isVtEnabledByPlatform()
4038 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4039 && imsManager.isVtEnabledByUser();
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004043 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004044
Andrew Leea1239f22015-03-02 17:44:07 -08004045 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4048 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4049 return false;
4050 }
4051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 CarrierConfigManager configManager =
4055 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4056 return configManager.getConfigForSubId(mPhone.getSubId())
4057 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
Andrew Leea1239f22015-03-02 17:44:07 -08004061 }
4062
4063 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 public boolean isWorldPhone(int subId, String callingPackage) {
4065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4066 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4067 return false;
4068 }
4069
4070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 CarrierConfigManager configManager =
4073 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4074 return configManager.getConfigForSubId(mPhone.getSubId())
4075 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4076 } finally {
4077 Binder.restoreCallingIdentity(identity);
4078 }
Andrew Leea1239f22015-03-02 17:44:07 -08004079 }
4080
Andrew Lee9431b832015-03-09 18:46:45 -07004081 @Override
4082 public boolean isTtyModeSupported() {
4083 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004084 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004085 }
4086
4087 @Override
4088 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089 final long identity = Binder.clearCallingIdentity();
4090 try {
4091 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4092 } finally {
4093 Binder.restoreCallingIdentity(identity);
4094 }
Andrew Lee9431b832015-03-09 18:46:45 -07004095 }
4096
Hall Liu98187582018-01-22 19:15:32 -08004097 public boolean isRttSupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4101 mPhone.getSubId()).getBoolean(
4102 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4103 boolean isDeviceSupported =
4104 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4105 return isCarrierSupported && isDeviceSupported;
4106 } finally {
4107 Binder.restoreCallingIdentity(identity);
4108 }
Hall Liu98187582018-01-22 19:15:32 -08004109 }
4110
Hall Liu3ad5f012018-04-06 16:23:39 -07004111 public boolean isRttEnabled() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 return isRttSupported() && Settings.Secure.getInt(
4115 mPhone.getContext().getContentResolver(),
4116 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
Hall Liu3ad5f012018-04-06 16:23:39 -07004120 }
4121
Sanket Padawe7310cc72015-01-14 09:53:20 -08004122 /**
4123 * Returns the unique device ID of phone, for example, the IMEI for
4124 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4125 *
4126 * <p>Requires Permission:
4127 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4128 */
4129 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004130 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004131 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08004132 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004133 return null;
4134 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004135 int subId = phone.getSubId();
4136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4137 mApp, subId, callingPackage, "getDeviceId")) {
4138 return null;
4139 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140
4141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 return phone.getDeviceId();
4144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004147 }
4148
Ping Sunc67b7c22016-03-02 19:16:45 +08004149 /**
4150 * {@hide}
4151 * Returns the IMS Registration Status on a particular subid
4152 *
4153 * @param subId
4154 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004155 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08004156 Phone phone = getPhone(subId);
4157 if (phone != null) {
4158 return phone.isImsRegistered();
4159 } else {
4160 return false;
4161 }
4162 }
4163
Santos Cordon7a1885b2015-02-03 11:15:19 -08004164 @Override
4165 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004172 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004173
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004174 /**
4175 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004176 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004177 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 Phone phone = getPhone(subId);
4181 if (phone != null) {
4182 return phone.isWifiCallingEnabled();
4183 } else {
4184 return false;
4185 }
4186 } finally {
4187 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004188 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004189 }
4190
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004191 /**
4192 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004193 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004194 public boolean isVolteAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 Phone phone = getPhone(subId);
4198 if (phone != null) {
4199 return phone.isVolteEnabled();
4200 } else {
4201 return false;
4202 }
4203 } finally {
4204 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004205 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004206 }
Svet Ganovb320e182015-04-16 12:30:10 -07004207
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004208 /**
4209 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004210 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004211 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 Phone phone = getPhone(subId);
4215 if (phone != null) {
4216 return phone.isVideoEnabled();
4217 } else {
4218 return false;
4219 }
4220 } finally {
4221 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004222 }
4223 }
4224
4225 /**
4226 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4227 * defined in {@link ImsRegistrationImplBase}.
4228 */
4229 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004230 final long identity = Binder.clearCallingIdentity();
4231 try {
4232 Phone phone = getPhone(subId);
4233 if (phone != null) {
4234 return phone.getImsRegistrationTech();
4235 } else {
4236 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4237 }
4238 } finally {
4239 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08004240 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004241 }
4242
Stuart Scott8eef64f2015-04-08 15:13:54 -07004243 @Override
4244 public void factoryReset(int subId) {
4245 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004246 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4247 return;
4248 }
4249
Svet Ganovcc087f82015-05-12 20:35:54 -07004250 final long identity = Binder.clearCallingIdentity();
4251 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004252 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4253 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07004254 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07004255 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07004256 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
4257 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07004258 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07004259 }
4260 } finally {
4261 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004262 }
4263 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004264
4265 @Override
4266 public String getLocaleFromDefaultSim() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004267 final long identity = Binder.clearCallingIdentity();
4268 try {
4269 // We query all subscriptions instead of just the active ones, because
4270 // this might be called early on in the provisioning flow when the
4271 // subscriptions potentially aren't active yet.
4272 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4273 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004274 return null;
4275 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277 // This function may be called very early, say, from the setup wizard, at
4278 // which point we won't have a default subscription set. If that's the case
4279 // we just choose the first, which will be valid in "most cases".
4280 final int defaultSubId = getDefaultSubscription();
4281 SubscriptionInfo info = null;
4282 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4283 info = slist.get(0);
4284 } else {
4285 for (SubscriptionInfo item : slist) {
4286 if (item.getSubscriptionId() == defaultSubId) {
4287 info = item;
4288 break;
4289 }
4290 }
4291
4292 if (info == null) {
4293 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004294 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004295 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 // Try and fetch the locale from the carrier properties or from the SIM language
4298 // preferences (EF-PL and EF-LI)...
4299 final int mcc = info.getMcc();
4300 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4301 String simLanguage = null;
4302 if (defaultPhone != null) {
4303 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4304 if (localeFromDefaultSim != null) {
4305 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4306 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4307 return localeFromDefaultSim.toLanguageTag();
4308 } else {
4309 simLanguage = localeFromDefaultSim.getLanguage();
4310 }
4311 }
4312 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004314 // The SIM language preferences only store a language (e.g. fr = French), not an
4315 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4316 // the SIM and carrier preferences does not include a country we add the country
4317 // determined from the SIM MCC to provide an exact locale.
4318 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4319 simLanguage);
4320 if (mccLocale != null) {
4321 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4322 return mccLocale.toLanguageTag();
4323 }
4324
4325 if (DBG) log("No locale found - returning null");
4326 return null;
4327 } finally {
4328 Binder.restoreCallingIdentity(identity);
4329 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004330 }
4331
4332 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333 return mSubscriptionController.getAllSubInfoList(
4334 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004335 }
4336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 /**
4338 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4339 */
4340 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4341 return mSubscriptionController.getActiveSubscriptionInfoList(
4342 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004343 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004344
Chenjie Yu1ba97252018-01-11 18:16:20 -08004345 private final ModemActivityInfo mLastModemActivityInfo =
4346 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
4347
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004348 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004349 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4350 * representing the state of the modem.
4351 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08004352 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
4353 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07004354 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004355 */
4356 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004357 public void requestModemActivityInfo(ResultReceiver result) {
4358 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359
4360 final long identity = Binder.clearCallingIdentity();
4361 try {
4362 ModemActivityInfo ret = null;
4363 synchronized (mLastModemActivityInfo) {
4364 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
4365 CMD_GET_MODEM_ACTIVITY_INFO,
4366 null);
4367 if (info != null) {
4368 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
4369 for (int i = 0; i < mergedTxTimeMs.length; i++) {
4370 mergedTxTimeMs[i] =
4371 info.getTxTimeMillis()[i]
4372 + mLastModemActivityInfo.getTxTimeMillis()[i];
4373 }
4374 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
4375 mLastModemActivityInfo.setSleepTimeMillis(
4376 info.getSleepTimeMillis()
4377 + mLastModemActivityInfo.getSleepTimeMillis());
4378 mLastModemActivityInfo.setIdleTimeMillis(
4379 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
4380 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
4381 mLastModemActivityInfo.setRxTimeMillis(
4382 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
4383 mLastModemActivityInfo.setEnergyUsed(
4384 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
4387 mLastModemActivityInfo.getSleepTimeMillis(),
4388 mLastModemActivityInfo.getIdleTimeMillis(),
4389 mLastModemActivityInfo.getTxTimeMillis(),
4390 mLastModemActivityInfo.getRxTimeMillis(),
4391 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08004392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 Bundle bundle = new Bundle();
4394 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
4395 result.send(0, bundle);
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08004398 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004399 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004400
4401 /**
4402 * {@hide}
4403 * Returns the service state information on specified subscription.
4404 */
4405 @Override
4406 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004408 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004409 return null;
4410 }
4411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 final long identity = Binder.clearCallingIdentity();
4413 try {
4414 final Phone phone = getPhone(subId);
4415 if (phone == null) {
4416 return null;
4417 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 return phone.getServiceState();
4420 } finally {
4421 Binder.restoreCallingIdentity(identity);
4422 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004423 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004424
4425 /**
4426 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4427 *
4428 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4429 * voicemail ringtone.
4430 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4431 * PhoneAccount.
4432 */
4433 @Override
4434 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 final long identity = Binder.clearCallingIdentity();
4436 try {
4437 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4438 if (phone == null) {
4439 phone = mPhone;
4440 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004446 }
4447
4448 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004449 * Sets the per-account voicemail ringtone.
4450 *
4451 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4452 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4453 *
4454 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4455 * voicemail ringtone.
4456 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4457 * PhoneAccount.
4458 */
4459 @Override
4460 public void setVoicemailRingtoneUri(String callingPackage,
4461 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4462 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4463 if (!TextUtils.equals(callingPackage,
4464 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4466 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4467 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4473 if (phone == null) {
4474 phone = mPhone;
4475 }
4476 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4477 } finally {
4478 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004479 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004480 }
4481
4482 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004483 * Returns whether vibration is set for voicemail notification in Phone settings.
4484 *
4485 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4486 * voicemail vibration setting.
4487 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4488 */
4489 @Override
4490 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 final long identity = Binder.clearCallingIdentity();
4492 try {
4493 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4494 if (phone == null) {
4495 phone = mPhone;
4496 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004502 }
4503
Youhan Wange64578a2016-05-02 15:32:42 -07004504 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004505 * Sets the per-account voicemail vibration.
4506 *
4507 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4508 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4509 *
4510 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4511 * voicemail vibration setting.
4512 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4513 * specific PhoneAccount.
4514 */
4515 @Override
4516 public void setVoicemailVibrationEnabled(String callingPackage,
4517 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4519 if (!TextUtils.equals(callingPackage,
4520 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4522 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4523 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004524 }
4525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 final long identity = Binder.clearCallingIdentity();
4527 try {
4528 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4529 if (phone == null) {
4530 phone = mPhone;
4531 }
4532 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4533 } finally {
4534 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004535 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004536 }
4537
4538 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004539 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4540 *
4541 * @throws SecurityException if the caller does not have the required permission
4542 */
4543 private void enforceReadPrivilegedPermission() {
4544 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4545 null);
4546 }
4547
4548 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004549 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4550 * permission.
4551 *
4552 * @throws SecurityException if the caller does not have the required permission
4553 */
4554 private void enforceSendSmsPermission() {
4555 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4556 }
4557
4558 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004559 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004560 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004561 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004562 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004563 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 final long identity = Binder.clearCallingIdentity();
4565 try {
4566 ComponentName componentName =
4567 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4568 if (componentName == null) {
4569 throw new SecurityException(
4570 "Caller not current active visual voicemail package[null]");
4571 }
4572 String vvmPackage = componentName.getPackageName();
4573 if (!callingPackage.equals(vvmPackage)) {
4574 throw new SecurityException("Caller not current active visual voicemail package["
4575 + vvmPackage + "]");
4576 }
4577 } finally {
4578 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004579 }
4580 }
4581
4582 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004583 * Return the application ID for the app type.
4584 *
4585 * @param subId the subscription ID that this request applies to.
4586 * @param appType the uicc app type.
4587 * @return Application ID for specificied app type, or null if no uicc.
4588 */
4589 @Override
4590 public String getAidForAppType(int subId, int appType) {
4591 enforceReadPrivilegedPermission();
4592 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593
4594 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004595 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 if (phone == null) {
4597 return null;
4598 }
4599 String aid = null;
4600 try {
4601 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4602 .getApplicationByType(appType).getAid();
4603 } catch (Exception e) {
4604 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4605 }
4606 return aid;
4607 } finally {
4608 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004609 }
Youhan Wange64578a2016-05-02 15:32:42 -07004610 }
4611
Youhan Wang4001d252016-05-11 10:29:41 -07004612 /**
4613 * Return the Electronic Serial Number.
4614 *
4615 * @param subId the subscription ID that this request applies to.
4616 * @return ESN or null if error.
4617 */
4618 @Override
4619 public String getEsn(int subId) {
4620 enforceReadPrivilegedPermission();
4621 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622
4623 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004624 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 if (phone == null) {
4626 return null;
4627 }
4628 String esn = null;
4629 try {
4630 esn = phone.getEsn();
4631 } catch (Exception e) {
4632 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4633 }
4634 return esn;
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004637 }
Youhan Wang4001d252016-05-11 10:29:41 -07004638 }
4639
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004640 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004641 * Return the Preferred Roaming List Version.
4642 *
4643 * @param subId the subscription ID that this request applies to.
4644 * @return PRLVersion or null if error.
4645 */
4646 @Override
4647 public String getCdmaPrlVersion(int subId) {
4648 enforceReadPrivilegedPermission();
4649 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650
4651 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004652 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 if (phone == null) {
4654 return null;
4655 }
4656 String cdmaPrlVersion = null;
4657 try {
4658 cdmaPrlVersion = phone.getCdmaPrlVersion();
4659 } catch (Exception e) {
4660 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4661 }
4662 return cdmaPrlVersion;
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004665 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004666 }
4667
4668 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004669 * Get snapshot of Telephony histograms
4670 * @return List of Telephony histograms
4671 * @hide
4672 */
4673 @Override
4674 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4676 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677
4678 final long identity = Binder.clearCallingIdentity();
4679 try {
4680 return RIL.getTelephonyRILTimingHistograms();
4681 } finally {
4682 Binder.restoreCallingIdentity(identity);
4683 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004684 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004685
4686 /**
4687 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004688 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004689 * Require system privileges. In the future we may add this to carrier APIs.
4690 *
4691 * @return The number of carriers set successfully, should match length of carriers
4692 */
4693 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004694 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004695 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004696
Meng Wang9b7c4e92017-02-17 11:41:27 -08004697 if (carriers == null) {
4698 throw new NullPointerException("carriers cannot be null");
4699 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4704 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4705 return retVal[0];
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
4708 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004709 }
4710
4711 /**
4712 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004713 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004714 * Require system privileges. In the future we may add this to carrier APIs.
4715 *
4716 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4717 * means all carriers are allowed.
4718 */
4719 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004720 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004721 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722
4723 final long identity = Binder.clearCallingIdentity();
4724 try {
4725 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4726 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004730 }
4731
fionaxu59545b42016-05-25 15:53:37 -07004732 /**
4733 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4734 * @param subId the subscription ID that this action applies to.
4735 * @param enabled control enable or disable metered apns.
4736 * {@hide}
4737 */
4738 @Override
4739 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4740 enforceModifyPermission();
4741 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742
4743 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004744 if (phone == null) {
4745 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4746 return;
4747 }
4748 try {
4749 phone.carrierActionSetMeteredApnsEnabled(enabled);
4750 } catch (Exception e) {
4751 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004752 } finally {
4753 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004754 }
4755 }
4756
4757 /**
4758 * Action set from carrier signalling broadcast receivers to enable/disable radio
4759 * @param subId the subscription ID that this action applies to.
4760 * @param enabled control enable or disable radio.
4761 * {@hide}
4762 */
4763 @Override
4764 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4765 enforceModifyPermission();
4766 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004767
4768 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004769 if (phone == null) {
4770 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4771 return;
4772 }
4773 try {
4774 phone.carrierActionSetRadioEnabled(enabled);
4775 } catch (Exception e) {
4776 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777 } finally {
4778 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004779 }
4780 }
4781
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004782 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004783 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4784 * network status based on which carrier apps could apply actions accordingly,
4785 * enable/disable default url handler for example.
4786 *
4787 * @param subId the subscription ID that this action applies to.
4788 * @param report control start/stop reporting the default network status.
4789 * {@hide}
4790 */
4791 @Override
4792 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4793 enforceModifyPermission();
4794 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004795
4796 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004797 if (phone == null) {
4798 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4799 return;
4800 }
4801 try {
4802 phone.carrierActionReportDefaultNetworkStatus(report);
4803 } catch (Exception e) {
4804 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805 } finally {
4806 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004807 }
4808 }
4809
4810 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004811 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4812 * bug report is being generated.
4813 */
4814 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004815 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004816 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4817 != PackageManager.PERMISSION_GRANTED) {
4818 writer.println("Permission Denial: can't dump Phone from pid="
4819 + Binder.getCallingPid()
4820 + ", uid=" + Binder.getCallingUid()
4821 + "without permission "
4822 + android.Manifest.permission.DUMP);
4823 return;
4824 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004825 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004826 }
Jack Yueb89b242016-06-22 13:27:47 -07004827
Brad Ebingerdac2f002018-04-03 15:17:52 -07004828 @Override
4829 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4830 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4831 throws RemoteException {
4832 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4833 }
4834
Jack Yueb89b242016-06-22 13:27:47 -07004835 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004836 * Get aggregated video call data usage since boot.
4837 *
4838 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4839 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004840 * {@hide}
4841 */
4842 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004843 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004844 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4845 null);
4846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 // NetworkStatsService keeps tracking the active network interface and identity. It
4850 // records the delta with the corresponding network identity.
4851 // We just return the total video call data usage snapshot since boot.
4852 Phone phone = getPhone(subId);
4853 if (phone != null) {
4854 return phone.getVtDataUsage(perUidStats);
4855 }
4856 return null;
4857 } finally {
4858 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004859 }
Jack Yueb89b242016-06-22 13:27:47 -07004860 }
Jack Yu75ab2952016-07-08 14:29:33 -07004861
4862 /**
4863 * Policy control of data connection. Usually used when data limit is passed.
4864 * @param enabled True if enabling the data, otherwise disabling.
4865 * @param subId Subscription index
4866 * {@hide}
4867 */
4868 @Override
4869 public void setPolicyDataEnabled(boolean enabled, int subId) {
4870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871
4872 final long identity = Binder.clearCallingIdentity();
4873 try {
4874 Phone phone = getPhone(subId);
4875 if (phone != null) {
4876 phone.setPolicyDataEnabled(enabled);
4877 }
4878 } finally {
4879 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004880 }
4881 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004882
4883 /**
4884 * Get Client request stats
4885 * @return List of Client Request Stats
4886 * @hide
4887 */
4888 @Override
4889 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004891 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004892 return null;
4893 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004894 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 if (phone != null) {
4899 return phone.getClientRequestStats();
4900 }
4901
4902 return null;
4903 } finally {
4904 Binder.restoreCallingIdentity(identity);
4905 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004906 }
4907
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004908 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004909 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004910 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004911 }
Jack Yueb4124c2017-02-16 15:32:43 -08004912
4913 /**
Grace Chen70990072017-03-24 17:21:30 -07004914 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004915 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004916 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004917 * @param state State of SIM (power down, power up, pass through)
4918 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4919 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4920 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004921 *
4922 **/
4923 @Override
Grace Chen70990072017-03-24 17:21:30 -07004924 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004925 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004926 Phone phone = PhoneFactory.getPhone(slotIndex);
4927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 if (phone != null) {
4931 phone.setSimPowerState(state);
4932 }
4933 } finally {
4934 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004935 }
4936 }
Shuo Qiandd210312017-04-12 22:11:33 +00004937
Tyler Gunn65d45c22017-06-05 11:22:26 -07004938 private boolean isUssdApiAllowed(int subId) {
4939 CarrierConfigManager configManager =
4940 (CarrierConfigManager) mPhone.getContext().getSystemService(
4941 Context.CARRIER_CONFIG_SERVICE);
4942 if (configManager == null) {
4943 return false;
4944 }
4945 PersistableBundle pb = configManager.getConfigForSubId(subId);
4946 if (pb == null) {
4947 return false;
4948 }
4949 return pb.getBoolean(
4950 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4951 }
4952
Shuo Qiandd210312017-04-12 22:11:33 +00004953 /**
4954 * Check if phone is in emergency callback mode
4955 * @return true if phone is in emergency callback mode
4956 * @param subId sub id
4957 */
goneil9c5f4872017-12-05 14:07:56 -08004958 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004959 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004960 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004961 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962
4963 final long identity = Binder.clearCallingIdentity();
4964 try {
4965 if (phone != null) {
4966 return phone.isInEcm();
4967 } else {
4968 return false;
4969 }
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004972 }
4973 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004974
4975 /**
4976 * Get the current signal strength information for the given subscription.
4977 * Because this information is not updated when the device is in a low power state
4978 * it should not be relied-upon to be current.
4979 * @param subId Subscription index
4980 * @return the most recent cached signal strength info from the modem
4981 */
4982 @Override
4983 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 final long identity = Binder.clearCallingIdentity();
4985 try {
4986 Phone p = getPhone(subId);
4987 if (p == null) {
4988 return null;
4989 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 return p.getSignalStrength();
4992 } finally {
4993 Binder.restoreCallingIdentity(identity);
4994 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004995 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004996
4997 @Override
4998 public UiccSlotInfo[] getUiccSlotsInfo() {
4999 enforceReadPrivilegedPermission();
5000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 final long identity = Binder.clearCallingIdentity();
5002 try {
5003 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
5004 if (slots == null) {
5005 Rlog.i(LOG_TAG, "slots is null.");
5006 return null;
5007 }
5008
5009 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
5010 for (int i = 0; i < slots.length; i++) {
5011 UiccSlot slot = slots[i];
5012 if (slot == null) {
5013 continue;
5014 }
5015
5016 String cardId;
5017 UiccCard card = slot.getUiccCard();
5018 if (card != null) {
5019 cardId = card.getCardId();
5020 } else {
5021 cardId = slot.getIccId();
5022 }
5023
5024 int cardState = 0;
5025 switch (slot.getCardState()) {
5026 case CARDSTATE_ABSENT:
5027 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5028 break;
5029 case CARDSTATE_PRESENT:
5030 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5031 break;
5032 case CARDSTATE_ERROR:
5033 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5034 break;
5035 case CARDSTATE_RESTRICTED:
5036 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5037 break;
5038 default:
5039 break;
5040
5041 }
5042
5043 infos[i] = new UiccSlotInfo(
5044 slot.isActive(),
5045 slot.isEuicc(),
5046 cardId,
5047 cardState,
5048 slot.getPhoneId(),
5049 slot.isExtendedApduSupported());
5050 }
5051 return infos;
5052 } finally {
5053 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07005054 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005055 }
5056
5057 @Override
5058 public boolean switchSlots(int[] physicalSlots) {
5059 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060
5061 final long identity = Binder.clearCallingIdentity();
5062 try {
5063 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005067 }
Jack Yu4c988042018-02-27 15:30:01 -08005068
5069 @Override
5070 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5071 enforceModifyPermission();
5072 final Phone phone = getPhone(subId);
5073 if (phone == null) {
5074 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5075 return;
5076 }
5077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 final long identity = Binder.clearCallingIdentity();
5079 try {
5080 phone.setRadioIndicationUpdateMode(filters, mode);
5081 } finally {
5082 Binder.restoreCallingIdentity(identity);
5083 }
Jack Yu4c988042018-02-27 15:30:01 -08005084 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07005085
5086 /**
goneil47ffb6e2018-04-06 15:40:58 -07005087 * A test API to reload the UICC profile.
5088 *
5089 * <p>Requires that the calling app has permission
5090 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5091 * @hide
5092 */
5093 @Override
5094 public void refreshUiccProfile(int subId) {
5095 enforceModifyPermission();
5096
5097 final long identity = Binder.clearCallingIdentity();
5098 try {
5099 Phone phone = getPhone(subId);
5100 if (phone == null) {
5101 return;
5102 }
5103 UiccCard uiccCard = phone.getUiccCard();
5104 if (uiccCard == null) {
5105 return;
5106 }
5107 UiccProfile uiccProfile = uiccCard.getUiccProfile();
5108 if (uiccProfile == null) {
5109 return;
5110 }
5111 uiccProfile.refresh();
5112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
5115 }
5116
5117 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07005118 * Returns false if the mobile data is disabled by default, otherwise return true.
5119 */
5120 private boolean getDefaultDataEnabled() {
5121 return "true".equalsIgnoreCase(
5122 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
5123 }
5124
5125 /**
5126 * Returns true if the data roaming is enabled by default, i.e the system property
5127 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
5128 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
5129 */
5130 private boolean getDefaultDataRoamingEnabled(int subId) {
5131 final CarrierConfigManager configMgr = (CarrierConfigManager)
5132 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
5133 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
5134 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
5135 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
5136 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
5137 return isDataRoamingEnabled;
5138 }
5139
5140 /**
5141 * Returns the default network type for the given {@code subId}, if the default network type is
5142 * not set, return {@link Phone#PREFERRED_NT_MODE}.
5143 */
5144 private int getDefaultNetworkType(int subId) {
5145 return Integer.parseInt(
5146 TelephonyManager.getTelephonyProperty(
5147 mSubscriptionController.getPhoneId(subId),
5148 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
5149 String.valueOf(Phone.PREFERRED_NT_MODE)));
5150 }
fionaxua13278b2018-03-21 00:08:13 -07005151
5152 @Override
5153 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5154 gid1, String gid2, String plmn, String spn) {
5155 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156
5157 final long identity = Binder.clearCallingIdentity();
5158 try {
5159 final Phone phone = getPhone(subId);
5160 if (phone == null) {
5161 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5162 return;
5163 }
5164 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5165 } finally {
5166 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005167 }
fionaxua13278b2018-03-21 00:08:13 -07005168 }
5169
5170 @Override
5171 public int getCarrierIdListVersion(int subId) {
5172 enforceReadPrivilegedPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173
5174 final long identity = Binder.clearCallingIdentity();
5175 try {
5176 final Phone phone = getPhone(subId);
5177 if (phone == null) {
5178 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5179 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5180 }
5181 return phone.getCarrierIdListVersion();
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07005184 }
fionaxua13278b2018-03-21 00:08:13 -07005185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005186}