blob: ed9804a5b8d081981b894e69a0e3340bd697ebd1 [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;
Nathan Haroldf180aac2018-06-01 18:43:55 -070057import android.telephony.CellInfoGsm;
58import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070059import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070060import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080061import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070062import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080063import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070064import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070065import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070066import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080068import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070069import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080070import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080071import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070072import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070073import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000074import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070075import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070076import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebingera12246d2018-01-16 09:39:35 -080077import android.telephony.ims.aidl.IImsConfig;
78import android.telephony.ims.aidl.IImsMmTelFeature;
79import android.telephony.ims.aidl.IImsRcsFeature;
80import android.telephony.ims.aidl.IImsRegistration;
Brad Ebingere21f25f2018-02-08 16:11:32 -080081import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080086import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080087
Andrew Lee312e8172014-10-23 17:01:36 -070088import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080089import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070091import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070092import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070093import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080096import com.android.internal.telephony.IccCard;
Jack Yu8e4fdc22018-04-13 14:05:37 -070097import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +010098import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070099import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700100import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800102import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700103import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700104import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700105import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700106import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700107import com.android.internal.telephony.RILConstants;
Jack Yu8e4fdc22018-04-13 14:05:37 -0700108import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800109import com.android.internal.telephony.SubscriptionController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800110import com.android.internal.telephony.TelephonyPermissions;
Derek Tan740e1672017-06-27 14:56:27 -0700111import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700112import com.android.internal.telephony.uicc.IccIoResult;
113import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800114import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700115import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800116import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.uicc.UiccController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800118import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000119import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700120import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800121import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700122import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800123import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700124import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700125import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800126
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700127import java.io.FileDescriptor;
128import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800129import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800131import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800132import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100133import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800134import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135
136/**
137 * Implementation of the ITelephony interface.
138 */
Santos Cordon117fee72014-05-16 17:56:12 -0700139public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140 private static final String LOG_TAG = "PhoneInterfaceManager";
141 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
142 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800143 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144
145 // Message codes used with mMainThreadHandler
146 private static final int CMD_HANDLE_PIN_MMI = 1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147 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
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700367 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800368 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700369 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800370 request.result = ""; // dummy result for notifying the waiting thread
371 // Wake up the requesting thread
372 synchronized (request) {
373 request.notifyAll();
374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 break;
376
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 case CMD_END_CALL:
378 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800379 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700380 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700381 Phone phone = getPhone(end_subId);
382 if (phone == null) {
383 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
384 break;
385 }
386 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
388 // CDMA: If the user presses the Power button we treat it as
389 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700390 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
392 // GSM: End the call as per the Phone state
393 hungUp = PhoneUtils.hangup(mCM);
394 } else {
395 throw new IllegalStateException("Unexpected phone type: " + phoneType);
396 }
397 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
398 request.result = hungUp;
399 // Wake up the requesting thread
400 synchronized (request) {
401 request.notifyAll();
402 }
403 break;
404
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700405 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700406 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700407 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800408 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700409 if (uiccCard == null) {
410 loge("iccTransmitApduLogicalChannel: No UICC");
411 request.result = new IccIoResult(0x6F, 0, (byte[])null);
412 synchronized (request) {
413 request.notifyAll();
414 }
415 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
417 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 iccArgument.channel, iccArgument.cla, iccArgument.command,
420 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 break;
424
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 ar = (AsyncResult) msg.obj;
427 request = (MainThreadRequest) ar.userObj;
428 if (ar.exception == null && ar.result != null) {
429 request.result = ar.result;
430 } else {
431 request.result = new IccIoResult(0x6F, 0, (byte[])null);
432 if (ar.result == null) {
433 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800434 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800436 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 } else {
438 loge("iccTransmitApduLogicalChannel: Unknown exception");
439 }
440 }
441 synchronized (request) {
442 request.notifyAll();
443 }
444 break;
445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
447 request = (MainThreadRequest) msg.obj;
448 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 if (uiccCard == null) {
451 loge("iccTransmitApduBasicChannel: No UICC");
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
453 synchronized (request) {
454 request.notifyAll();
455 }
456 } else {
457 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
458 request);
459 uiccCard.iccTransmitApduBasicChannel(
460 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
461 iccArgument.p3, iccArgument.data, onCompleted);
462 }
463 break;
464
465 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
466 ar = (AsyncResult) msg.obj;
467 request = (MainThreadRequest) ar.userObj;
468 if (ar.exception == null && ar.result != null) {
469 request.result = ar.result;
470 } else {
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
472 if (ar.result == null) {
473 loge("iccTransmitApduBasicChannel: Empty response");
474 } else if (ar.exception instanceof CommandException) {
475 loge("iccTransmitApduBasicChannel: CommandException: " +
476 ar.exception);
477 } else {
478 loge("iccTransmitApduBasicChannel: Unknown exception");
479 }
480 }
481 synchronized (request) {
482 request.notifyAll();
483 }
484 break;
485
486 case CMD_EXCHANGE_SIM_IO:
487 request = (MainThreadRequest) msg.obj;
488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 if (uiccCard == null) {
491 loge("iccExchangeSimIO: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
493 synchronized (request) {
494 request.notifyAll();
495 }
496 } else {
497 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
498 request);
499 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
500 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
501 iccArgument.data, onCompleted);
502 }
503 break;
504
505 case EVENT_EXCHANGE_SIM_IO_DONE:
506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6f, 0, (byte[])null);
512 }
513 synchronized (request) {
514 request.notifyAll();
515 }
516 break;
517
Derek Tan4d5e5c12014-02-04 11:54:58 -0800518 case CMD_SEND_ENVELOPE:
519 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800520 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700521 if (uiccCard == null) {
522 loge("sendEnvelopeWithStatus: No UICC");
523 request.result = new IccIoResult(0x6F, 0, (byte[])null);
524 synchronized (request) {
525 request.notifyAll();
526 }
527 } else {
528 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
529 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
530 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800531 break;
532
533 case EVENT_SEND_ENVELOPE_DONE:
534 ar = (AsyncResult) msg.obj;
535 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700536 if (ar.exception == null && ar.result != null) {
537 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
540 if (ar.result == null) {
541 loge("sendEnvelopeWithStatus: Empty response");
542 } else if (ar.exception instanceof CommandException) {
543 loge("sendEnvelopeWithStatus: CommandException: " +
544 ar.exception);
545 } else {
546 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
547 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 }
549 synchronized (request) {
550 request.notifyAll();
551 }
552 break;
553
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 case CMD_OPEN_CHANNEL:
555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800557 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 if (uiccCard == null) {
559 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800560 request.result = new IccOpenLogicalChannelResponse(-1,
561 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 synchronized (request) {
563 request.notifyAll();
564 }
565 } else {
566 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800567 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
568 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 break;
571
572 case EVENT_OPEN_CHANNEL_DONE:
573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 int[] result = (int[]) ar.result;
578 int channelId = result[0];
579 byte[] selectResponse = null;
580 if (result.length > 1) {
581 selectResponse = new byte[result.length - 1];
582 for (int i = 1; i < result.length; ++i) {
583 selectResponse[i - 1] = (byte) result[i];
584 }
585 }
586 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700587 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 if (ar.result == null) {
590 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 if (ar.exception != null) {
593 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
594 }
595
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700597 if (ar.exception instanceof CommandException) {
598 CommandException.Error error =
599 ((CommandException) (ar.exception)).getCommandError();
600 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700601 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700602 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700603 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 }
605 }
606 openChannelResp = new IccOpenLogicalChannelResponse(
607 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700609 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 synchronized (request) {
611 request.notifyAll();
612 }
613 break;
614
615 case CMD_CLOSE_CHANNEL:
616 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800617 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 if (uiccCard == null) {
619 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900620 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 synchronized (request) {
622 request.notifyAll();
623 }
624 } else {
625 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
626 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
627 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 break;
629
630 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800631 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
632 break;
633
634 case CMD_NV_READ_ITEM:
635 request = (MainThreadRequest) msg.obj;
636 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
637 mPhone.nvReadItem((Integer) request.argument, onCompleted);
638 break;
639
640 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800646 request.result = "";
647 if (ar.result == null) {
648 loge("nvReadItem: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("nvReadItem: CommandException: " +
651 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800653 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 }
655 }
656 synchronized (request) {
657 request.notifyAll();
658 }
659 break;
660
Jake Hambye994d462014-02-03 13:10:13 -0800661 case CMD_NV_WRITE_ITEM:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
664 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
665 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
666 break;
667
668 case EVENT_NV_WRITE_ITEM_DONE:
669 handleNullReturnEvent(msg, "nvWriteItem");
670 break;
671
672 case CMD_NV_WRITE_CDMA_PRL:
673 request = (MainThreadRequest) msg.obj;
674 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
675 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
676 break;
677
678 case EVENT_NV_WRITE_CDMA_PRL_DONE:
679 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
680 break;
681
682 case CMD_NV_RESET_CONFIG:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
685 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
686 break;
687
688 case EVENT_NV_RESET_CONFIG_DONE:
689 handleNullReturnEvent(msg, "nvResetConfig");
690 break;
691
Jake Hamby7c27be32014-03-03 13:25:59 -0800692 case CMD_GET_PREFERRED_NETWORK_TYPE:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700695 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800696 break;
697
698 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
701 if (ar.exception == null && ar.result != null) {
702 request.result = ar.result; // Integer
703 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800704 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800705 if (ar.result == null) {
706 loge("getPreferredNetworkType: Empty response");
707 } else if (ar.exception instanceof CommandException) {
708 loge("getPreferredNetworkType: CommandException: " +
709 ar.exception);
710 } else {
711 loge("getPreferredNetworkType: Unknown exception");
712 }
713 }
714 synchronized (request) {
715 request.notifyAll();
716 }
717 break;
718
719 case CMD_SET_PREFERRED_NETWORK_TYPE:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
722 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700723 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 break;
725
726 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
727 handleNullReturnEvent(msg, "setPreferredNetworkType");
728 break;
729
Shuo Qian74b16b12018-04-27 01:32:07 +0000730 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
731 request = (MainThreadRequest)msg.obj;
732 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
733 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
734 break;
735
736 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
737 ar = (AsyncResult)msg.obj;
738 request = (MainThreadRequest)ar.userObj;
739 request.result = ar;
740 synchronized (request) {
741 request.notifyAll();
742 }
743 break;
744
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800745 case CMD_SET_VOICEMAIL_NUMBER:
746 request = (MainThreadRequest) msg.obj;
747 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
748 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800749 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
750 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800751 break;
752
753 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
754 handleNullReturnEvent(msg, "setVoicemailNumber");
755 break;
756
Stuart Scott54788802015-03-30 13:18:01 -0700757 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
758 request = (MainThreadRequest) msg.obj;
759 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
760 request);
761 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
762 break;
763
764 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
765 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
766 break;
767
Shishir Agrawal302c8692015-06-19 13:49:39 -0700768 case CMD_PERFORM_NETWORK_SCAN:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
771 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
772 break;
773
774 case EVENT_PERFORM_NETWORK_SCAN_DONE:
775 ar = (AsyncResult) msg.obj;
776 request = (MainThreadRequest) ar.userObj;
777 CellNetworkScanResult cellScanResult;
778 if (ar.exception == null && ar.result != null) {
779 cellScanResult = new CellNetworkScanResult(
780 CellNetworkScanResult.STATUS_SUCCESS,
781 (List<OperatorInfo>) ar.result);
782 } else {
783 if (ar.result == null) {
784 loge("getCellNetworkScanResults: Empty response");
785 }
786 if (ar.exception != null) {
787 loge("getCellNetworkScanResults: Exception: " + ar.exception);
788 }
789 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
790 if (ar.exception instanceof CommandException) {
791 CommandException.Error error =
792 ((CommandException) (ar.exception)).getCommandError();
793 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
794 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
795 } else if (error == CommandException.Error.GENERIC_FAILURE) {
796 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
797 }
798 }
799 cellScanResult = new CellNetworkScanResult(errorCode, null);
800 }
801 request.result = cellScanResult;
802 synchronized (request) {
803 request.notifyAll();
804 }
805 break;
806
807 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
808 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700809 ManualNetworkSelectionArgument selArg =
810 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700811 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
812 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700813 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
814 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 break;
816
817 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
818 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
819 break;
820
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700821 case CMD_GET_MODEM_ACTIVITY_INFO:
822 request = (MainThreadRequest) msg.obj;
823 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700824 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700825 break;
826
827 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
828 ar = (AsyncResult) msg.obj;
829 request = (MainThreadRequest) ar.userObj;
830 if (ar.exception == null && ar.result != null) {
831 request.result = ar.result;
832 } else {
833 if (ar.result == null) {
834 loge("queryModemActivityInfo: Empty response");
835 } else if (ar.exception instanceof CommandException) {
836 loge("queryModemActivityInfo: CommandException: " +
837 ar.exception);
838 } else {
839 loge("queryModemActivityInfo: Unknown exception");
840 }
841 }
Amit Mahajand4766222016-01-28 15:28:28 -0800842 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
843 if (request.result == null) {
844 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
845 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700846 synchronized (request) {
847 request.notifyAll();
848 }
849 break;
850
Meng Wang1a7c35a2016-05-05 20:56:15 -0700851 case CMD_SET_ALLOWED_CARRIERS:
852 request = (MainThreadRequest) msg.obj;
853 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
854 mPhone.setAllowedCarriers(
855 (List<CarrierIdentifier>) request.argument,
856 onCompleted);
857 break;
858
859 case EVENT_SET_ALLOWED_CARRIERS_DONE:
860 ar = (AsyncResult) msg.obj;
861 request = (MainThreadRequest) ar.userObj;
862 if (ar.exception == null && ar.result != null) {
863 request.result = ar.result;
864 } else {
865 if (ar.result == null) {
866 loge("setAllowedCarriers: Empty response");
867 } else if (ar.exception instanceof CommandException) {
868 loge("setAllowedCarriers: CommandException: " +
869 ar.exception);
870 } else {
871 loge("setAllowedCarriers: Unknown exception");
872 }
873 }
874 // Result cannot be null. Return -1 on error.
875 if (request.result == null) {
876 request.result = new int[]{-1};
877 }
878 synchronized (request) {
879 request.notifyAll();
880 }
881 break;
882
883 case CMD_GET_ALLOWED_CARRIERS:
884 request = (MainThreadRequest) msg.obj;
885 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
886 mPhone.getAllowedCarriers(onCompleted);
887 break;
888
889 case EVENT_GET_ALLOWED_CARRIERS_DONE:
890 ar = (AsyncResult) msg.obj;
891 request = (MainThreadRequest) ar.userObj;
892 if (ar.exception == null && ar.result != null) {
893 request.result = ar.result;
894 } else {
895 if (ar.result == null) {
896 loge("getAllowedCarriers: Empty response");
897 } else if (ar.exception instanceof CommandException) {
898 loge("getAllowedCarriers: CommandException: " +
899 ar.exception);
900 } else {
901 loge("getAllowedCarriers: Unknown exception");
902 }
903 }
904 // Result cannot be null. Return empty list of CarrierIdentifier.
905 if (request.result == null) {
906 request.result = new ArrayList<CarrierIdentifier>(0);
907 }
908 synchronized (request) {
909 request.notifyAll();
910 }
911 break;
912
Nathan Haroldb3014052017-01-25 15:57:32 -0800913 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result;
918 } else {
919 request.result = new IllegalArgumentException(
920 "Failed to retrieve Forbidden Plmns");
921 if (ar.result == null) {
922 loge("getForbiddenPlmns: Empty response");
923 } else {
924 loge("getForbiddenPlmns: Unknown exception");
925 }
926 }
927 synchronized (request) {
928 request.notifyAll();
929 }
930 break;
931
932 case CMD_GET_FORBIDDEN_PLMNS:
933 request = (MainThreadRequest) msg.obj;
934 uiccCard = getUiccCardFromRequest(request);
935 if (uiccCard == null) {
936 loge("getForbiddenPlmns() UiccCard is null");
937 request.result = new IllegalArgumentException(
938 "getForbiddenPlmns() UiccCard is null");
939 synchronized (request) {
940 request.notifyAll();
941 }
942 break;
943 }
944 Integer appType = (Integer) request.argument;
945 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
946 if (uiccApp == null) {
947 loge("getForbiddenPlmns() no app with specified type -- "
948 + appType);
949 request.result = new IllegalArgumentException("Failed to get UICC App");
950 synchronized (request) {
951 request.notifyAll();
952 }
953 break;
954 } else {
955 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
956 + " specified type -- " + appType);
957 }
958 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
959 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
960 onCompleted);
961 break;
962
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000963 case CMD_SWITCH_SLOTS:
964 request = (MainThreadRequest) msg.obj;
965 int[] physicalSlots = (int[]) request.argument;
966 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
967 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
968 break;
969
970 case EVENT_SWITCH_SLOTS_DONE:
971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
973 request.result = (ar.exception == null);
974 synchronized (request) {
975 request.notifyAll();
976 }
977 break;
978
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700979 default:
980 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
981 break;
982 }
983 }
Jake Hambye994d462014-02-03 13:10:13 -0800984
985 private void handleNullReturnEvent(Message msg, String command) {
986 AsyncResult ar = (AsyncResult) msg.obj;
987 MainThreadRequest request = (MainThreadRequest) ar.userObj;
988 if (ar.exception == null) {
989 request.result = true;
990 } else {
991 request.result = false;
992 if (ar.exception instanceof CommandException) {
993 loge(command + ": CommandException: " + ar.exception);
994 } else {
995 loge(command + ": Unknown exception");
996 }
997 }
998 synchronized (request) {
999 request.notifyAll();
1000 }
1001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001002 }
1003
1004 /**
1005 * Posts the specified command to be executed on the main thread,
1006 * waits for the request to complete, and returns the result.
1007 * @see #sendRequestAsync
1008 */
1009 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001010 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001011 }
1012
1013 /**
1014 * Posts the specified command to be executed on the main thread,
1015 * waits for the request to complete, and returns the result.
1016 * @see #sendRequestAsync
1017 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001018 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001019 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1020 throw new RuntimeException("This method will deadlock if called from the main thread.");
1021 }
1022
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001023 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001024 Message msg = mMainThreadHandler.obtainMessage(command, request);
1025 msg.sendToTarget();
1026
1027 // Wait for the request to complete
1028 synchronized (request) {
1029 while (request.result == null) {
1030 try {
1031 request.wait();
1032 } catch (InterruptedException e) {
1033 // Do nothing, go back and wait until the request is complete
1034 }
1035 }
1036 }
1037 return request.result;
1038 }
1039
1040 /**
1041 * Asynchronous ("fire and forget") version of sendRequest():
1042 * Posts the specified command to be executed on the main thread, and
1043 * returns immediately.
1044 * @see #sendRequest
1045 */
1046 private void sendRequestAsync(int command) {
1047 mMainThreadHandler.sendEmptyMessage(command);
1048 }
1049
1050 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001051 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1052 * @see {@link #sendRequest(int,Object)}
1053 */
1054 private void sendRequestAsync(int command, Object argument) {
1055 MainThreadRequest request = new MainThreadRequest(argument);
1056 Message msg = mMainThreadHandler.obtainMessage(command, request);
1057 msg.sendToTarget();
1058 }
1059
1060 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001061 * Initialize the singleton PhoneInterfaceManager instance.
1062 * This is only done once, at startup, from PhoneApp.onCreate().
1063 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001064 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001065 synchronized (PhoneInterfaceManager.class) {
1066 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001067 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001068 } else {
1069 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1070 }
1071 return sInstance;
1072 }
1073 }
1074
1075 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001076 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001077 mApp = app;
1078 mPhone = phone;
1079 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001080 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001081 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1082 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001083 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001084 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001085 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001086 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001087
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001088 publish();
1089 }
1090
1091 private void publish() {
1092 if (DBG) log("publish: " + this);
1093
1094 ServiceManager.addService("phone", this);
1095 }
1096
Stuart Scott584921c2015-01-15 17:10:34 -08001097 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001098 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1099 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001100 }
1101
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001102 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1103 Phone phone = getPhoneFromRequest(request);
1104 return phone == null ? null :
1105 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1106 }
1107
Wink Saville36469e72014-06-11 15:17:00 -07001108 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001109 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001110 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001112 //
1113 // Implementation of the ITelephony interface.
1114 //
1115
1116 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001117 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001118 }
1119
Wink Savilleb564aae2014-10-23 10:18:09 -07001120 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001121 if (DBG) log("dial: " + number);
1122 // No permission check needed here: This is just a wrapper around the
1123 // ACTION_DIAL intent, which is available to any app since it puts up
1124 // the UI before it does anything.
1125
Malcolm Chenaabec062018-02-28 15:00:40 -08001126 final long identity = Binder.clearCallingIdentity();
1127 try {
1128 String url = createTelUrl(number);
1129 if (url == null) {
1130 return;
1131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001132
Malcolm Chenaabec062018-02-28 15:00:40 -08001133 // PENDING: should we just silently fail if phone is offhook or ringing?
1134 PhoneConstants.State state = mCM.getState(subId);
1135 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1136 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1137 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1138 mApp.startActivity(intent);
1139 }
1140 } finally {
1141 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 }
1143 }
1144
1145 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001146 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001147 }
1148
Wink Savilleb564aae2014-10-23 10:18:09 -07001149 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 if (DBG) log("call: " + number);
1151
1152 // This is just a wrapper around the ACTION_CALL intent, but we still
1153 // need to do a permission check since we're calling startActivity()
1154 // from the context of the phone app.
1155 enforceCallPermission();
1156
1157 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1158 != AppOpsManager.MODE_ALLOWED) {
1159 return;
1160 }
1161
Malcolm Chenaabec062018-02-28 15:00:40 -08001162 final long identity = Binder.clearCallingIdentity();
1163 try {
1164 String url = createTelUrl(number);
1165 if (url == null) {
1166 return;
1167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168
Malcolm Chenaabec062018-02-28 15:00:40 -08001169 boolean isValid = false;
1170 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1171 if (slist != null) {
1172 for (SubscriptionInfo subInfoRecord : slist) {
1173 if (subInfoRecord.getSubscriptionId() == subId) {
1174 isValid = true;
1175 break;
1176 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001177 }
Wink Saville08874612014-08-31 19:19:58 -07001178 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001179 if (!isValid) {
1180 return;
1181 }
Wink Saville08874612014-08-31 19:19:58 -07001182
Malcolm Chenaabec062018-02-28 15:00:40 -08001183 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1184 intent.putExtra(SUBSCRIPTION_KEY, subId);
1185 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1186 mApp.startActivity(intent);
1187 } finally {
1188 Binder.restoreCallingIdentity(identity);
1189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 }
1191
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 /**
1193 * End a call based on call state
1194 * @return true is a call was ended
1195 */
1196 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001197 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001198 }
1199
1200 /**
1201 * End a call based on the call state of the subId
1202 * @return true is a call was ended
1203 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001204 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 enforceCallPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001206
1207 final long identity = Binder.clearCallingIdentity();
1208 try {
1209 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
1210 } finally {
1211 Binder.restoreCallingIdentity(identity);
1212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001213 }
1214
1215 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001216 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001217 }
1218
Wink Savilleb564aae2014-10-23 10:18:09 -07001219 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 if (DBG) log("answerRingingCall...");
1221 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1222 // but that can probably wait till the big TelephonyManager API overhaul.
1223 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1224 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001225
1226 final long identity = Binder.clearCallingIdentity();
1227 try {
1228 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
1229 } finally {
1230 Binder.restoreCallingIdentity(identity);
1231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 }
1233
1234 /**
1235 * Make the actual telephony calls to implement answerRingingCall().
1236 * This should only be called from the main thread of the Phone app.
1237 * @see #answerRingingCall
1238 *
1239 * TODO: it would be nice to return true if we answered the call, or
1240 * false if there wasn't actually a ringing incoming call, or some
1241 * other error occurred. (In other words, pass back the return value
1242 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1243 * But that would require calling this method via sendRequest() rather
1244 * than sendRequestAsync(), and right now we don't actually *need* that
1245 * return value, so let's just return void for now.
1246 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001247 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001248 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001250 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1251 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 if (hasActiveCall && hasHoldingCall) {
1253 // Both lines are in use!
1254 // TODO: provide a flag to let the caller specify what
1255 // policy to use if both lines are in use. (The current
1256 // behavior is hardwired to "answer incoming, end ongoing",
1257 // which is how the CALL button is specced to behave.)
1258 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1259 return;
1260 } else {
1261 // answerCall() will automatically hold the current active
1262 // call, if there is one.
1263 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1264 return;
1265 }
1266 } else {
1267 // No call was ringing.
1268 return;
1269 }
1270 }
1271
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001273 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001275 public void silenceRinger() {
1276 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 }
1278
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001279 @Override
1280 public boolean isOffhook(String callingPackage) {
1281 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001284 @Override
1285 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001287 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 return false;
1289 }
1290
Malcolm Chenaabec062018-02-28 15:00:40 -08001291 final long identity = Binder.clearCallingIdentity();
1292 try {
1293 final Phone phone = getPhone(subId);
1294 if (phone != null) {
1295 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1296 } else {
1297 return false;
1298 }
1299 } finally {
1300 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 }
1303
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001304 @Override
1305 public boolean isRinging(String callingPackage) {
1306 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001307 }
1308
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001309 @Override
1310 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001312 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001313 return false;
1314 }
1315
Malcolm Chenaabec062018-02-28 15:00:40 -08001316 final long identity = Binder.clearCallingIdentity();
1317 try {
1318 final Phone phone = getPhone(subId);
1319 if (phone != null) {
1320 return (phone.getState() == PhoneConstants.State.RINGING);
1321 } else {
1322 return false;
1323 }
1324 } finally {
1325 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 }
1328
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001329 @Override
1330 public boolean isIdle(String callingPackage) {
1331 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001332 }
1333
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001334 @Override
1335 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001337 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001338 return false;
1339 }
1340
Malcolm Chenaabec062018-02-28 15:00:40 -08001341 final long identity = Binder.clearCallingIdentity();
1342 try {
1343 final Phone phone = getPhone(subId);
1344 if (phone != null) {
1345 return (phone.getState() == PhoneConstants.State.IDLE);
1346 } else {
1347 return false;
1348 }
1349 } finally {
1350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001352 }
1353
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001354 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001355 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001356 }
1357
Wink Savilleb564aae2014-10-23 10:18:09 -07001358 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001359 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001360 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1361 }
1362
1363 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001364 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001365 }
1366
Wink Savilleb564aae2014-10-23 10:18:09 -07001367 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001368 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001369 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1370 }
1371
1372 /** {@hide} */
1373 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
1376
Wink Savilleb564aae2014-10-23 10:18:09 -07001377 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001379
1380 final long identity = Binder.clearCallingIdentity();
1381 try {
1382 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1383 checkSimPin.start();
1384 return checkSimPin.unlockSim(null, pin);
1385 } finally {
1386 Binder.restoreCallingIdentity(identity);
1387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388 }
1389
Wink Saville9de0f752013-10-22 19:04:03 -07001390 /** {@hide} */
1391 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001392 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001393 }
1394
Wink Savilleb564aae2014-10-23 10:18:09 -07001395 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001397
1398 final long identity = Binder.clearCallingIdentity();
1399 try {
1400 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1401 checkSimPuk.start();
1402 return checkSimPuk.unlockSim(puk, pin);
1403 } finally {
1404 Binder.restoreCallingIdentity(identity);
1405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 }
1407
1408 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001409 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 * a synchronous one.
1411 */
1412 private static class UnlockSim extends Thread {
1413
1414 private final IccCard mSimCard;
1415
1416 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001417 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1418 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419
1420 // For replies from SimCard interface
1421 private Handler mHandler;
1422
1423 // For async handler to identify request type
1424 private static final int SUPPLY_PIN_COMPLETE = 100;
1425
1426 public UnlockSim(IccCard simCard) {
1427 mSimCard = simCard;
1428 }
1429
1430 @Override
1431 public void run() {
1432 Looper.prepare();
1433 synchronized (UnlockSim.this) {
1434 mHandler = new Handler() {
1435 @Override
1436 public void handleMessage(Message msg) {
1437 AsyncResult ar = (AsyncResult) msg.obj;
1438 switch (msg.what) {
1439 case SUPPLY_PIN_COMPLETE:
1440 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1441 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001442 mRetryCount = msg.arg1;
1443 if (ar.exception != null) {
1444 if (ar.exception instanceof CommandException &&
1445 ((CommandException)(ar.exception)).getCommandError()
1446 == CommandException.Error.PASSWORD_INCORRECT) {
1447 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1448 } else {
1449 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1450 }
1451 } else {
1452 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 mDone = true;
1455 UnlockSim.this.notifyAll();
1456 }
1457 break;
1458 }
1459 }
1460 };
1461 UnlockSim.this.notifyAll();
1462 }
1463 Looper.loop();
1464 }
1465
1466 /*
1467 * Use PIN or PUK to unlock SIM card
1468 *
1469 * If PUK is null, unlock SIM card with PIN
1470 *
1471 * If PUK is not null, unlock SIM card with PUK and set PIN code
1472 */
Wink Saville9de0f752013-10-22 19:04:03 -07001473 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474
1475 while (mHandler == null) {
1476 try {
1477 wait();
1478 } catch (InterruptedException e) {
1479 Thread.currentThread().interrupt();
1480 }
1481 }
1482 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1483
1484 if (puk == null) {
1485 mSimCard.supplyPin(pin, callback);
1486 } else {
1487 mSimCard.supplyPuk(puk, pin, callback);
1488 }
1489
1490 while (!mDone) {
1491 try {
1492 Log.d(LOG_TAG, "wait for done");
1493 wait();
1494 } catch (InterruptedException e) {
1495 // Restore the interrupted status
1496 Thread.currentThread().interrupt();
1497 }
1498 }
1499 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001500 int[] resultArray = new int[2];
1501 resultArray[0] = mResult;
1502 resultArray[1] = mRetryCount;
1503 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 }
1505 }
1506
1507 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001508 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001509
1510 }
1511
Wink Savilleb564aae2014-10-23 10:18:09 -07001512 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513 // No permission check needed here: this call is harmless, and it's
1514 // needed for the ServiceState.requestStateUpdate() call (which is
1515 // already intentionally exposed to 3rd parties.)
Malcolm Chenaabec062018-02-28 15:00:40 -08001516 final long identity = Binder.clearCallingIdentity();
1517 try {
1518 final Phone phone = getPhone(subId);
1519 if (phone != null) {
1520 phone.updateServiceLocation();
1521 }
1522 } finally {
1523 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 }
1526
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001527 @Override
1528 public boolean isRadioOn(String callingPackage) {
1529 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001530 }
1531
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001532 @Override
1533 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001535 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001536 return false;
1537 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001538
1539 final long identity = Binder.clearCallingIdentity();
1540 try {
1541 return isRadioOnForSubscriber(subId);
1542 } finally {
1543 Binder.restoreCallingIdentity(identity);
1544 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001545 }
1546
1547 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001548 final long identity = Binder.clearCallingIdentity();
1549 try {
1550 final Phone phone = getPhone(subId);
1551 if (phone != null) {
1552 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1553 } else {
1554 return false;
1555 }
1556 } finally {
1557 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 }
1560
1561 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001562 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
Wink Saville36469e72014-06-11 15:17:00 -07001564
Wink Savilleb564aae2014-10-23 10:18:09 -07001565 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001567
1568 final long identity = Binder.clearCallingIdentity();
1569 try {
1570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
1572 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1573 }
1574 } finally {
1575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 }
Wink Saville36469e72014-06-11 15:17:00 -07001577 }
1578
1579 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001580 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001581 }
1582
Wink Savilleb564aae2014-10-23 10:18:09 -07001583 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001584 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001585
1586 final long identity = Binder.clearCallingIdentity();
1587 try {
1588 final Phone phone = getPhone(subId);
1589 if (phone == null) {
1590 return false;
1591 }
1592 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1593 toggleRadioOnOffForSubscriber(subId);
1594 }
1595 return true;
1596 } finally {
1597 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
Wink Saville36469e72014-06-11 15:17:00 -07001600
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001601 public boolean needMobileRadioShutdown() {
1602 /*
1603 * If any of the Radios are available, it will need to be
1604 * shutdown. So return true if any Radio is available.
1605 */
Malcolm Chenaabec062018-02-28 15:00:40 -08001606 final long identity = Binder.clearCallingIdentity();
1607 try {
1608 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1609 Phone phone = PhoneFactory.getPhone(i);
1610 if (phone != null && phone.isRadioAvailable()) return true;
1611 }
1612 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1613 return false;
1614 } finally {
1615 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001616 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001617 }
1618
Malcolm Chenaabec062018-02-28 15:00:40 -08001619 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001620 public void shutdownMobileRadios() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001621 enforceModifyPermission();
1622
1623 final long identity = Binder.clearCallingIdentity();
1624 try {
1625 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1626 logv("Shutting down Phone " + i);
1627 shutdownRadioUsingPhoneId(i);
1628 }
1629 } finally {
1630 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001631 }
1632 }
1633
1634 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001635 Phone phone = PhoneFactory.getPhone(phoneId);
1636 if (phone != null && phone.isRadioAvailable()) {
1637 phone.shutdownRadio();
1638 }
1639 }
1640
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001642 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001643
1644 final long identity = Binder.clearCallingIdentity();
1645 try {
1646 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1647 if (defaultPhone != null) {
1648 defaultPhone.setRadioPower(turnOn);
1649 return true;
1650 } else {
1651 loge("There's no default phone.");
1652 return false;
1653 }
1654 } finally {
1655 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001656 }
Wink Saville36469e72014-06-11 15:17:00 -07001657 }
1658
Wink Savilleb564aae2014-10-23 10:18:09 -07001659 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001661
1662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 final Phone phone = getPhone(subId);
1665 if (phone != null) {
1666 phone.setRadioPower(turnOn);
1667 return true;
1668 } else {
1669 return false;
1670 }
1671 } finally {
1672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 }
1675
Wink Saville36469e72014-06-11 15:17:00 -07001676 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 public boolean enableDataConnectivity() {
1679 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001680
1681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 int subId = mSubscriptionController.getDefaultDataSubId();
1684 final Phone phone = getPhone(subId);
1685 if (phone != null) {
1686 phone.setUserDataEnabled(true);
1687 return true;
1688 } else {
1689 return false;
1690 }
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
1695
Wink Saville36469e72014-06-11 15:17:00 -07001696 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 public boolean disableDataConnectivity() {
1699 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001700
1701 final long identity = Binder.clearCallingIdentity();
1702 try {
1703 int subId = mSubscriptionController.getDefaultDataSubId();
1704 final Phone phone = getPhone(subId);
1705 if (phone != null) {
1706 phone.setUserDataEnabled(false);
1707 return true;
1708 } else {
1709 return false;
1710 }
1711 } finally {
1712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 }
1715
Sanket Padawe356d7632015-06-22 14:03:32 -07001716 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001717 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 final Phone phone = getPhone(subId);
1721 if (phone != null) {
1722 return phone.isDataAllowed();
1723 } else {
1724 return false;
1725 }
1726 } finally {
1727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 }
1730
1731 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001732 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001733 }
1734
pkanwarae03a6b2016-11-06 20:37:09 -08001735 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001736 enforceCallPermission();
1737
1738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1741 return;
1742 }
1743 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1744 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1745 } finally {
1746 Binder.restoreCallingIdentity(identity);
1747 }
pkanwar32d516d2016-10-14 19:37:38 -07001748 };
1749
Wink Savilleb564aae2014-10-23 10:18:09 -07001750 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08001752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1756 return false;
1757 }
1758 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1759 } finally {
1760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001765 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001768 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08001769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 Phone phone = PhoneFactory.getPhone(slotIndex);
1772 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1773 PhoneConstantConversions.convertCallState(phone.getState());
1774 } finally {
1775 Binder.restoreCallingIdentity(identity);
1776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
1778
Sanket Padawe356d7632015-06-22 14:03:32 -07001779 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 public int getDataState() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001781 final long identity = Binder.clearCallingIdentity();
1782 try {
1783 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1784 if (phone != null) {
1785 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1786 } else {
1787 return PhoneConstantConversions.convertDataState(
1788 PhoneConstants.DataState.DISCONNECTED);
1789 }
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
Sanket Padawe356d7632015-06-22 14:03:32 -07001795 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 public int getDataActivity() {
Malcolm Chenaabec062018-02-28 15:00:40 -08001797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1800 if (phone != null) {
1801 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1802 } else {
1803 return TelephonyManager.DATA_ACTIVITY_NONE;
1804 }
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
1810 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001811 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001812 mPhone.getContext().getSystemService(AppOpsManager.class)
1813 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001814 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov748b5752018-03-07 19:57:05 -08001815 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001816 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 }
1818
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00001819 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 if (DBG_LOC) log("getCellLocation: is active user");
1823 Bundle data = new Bundle();
1824 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1825 if (phone == null) {
1826 return null;
1827 }
1828
1829 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1830 return data;
1831 } finally {
1832 Binder.restoreCallingIdentity(identity);
1833 }
Svetoslav64fad262015-04-14 14:35:21 -07001834 }
1835
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001837 public String getNetworkCountryIsoForPhone(int phoneId) {
1838 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1839 // registered cell info, so return a NULL country instead.
1840 final long identity = Binder.clearCallingIdentity();
1841 try {
1842 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu8e4fdc22018-04-13 14:05:37 -07001843 // Todo: fix this when we can get the actual cellular network info when the device
1844 // is on IWLAN.
Jonathan Basseri03923952017-07-19 12:22:35 -07001845 if (TelephonyManager.NETWORK_TYPE_IWLAN
1846 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1847 return "";
1848 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001849 Phone phone = PhoneFactory.getPhone(phoneId);
1850 if (phone != null) {
1851 ServiceStateTracker sst = phone.getServiceStateTracker();
1852 if (sst != null) {
1853 LocaleTracker lt = sst.getLocaleTracker();
1854 if (lt != null) {
1855 return lt.getCurrentCountry();
1856 }
1857 }
1858 }
1859 return "";
Jonathan Basseri03923952017-07-19 12:22:35 -07001860 } finally {
1861 Binder.restoreCallingIdentity(identity);
1862 }
Jonathan Basseri03923952017-07-19 12:22:35 -07001863 }
1864
1865 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001867 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001868 }
1869
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001871 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 mApp.enforceCallingOrSelfPermission(
1873 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001874
1875 final long identity = Binder.clearCallingIdentity();
1876 try {
1877 final Phone phone = getPhone(subId);
1878 if (phone != null) {
1879 phone.enableLocationUpdates();
1880 }
1881 } finally {
1882 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
1886 @Override
1887 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001888 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001889 }
1890
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001892 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 mApp.enforceCallingOrSelfPermission(
1894 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaabec062018-02-28 15:00:40 -08001895
1896 final long identity = Binder.clearCallingIdentity();
1897 try {
1898 final Phone phone = getPhone(subId);
1899 if (phone != null) {
1900 phone.disableLocationUpdates();
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
1907 @Override
1908 @SuppressWarnings("unchecked")
Nathan Haroldb4d55612018-07-20 13:13:08 -07001909 public List<NeighboringCellInfo>
1910 getNeighboringCellInfo(String callingPackage, int targetSdk) {
1911 // FIXME: use the P constant when available
1912 if (targetSdk > android.os.Build.VERSION_CODES.O_MR1 + 1) return null;
1913
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1915 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1916 return null;
1917 }
Svetoslav64fad262015-04-14 14:35:21 -07001918
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001919 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920
Nathan Haroldf180aac2018-06-01 18:43:55 -07001921 List<CellInfo> info = getAllCellInfo(callingPackage);
1922 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923
Nathan Haroldf180aac2018-06-01 18:43:55 -07001924 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1925 for (CellInfo ci : info) {
1926 if (ci instanceof CellInfoGsm) {
1927 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1928 } else if (ci instanceof CellInfoWcdma) {
1929 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001932 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 }
1934
1935
1936 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001937 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001938 mPhone.getContext().getSystemService(AppOpsManager.class)
1939 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001940 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov748b5752018-03-07 19:57:05 -08001941 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001942 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001945 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00001946 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001947 final long identity = Binder.clearCallingIdentity();
1948 try {
1949 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1950 for (Phone phone : PhoneFactory.getPhones()) {
1951 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1952 if (info != null) cellInfos.addAll(info);
1953 }
1954 return cellInfos;
1955 } finally {
1956 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 }
1958 }
1959
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001960 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001962 enforceModifyPermission();
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00001963 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaabec062018-02-28 15:00:40 -08001964
1965 final long identity = Binder.clearCallingIdentity();
1966 try {
1967 mPhone.setCellInfoListRate(rateInMillis, workSource);
1968 } finally {
1969 Binder.restoreCallingIdentity(identity);
1970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 }
1972
Shishir Agrawala9f32182016-04-12 12:00:16 -07001973 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001974 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001975 Phone phone = PhoneFactory.getPhone(slotIndex);
1976 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001977 return null;
1978 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001979 int subId = phone.getSubId();
1980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1981 mApp, subId, callingPackage, "getImeiForSlot")) {
1982 return null;
1983 }
Malcolm Chenaabec062018-02-28 15:00:40 -08001984
1985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 return phone.getImei();
1988 } finally {
1989 Binder.restoreCallingIdentity(identity);
1990 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07001991 }
1992
1993 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001994 public String getTypeAllocationCodeForSlot(int slotIndex) {
1995 Phone phone = PhoneFactory.getPhone(slotIndex);
1996 String tac = null;
1997 if (phone != null) {
1998 String imei = phone.getImei();
1999 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2000 }
2001 return tac;
2002 }
2003
2004 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002005 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002006 Phone phone = PhoneFactory.getPhone(slotIndex);
2007 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002008 return null;
2009 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002010 int subId = phone.getSubId();
2011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2012 mApp, subId, callingPackage, "getMeidForSlot")) {
2013 return null;
2014 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002015
2016 final long identity = Binder.clearCallingIdentity();
2017 try {
2018 return phone.getMeid();
2019 } finally {
2020 Binder.restoreCallingIdentity(identity);
2021 }
Jack Yu2af8d712017-03-15 17:14:14 -07002022 }
2023
2024 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002025 public String getManufacturerCodeForSlot(int slotIndex) {
2026 Phone phone = PhoneFactory.getPhone(slotIndex);
2027 String manufacturerCode = null;
2028 if (phone != null) {
2029 String meid = phone.getMeid();
2030 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2031 }
2032 return manufacturerCode;
2033 }
2034
2035 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002036 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002037 Phone phone = PhoneFactory.getPhone(slotIndex);
2038 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002039 return null;
2040 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002041 int subId = phone.getSubId();
2042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2043 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2044 return null;
2045 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002046
2047 final long identity = Binder.clearCallingIdentity();
2048 try {
2049 return phone.getDeviceSvn();
2050 } finally {
2051 Binder.restoreCallingIdentity(identity);
2052 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002053 }
2054
fionaxuf32acdf2017-11-27 22:51:16 -08002055 @Override
2056 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002057 final long identity = Binder.clearCallingIdentity();
2058 try {
2059 final Phone phone = getPhone(subId);
2060 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2061 } finally {
2062 Binder.restoreCallingIdentity(identity);
2063 }
fionaxuf32acdf2017-11-27 22:51:16 -08002064 }
2065
2066 @Override
2067 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002068 final long identity = Binder.clearCallingIdentity();
2069 try {
2070 final Phone phone = getPhone(subId);
2071 return phone == null ? null : phone.getCarrierName();
2072 } finally {
2073 Binder.restoreCallingIdentity(identity);
2074 }
fionaxuf32acdf2017-11-27 22:51:16 -08002075 }
2076
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 //
2078 // Internal helper methods.
2079 //
2080
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002081 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2083 *
2084 * @throws SecurityException if the caller does not have the required permission
2085 */
2086 private void enforceModifyPermission() {
2087 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2088 }
2089
2090 /**
2091 * Make sure the caller has the CALL_PHONE permission.
2092 *
2093 * @throws SecurityException if the caller does not have the required permission
2094 */
2095 private void enforceCallPermission() {
2096 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2097 }
2098
Stuart Scott8eef64f2015-04-08 15:13:54 -07002099 private void enforceConnectivityInternalPermission() {
2100 mApp.enforceCallingOrSelfPermission(
2101 android.Manifest.permission.CONNECTIVITY_INTERNAL,
2102 "ConnectivityService");
2103 }
2104
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 private String createTelUrl(String number) {
2106 if (TextUtils.isEmpty(number)) {
2107 return null;
2108 }
2109
Jake Hambye994d462014-02-03 13:10:13 -08002110 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 }
2112
Ihab Awadf9e92732013-12-05 18:02:52 -08002113 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2115 }
2116
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002117 private static void logv(String msg) {
2118 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2119 }
2120
Ihab Awadf9e92732013-12-05 18:02:52 -08002121 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2123 }
2124
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002125 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002127 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002128 }
2129
Sanket Padawe356d7632015-06-22 14:03:32 -07002130 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002131 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 final Phone phone = PhoneFactory.getPhone(slotIndex);
2135 if (phone == null) {
2136 return PhoneConstants.PHONE_TYPE_NONE;
2137 } else {
2138 return phone.getPhoneType();
2139 }
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 }
2144
2145 /**
2146 * Returns the CDMA ERI icon index to display
2147 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002148 @Override
2149 public int getCdmaEriIconIndex(String callingPackage) {
2150 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002151 }
2152
Sanket Padawe356d7632015-06-22 14:03:32 -07002153 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002154 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002155 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002156 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002157 return -1;
2158 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002159
2160 final long identity = Binder.clearCallingIdentity();
2161 try {
2162 final Phone phone = getPhone(subId);
2163 if (phone != null) {
2164 return phone.getCdmaEriIconIndex();
2165 } else {
2166 return -1;
2167 }
2168 } finally {
2169 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002170 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 }
2172
2173 /**
2174 * Returns the CDMA ERI icon mode,
2175 * 0 - ON
2176 * 1 - FLASHING
2177 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002178 @Override
2179 public int getCdmaEriIconMode(String callingPackage) {
2180 return getCdmaEriIconModeForSubscriber(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 getCdmaEriIconModeForSubscriber(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, "getCdmaEriIconModeForSubscriber")) {
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.getCdmaEriIconMode();
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 text,
2205 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002206 @Override
2207 public String getCdmaEriText(String callingPackage) {
2208 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002209 }
2210
Sanket Padawe356d7632015-06-22 14:03:32 -07002211 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002212 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002213 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002214 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002215 return null;
2216 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002217
2218 final long identity = Binder.clearCallingIdentity();
2219 try {
2220 final Phone phone = getPhone(subId);
2221 if (phone != null) {
2222 return phone.getCdmaEriText();
2223 } else {
2224 return null;
2225 }
2226 } finally {
2227 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 }
2230
2231 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002232 * Returns the CDMA MDN.
2233 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002235 public String getCdmaMdn(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2237 mApp, subId, "getCdmaMdn");
Malcolm Chenaabec062018-02-28 15:00:40 -08002238
2239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 final Phone phone = getPhone(subId);
2242 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2243 return phone.getLine1Number();
2244 } else {
2245 return null;
2246 }
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002249 }
2250 }
2251
2252 /**
2253 * Returns the CDMA MIN.
2254 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002255 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002256 public String getCdmaMin(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2258 mApp, subId, "getCdmaMin");
Malcolm Chenaabec062018-02-28 15:00:40 -08002259
2260 final long identity = Binder.clearCallingIdentity();
2261 try {
2262 final Phone phone = getPhone(subId);
2263 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2264 return phone.getCdmaMin();
2265 } else {
2266 return null;
2267 }
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002270 }
2271 }
2272
2273 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 * Returns true if CDMA provisioning needs to run.
2275 */
2276 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002277 final long identity = Binder.clearCallingIdentity();
2278 try {
2279 return mPhone.needsOtaServiceProvisioning();
2280 } finally {
2281 Binder.restoreCallingIdentity(identity);
2282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 }
2284
2285 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002286 * Sets the voice mail number of a given subId.
2287 */
2288 @Override
2289 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002290 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaabec062018-02-28 15:00:40 -08002291
2292 final long identity = Binder.clearCallingIdentity();
2293 try {
2294 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2295 new Pair<String, String>(alphaTag, number), new Integer(subId));
2296 return success;
2297 } finally {
2298 Binder.restoreCallingIdentity(identity);
2299 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002300 }
2301
Ta-wei Yen87c49842016-05-13 21:19:52 -07002302 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002303 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2304 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2305 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2306 if (!TextUtils.equals(callingPackage, systemDialer)) {
2307 throw new SecurityException("caller must be system dialer");
2308 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002309
2310 final long identity = Binder.clearCallingIdentity();
2311 try {
2312 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2313 if (phoneAccountHandle == null) {
2314 return null;
2315 }
2316 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2317 } finally {
2318 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002319 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002320 }
2321
2322 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002323 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002324 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002326 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002327 return null;
2328 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002329
Jeff Davidson87b3c102018-03-15 17:16:18 -07002330 final long identity = Binder.clearCallingIdentity();
2331 try {
2332 return RemoteVvmTaskManager
2333 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2334 } finally {
2335 Binder.restoreCallingIdentity(identity);
2336 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002337 }
2338
2339 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002340 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2341 VisualVoicemailSmsFilterSettings settings) {
2342 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002343
2344 final long identity = Binder.clearCallingIdentity();
2345 try {
2346 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
2347 mPhone.getContext(), callingPackage, subId, settings);
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
2350 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002351 }
2352
2353 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002354 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
2360 mPhone.getContext(), callingPackage, subId);
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
2363 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002364 }
2365
2366 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002367 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2368 String callingPackage, int subId) {
2369 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaabec062018-02-28 15:00:40 -08002370
2371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
2374 mPhone.getContext(), callingPackage, subId);
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
2377 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002378 }
2379
2380 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002381 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002382 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002383
2384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
2387 mPhone.getContext(), subId);
2388 } finally {
2389 Binder.restoreCallingIdentity(identity);
2390 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002391 }
2392
2393 @Override
2394 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2395 String number, int port, String text, PendingIntent sentIntent) {
2396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002397 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002398 enforceSendSmsPermission();
2399 // Make the calls as the phone process.
2400 final long identity = Binder.clearCallingIdentity();
2401 try {
2402 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2403 if (port == 0) {
2404 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2405 sentIntent, null, false);
2406 } else {
2407 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2408 smsManager.sendDataMessageWithSelfPermissions(number, null,
2409 (short) port, data, sentIntent, null);
2410 }
2411 } finally {
2412 Binder.restoreCallingIdentity(identity);
2413 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002414 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002415 /**
fionaxu0152e512016-11-14 13:36:14 -08002416 * Sets the voice activation state of a given subId.
2417 */
2418 @Override
2419 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2421 mApp, subId, "setVoiceActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002422
2423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 final Phone phone = getPhone(subId);
2426 if (phone != null) {
2427 phone.setVoiceActivationState(activationState);
2428 } else {
2429 loge("setVoiceActivationState fails with invalid subId: " + subId);
2430 }
2431 } finally {
2432 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002433 }
2434 }
2435
2436 /**
2437 * Sets the data activation state of a given subId.
2438 */
2439 @Override
2440 public void setDataActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2442 mApp, subId, "setDataActivationState");
Malcolm Chenaabec062018-02-28 15:00:40 -08002443
2444 final long identity = Binder.clearCallingIdentity();
2445 try {
2446 final Phone phone = getPhone(subId);
2447 if (phone != null) {
2448 phone.setDataActivationState(activationState);
2449 } else {
2450 loge("setVoiceActivationState fails with invalid subId: " + subId);
2451 }
2452 } finally {
2453 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002454 }
2455 }
2456
2457 /**
2458 * Returns the voice activation state of a given subId.
2459 */
2460 @Override
2461 public int getVoiceActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002462 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002463
fionaxu0152e512016-11-14 13:36:14 -08002464 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 if (phone != null) {
2468 return phone.getVoiceActivationState();
2469 } else {
2470 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2471 }
2472 } finally {
2473 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002474 }
2475 }
2476
2477 /**
2478 * Returns the data activation state of a given subId.
2479 */
2480 @Override
2481 public int getDataActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002482 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08002483
fionaxu0152e512016-11-14 13:36:14 -08002484 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08002485 final long identity = Binder.clearCallingIdentity();
2486 try {
2487 if (phone != null) {
2488 return phone.getDataActivationState();
2489 } else {
2490 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2491 }
2492 } finally {
2493 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002494 }
2495 }
2496
2497 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 * Returns the unread count of voicemails
2499 */
2500 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002501 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002502 }
2503
2504 /**
2505 * Returns the unread count of voicemails for a subId
2506 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002507 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002508 public int getVoiceMessageCountForSubscriber( int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 final Phone phone = getPhone(subId);
2512 if (phone != null) {
2513 return phone.getVoiceMessageCount();
2514 } else {
2515 return 0;
2516 }
2517 } finally {
2518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 }
2521
2522 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002523 * returns true, if the device is in a state where both voice and data
2524 * are supported simultaneously. This can change based on location or network condition.
2525 */
2526 @Override
2527 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 final Phone phone = getPhone(subId);
2531 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2532 } finally {
2533 Binder.restoreCallingIdentity(identity);
2534 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002535 }
2536
2537 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002538 * Send the dialer code if called from the current default dialer or the caller has
2539 * carrier privilege.
2540 * @param inputCode The dialer code to send
2541 */
2542 @Override
2543 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2544 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2545 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2546 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002547 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2548 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002549 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002550
2551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 mPhone.sendDialerSpecialCode(inputCode);
2554 } finally {
2555 Binder.restoreCallingIdentity(identity);
2556 }
fionaxu235cc5e2017-03-06 22:25:57 -08002557 }
2558
2559 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002560 * Returns the data network type.
2561 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 *
2563 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2564 */
2565 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002566 public int getNetworkType() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 final Phone phone = getPhone(getDefaultSubscription());
2570 if (phone != null) {
2571 return phone.getServiceState().getDataNetworkType();
2572 } else {
2573 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2574 }
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002577 }
Wink Saville36469e72014-06-11 15:17:00 -07002578 }
2579
2580 /**
2581 * Returns the network type for a subId
2582 */
2583 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002584 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002586 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002587 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2588 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002589
Malcolm Chenaabec062018-02-28 15:00:40 -08002590 final long identity = Binder.clearCallingIdentity();
2591 try {
2592 final Phone phone = getPhone(subId);
2593 if (phone != null) {
2594 return phone.getServiceState().getDataNetworkType();
2595 } else {
2596 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2597 }
2598 } finally {
2599 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 }
2602
2603 /**
2604 * Returns the data network type
2605 */
2606 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002607 public int getDataNetworkType(String callingPackage) {
2608 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002609 }
2610
2611 /**
2612 * Returns the data network type for a subId
2613 */
2614 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002615 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002617 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002618 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2619 }
2620
Malcolm Chenaabec062018-02-28 15:00:40 -08002621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 final Phone phone = getPhone(subId);
2624 if (phone != null) {
2625 return phone.getServiceState().getDataNetworkType();
2626 } else {
2627 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2628 }
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 }
2633
2634 /**
Wink Saville36469e72014-06-11 15:17:00 -07002635 * Returns the Voice network type for a subId
2636 */
2637 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002638 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002640 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002641 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2642 }
2643
Malcolm Chenaabec062018-02-28 15:00:40 -08002644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
2647 if (phone != null) {
2648 return phone.getServiceState().getVoiceNetworkType();
2649 } else {
2650 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 }
2656
2657 /**
2658 * @return true if a ICC card is present
2659 */
2660 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002661 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002662 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2663 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002664 }
2665
2666 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002667 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002668 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002669 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002670 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002671 final long identity = Binder.clearCallingIdentity();
2672 try {
2673 final Phone phone = PhoneFactory.getPhone(slotIndex);
2674 if (phone != null) {
2675 return phone.getIccCard().hasIccCard();
2676 } else {
2677 return false;
2678 }
2679 } finally {
2680 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002681 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
2683
2684 /**
2685 * Return if the current radio is LTE on CDMA. This
2686 * is a tri-state return value as for a period of time
2687 * the mode may be unknown.
2688 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002689 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002691 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002693 @Override
2694 public int getLteOnCdmaMode(String callingPackage) {
2695 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002696 }
2697
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002699 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002701 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002702 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2703 }
2704
Malcolm Chenaabec062018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 final Phone phone = getPhone(subId);
2708 if (phone == null) {
2709 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2710 } else {
2711 return phone.getLteOnCdmaMode();
2712 }
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 }
Wink Saville36469e72014-06-11 15:17:00 -07002716 }
2717
2718 public void setPhone(Phone phone) {
2719 mPhone = phone;
2720 }
2721
2722 /**
2723 * {@hide}
2724 * Returns Default subId, 0 in the case of single standby.
2725 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002726 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002727 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002728 }
2729
Shishir Agrawala9f32182016-04-12 12:00:16 -07002730 private int getSlotForDefaultSubscription() {
2731 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2732 }
2733
Wink Savilleb564aae2014-10-23 10:18:09 -07002734 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002735 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002737
2738 /**
2739 * @see android.telephony.TelephonyManager.WifiCallingChoices
2740 */
2741 public int getWhenToMakeWifiCalls() {
Malcolm Chenaabec062018-02-28 15:00:40 -08002742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2745 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
2746 getWhenToMakeWifiCallsDefaultPreference());
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
2749 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002750 }
2751
2752 /**
2753 * @see android.telephony.TelephonyManager.WifiCallingChoices
2754 */
2755 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaabec062018-02-28 15:00:40 -08002756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2759 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2760 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
2761 } finally {
2762 Binder.restoreCallingIdentity(identity);
2763 }
Ihab Awadf9e92732013-12-05 18:02:52 -08002764 }
2765
Sailesh Nepald1e68152013-12-12 19:08:02 -08002766 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002767 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002768 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002769 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002770
Shishir Agrawal566b7612013-10-28 14:41:00 -07002771 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002772 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2773 int subId, String callingPackage, String aid, int p2) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2775 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002777
Malcolm Chenaabec062018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 if (TextUtils.equals(ISDR_AID, aid)) {
2781 // Only allows LPA to open logical channel to ISD-R.
2782 ComponentInfo bestComponent =
2783 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2784 if (bestComponent == null
2785 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2786 loge("The calling package is not allowed to access ISD-R.");
2787 throw new SecurityException(
2788 "The calling package is not allowed to access ISD-R.");
2789 }
Derek Tan740e1672017-06-27 14:56:27 -07002790 }
Derek Tan740e1672017-06-27 14:56:27 -07002791
Malcolm Chenaabec062018-02-28 15:00:40 -08002792 if (DBG) {
2793 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
2794 }
2795 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
2796 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
2797 if (DBG) log("iccOpenLogicalChannel: " + response);
2798 return response;
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002802 }
2803
2804 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002805 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2807 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002808
Malcolm Chenaabec062018-02-28 15:00:40 -08002809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
2812 if (channel < 0) {
2813 return false;
2814 }
2815 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
2816 if (DBG) log("iccCloseLogicalChannel: " + success);
2817 return success;
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002820 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002821 }
2822
2823 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002824 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002825 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2827 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002828
Malcolm Chenaabec062018-02-28 15:00:40 -08002829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 if (DBG) {
2832 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
2833 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
2834 + p3 + " data=" + data);
2835 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002836
Malcolm Chenaabec062018-02-28 15:00:40 -08002837 if (channel < 0) {
2838 return "";
2839 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002840
Malcolm Chenaabec062018-02-28 15:00:40 -08002841 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
2842 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
2843 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002844
Malcolm Chenaabec062018-02-28 15:00:40 -08002845 // Append the returned status code to the end of the response payload.
2846 String s = Integer.toHexString(
2847 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2848 if (response.payload != null) {
2849 s = IccUtils.bytesToHexString(response.payload) + s;
2850 }
2851 return s;
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002854 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002855 }
Jake Hambye994d462014-02-03 13:10:13 -08002856
Evan Charltonc66da362014-05-16 14:06:40 -07002857 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002858 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2859 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2861 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaabec062018-02-28 15:00:40 -08002862 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002863
Malcolm Chenaabec062018-02-28 15:00:40 -08002864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2867 && TextUtils.equals(ISDR_AID, data)) {
2868 // Only allows LPA to select ISD-R.
2869 ComponentInfo bestComponent =
2870 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2871 if (bestComponent == null
2872 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2873 loge("The calling package is not allowed to select ISD-R.");
2874 throw new SecurityException(
2875 "The calling package is not allowed to select ISD-R.");
2876 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002877 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002878
Malcolm Chenaabec062018-02-28 15:00:40 -08002879 if (DBG) {
2880 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
2881 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
2882 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002883
Malcolm Chenaabec062018-02-28 15:00:40 -08002884 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
2885 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
2886 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002887
Malcolm Chenaabec062018-02-28 15:00:40 -08002888 // Append the returned status code to the end of the response payload.
2889 String s = Integer.toHexString(
2890 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2891 if (response.payload != null) {
2892 s = IccUtils.bytesToHexString(response.payload) + s;
2893 }
2894 return s;
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002897 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002898 }
2899
2900 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002901 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002902 String filePath) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2904 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002905
Malcolm Chenaabec062018-02-28 15:00:40 -08002906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 if (DBG) {
2909 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
2910 + p1 + " " + p2 + " " + p3 + ":" + filePath);
2911 }
2912
2913 IccIoResult response =
2914 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
2915 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2916 subId);
2917
2918 if (DBG) {
2919 log("Exchange SIM_IO [R]" + response);
2920 }
2921
2922 byte[] result = null;
2923 int length = 2;
2924 if (response.payload != null) {
2925 length = 2 + response.payload.length;
2926 result = new byte[length];
2927 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2928 } else {
2929 result = new byte[length];
2930 }
2931
2932 result[length - 1] = (byte) response.sw2;
2933 result[length - 2] = (byte) response.sw1;
2934 return result;
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002937 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002938 }
2939
Nathan Haroldb3014052017-01-25 15:57:32 -08002940 /**
2941 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2942 * on a particular subscription
2943 */
2944 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002945 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002946 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2947 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002948 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2949 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2950 return null;
2951 }
Malcolm Chenaabec062018-02-28 15:00:40 -08002952
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 Object response = sendRequest(CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2956 if (response instanceof String[]) {
2957 return (String[]) response;
2958 }
2959 // Response is an Exception of some kind,
2960 // which is signalled to the user as a NULL retval
2961 return null;
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08002964 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002965 }
2966
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002967 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002968 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002969 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2970 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002971
Malcolm Chenaabec062018-02-28 15:00:40 -08002972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
2975 if (response.payload == null) {
2976 return "";
2977 }
Evan Charltonc66da362014-05-16 14:06:40 -07002978
Malcolm Chenaabec062018-02-28 15:00:40 -08002979 // Append the returned status code to the end of the response payload.
2980 String s = Integer.toHexString(
2981 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2982 s = IccUtils.bytesToHexString(response.payload) + s;
2983 return s;
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
Evan Charltonc66da362014-05-16 14:06:40 -07002987 }
2988
Jake Hambye994d462014-02-03 13:10:13 -08002989 /**
2990 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2991 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2992 *
2993 * @param itemID the ID of the item to read
2994 * @return the NV item as a String, or null on error.
2995 */
2996 @Override
2997 public String nvReadItem(int itemID) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2999 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003000
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 if (DBG) log("nvReadItem: item " + itemID);
3004 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
3005 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3006 return value;
3007 } finally {
3008 Binder.restoreCallingIdentity(identity);
3009 }
Jake Hambye994d462014-02-03 13:10:13 -08003010 }
3011
3012 /**
3013 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3014 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3015 *
3016 * @param itemID the ID of the item to read
3017 * @param itemValue the value to write, as a String
3018 * @return true on success; false on any failure
3019 */
3020 @Override
3021 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3023 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaabec062018-02-28 15:00:40 -08003024
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3028 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
3029 new Pair<Integer, String>(itemID, itemValue));
3030 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3031 return success;
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
Jake Hambye994d462014-02-03 13:10:13 -08003035 }
3036
3037 /**
3038 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3039 * Used for device configuration by some CDMA operators.
3040 *
3041 * @param preferredRoamingList byte array containing the new PRL
3042 * @return true on success; false on any failure
3043 */
3044 @Override
3045 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3047 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaabec062018-02-28 15:00:40 -08003048
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3052 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3053 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3054 return success;
3055 } finally {
3056 Binder.restoreCallingIdentity(identity);
3057 }
Jake Hambye994d462014-02-03 13:10:13 -08003058 }
3059
3060 /**
3061 * Perform the specified type of NV config reset.
3062 * Used for device configuration by some CDMA operators.
3063 *
3064 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
3065 * @return true on success; false on any failure
3066 */
3067 @Override
3068 public boolean nvResetConfig(int resetType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3070 mApp, getDefaultSubscription(), "nvResetConfig");
Malcolm Chenaabec062018-02-28 15:00:40 -08003071
3072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 if (DBG) log("nvResetConfig: type " + resetType);
3075 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
3076 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
3077 return success;
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
Jake Hambye994d462014-02-03 13:10:13 -08003081 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003082
Svet Ganovb320e182015-04-16 12:30:10 -07003083 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003085 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003086 return new String[0];
3087 }
3088
Malcolm Chenaabec062018-02-28 15:00:40 -08003089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 return mPhone.getPcscfAddress(apnType);
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
Wink Saville36469e72014-06-11 15:17:00 -07003095 }
3096
Brad Ebinger51f743a2017-01-23 13:50:20 -08003097 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08003098 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
3099 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08003100 */
Brad Ebingera12246d2018-01-16 09:39:35 -08003101 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08003102 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003103
3104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 PhoneFactory.getImsResolver().enableIms(slotId);
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003110 }
3111
3112 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08003113 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
3114 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08003115 */
Brad Ebingera12246d2018-01-16 09:39:35 -08003116 public void disableIms(int slotId) {
3117 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003118
3119 final long identity = Binder.clearCallingIdentity();
3120 try {
3121 PhoneFactory.getImsResolver().disableIms(slotId);
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
Brad Ebingera12246d2018-01-16 09:39:35 -08003125 }
3126
3127 /**
3128 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
3129 * feature or {@link null} if the service is not available. If the feature is available, the
3130 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
3131 */
3132 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08003133 IImsServiceFeatureCallback callback) {
3134 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003135
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
3141 }
Brad Ebinger34bef922017-11-09 10:27:08 -08003142 }
3143
3144 /**
3145 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
3146 * feature during emergency calling or {@link null} if the service is not available. If the
3147 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
3148 * listener for feature updates.
3149 */
3150 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
3151 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003152
3153 final long identity = Binder.clearCallingIdentity();
3154 try {
3155 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
3156 } finally {
3157 Binder.restoreCallingIdentity(identity);
3158 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08003159 }
3160
Brad Ebinger7e934f52017-12-14 14:26:15 -08003161 /**
3162 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
3163 * specified.
3164 */
3165 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
3166 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003167
3168 final long identity = Binder.clearCallingIdentity();
3169 try {
3170 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
3171 } finally {
3172 Binder.restoreCallingIdentity(identity);
3173 }
Brad Ebinger7e934f52017-12-14 14:26:15 -08003174 }
3175
Brad Ebingera12246d2018-01-16 09:39:35 -08003176 /**
3177 * Returns the {@link IImsConfig} structure associated with the slotId and feature
3178 * specified.
3179 */
3180 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
3181 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003182
3183 final long identity = Binder.clearCallingIdentity();
3184 try {
3185 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
Brad Ebingera12246d2018-01-16 09:39:35 -08003189 }
3190
Brad Ebinger884c07b2018-02-15 16:17:40 -08003191 /**
Brad Ebinger67801702018-03-02 13:43:36 -08003192 * @return true if the IMS resolver is busy resolving a binding and should not be considered
3193 * available, false if the IMS resolver is idle.
3194 */
3195 public boolean isResolvingImsBinding() {
3196 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003197
3198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 return PhoneFactory.getImsResolver().isResolvingBinding();
3201 } finally {
3202 Binder.restoreCallingIdentity(identity);
3203 }
Brad Ebinger67801702018-03-02 13:43:36 -08003204 }
3205
Brad Ebinger4dc095a2018-04-03 15:17:52 -07003206 /**
3207 * Sets the ImsService Package Name that Telephony will bind to.
3208 *
3209 * @param slotId the slot ID that the ImsService should bind for.
3210 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
3211 * ImsService is the device default ImsService.
3212 * @param packageName The package name of the application that contains the ImsService to bind
3213 * to.
3214 * @return true if setting the ImsService to bind to succeeded, false if it did not.
3215 * @hide
3216 */
3217 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingera6377d92018-04-06 09:56:40 -07003218 int[] subIds = SubscriptionManager.getSubId(slotId);
3219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3220 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3221 "setImsService");
3222
Malcolm Chenaabec062018-02-28 15:00:40 -08003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
3226 isCarrierImsService, packageName);
3227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
Brad Ebinger4dc095a2018-04-03 15:17:52 -07003230 }
3231
3232 /**
3233 * Return the ImsService configuration.
3234 *
3235 * @param slotId The slot that the ImsService is associated with.
3236 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
3237 * the device default.
3238 * @return the package name of the ImsService configuration.
3239 */
3240 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingera6377d92018-04-06 09:56:40 -07003241 int[] subIds = SubscriptionManager.getSubId(slotId);
3242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
3243 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
3244 "getImsService");
3245
Malcolm Chenaabec062018-02-28 15:00:40 -08003246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
3249 isCarrierImsService);
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
3252 }
Brad Ebinger4dc095a2018-04-03 15:17:52 -07003253 }
3254
Wink Saville36469e72014-06-11 15:17:00 -07003255 public void setImsRegistrationState(boolean registered) {
3256 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003257
3258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 mPhone.setImsRegistrationState(registered);
3261 } finally {
3262 Binder.restoreCallingIdentity(identity);
3263 }
Wink Saville36469e72014-06-11 15:17:00 -07003264 }
3265
3266 /**
Stuart Scott54788802015-03-30 13:18:01 -07003267 * Set the network selection mode to automatic.
3268 *
3269 */
3270 @Override
3271 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3273 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaabec062018-02-28 15:00:40 -08003274
3275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
3278 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
3281 }
Stuart Scott54788802015-03-30 13:18:01 -07003282 }
3283
3284 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07003285 * Set the network selection mode to manual with the selected carrier.
3286 */
3287 @Override
yinxu6e5abd72017-12-01 11:35:19 -08003288 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07003289 boolean persistSelection) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3291 mApp, subId, "setNetworkSelectionModeManual");
Malcolm Chenaabec062018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 OperatorInfo operator = new OperatorInfo(
yinxu6e5abd72017-12-01 11:35:19 -08003296 /* operatorAlphaLong */ "",
3297 /* operatorAlphaShort */ "",
Malcolm Chenaabec062018-02-28 15:00:40 -08003298 operatorNumeric);
3299 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
3300 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
3301 persistSelection);
3302 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003306 }
3307
3308 /**
3309 * Scans for available networks.
3310 */
3311 @Override
3312 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3314 mApp, subId, "getCellNetworkScanResults");
Malcolm Chenaabec062018-02-28 15:00:40 -08003315
3316 final long identity = Binder.clearCallingIdentity();
3317 try {
3318 if (DBG) log("getCellNetworkScanResults: subId " + subId);
3319 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
3320 CMD_PERFORM_NETWORK_SCAN, null, subId);
3321 return result;
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07003325 }
3326
3327 /**
yinxub1bed742017-04-17 11:45:04 -07003328 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07003329 *
yinxub1bed742017-04-17 11:45:04 -07003330 * @param subId id of the subscription
3331 * @param request contains the radio access networks with bands/channels to scan
3332 * @param messenger callback messenger for scan results or errors
3333 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07003334 * @return the id of the requested scan which can be used to stop the scan.
3335 */
3336 @Override
3337 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
3338 IBinder binder) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3340 mApp, subId, "requestNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003341
3342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 return mNetworkScanRequestTracker.startNetworkScan(
3345 request, messenger, binder, getPhone(subId));
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
yinxu504e1392017-04-12 16:03:22 -07003349 }
3350
3351 /**
3352 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07003353 *
3354 * @param subId id of the subscription
3355 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07003356 */
3357 @Override
3358 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3360 mApp, subId, "stopNetworkScan");
Malcolm Chenaabec062018-02-28 15:00:40 -08003361
3362 final long identity = Binder.clearCallingIdentity();
3363 try {
3364 mNetworkScanRequestTracker.stopNetworkScan(scanId);
3365 } finally {
3366 Binder.restoreCallingIdentity(identity);
3367 }
yinxu504e1392017-04-12 16:03:22 -07003368 }
3369
3370 /**
Junda Liu84d15a22014-07-02 11:21:04 -07003371 * Get the calculated preferred network type.
3372 * Used for debugging incorrect network type.
3373 *
3374 * @return the preferred network type, defined in RILConstants.java.
3375 */
3376 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003377 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003379 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003380 return RILConstants.PREFERRED_NETWORK_MODE;
3381 }
3382
Malcolm Chenaabec062018-02-28 15:00:40 -08003383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 // FIXME: need to get SubId from somewhere.
3386 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0);
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
3389 }
Junda Liu84d15a22014-07-02 11:21:04 -07003390 }
3391
3392 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08003393 * Get the preferred network type.
3394 * Used for device configuration by some CDMA operators.
3395 *
3396 * @return the preferred network type, defined in RILConstants.java.
3397 */
3398 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003399 public int getPreferredNetworkType(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3401 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003402
3403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 if (DBG) log("getPreferredNetworkType");
3406 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
3407 int networkType = (result != null ? result[0] : -1);
3408 if (DBG) log("getPreferredNetworkType: " + networkType);
3409 return networkType;
3410 } finally {
3411 Binder.restoreCallingIdentity(identity);
3412 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003413 }
3414
3415 /**
3416 * Set the preferred network type.
3417 * Used for device configuration by some CDMA operators.
3418 *
3419 * @param networkType the preferred network type, defined in RILConstants.java.
3420 * @return true on success; false on any failure.
3421 */
3422 @Override
Stuart Scott54788802015-03-30 13:18:01 -07003423 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3425 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaabec062018-02-28 15:00:40 -08003426
3427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
3430 Boolean success = (Boolean) sendRequest(
3431 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
3432 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
3433 if (success) {
3434 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
3435 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
3436 }
3437 return success;
3438 } finally {
3439 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07003440 }
Jake Hamby7c27be32014-03-03 13:25:59 -08003441 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003442
3443 /**
Junda Liu475951f2014-11-07 16:45:03 -08003444 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
3445 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
3446 * tethering.
3447 *
3448 * @return 0: Not required. 1: required. 2: Not set.
3449 * @hide
3450 */
3451 @Override
3452 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003453 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003454
3455 final long identity = Binder.clearCallingIdentity();
3456 try {
3457 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
3458 Settings.Global.TETHER_DUN_REQUIRED, 2);
3459 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
3460 // config_tether_apndata.
3461 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
3462 dunRequired = 1;
3463 }
3464 return dunRequired;
3465 } finally {
3466 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08003467 }
Junda Liu475951f2014-11-07 16:45:03 -08003468 }
3469
3470 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07003471 * Set mobile data enabled
3472 * Used by the user through settings etc to turn on/off mobile data
3473 *
3474 * @param enable {@code true} turn turn data on, else {@code false}
3475 */
3476 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003477 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3479 mApp, subId, "setUserDataEnabled");
Malcolm Chenaabec062018-02-28 15:00:40 -08003480
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 int phoneId = mSubscriptionController.getPhoneId(subId);
3484 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3485 Phone phone = PhoneFactory.getPhone(phoneId);
3486 if (phone != null) {
3487 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
3488 phone.setUserDataEnabled(enable);
3489 } else {
3490 loge("setUserDataEnabled: no phone for subId=" + subId);
3491 }
3492 } finally {
3493 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003494 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003495 }
3496
3497 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003498 * Get the user enabled state of Mobile Data.
3499 *
3500 * TODO: remove and use isUserDataEnabled.
3501 * This can't be removed now because some vendor codes
3502 * calls through ITelephony directly while they should
3503 * use TelephonyManager.
3504 *
3505 * @return true on enabled
3506 */
3507 @Override
3508 public boolean getDataEnabled(int subId) {
3509 return isUserDataEnabled(subId);
3510 }
3511
3512 /**
3513 * Get whether mobile data is enabled per user setting.
3514 *
3515 * There are other factors deciding whether mobile data is actually enabled, but they are
3516 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07003517 *
Jeff Davidsona1920712016-11-18 17:05:56 -08003518 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003519 *
3520 * @return {@code true} if data is enabled else {@code false}
3521 */
3522 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003523 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003524 try {
3525 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3526 null);
3527 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3529 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003530 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003531
3532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 int phoneId = mSubscriptionController.getPhoneId(subId);
3535 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3536 Phone phone = PhoneFactory.getPhone(phoneId);
3537 if (phone != null) {
3538 boolean retVal = phone.isUserDataEnabled();
3539 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
3540 return retVal;
3541 } else {
3542 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3543 return false;
3544 }
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003547 }
3548 }
3549
3550 /**
3551 * Get whether mobile data is enabled.
3552 *
3553 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3554 * whether mobile data is actually enabled.
3555 *
3556 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3557 *
3558 * @return {@code true} if data is enabled else {@code false}
3559 */
3560 @Override
3561 public boolean isDataEnabled(int subId) {
3562 try {
3563 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3564 null);
3565 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3567 mApp, subId, "isDataEnabled");
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003568 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003569
3570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 int phoneId = mSubscriptionController.getPhoneId(subId);
3573 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3574 Phone phone = PhoneFactory.getPhone(phoneId);
3575 if (phone != null) {
3576 boolean retVal = phone.isDataEnabled();
3577 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3578 return retVal;
3579 } else {
3580 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
3581 return false;
3582 }
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08003585 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003586 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003587
3588 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003589 public int getCarrierPrivilegeStatus(int subId) {
3590 final Phone phone = getPhone(subId);
3591 if (phone == null) {
3592 loge("getCarrierPrivilegeStatus: Invalid subId");
3593 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3594 }
3595 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003596 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003597 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003598 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3599 }
3600 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003601 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003602 }
Junda Liu29340342014-07-10 15:23:27 -07003603
3604 @Override
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003605 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3606 final Phone phone = getPhone(subId);
3607 if (phone == null) {
3608 loge("getCarrierPrivilegeStatus: Invalid subId");
3609 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3610 }
3611 UiccProfile profile =
3612 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3613 if (profile == null) {
3614 loge("getCarrierPrivilegeStatus: No UICC");
3615 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3616 }
3617 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3618 }
3619
3620 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003621 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003622 if (TextUtils.isEmpty(pkgName))
3623 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003624 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003625 if (card == null) {
3626 loge("checkCarrierPrivilegesForPackage: No UICC");
3627 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3628 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003629 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3630 }
3631
3632 @Override
3633 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003634 if (TextUtils.isEmpty(pkgName))
3635 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003636 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3637 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3638 UiccCard card = UiccController.getInstance().getUiccCard(i);
3639 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003640 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003641 continue;
3642 }
3643
3644 result = card.getCarrierPrivilegeStatus(
3645 mPhone.getContext().getPackageManager(), pkgName);
3646 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3647 break;
3648 }
3649 }
3650
3651 return result;
Junda Liu29340342014-07-10 15:23:27 -07003652 }
Derek Tan89e89d42014-07-08 17:00:10 -07003653
3654 @Override
Junda Liue64de782015-04-16 17:19:16 -07003655 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3656 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3657 loge("phoneId " + phoneId + " is not valid.");
3658 return null;
3659 }
3660 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003661 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003662 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003663 return null ;
3664 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003665 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003666 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003667 }
3668
Amith Yamasani6e118872016-02-19 12:53:51 -08003669 @Override
3670 public List<String> getPackagesWithCarrierPrivileges() {
3671 PackageManager pm = mPhone.getContext().getPackageManager();
3672 List<String> privilegedPackages = new ArrayList<>();
3673 List<PackageInfo> packages = null;
3674 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3675 UiccCard card = UiccController.getInstance().getUiccCard(i);
3676 if (card == null) {
3677 // No UICC in that slot.
3678 continue;
3679 }
3680 if (card.hasCarrierPrivilegeRules()) {
3681 if (packages == null) {
3682 // Only check packages in user 0 for now
3683 packages = pm.getInstalledPackagesAsUser(
3684 PackageManager.MATCH_DISABLED_COMPONENTS
3685 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3686 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3687 }
3688 for (int p = packages.size() - 1; p >= 0; p--) {
3689 PackageInfo pkgInfo = packages.get(p);
3690 if (pkgInfo != null && pkgInfo.packageName != null
3691 && card.getCarrierPrivilegeStatus(pkgInfo)
3692 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3693 privilegedPackages.add(pkgInfo.packageName);
3694 }
3695 }
3696 }
3697 }
3698 return privilegedPackages;
3699 }
3700
Wink Savilleb564aae2014-10-23 10:18:09 -07003701 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003702 final Phone phone = getPhone(subId);
3703 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003704 if (card == null) {
3705 loge("getIccId: No UICC");
3706 return null;
3707 }
3708 String iccId = card.getIccId();
3709 if (TextUtils.isEmpty(iccId)) {
3710 loge("getIccId: ICC ID is null or empty.");
3711 return null;
3712 }
3713 return iccId;
3714 }
3715
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003716 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003717 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3718 String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003719 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3720 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003721
Malcolm Chenaabec062018-02-28 15:00:40 -08003722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 final String iccId = getIccId(subId);
3725 final Phone phone = getPhone(subId);
3726 if (phone == null) {
3727 return false;
3728 }
3729 final String subscriberId = phone.getSubscriberId();
3730
3731 if (DBG_MERGE) {
3732 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3733 + subscriberId + " to " + number);
3734 }
3735
3736 if (TextUtils.isEmpty(iccId)) {
3737 return false;
3738 }
3739
3740 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3741
3742 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3743 if (alphaTag == null) {
3744 editor.remove(alphaTagPrefKey);
3745 } else {
3746 editor.putString(alphaTagPrefKey, alphaTag);
3747 }
3748
3749 // Record both the line number and IMSI for this ICCID, since we need to
3750 // track all merged IMSIs based on line number
3751 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3752 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3753 if (number == null) {
3754 editor.remove(numberPrefKey);
3755 editor.remove(subscriberPrefKey);
3756 } else {
3757 editor.putString(numberPrefKey, number);
3758 editor.putString(subscriberPrefKey, subscriberId);
3759 }
3760
3761 editor.commit();
3762 return true;
3763 } finally {
3764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003765 }
Derek Tan7226c842014-07-02 17:42:23 -07003766 }
3767
3768 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003769 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003770 // This is open to apps with WRITE_SMS.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003772 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003773 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003774 return null;
3775 }
Derek Tan97ebb422014-09-05 16:55:38 -07003776
Malcolm Chenaabec062018-02-28 15:00:40 -08003777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 String iccId = getIccId(subId);
3780 if (iccId != null) {
3781 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3782 if (DBG_MERGE) {
3783 log("getLine1NumberForDisplay returning "
3784 + mTelephonySharedPreferences.getString(numberPrefKey, null));
3785 }
3786 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08003787 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003788 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
3789 return null;
3790 } finally {
3791 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003792 }
Derek Tan7226c842014-07-02 17:42:23 -07003793 }
3794
3795 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003796 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003798 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003799 return null;
3800 }
Derek Tan97ebb422014-09-05 16:55:38 -07003801
Malcolm Chenaabec062018-02-28 15:00:40 -08003802 final long identity = Binder.clearCallingIdentity();
3803 try {
3804 String iccId = getIccId(subId);
3805 if (iccId != null) {
3806 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
3807 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
3808 }
3809 return null;
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07003812 }
Derek Tan7226c842014-07-02 17:42:23 -07003813 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003814
3815 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003816 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003817 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3818 // about carrier-privileged callers not having access.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003819 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003820 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3821 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003822 return null;
3823 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003824
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003825 final long identity = Binder.clearCallingIdentity();
3826 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08003827 final Context context = mPhone.getContext();
3828 final TelephonyManager tele = TelephonyManager.from(context);
3829 final SubscriptionManager sub = SubscriptionManager.from(context);
3830
3831 // Figure out what subscribers are currently active
3832 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
3833 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3834 // the process, where TelephonyManager was instantiated.
3835 // Otherwise AppOps check will fail.
3836
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003837 final int[] subIds = sub.getActiveSubscriptionIdList();
3838 for (int subId : subIds) {
3839 activeSubscriberIds.add(tele.getSubscriberId(subId));
3840 }
Malcolm Chenaabec062018-02-28 15:00:40 -08003841
3842 // First pass, find a number override for an active subscriber
3843 String mergeNumber = null;
3844 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3845 for (String key : prefs.keySet()) {
3846 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3847 final String subscriberId = (String) prefs.get(key);
3848 if (activeSubscriberIds.contains(subscriberId)) {
3849 final String iccId = key.substring(
3850 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3851 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3852 mergeNumber = (String) prefs.get(numberKey);
3853 if (DBG_MERGE) {
3854 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3855 + " for active subscriber " + subscriberId);
3856 }
3857 if (!TextUtils.isEmpty(mergeNumber)) {
3858 break;
3859 }
3860 }
3861 }
3862 }
3863
3864 // Shortcut when no active merged subscribers
3865 if (TextUtils.isEmpty(mergeNumber)) {
3866 return null;
3867 }
3868
3869 // Second pass, find all subscribers under that line override
3870 final ArraySet<String> result = new ArraySet<>();
3871 for (String key : prefs.keySet()) {
3872 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3873 final String number = (String) prefs.get(key);
3874 if (mergeNumber.equals(number)) {
3875 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3876 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3877 final String subscriberId = (String) prefs.get(subscriberKey);
3878 if (!TextUtils.isEmpty(subscriberId)) {
3879 result.add(subscriberId);
3880 }
3881 }
3882 }
3883 }
3884
3885 final String[] resultArray = result.toArray(new String[result.size()]);
3886 Arrays.sort(resultArray);
3887 if (DBG_MERGE) {
3888 Slog.d(LOG_TAG,
3889 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3890 }
3891 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003892 } finally {
3893 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003894 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003895 }
3896
3897 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003898 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003899 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3900 subId, "setOperatorBrandOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003901
3902 final long identity = Binder.clearCallingIdentity();
3903 try {
3904 final Phone phone = getPhone(subId);
3905 return phone == null ? false : phone.setOperatorBrandOverride(brand);
3906 } finally {
3907 Binder.restoreCallingIdentity(identity);
3908 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003909 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003910
3911 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003912 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003913 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3914 List<String> cdmaNonRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003915 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaabec062018-02-28 15:00:40 -08003916
3917 final long identity = Binder.clearCallingIdentity();
3918 try {
3919 final Phone phone = getPhone(subId);
3920 if (phone == null) {
3921 return false;
3922 }
3923 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
3924 cdmaNonRoamingList);
3925 } finally {
3926 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003927 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003928 }
3929
3930 @Override
Shuo Qian74b16b12018-04-27 01:32:07 +00003931 @Deprecated
3932 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3933 enforceModifyPermission();
3934
3935 int returnValue = 0;
3936 try {
3937 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3938 if(result.exception == null) {
3939 if (result.result != null) {
3940 byte[] responseData = (byte[])(result.result);
3941 if(responseData.length > oemResp.length) {
3942 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3943 responseData.length + "bytes. Buffer Size is " +
3944 oemResp.length + "bytes.");
3945 }
3946 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3947 returnValue = responseData.length;
3948 }
3949 } else {
3950 CommandException ex = (CommandException) result.exception;
3951 returnValue = ex.getCommandError().ordinal();
3952 if(returnValue > 0) returnValue *= -1;
3953 }
3954 } catch (RuntimeException e) {
3955 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3956 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3957 if(returnValue > 0) returnValue *= -1;
3958 }
3959
3960 return returnValue;
3961 }
3962
3963 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003964 public void setRadioCapability(RadioAccessFamily[] rafs) {
3965 try {
3966 ProxyController.getInstance().setRadioCapability(rafs);
3967 } catch (RuntimeException e) {
3968 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3969 }
3970 }
3971
3972 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003973 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003974 Phone phone = PhoneFactory.getPhone(phoneId);
3975 if (phone == null) {
3976 return RadioAccessFamily.RAF_UNKNOWN;
3977 }
3978 int subId = phone.getSubId();
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003980 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003981 return RadioAccessFamily.RAF_UNKNOWN;
3982 }
3983
Malcolm Chenaabec062018-02-28 15:00:40 -08003984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003990 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003991
3992 @Override
3993 public void enableVideoCalling(boolean enable) {
3994 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08003995
3996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
4001 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004002 }
4003
4004 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004005 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004007 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004008 return false;
4009 }
4010
Malcolm Chenaabec062018-02-28 15:00:40 -08004011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 // Check the user preference and the system-level IMS setting. Even if the user has
4014 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4015 // In the long run, we may instead need to check if there exists a connection service
4016 // which can support video calling.
4017 ImsManager imsManager =
4018 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
4019 return imsManager.isVtEnabledByPlatform()
4020 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4021 && imsManager.isVtEnabledByUser();
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
4024 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004025 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004026
Andrew Leea1239f22015-03-02 17:44:07 -08004027 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004028 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4030 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4031 return false;
4032 }
4033
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 CarrierConfigManager configManager =
4037 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4038 return configManager.getConfigForSubId(mPhone.getSubId())
4039 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
Andrew Leea1239f22015-03-02 17:44:07 -08004043 }
4044
4045 @Override
Malcolm Chenaabec062018-02-28 15:00:40 -08004046 public boolean isWorldPhone(int subId, String callingPackage) {
4047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4048 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4049 return false;
4050 }
4051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 CarrierConfigManager configManager =
4055 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
4056 return configManager.getConfigForSubId(mPhone.getSubId())
4057 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
Andrew Leea1239f22015-03-02 17:44:07 -08004061 }
4062
Andrew Lee9431b832015-03-09 18:46:45 -07004063 @Override
4064 public boolean isTtyModeSupported() {
4065 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
Wooki Wu1f82f7a2016-02-15 15:59:58 +08004066 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07004067 }
4068
4069 @Override
4070 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004071 final long identity = Binder.clearCallingIdentity();
4072 try {
4073 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
4074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
Andrew Lee9431b832015-03-09 18:46:45 -07004077 }
4078
Hall Liu73714012018-01-22 19:15:32 -08004079 public boolean isRttSupported() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(
4083 mPhone.getSubId()).getBoolean(
4084 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
4085 boolean isDeviceSupported =
4086 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
4087 return isCarrierSupported && isDeviceSupported;
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
Hall Liu73714012018-01-22 19:15:32 -08004091 }
4092
Hall Liub1585172018-04-06 16:23:39 -07004093 public boolean isRttEnabled() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 return isRttSupported() && Settings.Secure.getInt(
4097 mPhone.getContext().getContentResolver(),
4098 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
4101 }
Hall Liub1585172018-04-06 16:23:39 -07004102 }
4103
Sanket Padawe7310cc72015-01-14 09:53:20 -08004104 /**
4105 * Returns the unique device ID of phone, for example, the IMEI for
4106 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
4107 *
4108 * <p>Requires Permission:
4109 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
4110 */
4111 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004112 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004113 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004114 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08004115 return null;
4116 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004117 int subId = phone.getSubId();
4118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4119 mApp, subId, callingPackage, "getDeviceId")) {
4120 return null;
4121 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004122
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 return phone.getDeviceId();
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08004129 }
4130
Ping Sun014fe8e2016-03-02 19:16:45 +08004131 /**
4132 * {@hide}
4133 * Returns the IMS Registration Status on a particular subid
4134 *
4135 * @param subId
4136 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08004137 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08004138 Phone phone = getPhone(subId);
4139 if (phone != null) {
4140 return phone.isImsRegistered();
4141 } else {
4142 return false;
4143 }
4144 }
4145
Santos Cordon7a1885b2015-02-03 11:15:19 -08004146 @Override
4147 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
4151 } finally {
4152 Binder.restoreCallingIdentity(identity);
4153 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08004154 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07004155
Brad Ebingere21f25f2018-02-08 16:11:32 -08004156 /**
4157 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004158 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08004159 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 Phone phone = getPhone(subId);
4163 if (phone != null) {
4164 return phone.isWifiCallingEnabled();
4165 } else {
4166 return false;
4167 }
4168 } finally {
4169 Binder.restoreCallingIdentity(identity);
Brad Ebingere21f25f2018-02-08 16:11:32 -08004170 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004171 }
4172
Brad Ebingere21f25f2018-02-08 16:11:32 -08004173 /**
4174 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07004175 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08004176 public boolean isVolteAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 Phone phone = getPhone(subId);
4180 if (phone != null) {
4181 return phone.isVolteEnabled();
4182 } else {
4183 return false;
4184 }
4185 } finally {
4186 Binder.restoreCallingIdentity(identity);
Brad Ebingere21f25f2018-02-08 16:11:32 -08004187 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07004188 }
Svet Ganovb320e182015-04-16 12:30:10 -07004189
Brad Ebingere21f25f2018-02-08 16:11:32 -08004190 /**
4191 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004192 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08004193 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 Phone phone = getPhone(subId);
4197 if (phone != null) {
4198 return phone.isVideoEnabled();
4199 } else {
4200 return false;
4201 }
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
Brad Ebingere21f25f2018-02-08 16:11:32 -08004204 }
4205 }
4206
4207 /**
4208 * @return the IMS registration technology for the MMTEL feature. Valid return values are
4209 * defined in {@link ImsRegistrationImplBase}.
4210 */
4211 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 Phone phone = getPhone(subId);
4215 if (phone != null) {
4216 return phone.getImsRegistrationTech();
4217 } else {
4218 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
4219 }
4220 } finally {
4221 Binder.restoreCallingIdentity(identity);
Brad Ebingere21f25f2018-02-08 16:11:32 -08004222 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07004223 }
4224
Stuart Scott8eef64f2015-04-08 15:13:54 -07004225 @Override
4226 public void factoryReset(int subId) {
4227 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07004228 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
4229 return;
4230 }
4231
Svet Ganovcc087f82015-05-12 20:35:54 -07004232 final long identity = Binder.clearCallingIdentity();
4233 try {
Stuart Scott981d8582015-04-21 14:09:50 -07004234 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
4235 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07004236 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08004237 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07004238 // Set network selection mode to automatic
4239 setNetworkSelectionModeAutomatic(subId);
4240 // Set preferred mobile network type to the best available
Kitta Koutarouab8a69b2018-03-05 14:16:45 +09004241 String defaultNetwork = TelephonyManager.getTelephonyProperty(
4242 mSubscriptionController.getPhoneId(subId),
4243 "ro.telephony.default_network",
4244 null);
4245 int networkType = !TextUtils.isEmpty(defaultNetwork)
4246 ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
4247 setPreferredNetworkType(subId, networkType);
Svet Ganovcc087f82015-05-12 20:35:54 -07004248 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07004249 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07004250 }
4251 } finally {
4252 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004253 }
4254 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004255
4256 @Override
4257 public String getLocaleFromDefaultSim() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004258 final long identity = Binder.clearCallingIdentity();
4259 try {
4260 // We query all subscriptions instead of just the active ones, because
4261 // this might be called early on in the provisioning flow when the
4262 // subscriptions potentially aren't active yet.
4263 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
4264 if (slist == null || slist.isEmpty()) {
Narayan Kamath1c496c22015-04-16 14:40:19 +01004265 return null;
4266 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004267
Malcolm Chenaabec062018-02-28 15:00:40 -08004268 // This function may be called very early, say, from the setup wizard, at
4269 // which point we won't have a default subscription set. If that's the case
4270 // we just choose the first, which will be valid in "most cases".
4271 final int defaultSubId = getDefaultSubscription();
4272 SubscriptionInfo info = null;
4273 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
4274 info = slist.get(0);
4275 } else {
4276 for (SubscriptionInfo item : slist) {
4277 if (item.getSubscriptionId() == defaultSubId) {
4278 info = item;
4279 break;
4280 }
4281 }
4282
4283 if (info == null) {
4284 return null;
Tony Hill183b2de2015-06-24 14:53:58 +01004285 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004286 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004287
Malcolm Chenaabec062018-02-28 15:00:40 -08004288 // Try and fetch the locale from the carrier properties or from the SIM language
4289 // preferences (EF-PL and EF-LI)...
4290 final int mcc = info.getMcc();
4291 final Phone defaultPhone = getPhone(info.getSubscriptionId());
4292 String simLanguage = null;
4293 if (defaultPhone != null) {
4294 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
4295 if (localeFromDefaultSim != null) {
4296 if (!localeFromDefaultSim.getCountry().isEmpty()) {
4297 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
4298 return localeFromDefaultSim.toLanguageTag();
4299 } else {
4300 simLanguage = localeFromDefaultSim.getLanguage();
4301 }
4302 }
4303 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004304
Malcolm Chenaabec062018-02-28 15:00:40 -08004305 // The SIM language preferences only store a language (e.g. fr = French), not an
4306 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
4307 // the SIM and carrier preferences does not include a country we add the country
4308 // determined from the SIM MCC to provide an exact locale.
4309 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc,
4310 simLanguage);
4311 if (mccLocale != null) {
4312 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
4313 return mccLocale.toLanguageTag();
4314 }
4315
4316 if (DBG) log("No locale found - returning null");
4317 return null;
4318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01004321 }
4322
4323 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Malcolm Chenaabec062018-02-28 15:00:40 -08004324 return mSubscriptionController.getAllSubInfoList(
4325 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004326 }
4327
Malcolm Chenaabec062018-02-28 15:00:40 -08004328 /**
4329 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
4330 */
4331 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
4332 return mSubscriptionController.getActiveSubscriptionInfoList(
4333 mPhone.getContext().getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01004334 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004335
4336 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07004337 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
4338 * representing the state of the modem.
4339 *
4340 * NOTE: This clears the modem state, so there should only every be one caller.
4341 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004342 */
4343 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07004344 public void requestModemActivityInfo(ResultReceiver result) {
4345 enforceModifyPermission();
4346
Malcolm Chenaabec062018-02-28 15:00:40 -08004347 final long identity = Binder.clearCallingIdentity();
4348 try {
4349 ModemActivityInfo info =
4350 (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
4351 Bundle bundle = new Bundle();
4352 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
4353 result.send(0, bundle);
4354 } finally {
4355 Binder.restoreCallingIdentity(identity);
4356 }
4357
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07004358 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004359
4360 /**
4361 * {@hide}
4362 * Returns the service state information on specified subscription.
4363 */
4364 @Override
4365 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004367 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08004368 return null;
4369 }
4370
Malcolm Chenaabec062018-02-28 15:00:40 -08004371 final long identity = Binder.clearCallingIdentity();
4372 try {
4373 final Phone phone = getPhone(subId);
4374 if (phone == null) {
4375 return null;
4376 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004377
Malcolm Chenaabec062018-02-28 15:00:40 -08004378 return phone.getServiceState();
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
Jack Yu85bd38a2015-11-09 11:34:32 -08004382 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004383
4384 /**
4385 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
4386 *
4387 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4388 * voicemail ringtone.
4389 * @return The URI for the ringtone to play when receiving a voicemail from a specific
4390 * PhoneAccount.
4391 */
4392 @Override
4393 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004394 final long identity = Binder.clearCallingIdentity();
4395 try {
4396 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4397 if (phone == null) {
4398 phone = mPhone;
4399 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004400
Malcolm Chenaabec062018-02-28 15:00:40 -08004401 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
4402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004405 }
4406
4407 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004408 * Sets the per-account voicemail ringtone.
4409 *
4410 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4411 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4412 *
4413 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4414 * voicemail ringtone.
4415 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
4416 * PhoneAccount.
4417 */
4418 @Override
4419 public void setVoicemailRingtoneUri(String callingPackage,
4420 PhoneAccountHandle phoneAccountHandle, Uri uri) {
4421 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4422 if (!TextUtils.equals(callingPackage,
4423 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4425 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4426 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004427 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004428
4429 final long identity = Binder.clearCallingIdentity();
4430 try {
4431 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4432 if (phone == null) {
4433 phone = mPhone;
4434 }
4435 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
4436 } finally {
4437 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004438 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004439 }
4440
4441 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08004442 * Returns whether vibration is set for voicemail notification in Phone settings.
4443 *
4444 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
4445 * voicemail vibration setting.
4446 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
4447 */
4448 @Override
4449 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004450 final long identity = Binder.clearCallingIdentity();
4451 try {
4452 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
4453 if (phone == null) {
4454 phone = mPhone;
4455 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004456
Malcolm Chenaabec062018-02-28 15:00:40 -08004457 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
4458 } finally {
4459 Binder.restoreCallingIdentity(identity);
4460 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08004461 }
4462
Youhan Wange64578a2016-05-02 15:32:42 -07004463 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004464 * Sets the per-account voicemail vibration.
4465 *
4466 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
4467 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
4468 *
4469 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
4470 * voicemail vibration setting.
4471 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
4472 * specific PhoneAccount.
4473 */
4474 @Override
4475 public void setVoicemailVibrationEnabled(String callingPackage,
4476 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
4477 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4478 if (!TextUtils.equals(callingPackage,
4479 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4481 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
4482 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004483 }
4484
Malcolm Chenaabec062018-02-28 15:00:40 -08004485 final long identity = Binder.clearCallingIdentity();
4486 try {
4487 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
4488 if (phone == null) {
4489 phone = mPhone;
4490 }
4491 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
4492 } finally {
4493 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004494 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08004495 }
4496
4497 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004498 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
4499 *
4500 * @throws SecurityException if the caller does not have the required permission
4501 */
4502 private void enforceReadPrivilegedPermission() {
4503 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
4504 null);
4505 }
4506
4507 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004508 * Make sure either called from same process as self (phone) or IPC caller has send SMS
4509 * permission.
4510 *
4511 * @throws SecurityException if the caller does not have the required permission
4512 */
4513 private void enforceSendSmsPermission() {
4514 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
4515 }
4516
4517 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004518 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004519 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004520 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004521 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004522 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004523 final long identity = Binder.clearCallingIdentity();
4524 try {
4525 ComponentName componentName =
4526 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
4527 if (componentName == null) {
4528 throw new SecurityException(
4529 "Caller not current active visual voicemail package[null]");
4530 }
4531 String vvmPackage = componentName.getPackageName();
4532 if (!callingPackage.equals(vvmPackage)) {
4533 throw new SecurityException("Caller not current active visual voicemail package["
4534 + vvmPackage + "]");
4535 }
4536 } finally {
4537 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004538 }
4539 }
4540
4541 /**
Youhan Wange64578a2016-05-02 15:32:42 -07004542 * Return the application ID for the app type.
4543 *
4544 * @param subId the subscription ID that this request applies to.
4545 * @param appType the uicc app type.
4546 * @return Application ID for specificied app type, or null if no uicc.
4547 */
4548 @Override
4549 public String getAidForAppType(int subId, int appType) {
4550 enforceReadPrivilegedPermission();
4551 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004552
4553 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07004554 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004555 if (phone == null) {
4556 return null;
4557 }
4558 String aid = null;
4559 try {
4560 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
4561 .getApplicationByType(appType).getAid();
4562 } catch (Exception e) {
4563 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
4564 }
4565 return aid;
4566 } finally {
4567 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07004568 }
Youhan Wange64578a2016-05-02 15:32:42 -07004569 }
4570
Youhan Wang4001d252016-05-11 10:29:41 -07004571 /**
4572 * Return the Electronic Serial Number.
4573 *
4574 * @param subId the subscription ID that this request applies to.
4575 * @return ESN or null if error.
4576 */
4577 @Override
4578 public String getEsn(int subId) {
4579 enforceReadPrivilegedPermission();
4580 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004581
4582 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07004583 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004584 if (phone == null) {
4585 return null;
4586 }
4587 String esn = null;
4588 try {
4589 esn = phone.getEsn();
4590 } catch (Exception e) {
4591 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
4592 }
4593 return esn;
4594 } finally {
4595 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07004596 }
Youhan Wang4001d252016-05-11 10:29:41 -07004597 }
4598
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004599 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07004600 * Return the Preferred Roaming List Version.
4601 *
4602 * @param subId the subscription ID that this request applies to.
4603 * @return PRLVersion or null if error.
4604 */
4605 @Override
4606 public String getCdmaPrlVersion(int subId) {
4607 enforceReadPrivilegedPermission();
4608 Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004609
4610 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07004611 try {
Malcolm Chenaabec062018-02-28 15:00:40 -08004612 if (phone == null) {
4613 return null;
4614 }
4615 String cdmaPrlVersion = null;
4616 try {
4617 cdmaPrlVersion = phone.getCdmaPrlVersion();
4618 } catch (Exception e) {
4619 Log.e(LOG_TAG, "Not getting PRLVersion", e);
4620 }
4621 return cdmaPrlVersion;
4622 } finally {
4623 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07004624 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07004625 }
4626
4627 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004628 * Get snapshot of Telephony histograms
4629 * @return List of Telephony histograms
4630 * @hide
4631 */
4632 @Override
4633 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4635 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaabec062018-02-28 15:00:40 -08004636
4637 final long identity = Binder.clearCallingIdentity();
4638 try {
4639 return RIL.getTelephonyRILTimingHistograms();
4640 } finally {
4641 Binder.restoreCallingIdentity(identity);
4642 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07004643 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004644
4645 /**
4646 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004647 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07004648 * Require system privileges. In the future we may add this to carrier APIs.
4649 *
4650 * @return The number of carriers set successfully, should match length of carriers
4651 */
4652 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004653 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004654 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004655
Meng Wang9b7c4e92017-02-17 11:41:27 -08004656 if (carriers == null) {
4657 throw new NullPointerException("carriers cannot be null");
4658 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004659
Malcolm Chenaabec062018-02-28 15:00:40 -08004660 final long identity = Binder.clearCallingIdentity();
4661 try {
4662 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4663 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
4664 return retVal[0];
4665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004668 }
4669
4670 /**
4671 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004672 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07004673 * Require system privileges. In the future we may add this to carrier APIs.
4674 *
4675 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
4676 * means all carriers are allowed.
4677 */
4678 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004679 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07004680 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004681
4682 final long identity = Binder.clearCallingIdentity();
4683 try {
4684 int subId = SubscriptionManager.getSubId(slotIndex)[0];
4685 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
4686 } finally {
4687 Binder.restoreCallingIdentity(identity);
4688 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07004689 }
4690
fionaxu59545b42016-05-25 15:53:37 -07004691 /**
4692 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
4693 * @param subId the subscription ID that this action applies to.
4694 * @param enabled control enable or disable metered apns.
4695 * {@hide}
4696 */
4697 @Override
4698 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
4699 enforceModifyPermission();
4700 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004701
4702 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004703 if (phone == null) {
4704 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
4705 return;
4706 }
4707 try {
4708 phone.carrierActionSetMeteredApnsEnabled(enabled);
4709 } catch (Exception e) {
4710 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004711 } finally {
4712 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004713 }
4714 }
4715
4716 /**
4717 * Action set from carrier signalling broadcast receivers to enable/disable radio
4718 * @param subId the subscription ID that this action applies to.
4719 * @param enabled control enable or disable radio.
4720 * {@hide}
4721 */
4722 @Override
4723 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
4724 enforceModifyPermission();
4725 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004726
4727 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07004728 if (phone == null) {
4729 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4730 return;
4731 }
4732 try {
4733 phone.carrierActionSetRadioEnabled(enabled);
4734 } catch (Exception e) {
4735 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004736 } finally {
4737 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07004738 }
4739 }
4740
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004741 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004742 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4743 * network status based on which carrier apps could apply actions accordingly,
4744 * enable/disable default url handler for example.
4745 *
4746 * @param subId the subscription ID that this action applies to.
4747 * @param report control start/stop reporting the default network status.
4748 * {@hide}
4749 */
4750 @Override
4751 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4752 enforceModifyPermission();
4753 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004754
4755 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07004756 if (phone == null) {
4757 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4758 return;
4759 }
4760 try {
4761 phone.carrierActionReportDefaultNetworkStatus(report);
4762 } catch (Exception e) {
4763 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaabec062018-02-28 15:00:40 -08004764 } finally {
4765 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07004766 }
4767 }
4768
4769 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004770 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4771 * bug report is being generated.
4772 */
4773 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004774 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004775 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4776 != PackageManager.PERMISSION_GRANTED) {
4777 writer.println("Permission Denial: can't dump Phone from pid="
4778 + Binder.getCallingPid()
4779 + ", uid=" + Binder.getCallingUid()
4780 + "without permission "
4781 + android.Manifest.permission.DUMP);
4782 return;
4783 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004784 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004785 }
Jack Yueb89b242016-06-22 13:27:47 -07004786
Brad Ebinger4dc095a2018-04-03 15:17:52 -07004787 @Override
4788 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4789 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4790 throws RemoteException {
4791 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4792 }
4793
Jack Yueb89b242016-06-22 13:27:47 -07004794 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004795 * Get aggregated video call data usage since boot.
4796 *
4797 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4798 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004799 * {@hide}
4800 */
4801 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004802 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004803 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4804 null);
4805
Malcolm Chenaabec062018-02-28 15:00:40 -08004806 final long identity = Binder.clearCallingIdentity();
4807 try {
4808 // NetworkStatsService keeps tracking the active network interface and identity. It
4809 // records the delta with the corresponding network identity.
4810 // We just return the total video call data usage snapshot since boot.
4811 Phone phone = getPhone(subId);
4812 if (phone != null) {
4813 return phone.getVtDataUsage(perUidStats);
4814 }
4815 return null;
4816 } finally {
4817 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07004818 }
Jack Yueb89b242016-06-22 13:27:47 -07004819 }
Jack Yu75ab2952016-07-08 14:29:33 -07004820
4821 /**
4822 * Policy control of data connection. Usually used when data limit is passed.
4823 * @param enabled True if enabling the data, otherwise disabling.
4824 * @param subId Subscription index
4825 * {@hide}
4826 */
4827 @Override
4828 public void setPolicyDataEnabled(boolean enabled, int subId) {
4829 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08004830
4831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 Phone phone = getPhone(subId);
4834 if (phone != null) {
4835 phone.setPolicyDataEnabled(enabled);
4836 }
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07004839 }
4840 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004841
4842 /**
4843 * Get Client request stats
4844 * @return List of Client Request Stats
4845 * @hide
4846 */
4847 @Override
4848 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004850 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004851 return null;
4852 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004853 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004854
Malcolm Chenaabec062018-02-28 15:00:40 -08004855 final long identity = Binder.clearCallingIdentity();
4856 try {
4857 if (phone != null) {
4858 return phone.getClientRequestStats();
4859 }
4860
4861 return null;
4862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004865 }
4866
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00004867 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004868 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathbb8f7c42018-01-09 11:47:15 +00004869 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004870 }
Jack Yueb4124c2017-02-16 15:32:43 -08004871
4872 /**
Grace Chen70990072017-03-24 17:21:30 -07004873 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004874 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004875 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004876 * @param state State of SIM (power down, power up, pass through)
4877 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4878 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4879 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004880 *
4881 **/
4882 @Override
Grace Chen70990072017-03-24 17:21:30 -07004883 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004884 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004885 Phone phone = PhoneFactory.getPhone(slotIndex);
4886
Malcolm Chenaabec062018-02-28 15:00:40 -08004887 final long identity = Binder.clearCallingIdentity();
4888 try {
4889 if (phone != null) {
4890 phone.setSimPowerState(state);
4891 }
4892 } finally {
4893 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08004894 }
4895 }
Shuo Qiandd210312017-04-12 22:11:33 +00004896
Tyler Gunn65d45c22017-06-05 11:22:26 -07004897 private boolean isUssdApiAllowed(int subId) {
4898 CarrierConfigManager configManager =
4899 (CarrierConfigManager) mPhone.getContext().getSystemService(
4900 Context.CARRIER_CONFIG_SERVICE);
4901 if (configManager == null) {
4902 return false;
4903 }
4904 PersistableBundle pb = configManager.getConfigForSubId(subId);
4905 if (pb == null) {
4906 return false;
4907 }
4908 return pb.getBoolean(
4909 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4910 }
4911
Shuo Qiandd210312017-04-12 22:11:33 +00004912 /**
4913 * Check if phone is in emergency callback mode
4914 * @return true if phone is in emergency callback mode
4915 * @param subId sub id
4916 */
4917 public boolean getEmergencyCallbackMode(int subId) {
4918 final Phone phone = getPhone(subId);
Malcolm Chenaabec062018-02-28 15:00:40 -08004919
4920 final long identity = Binder.clearCallingIdentity();
4921 try {
4922 if (phone != null) {
4923 return phone.isInEcm();
4924 } else {
4925 return false;
4926 }
4927 } finally {
4928 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00004929 }
4930 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004931
4932 /**
4933 * Get the current signal strength information for the given subscription.
4934 * Because this information is not updated when the device is in a low power state
4935 * it should not be relied-upon to be current.
4936 * @param subId Subscription index
4937 * @return the most recent cached signal strength info from the modem
4938 */
4939 @Override
4940 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaabec062018-02-28 15:00:40 -08004941 final long identity = Binder.clearCallingIdentity();
4942 try {
4943 Phone p = getPhone(subId);
4944 if (p == null) {
4945 return null;
4946 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004947
Malcolm Chenaabec062018-02-28 15:00:40 -08004948 return p.getSignalStrength();
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004952 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004953
4954 @Override
4955 public UiccSlotInfo[] getUiccSlotsInfo() {
4956 enforceReadPrivilegedPermission();
4957
Malcolm Chenaabec062018-02-28 15:00:40 -08004958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4961 if (slots == null) return null;
4962 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4963 for (int i = 0; i < slots.length; i++) {
4964 UiccSlot slot = slots[i];
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004965
Malcolm Chenaabec062018-02-28 15:00:40 -08004966 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004967
Malcolm Chenaabec062018-02-28 15:00:40 -08004968 int cardState = 0;
4969 switch (slot.getCardState()) {
4970 case CARDSTATE_ABSENT:
4971 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4972 break;
4973 case CARDSTATE_PRESENT:
4974 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4975 break;
4976 case CARDSTATE_ERROR:
4977 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4978 break;
4979 case CARDSTATE_RESTRICTED:
4980 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4981 break;
4982 default:
4983 break;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004984
Malcolm Chenaabec062018-02-28 15:00:40 -08004985 }
4986
4987 infos[i] = new UiccSlotInfo(
4988 slot.isActive(),
4989 slot.isEuicc(),
4990 cardId,
4991 cardState,
4992 slot.getPhoneId(),
4993 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004994 }
Malcolm Chenaabec062018-02-28 15:00:40 -08004995 return infos;
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004998 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004999 }
5000
5001 @Override
5002 public boolean switchSlots(int[] physicalSlots) {
5003 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005004
5005 final long identity = Binder.clearCallingIdentity();
5006 try {
5007 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
5008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005011 }
Jack Yue6146032018-02-27 15:30:01 -08005012
5013 @Override
5014 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
5015 enforceModifyPermission();
5016 final Phone phone = getPhone(subId);
5017 if (phone == null) {
5018 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
5019 return;
5020 }
5021
Malcolm Chenaabec062018-02-28 15:00:40 -08005022 final long identity = Binder.clearCallingIdentity();
5023 try {
5024 phone.setRadioIndicationUpdateMode(filters, mode);
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
5027 }
Jack Yue6146032018-02-27 15:30:01 -08005028 }
fionaxu2c8bbbd2018-03-21 00:08:13 -07005029
5030 @Override
5031 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
5032 gid1, String gid2, String plmn, String spn) {
5033 enforceModifyPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005034
5035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 final Phone phone = getPhone(subId);
5038 if (phone == null) {
5039 loge("setCarrierTestOverride fails with invalid subId: " + subId);
5040 return;
5041 }
5042 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
fionaxu2c8bbbd2018-03-21 00:08:13 -07005045 }
fionaxu2c8bbbd2018-03-21 00:08:13 -07005046 }
5047
5048 @Override
5049 public int getCarrierIdListVersion(int subId) {
5050 enforceReadPrivilegedPermission();
Malcolm Chenaabec062018-02-28 15:00:40 -08005051
5052 final long identity = Binder.clearCallingIdentity();
5053 try {
5054 final Phone phone = getPhone(subId);
5055 if (phone == null) {
5056 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
5057 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
5058 }
5059 return phone.getCarrierIdListVersion();
5060 } finally {
5061 Binder.restoreCallingIdentity(identity);
fionaxu2c8bbbd2018-03-21 00:08:13 -07005062 }
fionaxu2c8bbbd2018-03-21 00:08:13 -07005063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005064}