blob: dbfb3177e8647f41b20185167b5ba08cd2870164 [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 Ebinger7e934f52017-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 Ebinger4dc095a2018-04-03 15:17:52 -070045import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070047import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070048import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070049import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080050import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070051import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080052import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080053import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070054import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070055import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070058import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080059import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070060import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080061import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070062import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070063import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080066import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070067import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080068import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080069import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070070import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070071import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000072import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070074import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebingera12246d2018-01-16 09:39:35 -080075import android.telephony.ims.aidl.IImsConfig;
76import android.telephony.ims.aidl.IImsMmTelFeature;
77import android.telephony.ims.aidl.IImsRcsFeature;
78import android.telephony.ims.aidl.IImsRegistration;
Brad Ebingere21f25f2018-02-08 16:11:32 -080079import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080081import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080083import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080085
Andrew Lee312e8172014-10-23 17:01:36 -070086import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080087import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070088import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070089import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070090import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070091import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080094import com.android.internal.telephony.IccCard;
Jack Yu8e4fdc22018-04-13 14:05:37 -070095import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +010096import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070097import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070098import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800100import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700101import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700102import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700103import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700104import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700105import com.android.internal.telephony.RILConstants;
Jack Yu8e4fdc22018-04-13 14:05:37 -0700106import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800107import com.android.internal.telephony.SubscriptionController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800108import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700109import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700110import com.android.internal.telephony.uicc.IccIoResult;
111import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800112import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700113import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800114import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700115import com.android.internal.telephony.uicc.UiccController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800116import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000117import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700118import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800119import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700120import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800121import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700122import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700123import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800124
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700125import java.io.FileDescriptor;
126import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800127import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800129import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800130import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100131import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133
134/**
135 * Implementation of the ITelephony interface.
136 */
Santos Cordon117fee72014-05-16 17:56:12 -0700137public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138 private static final String LOG_TAG = "PhoneInterfaceManager";
139 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
140 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142
143 // Message codes used with mMainThreadHandler
144 private static final int CMD_HANDLE_PIN_MMI = 1;
145 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
146 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
147 private static final int CMD_ANSWER_RINGING_CALL = 4;
148 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700149 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
150 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151 private static final int CMD_OPEN_CHANNEL = 9;
152 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
153 private static final int CMD_CLOSE_CHANNEL = 11;
154 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800155 private static final int CMD_NV_READ_ITEM = 13;
156 private static final int EVENT_NV_READ_ITEM_DONE = 14;
157 private static final int CMD_NV_WRITE_ITEM = 15;
158 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
159 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
160 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
161 private static final int CMD_NV_RESET_CONFIG = 19;
162 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800163 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
164 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
165 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
166 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800167 private static final int CMD_SEND_ENVELOPE = 25;
168 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian74b16b12018-04-27 01:32:07 +0000169 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
170 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700171 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
172 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
173 private static final int CMD_EXCHANGE_SIM_IO = 31;
174 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800175 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
176 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700177 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
178 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700179 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
180 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700181 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
182 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
183 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
184 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700185 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
186 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
187 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
188 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700189 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
191 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000192 private static final int CMD_SWITCH_SLOTS = 50;
193 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800195 // Parameters of select command.
196 private static final int SELECT_COMMAND = 0xA4;
197 private static final int SELECT_P1 = 0x04;
198 private static final int SELECT_P2 = 0;
199 private static final int SELECT_P3 = 0x10;
200
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 /** The singleton instance. */
202 private static PhoneInterfaceManager sInstance;
203
Wink Saville3ab207e2014-11-20 13:07:20 -0800204 private PhoneGlobals mApp;
205 private Phone mPhone;
206 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700207 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800208 private AppOpsManager mAppOps;
209 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800210 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800211 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212
Derek Tan97ebb422014-09-05 16:55:38 -0700213 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
214 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800215 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700216
Derek Tan740e1672017-06-27 14:56:27 -0700217 // The AID of ISD-R.
218 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
219
yinxub1bed742017-04-17 11:45:04 -0700220 private NetworkScanRequestTracker mNetworkScanRequestTracker;
221
David Kelly5e06a7f2018-03-12 14:10:59 +0000222 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
223 private static final int MANUFACTURER_CODE_LENGTH = 8;
224
Derek Tan89e89d42014-07-08 17:00:10 -0700225 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226 * A request object to use for transmitting data to an ICC.
227 */
228 private static final class IccAPDUArgument {
229 public int channel, cla, command, p1, p2, p3;
230 public String data;
231
232 public IccAPDUArgument(int channel, int cla, int command,
233 int p1, int p2, int p3, String data) {
234 this.channel = channel;
235 this.cla = cla;
236 this.command = command;
237 this.p1 = p1;
238 this.p2 = p2;
239 this.p3 = p3;
240 this.data = data;
241 }
242 }
243
244 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700245 * A request object to use for transmitting data to an ICC.
246 */
247 private static final class ManualNetworkSelectionArgument {
248 public OperatorInfo operatorInfo;
249 public boolean persistSelection;
250
251 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
252 this.operatorInfo = operatorInfo;
253 this.persistSelection = persistSelection;
254 }
255 }
256
257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
259 * request after sending. The main thread will notify the request when it is complete.
260 */
261 private static final class MainThreadRequest {
262 /** The argument to use for the request */
263 public Object argument;
264 /** The result of the request that is run on the main thread */
265 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800266 // The subscriber id that this request applies to. Defaults to
267 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
268 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
270 public MainThreadRequest(Object argument) {
271 this.argument = argument;
272 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800273
274 public MainThreadRequest(Object argument, Integer subId) {
275 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800276 if (subId != null) {
277 this.subId = subId;
278 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 }
281
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800282 private static final class IncomingThirdPartyCallArgs {
283 public final ComponentName component;
284 public final String callId;
285 public final String callerDisplayName;
286
287 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
288 String callerDisplayName) {
289 this.component = component;
290 this.callId = callId;
291 this.callerDisplayName = callerDisplayName;
292 }
293 }
294
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 /**
296 * A handler that processes messages on the main thread in the phone process. Since many
297 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
298 * inbound binder threads to the main thread in the phone process. The Binder thread
299 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
300 * on, which will be notified when the operation completes and will contain the result of the
301 * request.
302 *
303 * <p>If a MainThreadRequest object is provided in the msg.obj field,
304 * note that request.result must be set to something non-null for the calling thread to
305 * unblock.
306 */
307 private final class MainThreadHandler extends Handler {
308 @Override
309 public void handleMessage(Message msg) {
310 MainThreadRequest request;
311 Message onCompleted;
312 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800313 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700314 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
316 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700317 case CMD_HANDLE_USSD_REQUEST: {
318 request = (MainThreadRequest) msg.obj;
319 final Phone phone = getPhoneFromRequest(request);
320 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
321 String ussdRequest = ussdObject.first;
322 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700323
324 if (!isUssdApiAllowed(request.subId)) {
325 // Carrier does not support use of this API, return failure.
326 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
327 UssdResponse response = new UssdResponse(ussdRequest, null);
328 Bundle returnData = new Bundle();
329 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
330 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
331
332 request.result = true;
333 synchronized (request) {
334 request.notifyAll();
335 }
336 return;
337 }
338
Tyler Gunn52dcf772017-04-26 11:30:31 -0700339 try {
340 request.result = phone != null ?
341 phone.handleUssdRequest(ussdRequest, wrappedCallback)
342 : false;
343 } catch (CallStateException cse) {
344 request.result = false;
345 }
pkanwar32d516d2016-10-14 19:37:38 -0700346 // Wake up the requesting thread
347 synchronized (request) {
348 request.notifyAll();
349 }
350 break;
351 }
352
Yorke Lee716f67e2015-06-17 15:39:16 -0700353 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700355 final Phone phone = getPhoneFromRequest(request);
356 request.result = phone != null ?
357 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
358 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 // Wake up the requesting thread
360 synchronized (request) {
361 request.notifyAll();
362 }
363 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
366 case CMD_HANDLE_NEIGHBORING_CELL:
367 request = (MainThreadRequest) msg.obj;
368 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
369 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700370 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 break;
372
373 case EVENT_NEIGHBORING_CELL_DONE:
374 ar = (AsyncResult) msg.obj;
375 request = (MainThreadRequest) ar.userObj;
376 if (ar.exception == null && ar.result != null) {
377 request.result = ar.result;
378 } else {
379 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800380 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382 // Wake up the requesting thread
383 synchronized (request) {
384 request.notifyAll();
385 }
386 break;
387
388 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700389 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800390 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700391 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800392 request.result = ""; // dummy result for notifying the waiting thread
393 // Wake up the requesting thread
394 synchronized (request) {
395 request.notifyAll();
396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 break;
398
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 case CMD_END_CALL:
400 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800401 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700402 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700403 Phone phone = getPhone(end_subId);
404 if (phone == null) {
405 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
406 break;
407 }
408 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
410 // CDMA: If the user presses the Power button we treat it as
411 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700412 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
414 // GSM: End the call as per the Phone state
415 hungUp = PhoneUtils.hangup(mCM);
416 } else {
417 throw new IllegalStateException("Unexpected phone type: " + phoneType);
418 }
419 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
420 request.result = hungUp;
421 // Wake up the requesting thread
422 synchronized (request) {
423 request.notifyAll();
424 }
425 break;
426
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800430 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700431 if (uiccCard == null) {
432 loge("iccTransmitApduLogicalChannel: No UICC");
433 request.result = new IccIoResult(0x6F, 0, (byte[])null);
434 synchronized (request) {
435 request.notifyAll();
436 }
437 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
439 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700440 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 iccArgument.channel, iccArgument.cla, iccArgument.command,
442 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700444 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 break;
446
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 ar = (AsyncResult) msg.obj;
449 request = (MainThreadRequest) ar.userObj;
450 if (ar.exception == null && ar.result != null) {
451 request.result = ar.result;
452 } else {
453 request.result = new IccIoResult(0x6F, 0, (byte[])null);
454 if (ar.result == null) {
455 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800456 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700457 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800458 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 } else {
460 loge("iccTransmitApduLogicalChannel: Unknown exception");
461 }
462 }
463 synchronized (request) {
464 request.notifyAll();
465 }
466 break;
467
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
469 request = (MainThreadRequest) msg.obj;
470 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800471 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 if (uiccCard == null) {
473 loge("iccTransmitApduBasicChannel: No UICC");
474 request.result = new IccIoResult(0x6F, 0, (byte[])null);
475 synchronized (request) {
476 request.notifyAll();
477 }
478 } else {
479 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
480 request);
481 uiccCard.iccTransmitApduBasicChannel(
482 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
483 iccArgument.p3, iccArgument.data, onCompleted);
484 }
485 break;
486
487 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
488 ar = (AsyncResult) msg.obj;
489 request = (MainThreadRequest) ar.userObj;
490 if (ar.exception == null && ar.result != null) {
491 request.result = ar.result;
492 } else {
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
494 if (ar.result == null) {
495 loge("iccTransmitApduBasicChannel: Empty response");
496 } else if (ar.exception instanceof CommandException) {
497 loge("iccTransmitApduBasicChannel: CommandException: " +
498 ar.exception);
499 } else {
500 loge("iccTransmitApduBasicChannel: Unknown exception");
501 }
502 }
503 synchronized (request) {
504 request.notifyAll();
505 }
506 break;
507
508 case CMD_EXCHANGE_SIM_IO:
509 request = (MainThreadRequest) msg.obj;
510 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800511 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 if (uiccCard == null) {
513 loge("iccExchangeSimIO: No UICC");
514 request.result = new IccIoResult(0x6F, 0, (byte[])null);
515 synchronized (request) {
516 request.notifyAll();
517 }
518 } else {
519 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
520 request);
521 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
522 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
523 iccArgument.data, onCompleted);
524 }
525 break;
526
527 case EVENT_EXCHANGE_SIM_IO_DONE:
528 ar = (AsyncResult) msg.obj;
529 request = (MainThreadRequest) ar.userObj;
530 if (ar.exception == null && ar.result != null) {
531 request.result = ar.result;
532 } else {
533 request.result = new IccIoResult(0x6f, 0, (byte[])null);
534 }
535 synchronized (request) {
536 request.notifyAll();
537 }
538 break;
539
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 case CMD_SEND_ENVELOPE:
541 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800542 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 if (uiccCard == null) {
544 loge("sendEnvelopeWithStatus: No UICC");
545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
546 synchronized (request) {
547 request.notifyAll();
548 }
549 } else {
550 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
551 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
552 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800553 break;
554
555 case EVENT_SEND_ENVELOPE_DONE:
556 ar = (AsyncResult) msg.obj;
557 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700558 if (ar.exception == null && ar.result != null) {
559 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700561 request.result = new IccIoResult(0x6F, 0, (byte[])null);
562 if (ar.result == null) {
563 loge("sendEnvelopeWithStatus: Empty response");
564 } else if (ar.exception instanceof CommandException) {
565 loge("sendEnvelopeWithStatus: CommandException: " +
566 ar.exception);
567 } else {
568 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
569 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 }
571 synchronized (request) {
572 request.notifyAll();
573 }
574 break;
575
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 case CMD_OPEN_CHANNEL:
577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800578 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800579 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 if (uiccCard == null) {
581 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800582 request.result = new IccOpenLogicalChannelResponse(-1,
583 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 synchronized (request) {
585 request.notifyAll();
586 }
587 } else {
588 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800589 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
590 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 break;
593
594 case EVENT_OPEN_CHANNEL_DONE:
595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 int[] result = (int[]) ar.result;
600 int channelId = result[0];
601 byte[] selectResponse = null;
602 if (result.length > 1) {
603 selectResponse = new byte[result.length - 1];
604 for (int i = 1; i < result.length; ++i) {
605 selectResponse[i - 1] = (byte) result[i];
606 }
607 }
608 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.result == null) {
612 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 if (ar.exception != null) {
615 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
616 }
617
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700619 if (ar.exception instanceof CommandException) {
620 CommandException.Error error =
621 ((CommandException) (ar.exception)).getCommandError();
622 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700624 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 }
627 }
628 openChannelResp = new IccOpenLogicalChannelResponse(
629 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700631 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 synchronized (request) {
633 request.notifyAll();
634 }
635 break;
636
637 case CMD_CLOSE_CHANNEL:
638 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800639 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 if (uiccCard == null) {
641 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900642 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 synchronized (request) {
644 request.notifyAll();
645 }
646 } else {
647 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
648 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
649 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800653 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
654 break;
655
656 case CMD_NV_READ_ITEM:
657 request = (MainThreadRequest) msg.obj;
658 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
659 mPhone.nvReadItem((Integer) request.argument, onCompleted);
660 break;
661
662 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800668 request.result = "";
669 if (ar.result == null) {
670 loge("nvReadItem: Empty response");
671 } else if (ar.exception instanceof CommandException) {
672 loge("nvReadItem: CommandException: " +
673 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800675 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 }
677 }
678 synchronized (request) {
679 request.notifyAll();
680 }
681 break;
682
Jake Hambye994d462014-02-03 13:10:13 -0800683 case CMD_NV_WRITE_ITEM:
684 request = (MainThreadRequest) msg.obj;
685 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
686 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
687 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
688 break;
689
690 case EVENT_NV_WRITE_ITEM_DONE:
691 handleNullReturnEvent(msg, "nvWriteItem");
692 break;
693
694 case CMD_NV_WRITE_CDMA_PRL:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
697 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
698 break;
699
700 case EVENT_NV_WRITE_CDMA_PRL_DONE:
701 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
702 break;
703
704 case CMD_NV_RESET_CONFIG:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
707 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
708 break;
709
710 case EVENT_NV_RESET_CONFIG_DONE:
711 handleNullReturnEvent(msg, "nvResetConfig");
712 break;
713
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 case CMD_GET_PREFERRED_NETWORK_TYPE:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700717 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 break;
719
720 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
721 ar = (AsyncResult) msg.obj;
722 request = (MainThreadRequest) ar.userObj;
723 if (ar.exception == null && ar.result != null) {
724 request.result = ar.result; // Integer
725 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800726 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 if (ar.result == null) {
728 loge("getPreferredNetworkType: Empty response");
729 } else if (ar.exception instanceof CommandException) {
730 loge("getPreferredNetworkType: CommandException: " +
731 ar.exception);
732 } else {
733 loge("getPreferredNetworkType: Unknown exception");
734 }
735 }
736 synchronized (request) {
737 request.notifyAll();
738 }
739 break;
740
741 case CMD_SET_PREFERRED_NETWORK_TYPE:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
744 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700745 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
749 handleNullReturnEvent(msg, "setPreferredNetworkType");
750 break;
751
Shuo Qian74b16b12018-04-27 01:32:07 +0000752 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
753 request = (MainThreadRequest)msg.obj;
754 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
755 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
756 break;
757
758 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
759 ar = (AsyncResult)msg.obj;
760 request = (MainThreadRequest)ar.userObj;
761 request.result = ar;
762 synchronized (request) {
763 request.notifyAll();
764 }
765 break;
766
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800767 case CMD_SET_VOICEMAIL_NUMBER:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
770 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800771 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
772 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 break;
774
775 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
776 handleNullReturnEvent(msg, "setVoicemailNumber");
777 break;
778
Stuart Scott54788802015-03-30 13:18:01 -0700779 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
782 request);
783 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
784 break;
785
786 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
787 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
788 break;
789
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 case CMD_PERFORM_NETWORK_SCAN:
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
793 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
794 break;
795
796 case EVENT_PERFORM_NETWORK_SCAN_DONE:
797 ar = (AsyncResult) msg.obj;
798 request = (MainThreadRequest) ar.userObj;
799 CellNetworkScanResult cellScanResult;
800 if (ar.exception == null && ar.result != null) {
801 cellScanResult = new CellNetworkScanResult(
802 CellNetworkScanResult.STATUS_SUCCESS,
803 (List<OperatorInfo>) ar.result);
804 } else {
805 if (ar.result == null) {
806 loge("getCellNetworkScanResults: Empty response");
807 }
808 if (ar.exception != null) {
809 loge("getCellNetworkScanResults: Exception: " + ar.exception);
810 }
811 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
812 if (ar.exception instanceof CommandException) {
813 CommandException.Error error =
814 ((CommandException) (ar.exception)).getCommandError();
815 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
816 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
817 } else if (error == CommandException.Error.GENERIC_FAILURE) {
818 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
819 }
820 }
821 cellScanResult = new CellNetworkScanResult(errorCode, null);
822 }
823 request.result = cellScanResult;
824 synchronized (request) {
825 request.notifyAll();
826 }
827 break;
828
829 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
830 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700831 ManualNetworkSelectionArgument selArg =
832 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
834 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700835 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
836 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 break;
838
839 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
840 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
841 break;
842
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 case CMD_GET_MODEM_ACTIVITY_INFO:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700846 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700847 break;
848
849 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result;
854 } else {
855 if (ar.result == null) {
856 loge("queryModemActivityInfo: Empty response");
857 } else if (ar.exception instanceof CommandException) {
858 loge("queryModemActivityInfo: CommandException: " +
859 ar.exception);
860 } else {
861 loge("queryModemActivityInfo: Unknown exception");
862 }
863 }
Amit Mahajand4766222016-01-28 15:28:28 -0800864 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
865 if (request.result == null) {
866 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
867 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700868 synchronized (request) {
869 request.notifyAll();
870 }
871 break;
872
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 case CMD_SET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
876 mPhone.setAllowedCarriers(
877 (List<CarrierIdentifier>) request.argument,
878 onCompleted);
879 break;
880
881 case EVENT_SET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
887 if (ar.result == null) {
888 loge("setAllowedCarriers: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("setAllowedCarriers: CommandException: " +
891 ar.exception);
892 } else {
893 loge("setAllowedCarriers: Unknown exception");
894 }
895 }
896 // Result cannot be null. Return -1 on error.
897 if (request.result == null) {
898 request.result = new int[]{-1};
899 }
900 synchronized (request) {
901 request.notifyAll();
902 }
903 break;
904
905 case CMD_GET_ALLOWED_CARRIERS:
906 request = (MainThreadRequest) msg.obj;
907 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
908 mPhone.getAllowedCarriers(onCompleted);
909 break;
910
911 case EVENT_GET_ALLOWED_CARRIERS_DONE:
912 ar = (AsyncResult) msg.obj;
913 request = (MainThreadRequest) ar.userObj;
914 if (ar.exception == null && ar.result != null) {
915 request.result = ar.result;
916 } else {
917 if (ar.result == null) {
918 loge("getAllowedCarriers: Empty response");
919 } else if (ar.exception instanceof CommandException) {
920 loge("getAllowedCarriers: CommandException: " +
921 ar.exception);
922 } else {
923 loge("getAllowedCarriers: Unknown exception");
924 }
925 }
926 // Result cannot be null. Return empty list of CarrierIdentifier.
927 if (request.result == null) {
928 request.result = new ArrayList<CarrierIdentifier>(0);
929 }
930 synchronized (request) {
931 request.notifyAll();
932 }
933 break;
934
Nathan Haroldb3014052017-01-25 15:57:32 -0800935 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
938 if (ar.exception == null && ar.result != null) {
939 request.result = ar.result;
940 } else {
941 request.result = new IllegalArgumentException(
942 "Failed to retrieve Forbidden Plmns");
943 if (ar.result == null) {
944 loge("getForbiddenPlmns: Empty response");
945 } else {
946 loge("getForbiddenPlmns: Unknown exception");
947 }
948 }
949 synchronized (request) {
950 request.notifyAll();
951 }
952 break;
953
954 case CMD_GET_FORBIDDEN_PLMNS:
955 request = (MainThreadRequest) msg.obj;
956 uiccCard = getUiccCardFromRequest(request);
957 if (uiccCard == null) {
958 loge("getForbiddenPlmns() UiccCard is null");
959 request.result = new IllegalArgumentException(
960 "getForbiddenPlmns() UiccCard is null");
961 synchronized (request) {
962 request.notifyAll();
963 }
964 break;
965 }
966 Integer appType = (Integer) request.argument;
967 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
968 if (uiccApp == null) {
969 loge("getForbiddenPlmns() no app with specified type -- "
970 + appType);
971 request.result = new IllegalArgumentException("Failed to get UICC App");
972 synchronized (request) {
973 request.notifyAll();
974 }
975 break;
976 } else {
977 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
978 + " specified type -- " + appType);
979 }
980 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
981 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
982 onCompleted);
983 break;
984
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000985 case CMD_SWITCH_SLOTS:
986 request = (MainThreadRequest) msg.obj;
987 int[] physicalSlots = (int[]) request.argument;
988 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
989 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
990 break;
991
992 case EVENT_SWITCH_SLOTS_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 request.result = (ar.exception == null);
996 synchronized (request) {
997 request.notifyAll();
998 }
999 break;
1000
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001001 default:
1002 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1003 break;
1004 }
1005 }
Jake Hambye994d462014-02-03 13:10:13 -08001006
1007 private void handleNullReturnEvent(Message msg, String command) {
1008 AsyncResult ar = (AsyncResult) msg.obj;
1009 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1010 if (ar.exception == null) {
1011 request.result = true;
1012 } else {
1013 request.result = false;
1014 if (ar.exception instanceof CommandException) {
1015 loge(command + ": CommandException: " + ar.exception);
1016 } else {
1017 loge(command + ": Unknown exception");
1018 }
1019 }
1020 synchronized (request) {
1021 request.notifyAll();
1022 }
1023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001024 }
1025
1026 /**
1027 * Posts the specified command to be executed on the main thread,
1028 * waits for the request to complete, and returns the result.
1029 * @see #sendRequestAsync
1030 */
1031 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001032 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001033 }
1034
1035 /**
1036 * Posts the specified command to be executed on the main thread,
1037 * waits for the request to complete, and returns the result.
1038 * @see #sendRequestAsync
1039 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001040 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001041 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1042 throw new RuntimeException("This method will deadlock if called from the main thread.");
1043 }
1044
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001045 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001046 Message msg = mMainThreadHandler.obtainMessage(command, request);
1047 msg.sendToTarget();
1048
1049 // Wait for the request to complete
1050 synchronized (request) {
1051 while (request.result == null) {
1052 try {
1053 request.wait();
1054 } catch (InterruptedException e) {
1055 // Do nothing, go back and wait until the request is complete
1056 }
1057 }
1058 }
1059 return request.result;
1060 }
1061
1062 /**
1063 * Asynchronous ("fire and forget") version of sendRequest():
1064 * Posts the specified command to be executed on the main thread, and
1065 * returns immediately.
1066 * @see #sendRequest
1067 */
1068 private void sendRequestAsync(int command) {
1069 mMainThreadHandler.sendEmptyMessage(command);
1070 }
1071
1072 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001073 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1074 * @see {@link #sendRequest(int,Object)}
1075 */
1076 private void sendRequestAsync(int command, Object argument) {
1077 MainThreadRequest request = new MainThreadRequest(argument);
1078 Message msg = mMainThreadHandler.obtainMessage(command, request);
1079 msg.sendToTarget();
1080 }
1081
1082 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 * Initialize the singleton PhoneInterfaceManager instance.
1084 * This is only done once, at startup, from PhoneApp.onCreate().
1085 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001086 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 synchronized (PhoneInterfaceManager.class) {
1088 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001089 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 } else {
1091 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1092 }
1093 return sInstance;
1094 }
1095 }
1096
1097 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001098 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001099 mApp = app;
1100 mPhone = phone;
1101 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001102 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1104 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001105 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001106 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001107 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001108 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001109
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 publish();
1111 }
1112
1113 private void publish() {
1114 if (DBG) log("publish: " + this);
1115
1116 ServiceManager.addService("phone", this);
1117 }
1118
Stuart Scott584921c2015-01-15 17:10:34 -08001119 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001120 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1121 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001122 }
1123
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001124 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1125 Phone phone = getPhoneFromRequest(request);
1126 return phone == null ? null :
1127 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1128 }
1129
Wink Saville36469e72014-06-11 15:17:00 -07001130 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001131 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001132 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001134 //
1135 // Implementation of the ITelephony interface.
1136 //
1137
1138 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001139 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001140 }
1141
Wink Savilleb564aae2014-10-23 10:18:09 -07001142 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001143 if (DBG) log("dial: " + number);
1144 // No permission check needed here: This is just a wrapper around the
1145 // ACTION_DIAL intent, which is available to any app since it puts up
1146 // the UI before it does anything.
1147
Malcolm Chenaabec062018-02-28 15:00:40 -08001148 final long identity = Binder.clearCallingIdentity();
1149 try {
1150 String url = createTelUrl(number);
1151 if (url == null) {
1152 return;
1153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001154
Malcolm Chenaabec062018-02-28 15:00:40 -08001155 // PENDING: should we just silently fail if phone is offhook or ringing?
1156 PhoneConstants.State state = mCM.getState(subId);
1157 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1158 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1159 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1160 mApp.startActivity(intent);
1161 }
1162 } finally {
1163 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001164 }
1165 }
1166
1167 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001168 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001169 }
1170
Wink Savilleb564aae2014-10-23 10:18:09 -07001171 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172 if (DBG) log("call: " + number);
1173
1174 // This is just a wrapper around the ACTION_CALL intent, but we still
1175 // need to do a permission check since we're calling startActivity()
1176 // from the context of the phone app.
1177 enforceCallPermission();
1178
1179 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1180 != AppOpsManager.MODE_ALLOWED) {
1181 return;
1182 }
1183
Malcolm Chenaabec062018-02-28 15:00:40 -08001184 final long identity = Binder.clearCallingIdentity();
1185 try {
1186 String url = createTelUrl(number);
1187 if (url == null) {
1188 return;
1189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190
Malcolm Chenaabec062018-02-28 15:00:40 -08001191 boolean isValid = false;
1192 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1193 if (slist != null) {
1194 for (SubscriptionInfo subInfoRecord : slist) {
1195 if (subInfoRecord.getSubscriptionId() == subId) {
1196 isValid = true;
1197 break;
1198 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001199 }
Wink Saville08874612014-08-31 19:19:58 -07001200 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001201 if (!isValid) {
1202 return;
1203 }
Wink Saville08874612014-08-31 19:19:58 -07001204
Malcolm Chenaabec062018-02-28 15:00:40 -08001205 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1206 intent.putExtra(SUBSCRIPTION_KEY, subId);
1207 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1208 mApp.startActivity(intent);
1209 } finally {
1210 Binder.restoreCallingIdentity(identity);
1211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001212 }
1213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 /**
1215 * End a call based on call state
1216 * @return true is a call was ended
1217 */
1218 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001219 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001220 }
1221
1222 /**
1223 * End a call based on the call state of the subId
1224 * @return true is a call was ended
1225 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001226 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001227 enforceCallPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001228
1229 final long identity = Binder.clearCallingIdentity();
1230 try {
1231 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1232 } finally {
1233 Binder.restoreCallingIdentity(identity);
1234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 }
1236
1237 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001238 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001239 }
1240
Wink Savilleb564aae2014-10-23 10:18:09 -07001241 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 if (DBG) log("answerRingingCall...");
1243 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1244 // but that can probably wait till the big TelephonyManager API overhaul.
1245 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1246 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001247
1248 final long identity = Binder.clearCallingIdentity();
1249 try {
1250 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1251 } finally {
1252 Binder.restoreCallingIdentity(identity);
1253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 }
1255
1256 /**
1257 * Make the actual telephony calls to implement answerRingingCall().
1258 * This should only be called from the main thread of the Phone app.
1259 * @see #answerRingingCall
1260 *
1261 * TODO: it would be nice to return true if we answered the call, or
1262 * false if there wasn't actually a ringing incoming call, or some
1263 * other error occurred. (In other words, pass back the return value
1264 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1265 * But that would require calling this method via sendRequest() rather
1266 * than sendRequestAsync(), and right now we don't actually *need* that
1267 * return value, so let's just return void for now.
1268 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001269 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001270 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001272 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1273 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 if (hasActiveCall && hasHoldingCall) {
1275 // Both lines are in use!
1276 // TODO: provide a flag to let the caller specify what
1277 // policy to use if both lines are in use. (The current
1278 // behavior is hardwired to "answer incoming, end ongoing",
1279 // which is how the CALL button is specced to behave.)
1280 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1281 return;
1282 } else {
1283 // answerCall() will automatically hold the current active
1284 // call, if there is one.
1285 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1286 return;
1287 }
1288 } else {
1289 // No call was ringing.
1290 return;
1291 }
1292 }
1293
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001294 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001295 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001296 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001297 public void silenceRinger() {
1298 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299 }
1300
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001301 @Override
1302 public boolean isOffhook(String callingPackage) {
1303 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001304 }
1305
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001306 @Override
1307 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001309 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001310 return false;
1311 }
1312
Malcolm Chenaabec062018-02-28 15:00:40 -08001313 final long identity = Binder.clearCallingIdentity();
1314 try {
1315 final Phone phone = getPhone(subId);
1316 if (phone != null) {
1317 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1318 } else {
1319 return false;
1320 }
1321 } finally {
1322 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 }
1325
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001326 @Override
1327 public boolean isRinging(String callingPackage) {
1328 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001329 }
1330
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001331 @Override
1332 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001333 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001334 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001335 return false;
1336 }
1337
Malcolm Chenaabec062018-02-28 15:00:40 -08001338 final long identity = Binder.clearCallingIdentity();
1339 try {
1340 final Phone phone = getPhone(subId);
1341 if (phone != null) {
1342 return (phone.getState() == PhoneConstants.State.RINGING);
1343 } else {
1344 return false;
1345 }
1346 } finally {
1347 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 }
1350
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001351 @Override
1352 public boolean isIdle(String callingPackage) {
1353 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001354 }
1355
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001356 @Override
1357 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001359 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001360 return false;
1361 }
1362
Malcolm Chenaabec062018-02-28 15:00:40 -08001363 final long identity = Binder.clearCallingIdentity();
1364 try {
1365 final Phone phone = getPhone(subId);
1366 if (phone != null) {
1367 return (phone.getState() == PhoneConstants.State.IDLE);
1368 } else {
1369 return false;
1370 }
1371 } finally {
1372 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 }
1375
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001377 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001378 }
1379
Wink Savilleb564aae2014-10-23 10:18:09 -07001380 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001381 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001382 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1383 }
1384
1385 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001386 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001387 }
1388
Wink Savilleb564aae2014-10-23 10:18:09 -07001389 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001390 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001391 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1392 }
1393
1394 /** {@hide} */
1395 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001396 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001397 }
1398
Wink Savilleb564aae2014-10-23 10:18:09 -07001399 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001401
1402 final long identity = Binder.clearCallingIdentity();
1403 try {
1404 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1405 checkSimPin.start();
1406 return checkSimPin.unlockSim(null, pin);
1407 } finally {
1408 Binder.restoreCallingIdentity(identity);
1409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 }
1411
Wink Saville9de0f752013-10-22 19:04:03 -07001412 /** {@hide} */
1413 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001414 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001415 }
1416
Wink Savilleb564aae2014-10-23 10:18:09 -07001417 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001419
1420 final long identity = Binder.clearCallingIdentity();
1421 try {
1422 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1423 checkSimPuk.start();
1424 return checkSimPuk.unlockSim(puk, pin);
1425 } finally {
1426 Binder.restoreCallingIdentity(identity);
1427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 }
1429
1430 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001431 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432 * a synchronous one.
1433 */
1434 private static class UnlockSim extends Thread {
1435
1436 private final IccCard mSimCard;
1437
1438 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001439 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1440 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441
1442 // For replies from SimCard interface
1443 private Handler mHandler;
1444
1445 // For async handler to identify request type
1446 private static final int SUPPLY_PIN_COMPLETE = 100;
1447
1448 public UnlockSim(IccCard simCard) {
1449 mSimCard = simCard;
1450 }
1451
1452 @Override
1453 public void run() {
1454 Looper.prepare();
1455 synchronized (UnlockSim.this) {
1456 mHandler = new Handler() {
1457 @Override
1458 public void handleMessage(Message msg) {
1459 AsyncResult ar = (AsyncResult) msg.obj;
1460 switch (msg.what) {
1461 case SUPPLY_PIN_COMPLETE:
1462 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1463 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001464 mRetryCount = msg.arg1;
1465 if (ar.exception != null) {
1466 if (ar.exception instanceof CommandException &&
1467 ((CommandException)(ar.exception)).getCommandError()
1468 == CommandException.Error.PASSWORD_INCORRECT) {
1469 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1470 } else {
1471 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1472 }
1473 } else {
1474 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476 mDone = true;
1477 UnlockSim.this.notifyAll();
1478 }
1479 break;
1480 }
1481 }
1482 };
1483 UnlockSim.this.notifyAll();
1484 }
1485 Looper.loop();
1486 }
1487
1488 /*
1489 * Use PIN or PUK to unlock SIM card
1490 *
1491 * If PUK is null, unlock SIM card with PIN
1492 *
1493 * If PUK is not null, unlock SIM card with PUK and set PIN code
1494 */
Wink Saville9de0f752013-10-22 19:04:03 -07001495 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496
1497 while (mHandler == null) {
1498 try {
1499 wait();
1500 } catch (InterruptedException e) {
1501 Thread.currentThread().interrupt();
1502 }
1503 }
1504 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1505
1506 if (puk == null) {
1507 mSimCard.supplyPin(pin, callback);
1508 } else {
1509 mSimCard.supplyPuk(puk, pin, callback);
1510 }
1511
1512 while (!mDone) {
1513 try {
1514 Log.d(LOG_TAG, "wait for done");
1515 wait();
1516 } catch (InterruptedException e) {
1517 // Restore the interrupted status
1518 Thread.currentThread().interrupt();
1519 }
1520 }
1521 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001522 int[] resultArray = new int[2];
1523 resultArray[0] = mResult;
1524 resultArray[1] = mRetryCount;
1525 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 }
1527 }
1528
1529 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001530 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001531
1532 }
1533
Wink Savilleb564aae2014-10-23 10:18:09 -07001534 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 // No permission check needed here: this call is harmless, and it's
1536 // needed for the ServiceState.requestStateUpdate() call (which is
1537 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001538 final long identity = Binder.clearCallingIdentity();
1539 try {
1540 final Phone phone = getPhone(subId);
1541 if (phone != null) {
1542 phone.updateServiceLocation();
1543 }
1544 } finally {
1545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 }
1548
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001549 @Override
1550 public boolean isRadioOn(String callingPackage) {
1551 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001552 }
1553
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001554 @Override
1555 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001557 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001558 return false;
1559 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001560
1561 final long identity = Binder.clearCallingIdentity();
1562 try {
1563 return isRadioOnForSubscriber(subId);
1564 } finally {
1565 Binder.restoreCallingIdentity(identity);
1566 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001567 }
1568
1569 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001570 final long identity = Binder.clearCallingIdentity();
1571 try {
1572 final Phone phone = getPhone(subId);
1573 if (phone != null) {
1574 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1575 } else {
1576 return false;
1577 }
1578 } finally {
1579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 }
1582
1583 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001584 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 }
Wink Saville36469e72014-06-11 15:17:00 -07001586
Wink Savilleb564aae2014-10-23 10:18:09 -07001587 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001589
1590 final long identity = Binder.clearCallingIdentity();
1591 try {
1592 final Phone phone = getPhone(subId);
1593 if (phone != null) {
1594 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1595 }
1596 } finally {
1597 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001598 }
Wink Saville36469e72014-06-11 15:17:00 -07001599 }
1600
1601 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001602 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001603 }
1604
Wink Savilleb564aae2014-10-23 10:18:09 -07001605 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001606 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001607
1608 final long identity = Binder.clearCallingIdentity();
1609 try {
1610 final Phone phone = getPhone(subId);
1611 if (phone == null) {
1612 return false;
1613 }
1614 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1615 toggleRadioOnOffForSubscriber(subId);
1616 }
1617 return true;
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
Wink Saville36469e72014-06-11 15:17:00 -07001622
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001623 public boolean needMobileRadioShutdown() {
1624 /*
1625 * If any of the Radios are available, it will need to be
1626 * shutdown. So return true if any Radio is available.
1627 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001628 final long identity = Binder.clearCallingIdentity();
1629 try {
1630 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1631 Phone phone = PhoneFactory.getPhone(i);
1632 if (phone != null && phone.isRadioAvailable()) return true;
1633 }
1634 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1635 return false;
1636 } finally {
1637 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001638 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001639 }
1640
Malcolm Chenaabec062018-02-28 15:00:40 -08001641 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001642 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001643 enforceModifyPermission();
1644
1645 final long identity = Binder.clearCallingIdentity();
1646 try {
1647 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1648 logv("Shutting down Phone " + i);
1649 shutdownRadioUsingPhoneId(i);
1650 }
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001653 }
1654 }
1655
1656 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001657 Phone phone = PhoneFactory.getPhone(phoneId);
1658 if (phone != null && phone.isRadioAvailable()) {
1659 phone.shutdownRadio();
1660 }
1661 }
1662
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001664 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001665
1666 final long identity = Binder.clearCallingIdentity();
1667 try {
1668 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1669 if (defaultPhone != null) {
1670 defaultPhone.setRadioPower(turnOn);
1671 return true;
1672 } else {
1673 loge("There's no default phone.");
1674 return false;
1675 }
1676 } finally {
1677 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001678 }
Wink Saville36469e72014-06-11 15:17:00 -07001679 }
1680
Wink Savilleb564aae2014-10-23 10:18:09 -07001681 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001683
1684 final long identity = Binder.clearCallingIdentity();
1685 try {
1686 final Phone phone = getPhone(subId);
1687 if (phone != null) {
1688 phone.setRadioPower(turnOn);
1689 return true;
1690 } else {
1691 return false;
1692 }
1693 } finally {
1694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 }
1697
Wink Saville36469e72014-06-11 15:17:00 -07001698 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 public boolean enableDataConnectivity() {
1701 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001702
1703 final long identity = Binder.clearCallingIdentity();
1704 try {
1705 int subId = mSubscriptionController.getDefaultDataSubId();
1706 final Phone phone = getPhone(subId);
1707 if (phone != null) {
1708 phone.setUserDataEnabled(true);
1709 return true;
1710 } else {
1711 return false;
1712 }
1713 } finally {
1714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 }
1717
Wink Saville36469e72014-06-11 15:17:00 -07001718 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001719 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 public boolean disableDataConnectivity() {
1721 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001722
1723 final long identity = Binder.clearCallingIdentity();
1724 try {
1725 int subId = mSubscriptionController.getDefaultDataSubId();
1726 final Phone phone = getPhone(subId);
1727 if (phone != null) {
1728 phone.setUserDataEnabled(false);
1729 return true;
1730 } else {
1731 return false;
1732 }
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 }
1737
Sanket Padawe356d7632015-06-22 14:03:32 -07001738 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001739 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001740 final long identity = Binder.clearCallingIdentity();
1741 try {
1742 final Phone phone = getPhone(subId);
1743 if (phone != null) {
1744 return phone.isDataAllowed();
1745 } else {
1746 return false;
1747 }
1748 } finally {
1749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
1752
1753 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001754 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001755 }
1756
pkanwarae03a6b2016-11-06 20:37:09 -08001757 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001758 enforceCallPermission();
1759
1760 final long identity = Binder.clearCallingIdentity();
1761 try {
1762 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1763 return;
1764 }
1765 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1766 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1767 } finally {
1768 Binder.restoreCallingIdentity(identity);
1769 }
pkanwar32d516d2016-10-14 19:37:38 -07001770 };
1771
Wink Savilleb564aae2014-10-23 10:18:09 -07001772 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001774
1775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1778 return false;
1779 }
1780 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1781 } finally {
1782 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 }
1785
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001787 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001788 }
1789
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001790 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001791 final long identity = Binder.clearCallingIdentity();
1792 try {
1793 Phone phone = PhoneFactory.getPhone(slotIndex);
1794 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1795 PhoneConstantConversions.convertCallState(phone.getState());
1796 } finally {
1797 Binder.restoreCallingIdentity(identity);
1798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 }
1800
Sanket Padawe356d7632015-06-22 14:03:32 -07001801 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1806 if (phone != null) {
1807 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1808 } else {
1809 return PhoneConstantConversions.convertDataState(
1810 PhoneConstants.DataState.DISCONNECTED);
1811 }
1812 } finally {
1813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
1816
Sanket Padawe356d7632015-06-22 14:03:32 -07001817 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001819 final long identity = Binder.clearCallingIdentity();
1820 try {
1821 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1822 if (phone != null) {
1823 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1824 } else {
1825 return TelephonyManager.DATA_ACTIVITY_NONE;
1826 }
1827 } finally {
1828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
1831
1832 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001833 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001834 mPhone.getContext().getSystemService(AppOpsManager.class)
1835 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001836 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov748b5752018-03-07 19:57:05 -08001837 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001838 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 }
1840
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00001841 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001842 final long identity = Binder.clearCallingIdentity();
1843 try {
1844 if (DBG_LOC) log("getCellLocation: is active user");
1845 Bundle data = new Bundle();
1846 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1847 if (phone == null) {
1848 return null;
1849 }
1850
1851 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1852 return data;
1853 } finally {
1854 Binder.restoreCallingIdentity(identity);
1855 }
Svetoslav64fad262015-04-14 14:35:21 -07001856 }
1857
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001859 public String getNetworkCountryIsoForPhone(int phoneId) {
1860 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1861 // registered cell info, so return a NULL country instead.
1862 final long identity = Binder.clearCallingIdentity();
1863 try {
1864 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu8e4fdc22018-04-13 14:05:37 -07001865 // Todo: fix this when we can get the actual cellular network info when the device
1866 // is on IWLAN.
Jonathan Basseri03923952017-07-19 12:22:35 -07001867 if (TelephonyManager.NETWORK_TYPE_IWLAN
1868 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1869 return "";
1870 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001871 Phone phone = PhoneFactory.getPhone(phoneId);
1872 if (phone != null) {
1873 ServiceStateTracker sst = phone.getServiceStateTracker();
1874 if (sst != null) {
1875 LocaleTracker lt = sst.getLocaleTracker();
1876 if (lt != null) {
1877 return lt.getCurrentCountry();
1878 }
1879 }
1880 }
1881 return "";
Jonathan Basseri03923952017-07-19 12:22:35 -07001882 } finally {
1883 Binder.restoreCallingIdentity(identity);
1884 }
Jonathan Basseri03923952017-07-19 12:22:35 -07001885 }
1886
1887 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001889 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001890 }
1891
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001893 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 mApp.enforceCallingOrSelfPermission(
1895 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001896
1897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 final Phone phone = getPhone(subId);
1900 if (phone != null) {
1901 phone.enableLocationUpdates();
1902 }
1903 } finally {
1904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 }
1907
1908 @Override
1909 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001910 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001911 }
1912
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001914 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 mApp.enforceCallingOrSelfPermission(
1916 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001917
1918 final long identity = Binder.clearCallingIdentity();
1919 try {
1920 final Phone phone = getPhone(subId);
1921 if (phone != null) {
1922 phone.disableLocationUpdates();
1923 }
1924 } finally {
1925 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 }
1928
1929 @Override
1930 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001931 public List<NeighboringCellInfo>
1932 getNeighboringCellInfo(String callingPackage, int targetSdk) {
1933 // FIXME: use the P constant when available
1934 if (targetSdk > android.os.Build.VERSION_CODES.O_MR1 + 1) return null;
1935
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001936 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov748b5752018-03-07 19:57:05 -08001937 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001938 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 }
1940
1941 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1942 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1943 return null;
1944 }
Svetoslav64fad262015-04-14 14:35:21 -07001945
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001946 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001948 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00001950 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001951
1952 final long identity = Binder.clearCallingIdentity();
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001953 try {
1954 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1955 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1956 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1957 } catch (RuntimeException e) {
1958 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08001959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001962 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 }
1964
1965
1966 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001967 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001968 mPhone.getContext().getSystemService(AppOpsManager.class)
1969 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001970 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov748b5752018-03-07 19:57:05 -08001971 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001972 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 }
1974
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001975 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00001976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001977 final long identity = Binder.clearCallingIdentity();
1978 try {
1979 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1980 for (Phone phone : PhoneFactory.getPhones()) {
1981 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1982 if (info != null) cellInfos.addAll(info);
1983 }
1984 return cellInfos;
1985 } finally {
1986 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
1988 }
1989
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001990 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001992 enforceModifyPermission();
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00001993 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001994
1995 final long identity = Binder.clearCallingIdentity();
1996 try {
1997 mPhone.setCellInfoListRate(rateInMillis, workSource);
1998 } finally {
1999 Binder.restoreCallingIdentity(identity);
2000 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 }
2002
Shishir Agrawala9f32182016-04-12 12:00:16 -07002003 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002004 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002005 Phone phone = PhoneFactory.getPhone(slotIndex);
2006 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002007 return null;
2008 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002009 int subId = phone.getSubId();
2010 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2011 mApp, subId, callingPackage, "getImeiForSlot")) {
2012 return null;
2013 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002014
2015 final long identity = Binder.clearCallingIdentity();
2016 try {
2017 return phone.getImei();
2018 } finally {
2019 Binder.restoreCallingIdentity(identity);
2020 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002021 }
2022
2023 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002024 public String getTypeAllocationCodeForSlot(int slotIndex) {
2025 Phone phone = PhoneFactory.getPhone(slotIndex);
2026 String tac = null;
2027 if (phone != null) {
2028 String imei = phone.getImei();
2029 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2030 }
2031 return tac;
2032 }
2033
2034 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002035 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002036 Phone phone = PhoneFactory.getPhone(slotIndex);
2037 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002038 return null;
2039 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002040 int subId = phone.getSubId();
2041 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2042 mApp, subId, callingPackage, "getMeidForSlot")) {
2043 return null;
2044 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002045
2046 final long identity = Binder.clearCallingIdentity();
2047 try {
2048 return phone.getMeid();
2049 } finally {
2050 Binder.restoreCallingIdentity(identity);
2051 }
Jack Yu2af8d712017-03-15 17:14:14 -07002052 }
2053
2054 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002055 public String getManufacturerCodeForSlot(int slotIndex) {
2056 Phone phone = PhoneFactory.getPhone(slotIndex);
2057 String manufacturerCode = null;
2058 if (phone != null) {
2059 String meid = phone.getMeid();
2060 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2061 }
2062 return manufacturerCode;
2063 }
2064
2065 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002066 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002067 Phone phone = PhoneFactory.getPhone(slotIndex);
2068 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002069 return null;
2070 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002071 int subId = phone.getSubId();
2072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2073 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2074 return null;
2075 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002076
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 return phone.getDeviceSvn();
2080 } finally {
2081 Binder.restoreCallingIdentity(identity);
2082 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002083 }
2084
fionaxuf32acdf2017-11-27 22:51:16 -08002085 @Override
2086 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002087 final long identity = Binder.clearCallingIdentity();
2088 try {
2089 final Phone phone = getPhone(subId);
2090 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2091 } finally {
2092 Binder.restoreCallingIdentity(identity);
2093 }
fionaxuf32acdf2017-11-27 22:51:16 -08002094 }
2095
2096 @Override
2097 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002098 final long identity = Binder.clearCallingIdentity();
2099 try {
2100 final Phone phone = getPhone(subId);
2101 return phone == null ? null : phone.getCarrierName();
2102 } finally {
2103 Binder.restoreCallingIdentity(identity);
2104 }
fionaxuf32acdf2017-11-27 22:51:16 -08002105 }
2106
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 //
2108 // Internal helper methods.
2109 //
2110
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002111 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2113 *
2114 * @throws SecurityException if the caller does not have the required permission
2115 */
2116 private void enforceModifyPermission() {
2117 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2118 }
2119
2120 /**
2121 * Make sure the caller has the CALL_PHONE permission.
2122 *
2123 * @throws SecurityException if the caller does not have the required permission
2124 */
2125 private void enforceCallPermission() {
2126 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2127 }
2128
Stuart Scott8eef64f2015-04-08 15:13:54 -07002129 private void enforceConnectivityInternalPermission() {
2130 mApp.enforceCallingOrSelfPermission(
2131 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2132 "ConnectivityService");
2133 }
2134
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 private String createTelUrl(String number) {
2136 if (TextUtils.isEmpty(number)) {
2137 return null;
2138 }
2139
Jake Hambye994d462014-02-03 13:10:13 -08002140 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 }
2142
Ihab Awadf9e92732013-12-05 18:02:52 -08002143 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2145 }
2146
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002147 private static void logv(String msg) {
2148 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2149 }
2150
Ihab Awadf9e92732013-12-05 18:02:52 -08002151 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2153 }
2154
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002155 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002157 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002158 }
2159
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002161 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002162 final long identity = Binder.clearCallingIdentity();
2163 try {
2164 final Phone phone = PhoneFactory.getPhone(slotIndex);
2165 if (phone == null) {
2166 return PhoneConstants.PHONE_TYPE_NONE;
2167 } else {
2168 return phone.getPhoneType();
2169 }
2170 } finally {
2171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 }
2174
2175 /**
2176 * Returns the CDMA ERI icon index to display
2177 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002178 @Override
2179 public int getCdmaEriIconIndex(String callingPackage) {
2180 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002181 }
2182
Sanket Padawe356d7632015-06-22 14:03:32 -07002183 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002184 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002185 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002186 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002187 return -1;
2188 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002189
2190 final long identity = Binder.clearCallingIdentity();
2191 try {
2192 final Phone phone = getPhone(subId);
2193 if (phone != null) {
2194 return phone.getCdmaEriIconIndex();
2195 } else {
2196 return -1;
2197 }
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 }
2202
2203 /**
2204 * Returns the CDMA ERI icon mode,
2205 * 0 - ON
2206 * 1 - FLASHING
2207 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002208 @Override
2209 public int getCdmaEriIconMode(String callingPackage) {
2210 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002211 }
2212
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002214 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002216 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002217 return -1;
2218 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002219
2220 final long identity = Binder.clearCallingIdentity();
2221 try {
2222 final Phone phone = getPhone(subId);
2223 if (phone != null) {
2224 return phone.getCdmaEriIconMode();
2225 } else {
2226 return -1;
2227 }
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232
2233 /**
2234 * Returns the CDMA ERI text,
2235 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002236 @Override
2237 public String getCdmaEriText(String callingPackage) {
2238 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002239 }
2240
Sanket Padawe356d7632015-06-22 14:03:32 -07002241 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002242 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002244 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 return null;
2246 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002247
2248 final long identity = Binder.clearCallingIdentity();
2249 try {
2250 final Phone phone = getPhone(subId);
2251 if (phone != null) {
2252 return phone.getCdmaEriText();
2253 } else {
2254 return null;
2255 }
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
2261 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002262 * Returns the CDMA MDN.
2263 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002264 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002265 public String getCdmaMdn(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2267 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002268
2269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 final Phone phone = getPhone(subId);
2272 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2273 return phone.getLine1Number();
2274 } else {
2275 return null;
2276 }
2277 } finally {
2278 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002279 }
2280 }
2281
2282 /**
2283 * Returns the CDMA MIN.
2284 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002285 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002286 public String getCdmaMin(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2288 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002289
2290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 final Phone phone = getPhone(subId);
2293 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2294 return phone.getCdmaMin();
2295 } else {
2296 return null;
2297 }
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002300 }
2301 }
2302
2303 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 * Returns true if CDMA provisioning needs to run.
2305 */
2306 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002307 final long identity = Binder.clearCallingIdentity();
2308 try {
2309 return mPhone.needsOtaServiceProvisioning();
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
2312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
2315 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002316 * Sets the voice mail number of a given subId.
2317 */
2318 @Override
2319 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002320 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002321
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2325 new Pair<String, String>(alphaTag, number), new Integer(subId));
2326 return success;
2327 } finally {
2328 Binder.restoreCallingIdentity(identity);
2329 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002330 }
2331
Ta-wei Yen87c49842016-05-13 21:19:52 -07002332 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002333 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2334 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2335 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2336 if (!TextUtils.equals(callingPackage, systemDialer)) {
2337 throw new SecurityException("caller must be system dialer");
2338 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002339
2340 final long identity = Binder.clearCallingIdentity();
2341 try {
2342 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2343 if (phoneAccountHandle == null) {
2344 return null;
2345 }
2346 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002349 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002350 }
2351
2352 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002353 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002354 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002356 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002357 return null;
2358 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002359
Jeff Davidson87b3c102018-03-15 17:16:18 -07002360 final long identity = Binder.clearCallingIdentity();
2361 try {
2362 return RemoteVvmTaskManager
2363 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002367 }
2368
2369 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002370 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2371 VisualVoicemailSmsFilterSettings settings) {
2372 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002373
2374 final long identity = Binder.clearCallingIdentity();
2375 try {
2376 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2377 mPhone.getContext(), callingPackage, subId, settings);
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
2380 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002381 }
2382
2383 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002384 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2385 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002386
2387 final long identity = Binder.clearCallingIdentity();
2388 try {
2389 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2390 mPhone.getContext(), callingPackage, subId);
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002394 }
2395
2396 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002397 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2398 String callingPackage, int subId) {
2399 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002400
2401 final long identity = Binder.clearCallingIdentity();
2402 try {
2403 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2404 mPhone.getContext(), callingPackage, subId);
2405 } finally {
2406 Binder.restoreCallingIdentity(identity);
2407 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002408 }
2409
2410 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002411 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002412 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002413
2414 final long identity = Binder.clearCallingIdentity();
2415 try {
2416 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2417 mPhone.getContext(), subId);
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
2420 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002421 }
2422
2423 @Override
2424 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2425 String number, int port, String text, PendingIntent sentIntent) {
2426 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002427 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002428 enforceSendSmsPermission();
2429 // Make the calls as the phone process.
2430 final long identity = Binder.clearCallingIdentity();
2431 try {
2432 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2433 if (port == 0) {
2434 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2435 sentIntent, null, false);
2436 } else {
2437 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2438 smsManager.sendDataMessageWithSelfPermissions(number, null,
2439 (short) port, data, sentIntent, null);
2440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
2443 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002444 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002445 /**
fionaxu0152e512016-11-14 13:36:14 -08002446 * Sets the voice activation state of a given subId.
2447 */
2448 @Override
2449 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2451 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002452
2453 final long identity = Binder.clearCallingIdentity();
2454 try {
2455 final Phone phone = getPhone(subId);
2456 if (phone != null) {
2457 phone.setVoiceActivationState(activationState);
2458 } else {
2459 loge("setVoiceActivationState fails with invalid subId: " + subId);
2460 }
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002463 }
2464 }
2465
2466 /**
2467 * Sets the data activation state of a given subId.
2468 */
2469 @Override
2470 public void setDataActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2472 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002473
2474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(subId);
2477 if (phone != null) {
2478 phone.setDataActivationState(activationState);
2479 } else {
2480 loge("setVoiceActivationState fails with invalid subId: " + subId);
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002484 }
2485 }
2486
2487 /**
2488 * Returns the voice activation state of a given subId.
2489 */
2490 @Override
2491 public int getVoiceActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002492 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002493
fionaxu0152e512016-11-14 13:36:14 -08002494 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002495 final long identity = Binder.clearCallingIdentity();
2496 try {
2497 if (phone != null) {
2498 return phone.getVoiceActivationState();
2499 } else {
2500 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2501 }
2502 } finally {
2503 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002504 }
2505 }
2506
2507 /**
2508 * Returns the data activation state of a given subId.
2509 */
2510 @Override
2511 public int getDataActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002512 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002513
fionaxu0152e512016-11-14 13:36:14 -08002514 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002515 final long identity = Binder.clearCallingIdentity();
2516 try {
2517 if (phone != null) {
2518 return phone.getDataActivationState();
2519 } else {
2520 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2521 }
2522 } finally {
2523 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002524 }
2525 }
2526
2527 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 * Returns the unread count of voicemails
2529 */
2530 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002531 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002532 }
2533
2534 /**
2535 * Returns the unread count of voicemails for a subId
2536 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002537 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002538 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002539 final long identity = Binder.clearCallingIdentity();
2540 try {
2541 final Phone phone = getPhone(subId);
2542 if (phone != null) {
2543 return phone.getVoiceMessageCount();
2544 } else {
2545 return 0;
2546 }
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 }
2551
2552 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002553 * returns true, if the device is in a state where both voice and data
2554 * are supported simultaneously. This can change based on location or network condition.
2555 */
2556 @Override
2557 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 final Phone phone = getPhone(subId);
2561 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
2564 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002565 }
2566
2567 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002568 * Send the dialer code if called from the current default dialer or the caller has
2569 * carrier privilege.
2570 * @param inputCode The dialer code to send
2571 */
2572 @Override
2573 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2574 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2575 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2576 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002577 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2578 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002579 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002580
2581 final long identity = Binder.clearCallingIdentity();
2582 try {
2583 mPhone.sendDialerSpecialCode(inputCode);
2584 } finally {
2585 Binder.restoreCallingIdentity(identity);
2586 }
fionaxu235cc5e2017-03-06 22:25:57 -08002587 }
2588
2589 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002590 * Returns the data network type.
2591 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 *
2593 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2594 */
2595 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002596 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 final Phone phone = getPhone(getDefaultSubscription());
2600 if (phone != null) {
2601 return phone.getServiceState().getDataNetworkType();
2602 } else {
2603 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002607 }
Wink Saville36469e72014-06-11 15:17:00 -07002608 }
2609
2610 /**
2611 * Returns the network type for a subId
2612 */
2613 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002614 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002616 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002617 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2618 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002619
Malcolm Chenaabec062018-02-28 15:00:40 -08002620 final long identity = Binder.clearCallingIdentity();
2621 try {
2622 final Phone phone = getPhone(subId);
2623 if (phone != null) {
2624 return phone.getServiceState().getDataNetworkType();
2625 } else {
2626 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2627 }
2628 } finally {
2629 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002631 }
2632
2633 /**
2634 * Returns the data network type
2635 */
2636 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002637 public int getDataNetworkType(String callingPackage) {
2638 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002639 }
2640
2641 /**
2642 * Returns the data network type for a subId
2643 */
2644 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002645 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002647 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002648 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2649 }
2650
Malcolm Chenaabec062018-02-28 15:00:40 -08002651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 final Phone phone = getPhone(subId);
2654 if (phone != null) {
2655 return phone.getServiceState().getDataNetworkType();
2656 } else {
2657 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2658 }
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 }
2663
2664 /**
Wink Saville36469e72014-06-11 15:17:00 -07002665 * Returns the Voice network type for a subId
2666 */
2667 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002668 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002670 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002671 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2672 }
2673
Malcolm Chenaabec062018-02-28 15:00:40 -08002674 final long identity = Binder.clearCallingIdentity();
2675 try {
2676 final Phone phone = getPhone(subId);
2677 if (phone != null) {
2678 return phone.getServiceState().getVoiceNetworkType();
2679 } else {
2680 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2681 }
2682 } finally {
2683 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002684 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 }
2686
2687 /**
2688 * @return true if a ICC card is present
2689 */
2690 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002691 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002692 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2693 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002694 }
2695
2696 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002697 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002698 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002699 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002700 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 final Phone phone = PhoneFactory.getPhone(slotIndex);
2704 if (phone != null) {
2705 return phone.getIccCard().hasIccCard();
2706 } else {
2707 return false;
2708 }
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 }
2713
2714 /**
2715 * Return if the current radio is LTE on CDMA. This
2716 * is a tri-state return value as for a period of time
2717 * the mode may be unknown.
2718 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002719 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002721 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002723 @Override
2724 public int getLteOnCdmaMode(String callingPackage) {
2725 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002726 }
2727
Sanket Padawe356d7632015-06-22 14:03:32 -07002728 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002729 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002730 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002731 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002732 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2733 }
2734
Malcolm Chenaabec062018-02-28 15:00:40 -08002735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 final Phone phone = getPhone(subId);
2738 if (phone == null) {
2739 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2740 } else {
2741 return phone.getLteOnCdmaMode();
2742 }
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002745 }
Wink Saville36469e72014-06-11 15:17:00 -07002746 }
2747
2748 public void setPhone(Phone phone) {
2749 mPhone = phone;
2750 }
2751
2752 /**
2753 * {@hide}
2754 * Returns Default subId, 0 in the case of single standby.
2755 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002756 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002757 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002758 }
2759
Shishir Agrawala9f32182016-04-12 12:00:16 -07002760 private int getSlotForDefaultSubscription() {
2761 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2762 }
2763
Wink Savilleb564aae2014-10-23 10:18:09 -07002764 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002765 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002767
2768 /**
2769 * @see android.telephony.TelephonyManager.WifiCallingChoices
2770 */
2771 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2775 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2776 getWhenToMakeWifiCallsDefaultPreference());
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
2779 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002780 }
2781
2782 /**
2783 * @see android.telephony.TelephonyManager.WifiCallingChoices
2784 */
2785 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2789 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2790 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
2793 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002794 }
2795
Sailesh Nepald1e68152013-12-12 19:08:02 -08002796 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002797 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002798 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002799 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002800
Shishir Agrawal566b7612013-10-28 14:41:00 -07002801 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002802 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2803 int subId, String callingPackage, String aid, int p2) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2805 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002806 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002807
Malcolm Chenaabec062018-02-28 15:00:40 -08002808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 if (TextUtils.equals(ISDR_AID, aid)) {
2811 // Only allows LPA to open logical channel to ISD-R.
2812 ComponentInfo bestComponent =
2813 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2814 if (bestComponent == null
2815 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2816 loge("The calling package is not allowed to access ISD-R.");
2817 throw new SecurityException(
2818 "The calling package is not allowed to access ISD-R.");
2819 }
Derek Tan740e1672017-06-27 14:56:27 -07002820 }
Derek Tan740e1672017-06-27 14:56:27 -07002821
Malcolm Chenaabec062018-02-28 15:00:40 -08002822 if (DBG) {
2823 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2824 }
2825 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2826 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2827 if (DBG) log("iccOpenLogicalChannel: " + response);
2828 return response;
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
2831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002832 }
2833
2834 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002835 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2837 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002838
Malcolm Chenaabec062018-02-28 15:00:40 -08002839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2842 if (channel < 0) {
2843 return false;
2844 }
2845 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2846 if (DBG) log("iccCloseLogicalChannel: " + success);
2847 return success;
2848 } finally {
2849 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002851 }
2852
2853 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002854 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002855 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2857 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002858
Malcolm Chenaabec062018-02-28 15:00:40 -08002859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 if (DBG) {
2862 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2863 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2864 + p3 + " data=" + data);
2865 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002866
Malcolm Chenaabec062018-02-28 15:00:40 -08002867 if (channel < 0) {
2868 return "";
2869 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002870
Malcolm Chenaabec062018-02-28 15:00:40 -08002871 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2872 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2873 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002874
Malcolm Chenaabec062018-02-28 15:00:40 -08002875 // Append the returned status code to the end of the response payload.
2876 String s = Integer.toHexString(
2877 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2878 if (response.payload != null) {
2879 s = IccUtils.bytesToHexString(response.payload) + s;
2880 }
2881 return s;
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002884 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002885 }
Jake Hambye994d462014-02-03 13:10:13 -08002886
Evan Charltonc66da362014-05-16 14:06:40 -07002887 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002888 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2889 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2891 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002892 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002893
Malcolm Chenaabec062018-02-28 15:00:40 -08002894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2897 && TextUtils.equals(ISDR_AID, data)) {
2898 // Only allows LPA to select ISD-R.
2899 ComponentInfo bestComponent =
2900 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2901 if (bestComponent == null
2902 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2903 loge("The calling package is not allowed to select ISD-R.");
2904 throw new SecurityException(
2905 "The calling package is not allowed to select ISD-R.");
2906 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002907 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002908
Malcolm Chenaabec062018-02-28 15:00:40 -08002909 if (DBG) {
2910 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2911 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2912 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002913
Malcolm Chenaabec062018-02-28 15:00:40 -08002914 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2915 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2916 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002917
Malcolm Chenaabec062018-02-28 15:00:40 -08002918 // Append the returned status code to the end of the response payload.
2919 String s = Integer.toHexString(
2920 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2921 if (response.payload != null) {
2922 s = IccUtils.bytesToHexString(response.payload) + s;
2923 }
2924 return s;
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002927 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002928 }
2929
2930 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002931 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002932 String filePath) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2934 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002935
Malcolm Chenaabec062018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
2938 if (DBG) {
2939 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2940 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2941 }
2942
2943 IccIoResult response =
2944 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2945 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2946 subId);
2947
2948 if (DBG) {
2949 log("Exchange SIM_IO [R]" + response);
2950 }
2951
2952 byte[] result = null;
2953 int length = 2;
2954 if (response.payload != null) {
2955 length = 2 + response.payload.length;
2956 result = new byte[length];
2957 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2958 } else {
2959 result = new byte[length];
2960 }
2961
2962 result[length - 1] = (byte) response.sw2;
2963 result[length - 2] = (byte) response.sw1;
2964 return result;
2965 } finally {
2966 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002967 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002968 }
2969
Nathan Haroldb3014052017-01-25 15:57:32 -08002970 /**
2971 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2972 * on a particular subscription
2973 */
2974 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002975 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002976 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2977 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002978 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2979 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2980 return null;
2981 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002982
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2986 if (response instanceof String[]) {
2987 return (String[]) response;
2988 }
2989 // Response is an Exception of some kind,
2990 // which is signalled to the user as a NULL retval
2991 return null;
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002994 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002995 }
2996
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002997 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002998 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3000 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003001
Malcolm Chenaabec062018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3005 if (response.payload == null) {
3006 return "";
3007 }
Evan Charltonc66da362014-05-16 14:06:40 -07003008
Malcolm Chenaabec062018-02-28 15:00:40 -08003009 // Append the returned status code to the end of the response payload.
3010 String s = Integer.toHexString(
3011 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3012 s = IccUtils.bytesToHexString(response.payload) + s;
3013 return s;
3014 } finally {
3015 Binder.restoreCallingIdentity(identity);
3016 }
Evan Charltonc66da362014-05-16 14:06:40 -07003017 }
3018
Jake Hambye994d462014-02-03 13:10:13 -08003019 /**
3020 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3021 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3022 *
3023 * @param itemID the ID of the item to read
3024 * @return the NV item as a String, or null on error.
3025 */
3026 @Override
3027 public String nvReadItem(int itemID) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3029 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003030
3031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 if (DBG) log("nvReadItem: item " + itemID);
3034 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3035 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3036 return value;
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Jake Hambye994d462014-02-03 13:10:13 -08003040 }
3041
3042 /**
3043 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3044 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3045 *
3046 * @param itemID the ID of the item to read
3047 * @param itemValue the value to write, as a String
3048 * @return true on success; false on any failure
3049 */
3050 @Override
3051 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3053 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003054
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3058 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3059 new Pair<Integer, String>(itemID, itemValue));
3060 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3061 return success;
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
Jake Hambye994d462014-02-03 13:10:13 -08003065 }
3066
3067 /**
3068 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3069 * Used for device configuration by some CDMA operators.
3070 *
3071 * @param preferredRoamingList byte array containing the new PRL
3072 * @return true on success; false on any failure
3073 */
3074 @Override
3075 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3077 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003078
3079 final long identity = Binder.clearCallingIdentity();
3080 try {
3081 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3082 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3083 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3084 return success;
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
Jake Hambye994d462014-02-03 13:10:13 -08003088 }
3089
3090 /**
3091 * Perform the specified type of NV config reset.
3092 * Used for device configuration by some CDMA operators.
3093 *
3094 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3095 * @return true on success; false on any failure
3096 */
3097 @Override
3098 public boolean nvResetConfig(int resetType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3100 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003101
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 if (DBG) log("nvResetConfig: type " + resetType);
3105 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3106 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3107 return success;
3108 } finally {
3109 Binder.restoreCallingIdentity(identity);
3110 }
Jake Hambye994d462014-02-03 13:10:13 -08003111 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003112
Svet Ganovb320e182015-04-16 12:30:10 -07003113 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003114 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003115 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003116 return new String[0];
3117 }
3118
Malcolm Chenaabec062018-02-28 15:00:40 -08003119 final long identity = Binder.clearCallingIdentity();
3120 try {
3121 return mPhone.getPcscfAddress(apnType);
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
Wink Saville36469e72014-06-11 15:17:00 -07003125 }
3126
Brad Ebinger51f743a2017-01-23 13:50:20 -08003127 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08003128 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3129 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003130 */
Brad Ebingera12246d2018-01-16 09:39:35 -08003131 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003132 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003133
3134 final long identity = Binder.clearCallingIdentity();
3135 try {
3136 PhoneFactory.getImsResolver().enableIms(slotId);
3137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003140 }
3141
3142 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08003143 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3144 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003145 */
Brad Ebingera12246d2018-01-16 09:39:35 -08003146 public void disableIms(int slotId) {
3147 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003148
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 PhoneFactory.getImsResolver().disableIms(slotId);
3152 } finally {
3153 Binder.restoreCallingIdentity(identity);
3154 }
Brad Ebingera12246d2018-01-16 09:39:35 -08003155 }
3156
3157 /**
3158 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3159 * feature or {@link null} if the service is not available. If the feature is available, the
3160 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3161 */
3162 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003163 IImsServiceFeatureCallback callback) {
3164 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003165
3166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003172 }
3173
3174 /**
3175 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3176 * feature during emergency calling or {@link null} if the service is not available. If the
3177 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3178 * listener for feature updates.
3179 */
3180 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3181 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003182
3183 final long identity = Binder.clearCallingIdentity();
3184 try {
3185 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003189 }
3190
Brad Ebinger7e934f52017-12-14 14:26:15 -08003191 /**
3192 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3193 * specified.
3194 */
3195 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3196 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003197
3198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3201 } finally {
3202 Binder.restoreCallingIdentity(identity);
3203 }
Brad Ebinger7e934f52017-12-14 14:26:15 -08003204 }
3205
Brad Ebingera12246d2018-01-16 09:39:35 -08003206 /**
3207 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3208 * specified.
3209 */
3210 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3211 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003212
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
3215 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
Brad Ebingera12246d2018-01-16 09:39:35 -08003219 }
3220
Brad Ebinger884c07b2018-02-15 16:17:40 -08003221 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003222 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3223 * available, false if the IMS resolver is idle.
3224 */
3225 public boolean isResolvingImsBinding() {
3226 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003227
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 return PhoneFactory.getImsResolver().isResolvingBinding();
3231 } finally {
3232 Binder.restoreCallingIdentity(identity);
3233 }
Brad Ebinger67801702018-03-02 13:43:36 -08003234 }
3235
Brad Ebinger4dc095a2018-04-03 15:17:52 -07003236 /**
3237 * Sets the ImsService Package Name that Telephony will bind to.
3238 *
3239 * @param slotId the slot ID that the ImsService should bind for.
3240 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3241 * ImsService is the device default ImsService.
3242 * @param packageName The package name of the application that contains the ImsService to bind
3243 * to.
3244 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3245 * @hide
3246 */
3247 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingera6377d92018-04-06 09:56:40 -07003248 int[] subIds = SubscriptionManager.getSubId(slotId);
3249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3250 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3251 "setImsService");
3252
Malcolm Chenaabec062018-02-28 15:00:40 -08003253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3256 isCarrierImsService, packageName);
3257 } finally {
3258 Binder.restoreCallingIdentity(identity);
3259 }
Brad Ebinger4dc095a2018-04-03 15:17:52 -07003260 }
3261
3262 /**
3263 * Return the ImsService configuration.
3264 *
3265 * @param slotId The slot that the ImsService is associated with.
3266 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3267 * the device default.
3268 * @return the package name of the ImsService configuration.
3269 */
3270 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingera6377d92018-04-06 09:56:40 -07003271 int[] subIds = SubscriptionManager.getSubId(slotId);
3272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3273 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3274 "getImsService");
3275
Malcolm Chenaabec062018-02-28 15:00:40 -08003276 final long identity = Binder.clearCallingIdentity();
3277 try {
3278 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3279 isCarrierImsService);
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
Brad Ebinger4dc095a2018-04-03 15:17:52 -07003283 }
3284
Wink Saville36469e72014-06-11 15:17:00 -07003285 public void setImsRegistrationState(boolean registered) {
3286 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003287
3288 final long identity = Binder.clearCallingIdentity();
3289 try {
3290 mPhone.setImsRegistrationState(registered);
3291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
Wink Saville36469e72014-06-11 15:17:00 -07003294 }
3295
3296 /**
Stuart Scott54788802015-03-30 13:18:01 -07003297 * Set the network selection mode to automatic.
3298 *
3299 */
3300 @Override
3301 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3303 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003304
3305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3308 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
Stuart Scott54788802015-03-30 13:18:01 -07003312 }
3313
3314 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003315 * Set the network selection mode to manual with the selected carrier.
3316 */
3317 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003318 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003319 boolean persistSelection) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3321 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaabec062018-02-28 15:00:40 -08003322
3323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003326 /* operatorAlphaLong */ "",
3327 /* operatorAlphaShort */ "",
Malcolm Chenaabec062018-02-28 15:00:40 -08003328 operatorNumeric);
3329 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3330 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3331 persistSelection);
3332 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003336 }
3337
3338 /**
3339 * Scans for available networks.
3340 */
3341 @Override
3342 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3344 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003345
3346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3349 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3350 CMD_PERFORM_NETWORK_SCAN, null, subId);
3351 return result;
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003355 }
3356
3357 /**
yinxub1bed742017-04-17 11:45:04 -07003358 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003359 *
yinxub1bed742017-04-17 11:45:04 -07003360 * @param subId id of the subscription
3361 * @param request contains the radio access networks with bands/channels to scan
3362 * @param messenger callback messenger for scan results or errors
3363 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003364 * @return the id of the requested scan which can be used to stop the scan.
3365 */
3366 @Override
3367 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3368 IBinder binder) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3370 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003371
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 return mNetworkScanRequestTracker.startNetworkScan(
3375 request, messenger, binder, getPhone(subId));
3376 } finally {
3377 Binder.restoreCallingIdentity(identity);
3378 }
yinxu504e1392017-04-12 16:03:22 -07003379 }
3380
3381 /**
3382 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003383 *
3384 * @param subId id of the subscription
3385 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003386 */
3387 @Override
3388 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3390 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003391
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3395 } finally {
3396 Binder.restoreCallingIdentity(identity);
3397 }
yinxu504e1392017-04-12 16:03:22 -07003398 }
3399
3400 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003401 * Get the calculated preferred network type.
3402 * Used for debugging incorrect network type.
3403 *
3404 * @return the preferred network type, defined in RILConstants.java.
3405 */
3406 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003407 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003408 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003409 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003410 return RILConstants.PREFERRED_NETWORK_MODE;
3411 }
3412
Malcolm Chenaabec062018-02-28 15:00:40 -08003413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 // FIXME: need to get SubId from somewhere.
3416 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
Junda Liu84d15a22014-07-02 11:21:04 -07003420 }
3421
3422 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003423 * Get the preferred network type.
3424 * Used for device configuration by some CDMA operators.
3425 *
3426 * @return the preferred network type, defined in RILConstants.java.
3427 */
3428 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003429 public int getPreferredNetworkType(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3431 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003432
3433 final long identity = Binder.clearCallingIdentity();
3434 try {
3435 if (DBG) log("getPreferredNetworkType");
3436 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3437 int networkType = (result != null ? result[0] : -1);
3438 if (DBG) log("getPreferredNetworkType: " + networkType);
3439 return networkType;
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003443 }
3444
3445 /**
3446 * Set the preferred network type.
3447 * Used for device configuration by some CDMA operators.
3448 *
3449 * @param networkType the preferred network type, defined in RILConstants.java.
3450 * @return true on success; false on any failure.
3451 */
3452 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003453 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3455 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003456
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3460 Boolean success = (Boolean) sendRequest(
3461 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3462 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3463 if (success) {
3464 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3465 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3466 }
3467 return success;
3468 } finally {
3469 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003470 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003471 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003472
3473 /**
Junda Liu475951f2014-11-07 16:45:03 -08003474 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3475 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3476 * tethering.
3477 *
3478 * @return 0: Not required. 1: required. 2: Not set.
3479 * @hide
3480 */
3481 @Override
3482 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003483 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003484
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3488 Settings.Global.TETHER_DUN_REQUIRED, 2);
3489 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3490 // config_tether_apndata.
3491 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3492 dunRequired = 1;
3493 }
3494 return dunRequired;
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003497 }
Junda Liu475951f2014-11-07 16:45:03 -08003498 }
3499
3500 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003501 * Set mobile data enabled
3502 * Used by the user through settings etc to turn on/off mobile data
3503 *
3504 * @param enable {@code true} turn turn data on, else {@code false}
3505 */
3506 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003507 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3509 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003510
3511 final long identity = Binder.clearCallingIdentity();
3512 try {
3513 int phoneId = mSubscriptionController.getPhoneId(subId);
3514 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3515 Phone phone = PhoneFactory.getPhone(phoneId);
3516 if (phone != null) {
3517 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3518 phone.setUserDataEnabled(enable);
3519 } else {
3520 loge("setUserDataEnabled: no phone for subId=" + subId);
3521 }
3522 } finally {
3523 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003524 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003525 }
3526
3527 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003528 * Get the user enabled state of Mobile Data.
3529 *
3530 * TODO: remove and use isUserDataEnabled.
3531 * This can't be removed now because some vendor codes
3532 * calls through ITelephony directly while they should
3533 * use TelephonyManager.
3534 *
3535 * @return true on enabled
3536 */
3537 @Override
3538 public boolean getDataEnabled(int subId) {
3539 return isUserDataEnabled(subId);
3540 }
3541
3542 /**
3543 * Get whether mobile data is enabled per user setting.
3544 *
3545 * There are other factors deciding whether mobile data is actually enabled, but they are
3546 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003547 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003548 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003549 *
3550 * @return {@code true} if data is enabled else {@code false}
3551 */
3552 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003553 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003554 try {
3555 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3556 null);
3557 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3559 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003560 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003561
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 int phoneId = mSubscriptionController.getPhoneId(subId);
3565 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3566 Phone phone = PhoneFactory.getPhone(phoneId);
3567 if (phone != null) {
3568 boolean retVal = phone.isUserDataEnabled();
3569 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3570 return retVal;
3571 } else {
3572 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3573 return false;
3574 }
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003577 }
3578 }
3579
3580 /**
3581 * Get whether mobile data is enabled.
3582 *
3583 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3584 * whether mobile data is actually enabled.
3585 *
3586 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3587 *
3588 * @return {@code true} if data is enabled else {@code false}
3589 */
3590 @Override
3591 public boolean isDataEnabled(int subId) {
3592 try {
3593 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3594 null);
3595 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3597 mApp, subId, "isDataEnabled");
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003598 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003599
3600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 int phoneId = mSubscriptionController.getPhoneId(subId);
3603 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3604 Phone phone = PhoneFactory.getPhone(phoneId);
3605 if (phone != null) {
3606 boolean retVal = phone.isDataEnabled();
3607 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3608 return retVal;
3609 } else {
3610 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3611 return false;
3612 }
3613 } finally {
3614 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003615 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003616 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003617
3618 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003619 public int getCarrierPrivilegeStatus(int subId) {
3620 final Phone phone = getPhone(subId);
3621 if (phone == null) {
3622 loge("getCarrierPrivilegeStatus: Invalid subId");
3623 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3624 }
3625 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003626 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003627 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003628 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3629 }
3630 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003631 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003632 }
Junda Liu29340342014-07-10 15:23:27 -07003633
3634 @Override
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003635 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3636 final Phone phone = getPhone(subId);
3637 if (phone == null) {
3638 loge("getCarrierPrivilegeStatus: Invalid subId");
3639 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3640 }
3641 UiccProfile profile =
3642 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3643 if (profile == null) {
3644 loge("getCarrierPrivilegeStatus: No UICC");
3645 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3646 }
3647 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3648 }
3649
3650 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003651 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003652 if (TextUtils.isEmpty(pkgName))
3653 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003654 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003655 if (card == null) {
3656 loge("checkCarrierPrivilegesForPackage: No UICC");
3657 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3658 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003659 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3660 }
3661
3662 @Override
3663 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003664 if (TextUtils.isEmpty(pkgName))
3665 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003666 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3667 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3668 UiccCard card = UiccController.getInstance().getUiccCard(i);
3669 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003670 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003671 continue;
3672 }
3673
3674 result = card.getCarrierPrivilegeStatus(
3675 mPhone.getContext().getPackageManager(), pkgName);
3676 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3677 break;
3678 }
3679 }
3680
3681 return result;
Junda Liu29340342014-07-10 15:23:27 -07003682 }
Derek Tan89e89d42014-07-08 17:00:10 -07003683
3684 @Override
Junda Liue64de782015-04-16 17:19:16 -07003685 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3686 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3687 loge("phoneId " + phoneId + " is not valid.");
3688 return null;
3689 }
3690 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003691 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003692 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003693 return null ;
3694 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003695 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003696 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003697 }
3698
Amith Yamasani6e118872016-02-19 12:53:51 -08003699 @Override
3700 public List<String> getPackagesWithCarrierPrivileges() {
3701 PackageManager pm = mPhone.getContext().getPackageManager();
3702 List<String> privilegedPackages = new ArrayList<>();
3703 List<PackageInfo> packages = null;
3704 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3705 UiccCard card = UiccController.getInstance().getUiccCard(i);
3706 if (card == null) {
3707 // No UICC in that slot.
3708 continue;
3709 }
3710 if (card.hasCarrierPrivilegeRules()) {
3711 if (packages == null) {
3712 // Only check packages in user 0 for now
3713 packages = pm.getInstalledPackagesAsUser(
3714 PackageManager.MATCH_DISABLED_COMPONENTS
3715 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3716 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3717 }
3718 for (int p = packages.size() - 1; p >= 0; p--) {
3719 PackageInfo pkgInfo = packages.get(p);
3720 if (pkgInfo != null && pkgInfo.packageName != null
3721 && card.getCarrierPrivilegeStatus(pkgInfo)
3722 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3723 privilegedPackages.add(pkgInfo.packageName);
3724 }
3725 }
3726 }
3727 }
3728 return privilegedPackages;
3729 }
3730
Wink Savilleb564aae2014-10-23 10:18:09 -07003731 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003732 final Phone phone = getPhone(subId);
3733 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003734 if (card == null) {
3735 loge("getIccId: No UICC");
3736 return null;
3737 }
3738 String iccId = card.getIccId();
3739 if (TextUtils.isEmpty(iccId)) {
3740 loge("getIccId: ICC ID is null or empty.");
3741 return null;
3742 }
3743 return iccId;
3744 }
3745
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003746 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003747 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3748 String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003749 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3750 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003751
Malcolm Chenaabec062018-02-28 15:00:40 -08003752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 final String iccId = getIccId(subId);
3755 final Phone phone = getPhone(subId);
3756 if (phone == null) {
3757 return false;
3758 }
3759 final String subscriberId = phone.getSubscriberId();
3760
3761 if (DBG_MERGE) {
3762 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3763 + subscriberId + " to " + number);
3764 }
3765
3766 if (TextUtils.isEmpty(iccId)) {
3767 return false;
3768 }
3769
3770 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3771
3772 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3773 if (alphaTag == null) {
3774 editor.remove(alphaTagPrefKey);
3775 } else {
3776 editor.putString(alphaTagPrefKey, alphaTag);
3777 }
3778
3779 // Record both the line number and IMSI for this ICCID, since we need to
3780 // track all merged IMSIs based on line number
3781 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3782 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3783 if (number == null) {
3784 editor.remove(numberPrefKey);
3785 editor.remove(subscriberPrefKey);
3786 } else {
3787 editor.putString(numberPrefKey, number);
3788 editor.putString(subscriberPrefKey, subscriberId);
3789 }
3790
3791 editor.commit();
3792 return true;
3793 } finally {
3794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003795 }
Derek Tan7226c842014-07-02 17:42:23 -07003796 }
3797
3798 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003799 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003800 // This is open to apps with WRITE_SMS.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003802 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003803 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003804 return null;
3805 }
Derek Tan97ebb422014-09-05 16:55:38 -07003806
Malcolm Chenaabec062018-02-28 15:00:40 -08003807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 String iccId = getIccId(subId);
3810 if (iccId != null) {
3811 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3812 if (DBG_MERGE) {
3813 log("getLine1NumberForDisplay returning "
3814 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3815 }
3816 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003817 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003818 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3819 return null;
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003822 }
Derek Tan7226c842014-07-02 17:42:23 -07003823 }
3824
3825 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003826 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003828 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003829 return null;
3830 }
Derek Tan97ebb422014-09-05 16:55:38 -07003831
Malcolm Chenaabec062018-02-28 15:00:40 -08003832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 String iccId = getIccId(subId);
3835 if (iccId != null) {
3836 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3837 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3838 }
3839 return null;
3840 } finally {
3841 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003842 }
Derek Tan7226c842014-07-02 17:42:23 -07003843 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003844
3845 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003846 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003847 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3848 // about carrier-privileged callers not having access.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003850 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3851 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003852 return null;
3853 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003854
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003855 final long identity = Binder.clearCallingIdentity();
3856 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003857 final Context context = mPhone.getContext();
3858 final TelephonyManager tele = TelephonyManager.from(context);
3859 final SubscriptionManager sub = SubscriptionManager.from(context);
3860
3861 // Figure out what subscribers are currently active
3862 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3863 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3864 // the process, where TelephonyManager was instantiated.
3865 // Otherwise AppOps check will fail.
3866
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003867 final int[] subIds = sub.getActiveSubscriptionIdList();
3868 for (int subId : subIds) {
3869 activeSubscriberIds.add(tele.getSubscriberId(subId));
3870 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003871
3872 // First pass, find a number override for an active subscriber
3873 String mergeNumber = null;
3874 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3875 for (String key : prefs.keySet()) {
3876 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3877 final String subscriberId = (String) prefs.get(key);
3878 if (activeSubscriberIds.contains(subscriberId)) {
3879 final String iccId = key.substring(
3880 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3881 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3882 mergeNumber = (String) prefs.get(numberKey);
3883 if (DBG_MERGE) {
3884 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3885 + " for active subscriber " + subscriberId);
3886 }
3887 if (!TextUtils.isEmpty(mergeNumber)) {
3888 break;
3889 }
3890 }
3891 }
3892 }
3893
3894 // Shortcut when no active merged subscribers
3895 if (TextUtils.isEmpty(mergeNumber)) {
3896 return null;
3897 }
3898
3899 // Second pass, find all subscribers under that line override
3900 final ArraySet<String> result = new ArraySet<>();
3901 for (String key : prefs.keySet()) {
3902 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3903 final String number = (String) prefs.get(key);
3904 if (mergeNumber.equals(number)) {
3905 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3906 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3907 final String subscriberId = (String) prefs.get(subscriberKey);
3908 if (!TextUtils.isEmpty(subscriberId)) {
3909 result.add(subscriberId);
3910 }
3911 }
3912 }
3913 }
3914
3915 final String[] resultArray = result.toArray(new String[result.size()]);
3916 Arrays.sort(resultArray);
3917 if (DBG_MERGE) {
3918 Slog.d(LOG_TAG,
3919 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3920 }
3921 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003922 } finally {
3923 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003924 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003925 }
3926
3927 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003928 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003929 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3930 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003931
3932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 final Phone phone = getPhone(subId);
3935 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3936 } finally {
3937 Binder.restoreCallingIdentity(identity);
3938 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003939 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003940
3941 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003942 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003943 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3944 List<String> cdmaNonRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003945 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003946
3947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 final Phone phone = getPhone(subId);
3950 if (phone == null) {
3951 return false;
3952 }
3953 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3954 cdmaNonRoamingList);
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003957 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003958 }
3959
3960 @Override
Shuo Qian74b16b12018-04-27 01:32:07 +00003961 @Deprecated
3962 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3963 enforceModifyPermission();
3964
3965 int returnValue = 0;
3966 try {
3967 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3968 if(result.exception == null) {
3969 if (result.result != null) {
3970 byte[] responseData = (byte[])(result.result);
3971 if(responseData.length > oemResp.length) {
3972 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3973 responseData.length + "bytes. Buffer Size is " +
3974 oemResp.length + "bytes.");
3975 }
3976 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3977 returnValue = responseData.length;
3978 }
3979 } else {
3980 CommandException ex = (CommandException) result.exception;
3981 returnValue = ex.getCommandError().ordinal();
3982 if(returnValue > 0) returnValue *= -1;
3983 }
3984 } catch (RuntimeException e) {
3985 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3986 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3987 if(returnValue > 0) returnValue *= -1;
3988 }
3989
3990 return returnValue;
3991 }
3992
3993 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003994 public void setRadioCapability(RadioAccessFamily[] rafs) {
3995 try {
3996 ProxyController.getInstance().setRadioCapability(rafs);
3997 } catch (RuntimeException e) {
3998 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3999 }
4000 }
4001
4002 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004003 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004004 Phone phone = PhoneFactory.getPhone(phoneId);
4005 if (phone == null) {
4006 return RadioAccessFamily.RAF_UNKNOWN;
4007 }
4008 int subId = phone.getSubId();
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004010 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004011 return RadioAccessFamily.RAF_UNKNOWN;
4012 }
4013
Malcolm Chenaabec062018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Wink Saville5d475dd2014-10-17 15:00:58 -07004020 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004021
4022 @Override
4023 public void enableVideoCalling(boolean enable) {
4024 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004025
4026 final long identity = Binder.clearCallingIdentity();
4027 try {
4028 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
4029 } finally {
4030 Binder.restoreCallingIdentity(identity);
4031 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004032 }
4033
4034 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004035 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004037 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004038 return false;
4039 }
4040
Malcolm Chenaabec062018-02-28 15:00:40 -08004041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 // Check the user preference and the system-level IMS setting. Even if the user has
4044 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4045 // In the long run, we may instead need to check if there exists a connection service
4046 // which can support video calling.
4047 ImsManager imsManager =
4048 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4049 return imsManager.isVtEnabledByPlatform()
4050 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4051 && imsManager.isVtEnabledByUser();
4052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004055 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004056
Andrew Leea1239f22015-03-02 17:44:07 -08004057 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004058 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4059 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4060 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4061 return false;
4062 }
4063
4064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 CarrierConfigManager configManager =
4067 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4068 return configManager.getConfigForSubId(mPhone.getSubId())
4069 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
Andrew Leea1239f22015-03-02 17:44:07 -08004073 }
4074
4075 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004076 public boolean isWorldPhone(int subId, String callingPackage) {
4077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4078 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4079 return false;
4080 }
4081
4082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 CarrierConfigManager configManager =
4085 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4086 return configManager.getConfigForSubId(mPhone.getSubId())
4087 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
Andrew Leea1239f22015-03-02 17:44:07 -08004091 }
4092
Andrew Lee9431b832015-03-09 18:46:45 -07004093 @Override
4094 public boolean isTtyModeSupported() {
4095 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004096 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004097 }
4098
4099 @Override
4100 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
Andrew Lee9431b832015-03-09 18:46:45 -07004107 }
4108
Hall Liu73714012018-01-22 19:15:32 -08004109 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4113 mPhone.getSubId()).getBoolean(
4114 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4115 boolean isDeviceSupported =
4116 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4117 return isCarrierSupported && isDeviceSupported;
4118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
Hall Liu73714012018-01-22 19:15:32 -08004121 }
4122
Hall Liub1585172018-04-06 16:23:39 -07004123 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 return isRttSupported() && Settings.Secure.getInt(
4127 mPhone.getContext().getContentResolver(),
4128 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
Hall Liub1585172018-04-06 16:23:39 -07004132 }
4133
Sanket Padawe7310cc72015-01-14 09:53:20 -08004134 /**
4135 * Returns the unique device ID of phone, for example, the IMEI for
4136 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4137 *
4138 * <p>Requires Permission:
4139 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4140 */
4141 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004142 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004143 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004144 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004145 return null;
4146 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004147 int subId = phone.getSubId();
4148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4149 mApp, subId, callingPackage, "getDeviceId")) {
4150 return null;
4151 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004152
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 return phone.getDeviceId();
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
4158 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004159 }
4160
Ping Sun014fe8e2016-03-02 19:16:45 +08004161 /**
4162 * {@hide}
4163 * Returns the IMS Registration Status on a particular subid
4164 *
4165 * @param subId
4166 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08004167 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08004168 Phone phone = getPhone(subId);
4169 if (phone != null) {
4170 return phone.isImsRegistered();
4171 } else {
4172 return false;
4173 }
4174 }
4175
Santos Cordon7a1885b2015-02-03 11:15:19 -08004176 @Override
4177 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004184 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004185
Brad Ebingere21f25f2018-02-08 16:11:32 -08004186 /**
4187 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004188 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08004189 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 Phone phone = getPhone(subId);
4193 if (phone != null) {
4194 return phone.isWifiCallingEnabled();
4195 } else {
4196 return false;
4197 }
4198 } finally {
4199 Binder.restoreCallingIdentity(identity);
Brad Ebingere21f25f2018-02-08 16:11:32 -08004200 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004201 }
4202
Brad Ebingere21f25f2018-02-08 16:11:32 -08004203 /**
4204 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004205 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08004206 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004207 final long identity = Binder.clearCallingIdentity();
4208 try {
4209 Phone phone = getPhone(subId);
4210 if (phone != null) {
4211 return phone.isVolteEnabled();
4212 } else {
4213 return false;
4214 }
4215 } finally {
4216 Binder.restoreCallingIdentity(identity);
Brad Ebingere21f25f2018-02-08 16:11:32 -08004217 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004218 }
Svet Ganovb320e182015-04-16 12:30:10 -07004219
Brad Ebingere21f25f2018-02-08 16:11:32 -08004220 /**
4221 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004222 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08004223 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004224 final long identity = Binder.clearCallingIdentity();
4225 try {
4226 Phone phone = getPhone(subId);
4227 if (phone != null) {
4228 return phone.isVideoEnabled();
4229 } else {
4230 return false;
4231 }
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
Brad Ebingere21f25f2018-02-08 16:11:32 -08004234 }
4235 }
4236
4237 /**
4238 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4239 * defined in {@link ImsRegistrationImplBase}.
4240 */
4241 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004242 final long identity = Binder.clearCallingIdentity();
4243 try {
4244 Phone phone = getPhone(subId);
4245 if (phone != null) {
4246 return phone.getImsRegistrationTech();
4247 } else {
4248 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4249 }
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
Brad Ebingere21f25f2018-02-08 16:11:32 -08004252 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004253 }
4254
Stuart Scott8eef64f2015-04-08 15:13:54 -07004255 @Override
4256 public void factoryReset(int subId) {
4257 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004258 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4259 return;
4260 }
4261
Svet Ganovcc087f82015-05-12 20:35:54 -07004262 final long identity = Binder.clearCallingIdentity();
4263 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004264 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4265 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07004266 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08004267 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07004268 // Set network selection mode to automatic
4269 setNetworkSelectionModeAutomatic(subId);
4270 // Set preferred mobile network type to the best available
Kitta Koutarouab8a69b2018-03-05 14:16:45 +09004271 String defaultNetwork = TelephonyManager.getTelephonyProperty(
4272 mSubscriptionController.getPhoneId(subId),
4273 "ro.telephony.default_network",
4274 null);
4275 int networkType = !TextUtils.isEmpty(defaultNetwork)
4276 ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
4277 setPreferredNetworkType(subId, networkType);
Svet Ganovcc087f82015-05-12 20:35:54 -07004278 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07004279 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07004280 }
4281 } finally {
4282 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004283 }
4284 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004285
4286 @Override
4287 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004288 final long identity = Binder.clearCallingIdentity();
4289 try {
4290 // We query all subscriptions instead of just the active ones, because
4291 // this might be called early on in the provisioning flow when the
4292 // subscriptions potentially aren't active yet.
4293 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4294 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004295 return null;
4296 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004297
Malcolm Chenaabec062018-02-28 15:00:40 -08004298 // This function may be called very early, say, from the setup wizard, at
4299 // which point we won't have a default subscription set. If that's the case
4300 // we just choose the first, which will be valid in "most cases".
4301 final int defaultSubId = getDefaultSubscription();
4302 SubscriptionInfo info = null;
4303 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4304 info = slist.get(0);
4305 } else {
4306 for (SubscriptionInfo item : slist) {
4307 if (item.getSubscriptionId() == defaultSubId) {
4308 info = item;
4309 break;
4310 }
4311 }
4312
4313 if (info == null) {
4314 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004315 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004316 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004317
Malcolm Chenaabec062018-02-28 15:00:40 -08004318 // Try and fetch the locale from the carrier properties or from the SIM language
4319 // preferences (EF-PL and EF-LI)...
4320 final int mcc = info.getMcc();
4321 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4322 String simLanguage = null;
4323 if (defaultPhone != null) {
4324 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4325 if (localeFromDefaultSim != null) {
4326 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4327 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4328 return localeFromDefaultSim.toLanguageTag();
4329 } else {
4330 simLanguage = localeFromDefaultSim.getLanguage();
4331 }
4332 }
4333 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004334
Malcolm Chenaabec062018-02-28 15:00:40 -08004335 // The SIM language preferences only store a language (e.g. fr = French), not an
4336 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4337 // the SIM and carrier preferences does not include a country we add the country
4338 // determined from the SIM MCC to provide an exact locale.
4339 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4340 simLanguage);
4341 if (mccLocale != null) {
4342 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4343 return mccLocale.toLanguageTag();
4344 }
4345
4346 if (DBG) log("No locale found - returning null");
4347 return null;
4348 } finally {
4349 Binder.restoreCallingIdentity(identity);
4350 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004351 }
4352
4353 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004354 return mSubscriptionController.getAllSubInfoList(
4355 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004356 }
4357
Malcolm Chenaabec062018-02-28 15:00:40 -08004358 /**
4359 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4360 */
4361 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4362 return mSubscriptionController.getActiveSubscriptionInfoList(
4363 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004364 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004365
4366 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004367 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4368 * representing the state of the modem.
4369 *
4370 * NOTE: This clears the modem state, so there should only every be one caller.
4371 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004372 */
4373 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004374 public void requestModemActivityInfo(ResultReceiver result) {
4375 enforceModifyPermission();
4376
Malcolm Chenaabec062018-02-28 15:00:40 -08004377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 ModemActivityInfo info =
4380 (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
4381 Bundle bundle = new Bundle();
4382 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
4383 result.send(0, bundle);
4384 } finally {
4385 Binder.restoreCallingIdentity(identity);
4386 }
4387
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004388 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004389
4390 /**
4391 * {@hide}
4392 * Returns the service state information on specified subscription.
4393 */
4394 @Override
4395 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004397 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004398 return null;
4399 }
4400
Malcolm Chenaabec062018-02-28 15:00:40 -08004401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 final Phone phone = getPhone(subId);
4404 if (phone == null) {
4405 return null;
4406 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004407
Malcolm Chenaabec062018-02-28 15:00:40 -08004408 return phone.getServiceState();
4409 } finally {
4410 Binder.restoreCallingIdentity(identity);
4411 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004412 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004413
4414 /**
4415 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4416 *
4417 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4418 * voicemail ringtone.
4419 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4420 * PhoneAccount.
4421 */
4422 @Override
4423 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4427 if (phone == null) {
4428 phone = mPhone;
4429 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004430
Malcolm Chenaabec062018-02-28 15:00:40 -08004431 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004435 }
4436
4437 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004438 * Sets the per-account voicemail ringtone.
4439 *
4440 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4441 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4442 *
4443 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4444 * voicemail ringtone.
4445 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4446 * PhoneAccount.
4447 */
4448 @Override
4449 public void setVoicemailRingtoneUri(String callingPackage,
4450 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4452 if (!TextUtils.equals(callingPackage,
4453 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4455 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4456 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004457 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004458
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
4461 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4462 if (phone == null) {
4463 phone = mPhone;
4464 }
4465 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4466 } finally {
4467 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004468 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004469 }
4470
4471 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004472 * Returns whether vibration is set for voicemail notification in Phone settings.
4473 *
4474 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4475 * voicemail vibration setting.
4476 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4477 */
4478 @Override
4479 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004480 final long identity = Binder.clearCallingIdentity();
4481 try {
4482 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4483 if (phone == null) {
4484 phone = mPhone;
4485 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004486
Malcolm Chenaabec062018-02-28 15:00:40 -08004487 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4488 } finally {
4489 Binder.restoreCallingIdentity(identity);
4490 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004491 }
4492
Youhan Wange64578a2016-05-02 15:32:42 -07004493 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004494 * Sets the per-account voicemail vibration.
4495 *
4496 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4497 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4498 *
4499 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4500 * voicemail vibration setting.
4501 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4502 * specific PhoneAccount.
4503 */
4504 @Override
4505 public void setVoicemailVibrationEnabled(String callingPackage,
4506 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4507 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4508 if (!TextUtils.equals(callingPackage,
4509 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4511 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4512 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004513 }
4514
Malcolm Chenaabec062018-02-28 15:00:40 -08004515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4518 if (phone == null) {
4519 phone = mPhone;
4520 }
4521 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4522 } finally {
4523 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004524 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004525 }
4526
4527 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004528 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4529 *
4530 * @throws SecurityException if the caller does not have the required permission
4531 */
4532 private void enforceReadPrivilegedPermission() {
4533 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4534 null);
4535 }
4536
4537 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004538 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4539 * permission.
4540 *
4541 * @throws SecurityException if the caller does not have the required permission
4542 */
4543 private void enforceSendSmsPermission() {
4544 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4545 }
4546
4547 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004548 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004549 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004550 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004551 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004552 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004553 final long identity = Binder.clearCallingIdentity();
4554 try {
4555 ComponentName componentName =
4556 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4557 if (componentName == null) {
4558 throw new SecurityException(
4559 "Caller not current active visual voicemail package[null]");
4560 }
4561 String vvmPackage = componentName.getPackageName();
4562 if (!callingPackage.equals(vvmPackage)) {
4563 throw new SecurityException("Caller not current active visual voicemail package["
4564 + vvmPackage + "]");
4565 }
4566 } finally {
4567 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004568 }
4569 }
4570
4571 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004572 * Return the application ID for the app type.
4573 *
4574 * @param subId the subscription ID that this request applies to.
4575 * @param appType the uicc app type.
4576 * @return Application ID for specificied app type, or null if no uicc.
4577 */
4578 @Override
4579 public String getAidForAppType(int subId, int appType) {
4580 enforceReadPrivilegedPermission();
4581 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004582
4583 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004584 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004585 if (phone == null) {
4586 return null;
4587 }
4588 String aid = null;
4589 try {
4590 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4591 .getApplicationByType(appType).getAid();
4592 } catch (Exception e) {
4593 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4594 }
4595 return aid;
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004598 }
Youhan Wange64578a2016-05-02 15:32:42 -07004599 }
4600
Youhan Wang4001d252016-05-11 10:29:41 -07004601 /**
4602 * Return the Electronic Serial Number.
4603 *
4604 * @param subId the subscription ID that this request applies to.
4605 * @return ESN or null if error.
4606 */
4607 @Override
4608 public String getEsn(int subId) {
4609 enforceReadPrivilegedPermission();
4610 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004611
4612 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004613 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004614 if (phone == null) {
4615 return null;
4616 }
4617 String esn = null;
4618 try {
4619 esn = phone.getEsn();
4620 } catch (Exception e) {
4621 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4622 }
4623 return esn;
4624 } finally {
4625 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004626 }
Youhan Wang4001d252016-05-11 10:29:41 -07004627 }
4628
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004629 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004630 * Return the Preferred Roaming List Version.
4631 *
4632 * @param subId the subscription ID that this request applies to.
4633 * @return PRLVersion or null if error.
4634 */
4635 @Override
4636 public String getCdmaPrlVersion(int subId) {
4637 enforceReadPrivilegedPermission();
4638 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004639
4640 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004641 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004642 if (phone == null) {
4643 return null;
4644 }
4645 String cdmaPrlVersion = null;
4646 try {
4647 cdmaPrlVersion = phone.getCdmaPrlVersion();
4648 } catch (Exception e) {
4649 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4650 }
4651 return cdmaPrlVersion;
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004654 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004655 }
4656
4657 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004658 * Get snapshot of Telephony histograms
4659 * @return List of Telephony histograms
4660 * @hide
4661 */
4662 @Override
4663 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4665 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004666
4667 final long identity = Binder.clearCallingIdentity();
4668 try {
4669 return RIL.getTelephonyRILTimingHistograms();
4670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004673 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004674
4675 /**
4676 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004677 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004678 * Require system privileges. In the future we may add this to carrier APIs.
4679 *
4680 * @return The number of carriers set successfully, should match length of carriers
4681 */
4682 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004683 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004684 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004685
Meng Wang9b7c4e92017-02-17 11:41:27 -08004686 if (carriers == null) {
4687 throw new NullPointerException("carriers cannot be null");
4688 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004689
Malcolm Chenaabec062018-02-28 15:00:40 -08004690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4693 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4694 return retVal[0];
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004698 }
4699
4700 /**
4701 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004702 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004703 * Require system privileges. In the future we may add this to carrier APIs.
4704 *
4705 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4706 * means all carriers are allowed.
4707 */
4708 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004709 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004710 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004711
4712 final long identity = Binder.clearCallingIdentity();
4713 try {
4714 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4715 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4716 } finally {
4717 Binder.restoreCallingIdentity(identity);
4718 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004719 }
4720
fionaxu59545b42016-05-25 15:53:37 -07004721 /**
4722 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4723 * @param subId the subscription ID that this action applies to.
4724 * @param enabled control enable or disable metered apns.
4725 * {@hide}
4726 */
4727 @Override
4728 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4729 enforceModifyPermission();
4730 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004731
4732 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004733 if (phone == null) {
4734 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4735 return;
4736 }
4737 try {
4738 phone.carrierActionSetMeteredApnsEnabled(enabled);
4739 } catch (Exception e) {
4740 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004741 } finally {
4742 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004743 }
4744 }
4745
4746 /**
4747 * Action set from carrier signalling broadcast receivers to enable/disable radio
4748 * @param subId the subscription ID that this action applies to.
4749 * @param enabled control enable or disable radio.
4750 * {@hide}
4751 */
4752 @Override
4753 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4754 enforceModifyPermission();
4755 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004756
4757 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004758 if (phone == null) {
4759 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4760 return;
4761 }
4762 try {
4763 phone.carrierActionSetRadioEnabled(enabled);
4764 } catch (Exception e) {
4765 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004766 } finally {
4767 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004768 }
4769 }
4770
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004771 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004772 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4773 * network status based on which carrier apps could apply actions accordingly,
4774 * enable/disable default url handler for example.
4775 *
4776 * @param subId the subscription ID that this action applies to.
4777 * @param report control start/stop reporting the default network status.
4778 * {@hide}
4779 */
4780 @Override
4781 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4782 enforceModifyPermission();
4783 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004784
4785 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004786 if (phone == null) {
4787 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4788 return;
4789 }
4790 try {
4791 phone.carrierActionReportDefaultNetworkStatus(report);
4792 } catch (Exception e) {
4793 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004794 } finally {
4795 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004796 }
4797 }
4798
4799 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004800 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4801 * bug report is being generated.
4802 */
4803 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004804 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004805 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4806 != PackageManager.PERMISSION_GRANTED) {
4807 writer.println("Permission Denial: can't dump Phone from pid="
4808 + Binder.getCallingPid()
4809 + ", uid=" + Binder.getCallingUid()
4810 + "without permission "
4811 + android.Manifest.permission.DUMP);
4812 return;
4813 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004814 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004815 }
Jack Yueb89b242016-06-22 13:27:47 -07004816
Brad Ebinger4dc095a2018-04-03 15:17:52 -07004817 @Override
4818 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4819 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4820 throws RemoteException {
4821 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4822 }
4823
Jack Yueb89b242016-06-22 13:27:47 -07004824 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004825 * Get aggregated video call data usage since boot.
4826 *
4827 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4828 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004829 * {@hide}
4830 */
4831 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004832 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004833 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4834 null);
4835
Malcolm Chenaabec062018-02-28 15:00:40 -08004836 final long identity = Binder.clearCallingIdentity();
4837 try {
4838 // NetworkStatsService keeps tracking the active network interface and identity. It
4839 // records the delta with the corresponding network identity.
4840 // We just return the total video call data usage snapshot since boot.
4841 Phone phone = getPhone(subId);
4842 if (phone != null) {
4843 return phone.getVtDataUsage(perUidStats);
4844 }
4845 return null;
4846 } finally {
4847 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004848 }
Jack Yueb89b242016-06-22 13:27:47 -07004849 }
Jack Yu75ab2952016-07-08 14:29:33 -07004850
4851 /**
4852 * Policy control of data connection. Usually used when data limit is passed.
4853 * @param enabled True if enabling the data, otherwise disabling.
4854 * @param subId Subscription index
4855 * {@hide}
4856 */
4857 @Override
4858 public void setPolicyDataEnabled(boolean enabled, int subId) {
4859 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004860
4861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 Phone phone = getPhone(subId);
4864 if (phone != null) {
4865 phone.setPolicyDataEnabled(enabled);
4866 }
4867 } finally {
4868 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004869 }
4870 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004871
4872 /**
4873 * Get Client request stats
4874 * @return List of Client Request Stats
4875 * @hide
4876 */
4877 @Override
4878 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004880 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004881 return null;
4882 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004883 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004884
Malcolm Chenaabec062018-02-28 15:00:40 -08004885 final long identity = Binder.clearCallingIdentity();
4886 try {
4887 if (phone != null) {
4888 return phone.getClientRequestStats();
4889 }
4890
4891 return null;
4892 } finally {
4893 Binder.restoreCallingIdentity(identity);
4894 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004895 }
4896
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00004897 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004898 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00004899 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004900 }
Jack Yueb4124c2017-02-16 15:32:43 -08004901
4902 /**
Grace Chen70990072017-03-24 17:21:30 -07004903 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004904 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004905 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004906 * @param state State of SIM (power down, power up, pass through)
4907 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4908 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4909 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004910 *
4911 **/
4912 @Override
Grace Chen70990072017-03-24 17:21:30 -07004913 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004914 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004915 Phone phone = PhoneFactory.getPhone(slotIndex);
4916
Malcolm Chenaabec062018-02-28 15:00:40 -08004917 final long identity = Binder.clearCallingIdentity();
4918 try {
4919 if (phone != null) {
4920 phone.setSimPowerState(state);
4921 }
4922 } finally {
4923 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004924 }
4925 }
Shuo Qiandd210312017-04-12 22:11:33 +00004926
Tyler Gunn65d45c22017-06-05 11:22:26 -07004927 private boolean isUssdApiAllowed(int subId) {
4928 CarrierConfigManager configManager =
4929 (CarrierConfigManager) mPhone.getContext().getSystemService(
4930 Context.CARRIER_CONFIG_SERVICE);
4931 if (configManager == null) {
4932 return false;
4933 }
4934 PersistableBundle pb = configManager.getConfigForSubId(subId);
4935 if (pb == null) {
4936 return false;
4937 }
4938 return pb.getBoolean(
4939 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4940 }
4941
Shuo Qiandd210312017-04-12 22:11:33 +00004942 /**
4943 * Check if phone is in emergency callback mode
4944 * @return true if phone is in emergency callback mode
4945 * @param subId sub id
4946 */
4947 public boolean getEmergencyCallbackMode(int subId) {
4948 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004949
4950 final long identity = Binder.clearCallingIdentity();
4951 try {
4952 if (phone != null) {
4953 return phone.isInEcm();
4954 } else {
4955 return false;
4956 }
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004959 }
4960 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004961
4962 /**
4963 * Get the current signal strength information for the given subscription.
4964 * Because this information is not updated when the device is in a low power state
4965 * it should not be relied-upon to be current.
4966 * @param subId Subscription index
4967 * @return the most recent cached signal strength info from the modem
4968 */
4969 @Override
4970 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004971 final long identity = Binder.clearCallingIdentity();
4972 try {
4973 Phone p = getPhone(subId);
4974 if (p == null) {
4975 return null;
4976 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004977
Malcolm Chenaabec062018-02-28 15:00:40 -08004978 return p.getSignalStrength();
4979 } finally {
4980 Binder.restoreCallingIdentity(identity);
4981 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004982 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004983
4984 @Override
4985 public UiccSlotInfo[] getUiccSlotsInfo() {
4986 enforceReadPrivilegedPermission();
4987
Malcolm Chenaabec062018-02-28 15:00:40 -08004988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4991 if (slots == null) return null;
4992 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4993 for (int i = 0; i < slots.length; i++) {
4994 UiccSlot slot = slots[i];
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004995
Malcolm Chenaabec062018-02-28 15:00:40 -08004996 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004997
Malcolm Chenaabec062018-02-28 15:00:40 -08004998 int cardState = 0;
4999 switch (slot.getCardState()) {
5000 case CARDSTATE_ABSENT:
5001 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
5002 break;
5003 case CARDSTATE_PRESENT:
5004 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
5005 break;
5006 case CARDSTATE_ERROR:
5007 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
5008 break;
5009 case CARDSTATE_RESTRICTED:
5010 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
5011 break;
5012 default:
5013 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005014
Malcolm Chenaabec062018-02-28 15:00:40 -08005015 }
5016
5017 infos[i] = new UiccSlotInfo(
5018 slot.isActive(),
5019 slot.isEuicc(),
5020 cardId,
5021 cardState,
5022 slot.getPhoneId(),
5023 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005024 }
Malcolm Chenaabec062018-02-28 15:00:40 -08005025 return infos;
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005028 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005029 }
5030
5031 @Override
5032 public boolean switchSlots(int[] physicalSlots) {
5033 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005034
5035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
5040 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005041 }
Jack Yue6146032018-02-27 15:30:01 -08005042
5043 @Override
5044 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5045 enforceModifyPermission();
5046 final Phone phone = getPhone(subId);
5047 if (phone == null) {
5048 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5049 return;
5050 }
5051
Malcolm Chenaabec062018-02-28 15:00:40 -08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
5054 phone.setRadioIndicationUpdateMode(filters, mode);
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
5057 }
Jack Yue6146032018-02-27 15:30:01 -08005058 }
fionaxu2c8bbbd2018-03-21 00:08:13 -07005059
5060 @Override
5061 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5062 gid1, String gid2, String plmn, String spn) {
5063 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005064
5065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 final Phone phone = getPhone(subId);
5068 if (phone == null) {
5069 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5070 return;
5071 }
5072 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
fionaxu2c8bbbd2018-03-21 00:08:13 -07005075 }
fionaxu2c8bbbd2018-03-21 00:08:13 -07005076 }
5077
5078 @Override
5079 public int getCarrierIdListVersion(int subId) {
5080 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005081
5082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 final Phone phone = getPhone(subId);
5085 if (phone == null) {
5086 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5087 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5088 }
5089 return phone.getCarrierIdListVersion();
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
fionaxu2c8bbbd2018-03-21 00:08:13 -07005092 }
fionaxu2c8bbbd2018-03-21 00:08:13 -07005093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005094}