blob: f793a57d56d50592938520c6f9be3cb4771a4afe [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.ActivityManager;
23import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070025import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.content.Context;
27import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070028import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
yinxua368f0e2017-04-17 11:45:04 -070043import android.os.Process;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
46import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070047import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070048import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070049import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080050import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070051import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080052import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080053import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070054import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070055import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070058import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070059import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080060import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070061import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070062import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080065import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070066import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080067import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070069import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070071import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080076import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080077import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080078
Andrew Lee312e8172014-10-23 17:01:36 -070079import com.android.ims.ImsManager;
Brad Ebinger51f743a2017-01-23 13:50:20 -080080import com.android.ims.internal.IImsServiceController;
81import com.android.ims.internal.IImsServiceFeatureListener;
Shishir Agrawal566b7612013-10-28 14:41:00 -070082import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070083import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070084import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070085import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080088import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010089import com.android.internal.telephony.MccTable;
yinxua368f0e2017-04-17 11:45:04 -070090import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070091import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080093import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070094import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070095import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070096import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070097import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070098import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080099import com.android.internal.telephony.SubscriptionController;
Derek Tan740e1672017-06-27 14:56:27 -0700100import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700101import com.android.internal.telephony.uicc.IccIoResult;
102import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800103import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700104import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800105import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700107import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800108import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700109import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800110import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700111import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700112import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800113
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700114import java.io.FileDescriptor;
115import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800116import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800119import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100120import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800121import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122
123/**
124 * Implementation of the ITelephony interface.
125 */
Santos Cordon117fee72014-05-16 17:56:12 -0700126public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127 private static final String LOG_TAG = "PhoneInterfaceManager";
128 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
129 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131
132 // Message codes used with mMainThreadHandler
133 private static final int CMD_HANDLE_PIN_MMI = 1;
134 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
135 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
136 private static final int CMD_ANSWER_RINGING_CALL = 4;
137 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700138 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
139 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140 private static final int CMD_OPEN_CHANNEL = 9;
141 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
142 private static final int CMD_CLOSE_CHANNEL = 11;
143 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800144 private static final int CMD_NV_READ_ITEM = 13;
145 private static final int EVENT_NV_READ_ITEM_DONE = 14;
146 private static final int CMD_NV_WRITE_ITEM = 15;
147 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
148 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
149 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
150 private static final int CMD_NV_RESET_CONFIG = 19;
151 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800152 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
153 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
154 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
155 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800156 private static final int CMD_SEND_ENVELOPE = 25;
157 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700158 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
159 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
160 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
161 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
162 private static final int CMD_EXCHANGE_SIM_IO = 31;
163 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800164 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
165 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700166 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
167 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700168 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
169 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
171 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
172 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
173 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700174 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
175 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
176 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
177 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700178 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
180 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182 /** The singleton instance. */
183 private static PhoneInterfaceManager sInstance;
184
Wink Saville3ab207e2014-11-20 13:07:20 -0800185 private PhoneGlobals mApp;
186 private Phone mPhone;
187 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700188 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800189 private AppOpsManager mAppOps;
190 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800191 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800192 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
Derek Tan97ebb422014-09-05 16:55:38 -0700194 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
195 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800196 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700197
Derek Tan740e1672017-06-27 14:56:27 -0700198 // The AID of ISD-R.
199 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
200
yinxua368f0e2017-04-17 11:45:04 -0700201 private NetworkScanRequestTracker mNetworkScanRequestTracker;
202
Derek Tan89e89d42014-07-08 17:00:10 -0700203 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204 * A request object to use for transmitting data to an ICC.
205 */
206 private static final class IccAPDUArgument {
207 public int channel, cla, command, p1, p2, p3;
208 public String data;
209
210 public IccAPDUArgument(int channel, int cla, int command,
211 int p1, int p2, int p3, String data) {
212 this.channel = channel;
213 this.cla = cla;
214 this.command = command;
215 this.p1 = p1;
216 this.p2 = p2;
217 this.p3 = p3;
218 this.data = data;
219 }
220 }
221
222 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700223 * A request object to use for transmitting data to an ICC.
224 */
225 private static final class ManualNetworkSelectionArgument {
226 public OperatorInfo operatorInfo;
227 public boolean persistSelection;
228
229 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
230 this.operatorInfo = operatorInfo;
231 this.persistSelection = persistSelection;
232 }
233 }
234
235 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
237 * request after sending. The main thread will notify the request when it is complete.
238 */
239 private static final class MainThreadRequest {
240 /** The argument to use for the request */
241 public Object argument;
242 /** The result of the request that is run on the main thread */
243 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800244 // The subscriber id that this request applies to. Defaults to
245 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
246 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
248 public MainThreadRequest(Object argument) {
249 this.argument = argument;
250 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800251
252 public MainThreadRequest(Object argument, Integer subId) {
253 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800254 if (subId != null) {
255 this.subId = subId;
256 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 }
259
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800260 private static final class IncomingThirdPartyCallArgs {
261 public final ComponentName component;
262 public final String callId;
263 public final String callerDisplayName;
264
265 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
266 String callerDisplayName) {
267 this.component = component;
268 this.callId = callId;
269 this.callerDisplayName = callerDisplayName;
270 }
271 }
272
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 /**
274 * A handler that processes messages on the main thread in the phone process. Since many
275 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
276 * inbound binder threads to the main thread in the phone process. The Binder thread
277 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
278 * on, which will be notified when the operation completes and will contain the result of the
279 * request.
280 *
281 * <p>If a MainThreadRequest object is provided in the msg.obj field,
282 * note that request.result must be set to something non-null for the calling thread to
283 * unblock.
284 */
285 private final class MainThreadHandler extends Handler {
286 @Override
287 public void handleMessage(Message msg) {
288 MainThreadRequest request;
289 Message onCompleted;
290 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800291 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700292 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293
294 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700295 case CMD_HANDLE_USSD_REQUEST: {
296 request = (MainThreadRequest) msg.obj;
297 final Phone phone = getPhoneFromRequest(request);
298 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
299 String ussdRequest = ussdObject.first;
300 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700301
302 if (!isUssdApiAllowed(request.subId)) {
303 // Carrier does not support use of this API, return failure.
304 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
305 UssdResponse response = new UssdResponse(ussdRequest, null);
306 Bundle returnData = new Bundle();
307 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
308 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
309
310 request.result = true;
311 synchronized (request) {
312 request.notifyAll();
313 }
314 return;
315 }
316
Tyler Gunn52dcf772017-04-26 11:30:31 -0700317 try {
318 request.result = phone != null ?
319 phone.handleUssdRequest(ussdRequest, wrappedCallback)
320 : false;
321 } catch (CallStateException cse) {
322 request.result = false;
323 }
pkanwar32d516d2016-10-14 19:37:38 -0700324 // Wake up the requesting thread
325 synchronized (request) {
326 request.notifyAll();
327 }
328 break;
329 }
330
Yorke Lee716f67e2015-06-17 15:39:16 -0700331 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700333 final Phone phone = getPhoneFromRequest(request);
334 request.result = phone != null ?
335 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
336 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 // Wake up the requesting thread
338 synchronized (request) {
339 request.notifyAll();
340 }
341 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
344 case CMD_HANDLE_NEIGHBORING_CELL:
345 request = (MainThreadRequest) msg.obj;
346 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
347 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700348 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 break;
350
351 case EVENT_NEIGHBORING_CELL_DONE:
352 ar = (AsyncResult) msg.obj;
353 request = (MainThreadRequest) ar.userObj;
354 if (ar.exception == null && ar.result != null) {
355 request.result = ar.result;
356 } else {
357 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800358 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 }
360 // Wake up the requesting thread
361 synchronized (request) {
362 request.notifyAll();
363 }
364 break;
365
366 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);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 break;
371
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 case CMD_END_CALL:
373 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800374 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700375 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700376 Phone phone = getPhone(end_subId);
377 if (phone == null) {
378 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
379 break;
380 }
381 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
383 // CDMA: If the user presses the Power button we treat it as
384 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700385 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
387 // GSM: End the call as per the Phone state
388 hungUp = PhoneUtils.hangup(mCM);
389 } else {
390 throw new IllegalStateException("Unexpected phone type: " + phoneType);
391 }
392 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
393 request.result = hungUp;
394 // Wake up the requesting thread
395 synchronized (request) {
396 request.notifyAll();
397 }
398 break;
399
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700401 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700402 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800403 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700404 if (uiccCard == null) {
405 loge("iccTransmitApduLogicalChannel: No UICC");
406 request.result = new IccIoResult(0x6F, 0, (byte[])null);
407 synchronized (request) {
408 request.notifyAll();
409 }
410 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
412 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700413 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 iccArgument.channel, iccArgument.cla, iccArgument.command,
415 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 break;
419
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 ar = (AsyncResult) msg.obj;
422 request = (MainThreadRequest) ar.userObj;
423 if (ar.exception == null && ar.result != null) {
424 request.result = ar.result;
425 } else {
426 request.result = new IccIoResult(0x6F, 0, (byte[])null);
427 if (ar.result == null) {
428 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800429 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800431 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 } else {
433 loge("iccTransmitApduLogicalChannel: Unknown exception");
434 }
435 }
436 synchronized (request) {
437 request.notifyAll();
438 }
439 break;
440
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
442 request = (MainThreadRequest) msg.obj;
443 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800444 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 if (uiccCard == null) {
446 loge("iccTransmitApduBasicChannel: No UICC");
447 request.result = new IccIoResult(0x6F, 0, (byte[])null);
448 synchronized (request) {
449 request.notifyAll();
450 }
451 } else {
452 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
453 request);
454 uiccCard.iccTransmitApduBasicChannel(
455 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
456 iccArgument.p3, iccArgument.data, onCompleted);
457 }
458 break;
459
460 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
461 ar = (AsyncResult) msg.obj;
462 request = (MainThreadRequest) ar.userObj;
463 if (ar.exception == null && ar.result != null) {
464 request.result = ar.result;
465 } else {
466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
467 if (ar.result == null) {
468 loge("iccTransmitApduBasicChannel: Empty response");
469 } else if (ar.exception instanceof CommandException) {
470 loge("iccTransmitApduBasicChannel: CommandException: " +
471 ar.exception);
472 } else {
473 loge("iccTransmitApduBasicChannel: Unknown exception");
474 }
475 }
476 synchronized (request) {
477 request.notifyAll();
478 }
479 break;
480
481 case CMD_EXCHANGE_SIM_IO:
482 request = (MainThreadRequest) msg.obj;
483 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800484 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 if (uiccCard == null) {
486 loge("iccExchangeSimIO: No UICC");
487 request.result = new IccIoResult(0x6F, 0, (byte[])null);
488 synchronized (request) {
489 request.notifyAll();
490 }
491 } else {
492 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
493 request);
494 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
495 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
496 iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_EXCHANGE_SIM_IO_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6f, 0, (byte[])null);
507 }
508 synchronized (request) {
509 request.notifyAll();
510 }
511 break;
512
Derek Tan4d5e5c12014-02-04 11:54:58 -0800513 case CMD_SEND_ENVELOPE:
514 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800515 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700516 if (uiccCard == null) {
517 loge("sendEnvelopeWithStatus: No UICC");
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 synchronized (request) {
520 request.notifyAll();
521 }
522 } else {
523 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
524 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
525 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 break;
527
528 case EVENT_SEND_ENVELOPE_DONE:
529 ar = (AsyncResult) msg.obj;
530 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700531 if (ar.exception == null && ar.result != null) {
532 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
535 if (ar.result == null) {
536 loge("sendEnvelopeWithStatus: Empty response");
537 } else if (ar.exception instanceof CommandException) {
538 loge("sendEnvelopeWithStatus: CommandException: " +
539 ar.exception);
540 } else {
541 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
542 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 }
544 synchronized (request) {
545 request.notifyAll();
546 }
547 break;
548
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 case CMD_OPEN_CHANNEL:
550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800552 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800555 request.result = new IccOpenLogicalChannelResponse(-1,
556 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 synchronized (request) {
558 request.notifyAll();
559 }
560 } else {
561 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800562 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
563 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
567 case EVENT_OPEN_CHANNEL_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 int[] result = (int[]) ar.result;
573 int channelId = result[0];
574 byte[] selectResponse = null;
575 if (result.length > 1) {
576 selectResponse = new byte[result.length - 1];
577 for (int i = 1; i < result.length; ++i) {
578 selectResponse[i - 1] = (byte) result[i];
579 }
580 }
581 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 if (ar.result == null) {
585 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 if (ar.exception != null) {
588 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
589 }
590
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700591 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700592 if (ar.exception instanceof CommandException) {
593 CommandException.Error error =
594 ((CommandException) (ar.exception)).getCommandError();
595 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700597 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700598 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 }
600 }
601 openChannelResp = new IccOpenLogicalChannelResponse(
602 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700604 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 synchronized (request) {
606 request.notifyAll();
607 }
608 break;
609
610 case CMD_CLOSE_CHANNEL:
611 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800612 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700613 if (uiccCard == null) {
614 loge("iccCloseLogicalChannel: No UICC");
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
616 synchronized (request) {
617 request.notifyAll();
618 }
619 } else {
620 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
621 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
622 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
625 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800626 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
627 break;
628
629 case CMD_NV_READ_ITEM:
630 request = (MainThreadRequest) msg.obj;
631 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
632 mPhone.nvReadItem((Integer) request.argument, onCompleted);
633 break;
634
635 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800638 if (ar.exception == null && ar.result != null) {
639 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800641 request.result = "";
642 if (ar.result == null) {
643 loge("nvReadItem: Empty response");
644 } else if (ar.exception instanceof CommandException) {
645 loge("nvReadItem: CommandException: " +
646 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800648 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 }
650 }
651 synchronized (request) {
652 request.notifyAll();
653 }
654 break;
655
Jake Hambye994d462014-02-03 13:10:13 -0800656 case CMD_NV_WRITE_ITEM:
657 request = (MainThreadRequest) msg.obj;
658 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
659 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
660 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
661 break;
662
663 case EVENT_NV_WRITE_ITEM_DONE:
664 handleNullReturnEvent(msg, "nvWriteItem");
665 break;
666
667 case CMD_NV_WRITE_CDMA_PRL:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
670 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
671 break;
672
673 case EVENT_NV_WRITE_CDMA_PRL_DONE:
674 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
675 break;
676
677 case CMD_NV_RESET_CONFIG:
678 request = (MainThreadRequest) msg.obj;
679 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
680 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
681 break;
682
683 case EVENT_NV_RESET_CONFIG_DONE:
684 handleNullReturnEvent(msg, "nvResetConfig");
685 break;
686
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 case CMD_GET_PREFERRED_NETWORK_TYPE:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700690 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800691 break;
692
693 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
694 ar = (AsyncResult) msg.obj;
695 request = (MainThreadRequest) ar.userObj;
696 if (ar.exception == null && ar.result != null) {
697 request.result = ar.result; // Integer
698 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800699 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 if (ar.result == null) {
701 loge("getPreferredNetworkType: Empty response");
702 } else if (ar.exception instanceof CommandException) {
703 loge("getPreferredNetworkType: CommandException: " +
704 ar.exception);
705 } else {
706 loge("getPreferredNetworkType: Unknown exception");
707 }
708 }
709 synchronized (request) {
710 request.notifyAll();
711 }
712 break;
713
714 case CMD_SET_PREFERRED_NETWORK_TYPE:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
717 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700718 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800719 break;
720
721 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
722 handleNullReturnEvent(msg, "setPreferredNetworkType");
723 break;
724
Steven Liu4bf01bc2014-07-17 11:05:29 -0500725 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
726 request = (MainThreadRequest)msg.obj;
727 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
728 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
729 break;
730
731 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
732 ar = (AsyncResult)msg.obj;
733 request = (MainThreadRequest)ar.userObj;
734 request.result = ar;
735 synchronized (request) {
736 request.notifyAll();
737 }
738 break;
739
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800740 case CMD_SET_VOICEMAIL_NUMBER:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
743 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800744 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
745 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800746 break;
747
748 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
749 handleNullReturnEvent(msg, "setVoicemailNumber");
750 break;
751
Stuart Scott54788802015-03-30 13:18:01 -0700752 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
755 request);
756 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
757 break;
758
759 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
760 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
761 break;
762
Shishir Agrawal302c8692015-06-19 13:49:39 -0700763 case CMD_PERFORM_NETWORK_SCAN:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
766 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
767 break;
768
769 case EVENT_PERFORM_NETWORK_SCAN_DONE:
770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
772 CellNetworkScanResult cellScanResult;
773 if (ar.exception == null && ar.result != null) {
774 cellScanResult = new CellNetworkScanResult(
775 CellNetworkScanResult.STATUS_SUCCESS,
776 (List<OperatorInfo>) ar.result);
777 } else {
778 if (ar.result == null) {
779 loge("getCellNetworkScanResults: Empty response");
780 }
781 if (ar.exception != null) {
782 loge("getCellNetworkScanResults: Exception: " + ar.exception);
783 }
784 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
785 if (ar.exception instanceof CommandException) {
786 CommandException.Error error =
787 ((CommandException) (ar.exception)).getCommandError();
788 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
789 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
790 } else if (error == CommandException.Error.GENERIC_FAILURE) {
791 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
792 }
793 }
794 cellScanResult = new CellNetworkScanResult(errorCode, null);
795 }
796 request.result = cellScanResult;
797 synchronized (request) {
798 request.notifyAll();
799 }
800 break;
801
802 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
803 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700804 ManualNetworkSelectionArgument selArg =
805 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700806 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
807 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700808 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
809 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 break;
811
812 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
813 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
814 break;
815
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700816 case CMD_GET_MODEM_ACTIVITY_INFO:
817 request = (MainThreadRequest) msg.obj;
818 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700819 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700820 break;
821
822 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null && ar.result != null) {
826 request.result = ar.result;
827 } else {
828 if (ar.result == null) {
829 loge("queryModemActivityInfo: Empty response");
830 } else if (ar.exception instanceof CommandException) {
831 loge("queryModemActivityInfo: CommandException: " +
832 ar.exception);
833 } else {
834 loge("queryModemActivityInfo: Unknown exception");
835 }
836 }
Amit Mahajand4766222016-01-28 15:28:28 -0800837 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
838 if (request.result == null) {
839 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
840 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700841 synchronized (request) {
842 request.notifyAll();
843 }
844 break;
845
Meng Wang1a7c35a2016-05-05 20:56:15 -0700846 case CMD_SET_ALLOWED_CARRIERS:
847 request = (MainThreadRequest) msg.obj;
848 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
849 mPhone.setAllowedCarriers(
850 (List<CarrierIdentifier>) request.argument,
851 onCompleted);
852 break;
853
854 case EVENT_SET_ALLOWED_CARRIERS_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
860 if (ar.result == null) {
861 loge("setAllowedCarriers: Empty response");
862 } else if (ar.exception instanceof CommandException) {
863 loge("setAllowedCarriers: CommandException: " +
864 ar.exception);
865 } else {
866 loge("setAllowedCarriers: Unknown exception");
867 }
868 }
869 // Result cannot be null. Return -1 on error.
870 if (request.result == null) {
871 request.result = new int[]{-1};
872 }
873 synchronized (request) {
874 request.notifyAll();
875 }
876 break;
877
878 case CMD_GET_ALLOWED_CARRIERS:
879 request = (MainThreadRequest) msg.obj;
880 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
881 mPhone.getAllowedCarriers(onCompleted);
882 break;
883
884 case EVENT_GET_ALLOWED_CARRIERS_DONE:
885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null && ar.result != null) {
888 request.result = ar.result;
889 } else {
890 if (ar.result == null) {
891 loge("getAllowedCarriers: Empty response");
892 } else if (ar.exception instanceof CommandException) {
893 loge("getAllowedCarriers: CommandException: " +
894 ar.exception);
895 } else {
896 loge("getAllowedCarriers: Unknown exception");
897 }
898 }
899 // Result cannot be null. Return empty list of CarrierIdentifier.
900 if (request.result == null) {
901 request.result = new ArrayList<CarrierIdentifier>(0);
902 }
903 synchronized (request) {
904 request.notifyAll();
905 }
906 break;
907
Nathan Haroldb3014052017-01-25 15:57:32 -0800908 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
914 request.result = new IllegalArgumentException(
915 "Failed to retrieve Forbidden Plmns");
916 if (ar.result == null) {
917 loge("getForbiddenPlmns: Empty response");
918 } else {
919 loge("getForbiddenPlmns: Unknown exception");
920 }
921 }
922 synchronized (request) {
923 request.notifyAll();
924 }
925 break;
926
927 case CMD_GET_FORBIDDEN_PLMNS:
928 request = (MainThreadRequest) msg.obj;
929 uiccCard = getUiccCardFromRequest(request);
930 if (uiccCard == null) {
931 loge("getForbiddenPlmns() UiccCard is null");
932 request.result = new IllegalArgumentException(
933 "getForbiddenPlmns() UiccCard is null");
934 synchronized (request) {
935 request.notifyAll();
936 }
937 break;
938 }
939 Integer appType = (Integer) request.argument;
940 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
941 if (uiccApp == null) {
942 loge("getForbiddenPlmns() no app with specified type -- "
943 + appType);
944 request.result = new IllegalArgumentException("Failed to get UICC App");
945 synchronized (request) {
946 request.notifyAll();
947 }
948 break;
949 } else {
950 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
951 + " specified type -- " + appType);
952 }
953 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
954 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
955 onCompleted);
956 break;
957
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700958 default:
959 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
960 break;
961 }
962 }
Jake Hambye994d462014-02-03 13:10:13 -0800963
964 private void handleNullReturnEvent(Message msg, String command) {
965 AsyncResult ar = (AsyncResult) msg.obj;
966 MainThreadRequest request = (MainThreadRequest) ar.userObj;
967 if (ar.exception == null) {
968 request.result = true;
969 } else {
970 request.result = false;
971 if (ar.exception instanceof CommandException) {
972 loge(command + ": CommandException: " + ar.exception);
973 } else {
974 loge(command + ": Unknown exception");
975 }
976 }
977 synchronized (request) {
978 request.notifyAll();
979 }
980 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700981 }
982
983 /**
984 * Posts the specified command to be executed on the main thread,
985 * waits for the request to complete, and returns the result.
986 * @see #sendRequestAsync
987 */
988 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800989 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700990 }
991
992 /**
993 * Posts the specified command to be executed on the main thread,
994 * waits for the request to complete, and returns the result.
995 * @see #sendRequestAsync
996 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800997 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700998 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
999 throw new RuntimeException("This method will deadlock if called from the main thread.");
1000 }
1001
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001002 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001003 Message msg = mMainThreadHandler.obtainMessage(command, request);
1004 msg.sendToTarget();
1005
1006 // Wait for the request to complete
1007 synchronized (request) {
1008 while (request.result == null) {
1009 try {
1010 request.wait();
1011 } catch (InterruptedException e) {
1012 // Do nothing, go back and wait until the request is complete
1013 }
1014 }
1015 }
1016 return request.result;
1017 }
1018
1019 /**
1020 * Asynchronous ("fire and forget") version of sendRequest():
1021 * Posts the specified command to be executed on the main thread, and
1022 * returns immediately.
1023 * @see #sendRequest
1024 */
1025 private void sendRequestAsync(int command) {
1026 mMainThreadHandler.sendEmptyMessage(command);
1027 }
1028
1029 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001030 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1031 * @see {@link #sendRequest(int,Object)}
1032 */
1033 private void sendRequestAsync(int command, Object argument) {
1034 MainThreadRequest request = new MainThreadRequest(argument);
1035 Message msg = mMainThreadHandler.obtainMessage(command, request);
1036 msg.sendToTarget();
1037 }
1038
1039 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001040 * Initialize the singleton PhoneInterfaceManager instance.
1041 * This is only done once, at startup, from PhoneApp.onCreate().
1042 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001043 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001044 synchronized (PhoneInterfaceManager.class) {
1045 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001046 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001047 } else {
1048 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1049 }
1050 return sInstance;
1051 }
1052 }
1053
1054 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001055 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001056 mApp = app;
1057 mPhone = phone;
1058 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001059 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001060 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1061 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001062 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001063 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001064 mSubscriptionController = SubscriptionController.getInstance();
yinxua368f0e2017-04-17 11:45:04 -07001065 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001066
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001067 publish();
1068 }
1069
1070 private void publish() {
1071 if (DBG) log("publish: " + this);
1072
1073 ServiceManager.addService("phone", this);
1074 }
1075
Stuart Scott584921c2015-01-15 17:10:34 -08001076 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001077 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1078 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001079 }
1080
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001081 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1082 Phone phone = getPhoneFromRequest(request);
1083 return phone == null ? null :
1084 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1085 }
1086
Wink Saville36469e72014-06-11 15:17:00 -07001087 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001088 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001089 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 //
1092 // Implementation of the ITelephony interface.
1093 //
1094
1095 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001096 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001097 }
1098
Wink Savilleb564aae2014-10-23 10:18:09 -07001099 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001100 if (DBG) log("dial: " + number);
1101 // No permission check needed here: This is just a wrapper around the
1102 // ACTION_DIAL intent, which is available to any app since it puts up
1103 // the UI before it does anything.
1104
1105 String url = createTelUrl(number);
1106 if (url == null) {
1107 return;
1108 }
1109
1110 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001111 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001112 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1113 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1114 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1115 mApp.startActivity(intent);
1116 }
1117 }
1118
1119 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001120 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001121 }
1122
Wink Savilleb564aae2014-10-23 10:18:09 -07001123 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001124 if (DBG) log("call: " + number);
1125
1126 // This is just a wrapper around the ACTION_CALL intent, but we still
1127 // need to do a permission check since we're calling startActivity()
1128 // from the context of the phone app.
1129 enforceCallPermission();
1130
1131 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1132 != AppOpsManager.MODE_ALLOWED) {
1133 return;
1134 }
1135
1136 String url = createTelUrl(number);
1137 if (url == null) {
1138 return;
1139 }
1140
Wink Saville08874612014-08-31 19:19:58 -07001141 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001142 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001143 if (slist != null) {
1144 for (SubscriptionInfo subInfoRecord : slist) {
1145 if (subInfoRecord.getSubscriptionId() == subId) {
1146 isValid = true;
1147 break;
1148 }
Wink Saville08874612014-08-31 19:19:58 -07001149 }
1150 }
1151 if (isValid == false) {
1152 return;
1153 }
1154
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001155 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001156 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001157 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1158 mApp.startActivity(intent);
1159 }
1160
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001161 /**
1162 * End a call based on call state
1163 * @return true is a call was ended
1164 */
1165 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001166 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001167 }
1168
1169 /**
1170 * End a call based on the call state of the subId
1171 * @return true is a call was ended
1172 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001173 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001175 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001176 }
1177
1178 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001179 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001180 }
1181
Wink Savilleb564aae2014-10-23 10:18:09 -07001182 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001183 if (DBG) log("answerRingingCall...");
1184 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1185 // but that can probably wait till the big TelephonyManager API overhaul.
1186 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1187 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001188 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189 }
1190
1191 /**
1192 * Make the actual telephony calls to implement answerRingingCall().
1193 * This should only be called from the main thread of the Phone app.
1194 * @see #answerRingingCall
1195 *
1196 * TODO: it would be nice to return true if we answered the call, or
1197 * false if there wasn't actually a ringing incoming call, or some
1198 * other error occurred. (In other words, pass back the return value
1199 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1200 * But that would require calling this method via sendRequest() rather
1201 * than sendRequestAsync(), and right now we don't actually *need* that
1202 * return value, so let's just return void for now.
1203 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001204 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001205 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001207 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1208 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001209 if (hasActiveCall && hasHoldingCall) {
1210 // Both lines are in use!
1211 // TODO: provide a flag to let the caller specify what
1212 // policy to use if both lines are in use. (The current
1213 // behavior is hardwired to "answer incoming, end ongoing",
1214 // which is how the CALL button is specced to behave.)
1215 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1216 return;
1217 } else {
1218 // answerCall() will automatically hold the current active
1219 // call, if there is one.
1220 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1221 return;
1222 }
1223 } else {
1224 // No call was ringing.
1225 return;
1226 }
1227 }
1228
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001230 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001232 public void silenceRinger() {
1233 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 }
1235
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001236 @Override
1237 public boolean isOffhook(String callingPackage) {
1238 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001239 }
1240
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001241 @Override
1242 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1243 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1244 return false;
1245 }
1246
Sanket Padawe356d7632015-06-22 14:03:32 -07001247 final Phone phone = getPhone(subId);
1248 if (phone != null) {
1249 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1250 } else {
1251 return false;
1252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001253 }
1254
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001255 @Override
1256 public boolean isRinging(String callingPackage) {
1257 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001258 }
1259
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001260 @Override
1261 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1262 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1263 return false;
1264 }
1265
Sanket Padawe356d7632015-06-22 14:03:32 -07001266 final Phone phone = getPhone(subId);
1267 if (phone != null) {
1268 return (phone.getState() == PhoneConstants.State.RINGING);
1269 } else {
1270 return false;
1271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 }
1273
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001274 @Override
1275 public boolean isIdle(String callingPackage) {
1276 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001277 }
1278
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001279 @Override
1280 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1281 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1282 return false;
1283 }
1284
Sanket Padawe356d7632015-06-22 14:03:32 -07001285 final Phone phone = getPhone(subId);
1286 if (phone != null) {
1287 return (phone.getState() == PhoneConstants.State.IDLE);
1288 } else {
1289 return false;
1290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001291 }
1292
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001294 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001295 }
1296
Wink Savilleb564aae2014-10-23 10:18:09 -07001297 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001298 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001299 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1300 }
1301
1302 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001303 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001304 }
1305
Wink Savilleb564aae2014-10-23 10:18:09 -07001306 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001307 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001308 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1309 }
1310
1311 /** {@hide} */
1312 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001313 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Wink Savilleb564aae2014-10-23 10:18:09 -07001316 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001318 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 checkSimPin.start();
1320 return checkSimPin.unlockSim(null, pin);
1321 }
1322
Wink Saville9de0f752013-10-22 19:04:03 -07001323 /** {@hide} */
1324 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001325 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
1327
Wink Savilleb564aae2014-10-23 10:18:09 -07001328 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001330 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 checkSimPuk.start();
1332 return checkSimPuk.unlockSim(puk, pin);
1333 }
1334
1335 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001336 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337 * a synchronous one.
1338 */
1339 private static class UnlockSim extends Thread {
1340
1341 private final IccCard mSimCard;
1342
1343 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001344 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1345 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001346
1347 // For replies from SimCard interface
1348 private Handler mHandler;
1349
1350 // For async handler to identify request type
1351 private static final int SUPPLY_PIN_COMPLETE = 100;
1352
1353 public UnlockSim(IccCard simCard) {
1354 mSimCard = simCard;
1355 }
1356
1357 @Override
1358 public void run() {
1359 Looper.prepare();
1360 synchronized (UnlockSim.this) {
1361 mHandler = new Handler() {
1362 @Override
1363 public void handleMessage(Message msg) {
1364 AsyncResult ar = (AsyncResult) msg.obj;
1365 switch (msg.what) {
1366 case SUPPLY_PIN_COMPLETE:
1367 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1368 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001369 mRetryCount = msg.arg1;
1370 if (ar.exception != null) {
1371 if (ar.exception instanceof CommandException &&
1372 ((CommandException)(ar.exception)).getCommandError()
1373 == CommandException.Error.PASSWORD_INCORRECT) {
1374 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1375 } else {
1376 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1377 }
1378 } else {
1379 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 mDone = true;
1382 UnlockSim.this.notifyAll();
1383 }
1384 break;
1385 }
1386 }
1387 };
1388 UnlockSim.this.notifyAll();
1389 }
1390 Looper.loop();
1391 }
1392
1393 /*
1394 * Use PIN or PUK to unlock SIM card
1395 *
1396 * If PUK is null, unlock SIM card with PIN
1397 *
1398 * If PUK is not null, unlock SIM card with PUK and set PIN code
1399 */
Wink Saville9de0f752013-10-22 19:04:03 -07001400 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401
1402 while (mHandler == null) {
1403 try {
1404 wait();
1405 } catch (InterruptedException e) {
1406 Thread.currentThread().interrupt();
1407 }
1408 }
1409 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1410
1411 if (puk == null) {
1412 mSimCard.supplyPin(pin, callback);
1413 } else {
1414 mSimCard.supplyPuk(puk, pin, callback);
1415 }
1416
1417 while (!mDone) {
1418 try {
1419 Log.d(LOG_TAG, "wait for done");
1420 wait();
1421 } catch (InterruptedException e) {
1422 // Restore the interrupted status
1423 Thread.currentThread().interrupt();
1424 }
1425 }
1426 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001427 int[] resultArray = new int[2];
1428 resultArray[0] = mResult;
1429 resultArray[1] = mRetryCount;
1430 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 }
1432 }
1433
1434 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001435 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001436
1437 }
1438
Wink Savilleb564aae2014-10-23 10:18:09 -07001439 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 // No permission check needed here: this call is harmless, and it's
1441 // needed for the ServiceState.requestStateUpdate() call (which is
1442 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001443 final Phone phone = getPhone(subId);
1444 if (phone != null) {
1445 phone.updateServiceLocation();
1446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 }
1448
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001449 @Override
1450 public boolean isRadioOn(String callingPackage) {
1451 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001452 }
1453
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001454 @Override
1455 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1456 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1457 return false;
1458 }
1459 return isRadioOnForSubscriber(subId);
1460 }
1461
1462 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001463 final Phone phone = getPhone(subId);
1464 if (phone != null) {
1465 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1466 } else {
1467 return false;
1468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 }
1470
1471 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001472 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001473
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474 }
Wink Saville36469e72014-06-11 15:17:00 -07001475
Wink Savilleb564aae2014-10-23 10:18:09 -07001476 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001478 final Phone phone = getPhone(subId);
1479 if (phone != null) {
1480 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1481 }
Wink Saville36469e72014-06-11 15:17:00 -07001482 }
1483
1484 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001486 }
1487
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001489 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001490 final Phone phone = getPhone(subId);
1491 if (phone == null) {
1492 return false;
1493 }
1494 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001495 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001496 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 }
1498 return true;
1499 }
Wink Saville36469e72014-06-11 15:17:00 -07001500
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001501 public boolean needMobileRadioShutdown() {
1502 /*
1503 * If any of the Radios are available, it will need to be
1504 * shutdown. So return true if any Radio is available.
1505 */
1506 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1507 Phone phone = PhoneFactory.getPhone(i);
1508 if (phone != null && phone.isRadioAvailable()) return true;
1509 }
1510 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1511 return false;
1512 }
1513
1514 public void shutdownMobileRadios() {
1515 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1516 logv("Shutting down Phone " + i);
1517 shutdownRadioUsingPhoneId(i);
1518 }
1519 }
1520
1521 private void shutdownRadioUsingPhoneId(int phoneId) {
1522 enforceModifyPermission();
1523 Phone phone = PhoneFactory.getPhone(phoneId);
1524 if (phone != null && phone.isRadioAvailable()) {
1525 phone.shutdownRadio();
1526 }
1527 }
1528
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001530 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001531 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1532 if (defaultPhone != null) {
1533 defaultPhone.setRadioPower(turnOn);
1534 return true;
1535 } else {
1536 loge("There's no default phone.");
1537 return false;
1538 }
Wink Saville36469e72014-06-11 15:17:00 -07001539 }
1540
Wink Savilleb564aae2014-10-23 10:18:09 -07001541 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001542 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001543 final Phone phone = getPhone(subId);
1544 if (phone != null) {
1545 phone.setRadioPower(turnOn);
1546 return true;
1547 } else {
1548 return false;
1549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 }
1551
Wink Saville36469e72014-06-11 15:17:00 -07001552 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001553 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 public boolean enableDataConnectivity() {
1555 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001556 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001557 final Phone phone = getPhone(subId);
1558 if (phone != null) {
1559 phone.setDataEnabled(true);
1560 return true;
1561 } else {
1562 return false;
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Wink Saville36469e72014-06-11 15:17:00 -07001566 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001567 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 public boolean disableDataConnectivity() {
1569 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001570 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001571 final Phone phone = getPhone(subId);
1572 if (phone != null) {
1573 phone.setDataEnabled(false);
1574 return true;
1575 } else {
1576 return false;
1577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 }
1579
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001581 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001582 final Phone phone = getPhone(subId);
1583 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001584 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 } else {
1586 return false;
1587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 }
1589
1590 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001591 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001592 }
1593
pkanwarae03a6b2016-11-06 20:37:09 -08001594 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001595 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001596 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1597 return;
1598 }
1599 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1600 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1601 };
1602
Wink Savilleb564aae2014-10-23 10:18:09 -07001603 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001605 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1606 return false;
1607 }
Wink Saville36469e72014-06-11 15:17:00 -07001608 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 }
1610
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001612 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001613 }
1614
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001615 public int getCallStateForSlot(int slotIndex) {
1616 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001617 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001618 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001619 }
1620
Sanket Padawe356d7632015-06-22 14:03:32 -07001621 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001623 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001624 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001625 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001626 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001627 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001628 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
1630
Sanket Padawe356d7632015-06-22 14:03:32 -07001631 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001633 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001634 if (phone != null) {
1635 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1636 } else {
1637 return TelephonyManager.DATA_ACTIVITY_NONE;
1638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 }
1640
1641 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001642 public Bundle getCellLocation(String callingPackage) {
1643 enforceFineOrCoarseLocationPermission("getCellLocation");
1644
1645 // OP_COARSE_LOCATION controls both fine and coarse location.
1646 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1647 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001648 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001649 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001652 if (checkIfCallerIsSelfOrForegroundUser() ||
1653 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 if (DBG_LOC) log("getCellLocation: is active user");
1655 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001656 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001657 if (phone == null) {
1658 return null;
1659 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001660
1661 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1662 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 return data;
1664 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001665 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 return null;
1667 }
1668 }
1669
Svetoslav64fad262015-04-14 14:35:21 -07001670 private void enforceFineOrCoarseLocationPermission(String message) {
1671 try {
1672 mApp.enforceCallingOrSelfPermission(
1673 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1674 } catch (SecurityException e) {
1675 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1676 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1677 // is the weaker precondition
1678 mApp.enforceCallingOrSelfPermission(
1679 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1680 }
1681 }
1682
1683
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 @Override
1685 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001686 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001687 }
1688
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 mApp.enforceCallingOrSelfPermission(
1692 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 final Phone phone = getPhone(subId);
1694 if (phone != null) {
1695 phone.enableLocationUpdates();
1696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 }
1698
1699 @Override
1700 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001701 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001702 }
1703
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001705 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 mApp.enforceCallingOrSelfPermission(
1707 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 final Phone phone = getPhone(subId);
1709 if (phone != null) {
1710 phone.disableLocationUpdates();
1711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 }
1713
1714 @Override
1715 @SuppressWarnings("unchecked")
1716 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001717 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1718
1719 // OP_COARSE_LOCATION controls both fine and coarse location.
1720 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1721 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1722 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 }
1724
1725 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1726 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1727 return null;
1728 }
Svetoslav64fad262015-04-14 14:35:21 -07001729
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001730 if (checkIfCallerIsSelfOrForegroundUser() ||
1731 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1733
1734 ArrayList<NeighboringCellInfo> cells = null;
1735
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001736 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 try {
1738 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001739 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001740 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001742 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
1744 return cells;
1745 } else {
1746 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1747 return null;
1748 }
1749 }
1750
1751
1752 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001753 public List<CellInfo> getAllCellInfo(String callingPackage) {
1754 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1755
1756 // OP_COARSE_LOCATION controls both fine and coarse location.
1757 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1758 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1759 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 }
1761
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001762 if (checkIfCallerIsSelfOrForegroundUser() ||
1763 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001765 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001766 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1767 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001768 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1769 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001770 }
1771 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 } else {
1773 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1774 return null;
1775 }
1776 }
1777
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001778 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001780 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001781 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1782 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 }
1784
Shishir Agrawala9f32182016-04-12 12:00:16 -07001785 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001786 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001787 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1788 return null;
1789 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001790 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001791 return phone == null ? null : phone.getImei();
1792 }
1793
1794 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001795 public String getMeidForSlot(int slotIndex, String callingPackage) {
1796 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1797 return null;
1798 }
1799 Phone phone = PhoneFactory.getPhone(slotIndex);
1800 return phone == null ? null : phone.getMeid();
1801 }
1802
1803 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001804 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001805 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1806 return null;
1807 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001808 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001809 return phone == null ? null : phone.getDeviceSvn();
1810 }
1811
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 //
1813 // Internal helper methods.
1814 //
1815
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001816 /**
1817 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1818 */
1819 private boolean checkCallerInteractAcrossUsersFull() {
1820 return mPhone.getContext().checkCallingOrSelfPermission(
1821 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1822 == PackageManager.PERMISSION_GRANTED;
1823 }
1824
Jake Hambye994d462014-02-03 13:10:13 -08001825 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 boolean ok;
1827
1828 boolean self = Binder.getCallingUid() == Process.myUid();
1829 if (!self) {
1830 // Get the caller's user id then clear the calling identity
1831 // which will be restored in the finally clause.
1832 int callingUser = UserHandle.getCallingUserId();
1833 long ident = Binder.clearCallingIdentity();
1834
1835 try {
1836 // With calling identity cleared the current user is the foreground user.
1837 int foregroundUser = ActivityManager.getCurrentUser();
1838 ok = (foregroundUser == callingUser);
1839 if (DBG_LOC) {
1840 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1841 + " callingUser=" + callingUser + " ok=" + ok);
1842 }
1843 } catch (Exception ex) {
1844 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1845 ok = false;
1846 } finally {
1847 Binder.restoreCallingIdentity(ident);
1848 }
1849 } else {
1850 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1851 ok = true;
1852 }
1853 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1854 return ok;
1855 }
1856
1857 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1859 *
1860 * @throws SecurityException if the caller does not have the required permission
1861 */
1862 private void enforceModifyPermission() {
1863 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1864 }
1865
1866 /**
Junda Liua2e36012014-07-09 18:30:01 -07001867 * Make sure either system app or the caller has carrier privilege.
1868 *
1869 * @throws SecurityException if the caller does not have the required permission/privilege
1870 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001871 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001872 int permission = mApp.checkCallingOrSelfPermission(
1873 android.Manifest.permission.MODIFY_PHONE_STATE);
1874 if (permission == PackageManager.PERMISSION_GRANTED) {
1875 return;
1876 }
1877
1878 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001879 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001880 }
1881
1882 /**
1883 * Make sure the caller has carrier privilege.
1884 *
1885 * @throws SecurityException if the caller does not have the required permission
1886 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001887 private void enforceCarrierPrivilege(int subId) {
1888 if (getCarrierPrivilegeStatus(subId) !=
1889 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001890 loge("No Carrier Privilege.");
1891 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001892 }
1893 }
1894
1895 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 * Make sure the caller has the CALL_PHONE permission.
1897 *
1898 * @throws SecurityException if the caller does not have the required permission
1899 */
1900 private void enforceCallPermission() {
1901 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1902 }
1903
Stuart Scott8eef64f2015-04-08 15:13:54 -07001904 private void enforceConnectivityInternalPermission() {
1905 mApp.enforceCallingOrSelfPermission(
1906 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1907 "ConnectivityService");
1908 }
1909
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 private String createTelUrl(String number) {
1911 if (TextUtils.isEmpty(number)) {
1912 return null;
1913 }
1914
Jake Hambye994d462014-02-03 13:10:13 -08001915 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 }
1917
Ihab Awadf9e92732013-12-05 18:02:52 -08001918 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1920 }
1921
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001922 private static void logv(String msg) {
1923 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1924 }
1925
Ihab Awadf9e92732013-12-05 18:02:52 -08001926 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001927 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1928 }
1929
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001930 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001932 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001933 }
1934
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001936 public int getActivePhoneTypeForSlot(int slotIndex) {
1937 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001938 if (phone == null) {
1939 return PhoneConstants.PHONE_TYPE_NONE;
1940 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001941 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
1945 /**
1946 * Returns the CDMA ERI icon index to display
1947 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001948 @Override
1949 public int getCdmaEriIconIndex(String callingPackage) {
1950 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001951 }
1952
Sanket Padawe356d7632015-06-22 14:03:32 -07001953 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001954 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1955 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1956 return -1;
1957 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 final Phone phone = getPhone(subId);
1959 if (phone != null) {
1960 return phone.getCdmaEriIconIndex();
1961 } else {
1962 return -1;
1963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964 }
1965
1966 /**
1967 * Returns the CDMA ERI icon mode,
1968 * 0 - ON
1969 * 1 - FLASHING
1970 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001971 @Override
1972 public int getCdmaEriIconMode(String callingPackage) {
1973 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001974 }
1975
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001977 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1978 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1979 return -1;
1980 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001981 final Phone phone = getPhone(subId);
1982 if (phone != null) {
1983 return phone.getCdmaEriIconMode();
1984 } else {
1985 return -1;
1986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
1988
1989 /**
1990 * Returns the CDMA ERI text,
1991 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001992 @Override
1993 public String getCdmaEriText(String callingPackage) {
1994 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001995 }
1996
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001998 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1999 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
2000 return null;
2001 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002002 final Phone phone = getPhone(subId);
2003 if (phone != null) {
2004 return phone.getCdmaEriText();
2005 } else {
2006 return null;
2007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 }
2009
2010 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002011 * Returns the CDMA MDN.
2012 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002013 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002014 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002015 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002016 final Phone phone = getPhone(subId);
2017 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2018 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002019 } else {
2020 return null;
2021 }
2022 }
2023
2024 /**
2025 * Returns the CDMA MIN.
2026 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002027 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002028 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002029 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002030 final Phone phone = getPhone(subId);
2031 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2032 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002033 } else {
2034 return null;
2035 }
2036 }
2037
2038 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 * Returns true if CDMA provisioning needs to run.
2040 */
2041 public boolean needsOtaServiceProvisioning() {
2042 return mPhone.needsOtaServiceProvisioning();
2043 }
2044
2045 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002046 * Sets the voice mail number of a given subId.
2047 */
2048 @Override
2049 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002050 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002051 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2052 new Pair<String, String>(alphaTag, number), new Integer(subId));
2053 return success;
2054 }
2055
Ta-wei Yen87c49842016-05-13 21:19:52 -07002056 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002057 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2059 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2060 if (!TextUtils.equals(callingPackage, systemDialer)) {
2061 throw new SecurityException("caller must be system dialer");
2062 }
2063 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2064 if (phoneAccountHandle == null){
2065 return null;
2066 }
2067 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2068 }
2069
2070 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002071 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002072 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2073 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2074 return null;
2075 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002076 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2077 }
2078
2079 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002080 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2081 VisualVoicemailSmsFilterSettings settings) {
2082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002083 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002084 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2085 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002086 }
2087
2088 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002089 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2090 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002091 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002092 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002093 }
2094
2095 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002096 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2097 String callingPackage, int subId) {
2098 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002099 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002100 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002101 }
2102
2103 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002104 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002105 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002106 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002107 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2108 }
2109
2110 @Override
2111 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2112 String number, int port, String text, PendingIntent sentIntent) {
2113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002114 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002115 enforceSendSmsPermission();
2116 // Make the calls as the phone process.
2117 final long identity = Binder.clearCallingIdentity();
2118 try {
2119 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2120 if (port == 0) {
2121 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2122 sentIntent, null, false);
2123 } else {
2124 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2125 smsManager.sendDataMessageWithSelfPermissions(number, null,
2126 (short) port, data, sentIntent, null);
2127 }
2128 } finally {
2129 Binder.restoreCallingIdentity(identity);
2130 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002131 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002132 /**
fionaxu0152e512016-11-14 13:36:14 -08002133 * Sets the voice activation state of a given subId.
2134 */
2135 @Override
2136 public void setVoiceActivationState(int subId, int activationState) {
2137 enforceModifyPermissionOrCarrierPrivilege(subId);
2138 final Phone phone = getPhone(subId);
2139 if (phone != null) {
2140 phone.setVoiceActivationState(activationState);
2141 } else {
2142 loge("setVoiceActivationState fails with invalid subId: " + subId);
2143 }
2144 }
2145
2146 /**
2147 * Sets the data activation state of a given subId.
2148 */
2149 @Override
2150 public void setDataActivationState(int subId, int activationState) {
2151 enforceModifyPermissionOrCarrierPrivilege(subId);
2152 final Phone phone = getPhone(subId);
2153 if (phone != null) {
2154 phone.setDataActivationState(activationState);
2155 } else {
2156 loge("setVoiceActivationState fails with invalid subId: " + subId);
2157 }
2158 }
2159
2160 /**
2161 * Returns the voice activation state of a given subId.
2162 */
2163 @Override
2164 public int getVoiceActivationState(int subId, String callingPackage) {
2165 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2166 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2167 }
2168 final Phone phone = getPhone(subId);
2169 if (phone != null) {
2170 return phone.getVoiceActivationState();
2171 } else {
2172 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2173 }
2174 }
2175
2176 /**
2177 * Returns the data activation state of a given subId.
2178 */
2179 @Override
2180 public int getDataActivationState(int subId, String callingPackage) {
2181 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2182 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2183 }
2184 final Phone phone = getPhone(subId);
2185 if (phone != null) {
2186 return phone.getDataActivationState();
2187 } else {
2188 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2189 }
2190 }
2191
2192 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 * Returns the unread count of voicemails
2194 */
2195 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002196 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002197 }
2198
2199 /**
2200 * Returns the unread count of voicemails for a subId
2201 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002202 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002203 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002204 final Phone phone = getPhone(subId);
2205 if (phone != null) {
2206 return phone.getVoiceMessageCount();
2207 } else {
2208 return 0;
2209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
2211
2212 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002213 * returns true, if the device is in a state where both voice and data
2214 * are supported simultaneously. This can change based on location or network condition.
2215 */
2216 @Override
2217 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2218 final Phone phone = getPhone(subId);
2219 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2220 }
2221
2222 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002223 * Send the dialer code if called from the current default dialer or the caller has
2224 * carrier privilege.
2225 * @param inputCode The dialer code to send
2226 */
2227 @Override
2228 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2229 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2230 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2231 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2232 enforceCarrierPrivilege(getDefaultSubscription());
2233 }
2234 mPhone.sendDialerSpecialCode(inputCode);
2235 }
2236
2237 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002238 * Returns the data network type.
2239 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 *
2241 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2242 */
2243 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002244 public int getNetworkType() {
2245 final Phone phone = getPhone(getDefaultSubscription());
2246 if (phone != null) {
2247 return phone.getServiceState().getDataNetworkType();
2248 } else {
2249 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2250 }
Wink Saville36469e72014-06-11 15:17:00 -07002251 }
2252
2253 /**
2254 * Returns the network type for a subId
2255 */
2256 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002257 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2258 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2259 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2260 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002261
Sanket Padawe356d7632015-06-22 14:03:32 -07002262 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002263 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002264 return phone.getServiceState().getDataNetworkType();
2265 } else {
2266 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269
2270 /**
2271 * Returns the data network type
2272 */
2273 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002274 public int getDataNetworkType(String callingPackage) {
2275 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002276 }
2277
2278 /**
2279 * Returns the data network type for a subId
2280 */
2281 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002282 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2283 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2284 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2285 }
2286
Sanket Padawe356d7632015-06-22 14:03:32 -07002287 final Phone phone = getPhone(subId);
2288 if (phone != null) {
2289 return phone.getServiceState().getDataNetworkType();
2290 } else {
2291 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
2295 /**
Wink Saville36469e72014-06-11 15:17:00 -07002296 * Returns the Voice network type for a subId
2297 */
2298 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002299 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2300 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2301 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2302 }
2303
Sanket Padawe356d7632015-06-22 14:03:32 -07002304 final Phone phone = getPhone(subId);
2305 if (phone != null) {
2306 return phone.getServiceState().getVoiceNetworkType();
2307 } else {
2308 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 }
2311
2312 /**
2313 * @return true if a ICC card is present
2314 */
2315 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002316 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002317 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2318 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002319 }
2320
2321 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002322 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002323 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002324 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002325 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2326 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002327 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002328 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002329 } else {
2330 return false;
2331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 }
2333
2334 /**
2335 * Return if the current radio is LTE on CDMA. This
2336 * is a tri-state return value as for a period of time
2337 * the mode may be unknown.
2338 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002339 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002341 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002343 @Override
2344 public int getLteOnCdmaMode(String callingPackage) {
2345 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002346 }
2347
Sanket Padawe356d7632015-06-22 14:03:32 -07002348 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002349 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2350 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2351 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2352 }
2353
Sanket Padawe356d7632015-06-22 14:03:32 -07002354 final Phone phone = getPhone(subId);
2355 if (phone == null) {
2356 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2357 } else {
2358 return phone.getLteOnCdmaMode();
2359 }
Wink Saville36469e72014-06-11 15:17:00 -07002360 }
2361
2362 public void setPhone(Phone phone) {
2363 mPhone = phone;
2364 }
2365
2366 /**
2367 * {@hide}
2368 * Returns Default subId, 0 in the case of single standby.
2369 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002370 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002371 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002372 }
2373
Shishir Agrawala9f32182016-04-12 12:00:16 -07002374 private int getSlotForDefaultSubscription() {
2375 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2376 }
2377
Wink Savilleb564aae2014-10-23 10:18:09 -07002378 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002379 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002381
2382 /**
2383 * @see android.telephony.TelephonyManager.WifiCallingChoices
2384 */
2385 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002386 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2387 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002388 }
2389
2390 /**
2391 * @see android.telephony.TelephonyManager.WifiCallingChoices
2392 */
2393 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002394 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2395 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2396 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002397 }
2398
Sailesh Nepald1e68152013-12-12 19:08:02 -08002399 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002400 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002401 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002402 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002403
Shishir Agrawal566b7612013-10-28 14:41:00 -07002404 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002405 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2406 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002407 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002408
Derek Tan740e1672017-06-27 14:56:27 -07002409 if (TextUtils.equals(ISDR_AID, aid)) {
2410 // Only allows LPA to open logical channel to ISD-R.
2411 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2412 ComponentInfo bestComponent =
2413 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2414 if (bestComponent == null
2415 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2416 loge("The calling package is not allowed to access ISD-R.");
2417 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2418 }
2419 }
2420
2421 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002422 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002423 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002424 if (DBG) log("iccOpenLogicalChannel: " + response);
2425 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002426 }
2427
2428 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002429 public boolean iccCloseLogicalChannel(int subId, int channel) {
2430 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002431
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002432 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002433 if (channel < 0) {
2434 return false;
2435 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002436 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002437 if (DBG) log("iccCloseLogicalChannel: " + success);
2438 return success;
2439 }
2440
2441 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002442 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002443 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002444 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002445
2446 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002447 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2448 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002449 " data=" + data);
2450 }
2451
2452 if (channel < 0) {
2453 return "";
2454 }
2455
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002456 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002457 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002458 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2459
Shishir Agrawal566b7612013-10-28 14:41:00 -07002460 // Append the returned status code to the end of the response payload.
2461 String s = Integer.toHexString(
2462 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002463 if (response.payload != null) {
2464 s = IccUtils.bytesToHexString(response.payload) + s;
2465 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002466 return s;
2467 }
Jake Hambye994d462014-02-03 13:10:13 -08002468
Evan Charltonc66da362014-05-16 14:06:40 -07002469 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002470 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002471 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002472 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002473
2474 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002475 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2476 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002477 }
2478
2479 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002480 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002481 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2482
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002483 // Append the returned status code to the end of the response payload.
2484 String s = Integer.toHexString(
2485 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002486 if (response.payload != null) {
2487 s = IccUtils.bytesToHexString(response.payload) + s;
2488 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002489 return s;
2490 }
2491
2492 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002493 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002494 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002495 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002496
2497 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002498 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002499 p1 + " " + p2 + " " + p3 + ":" + filePath);
2500 }
2501
2502 IccIoResult response =
2503 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002504 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2505 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002506
2507 if (DBG) {
2508 log("Exchange SIM_IO [R]" + response);
2509 }
2510
2511 byte[] result = null;
2512 int length = 2;
2513 if (response.payload != null) {
2514 length = 2 + response.payload.length;
2515 result = new byte[length];
2516 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2517 } else {
2518 result = new byte[length];
2519 }
2520
2521 result[length - 1] = (byte) response.sw2;
2522 result[length - 2] = (byte) response.sw1;
2523 return result;
2524 }
2525
Nathan Haroldb3014052017-01-25 15:57:32 -08002526 /**
2527 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2528 * on a particular subscription
2529 */
2530 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002531 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2532 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002533 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2534 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2535 return null;
2536 }
2537 Object response = sendRequest(
2538 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2539 if (response instanceof String[]) {
2540 return (String[]) response;
2541 }
2542 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2543 return null;
2544 }
2545
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002546 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002547 public String sendEnvelopeWithStatus(int subId, String content) {
2548 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002549
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002550 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002551 if (response.payload == null) {
2552 return "";
2553 }
2554
2555 // Append the returned status code to the end of the response payload.
2556 String s = Integer.toHexString(
2557 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2558 s = IccUtils.bytesToHexString(response.payload) + s;
2559 return s;
2560 }
2561
Jake Hambye994d462014-02-03 13:10:13 -08002562 /**
2563 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2564 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2565 *
2566 * @param itemID the ID of the item to read
2567 * @return the NV item as a String, or null on error.
2568 */
2569 @Override
2570 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002571 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002572 if (DBG) log("nvReadItem: item " + itemID);
2573 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2574 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2575 return value;
2576 }
2577
2578 /**
2579 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2580 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2581 *
2582 * @param itemID the ID of the item to read
2583 * @param itemValue the value to write, as a String
2584 * @return true on success; false on any failure
2585 */
2586 @Override
2587 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002588 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002589 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2590 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2591 new Pair<Integer, String>(itemID, itemValue));
2592 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2593 return success;
2594 }
2595
2596 /**
2597 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2598 * Used for device configuration by some CDMA operators.
2599 *
2600 * @param preferredRoamingList byte array containing the new PRL
2601 * @return true on success; false on any failure
2602 */
2603 @Override
2604 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002605 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002606 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2607 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2608 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2609 return success;
2610 }
2611
2612 /**
2613 * Perform the specified type of NV config reset.
2614 * Used for device configuration by some CDMA operators.
2615 *
2616 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2617 * @return true on success; false on any failure
2618 */
2619 @Override
2620 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002621 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002622 if (DBG) log("nvResetConfig: type " + resetType);
2623 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2624 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2625 return success;
2626 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002627
2628 /**
Wink Saville36469e72014-06-11 15:17:00 -07002629 * {@hide}
2630 * Returns Default sim, 0 in the case of single standby.
2631 */
2632 public int getDefaultSim() {
2633 //TODO Need to get it from Telephony Devcontroller
2634 return 0;
2635 }
2636
Svet Ganovb320e182015-04-16 12:30:10 -07002637 public String[] getPcscfAddress(String apnType, String callingPackage) {
2638 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2639 return new String[0];
2640 }
2641
2642
ram87fca6f2014-07-18 18:58:44 +05302643 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002644 }
2645
Brad Ebinger51f743a2017-01-23 13:50:20 -08002646 /**
2647 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2648 * feature or {@link null} if the service is not available. If an ImsServiceController is
2649 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2650 * feature updates.
2651 */
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002652 public IImsServiceController getImsServiceControllerAndListen(int slotIndex, int feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002653 IImsServiceFeatureListener callback) {
2654 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002655 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotIndex, feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002656 callback);
2657 }
2658
Wink Saville36469e72014-06-11 15:17:00 -07002659 public void setImsRegistrationState(boolean registered) {
2660 enforceModifyPermission();
2661 mPhone.setImsRegistrationState(registered);
2662 }
2663
2664 /**
Stuart Scott54788802015-03-30 13:18:01 -07002665 * Set the network selection mode to automatic.
2666 *
2667 */
2668 @Override
2669 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002670 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002671 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2672 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2673 }
2674
2675 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002676 * Set the network selection mode to manual with the selected carrier.
2677 */
2678 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002679 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2680 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002681 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002682 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002683 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2684 persistSelection);
2685 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002686 }
2687
2688 /**
2689 * Scans for available networks.
2690 */
2691 @Override
2692 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002693 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002694 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2695 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2696 CMD_PERFORM_NETWORK_SCAN, null, subId);
2697 return result;
2698 }
2699
2700 /**
yinxua368f0e2017-04-17 11:45:04 -07002701 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002702 *
yinxua368f0e2017-04-17 11:45:04 -07002703 * @param subId id of the subscription
2704 * @param request contains the radio access networks with bands/channels to scan
2705 * @param messenger callback messenger for scan results or errors
2706 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002707 * @return the id of the requested scan which can be used to stop the scan.
2708 */
2709 @Override
2710 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2711 IBinder binder) {
yinxua368f0e2017-04-17 11:45:04 -07002712 enforceModifyPermissionOrCarrierPrivilege(subId);
2713 return mNetworkScanRequestTracker.startNetworkScan(
2714 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002715 }
2716
2717 /**
2718 * Stops an existing network scan with the given scanId.
yinxua368f0e2017-04-17 11:45:04 -07002719 *
2720 * @param subId id of the subscription
2721 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002722 */
2723 @Override
2724 public void stopNetworkScan(int subId, int scanId) {
yinxua368f0e2017-04-17 11:45:04 -07002725 enforceModifyPermissionOrCarrierPrivilege(subId);
2726 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002727 }
2728
2729 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002730 * Get the calculated preferred network type.
2731 * Used for debugging incorrect network type.
2732 *
2733 * @return the preferred network type, defined in RILConstants.java.
2734 */
2735 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002736 public int getCalculatedPreferredNetworkType(String callingPackage) {
2737 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2738 return RILConstants.PREFERRED_NETWORK_MODE;
2739 }
2740
Amit Mahajan43330e02014-11-18 11:54:45 -08002741 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002742 }
2743
2744 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002745 * Get the preferred network type.
2746 * Used for device configuration by some CDMA operators.
2747 *
2748 * @return the preferred network type, defined in RILConstants.java.
2749 */
2750 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002751 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002752 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002753 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002754 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002755 int networkType = (result != null ? result[0] : -1);
2756 if (DBG) log("getPreferredNetworkType: " + networkType);
2757 return networkType;
2758 }
2759
2760 /**
2761 * Set the preferred network type.
2762 * Used for device configuration by some CDMA operators.
2763 *
2764 * @param networkType the preferred network type, defined in RILConstants.java.
2765 * @return true on success; false on any failure.
2766 */
2767 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002768 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002769 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002770 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2771 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002772 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002773 if (success) {
2774 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002775 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002776 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002777 return success;
2778 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002779
2780 /**
Junda Liu475951f2014-11-07 16:45:03 -08002781 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2782 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2783 * tethering.
2784 *
2785 * @return 0: Not required. 1: required. 2: Not set.
2786 * @hide
2787 */
2788 @Override
2789 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002790 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002791 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2792 Settings.Global.TETHER_DUN_REQUIRED, 2);
2793 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2794 // config_tether_apndata.
2795 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2796 dunRequired = 1;
2797 }
2798 return dunRequired;
2799 }
2800
2801 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002802 * Set mobile data enabled
2803 * Used by the user through settings etc to turn on/off mobile data
2804 *
2805 * @param enable {@code true} turn turn data on, else {@code false}
2806 */
2807 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002808 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002809 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002810 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002811 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002812 Phone phone = PhoneFactory.getPhone(phoneId);
2813 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002814 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002815 phone.setDataEnabled(enable);
2816 } else {
2817 loge("setDataEnabled: no phone for subId=" + subId);
2818 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002819 }
2820
2821 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002822 * Get whether mobile data is enabled.
2823 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002824 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002825 *
2826 * @return {@code true} if data is enabled else {@code false}
2827 */
2828 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002829 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002830 try {
2831 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2832 null);
2833 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002834 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002835 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002836 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002837 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002838 Phone phone = PhoneFactory.getPhone(phoneId);
2839 if (phone != null) {
2840 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002841 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002842 return retVal;
2843 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002844 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002845 return false;
2846 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002847 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002848
2849 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002850 public int getCarrierPrivilegeStatus(int subId) {
2851 final Phone phone = getPhone(subId);
2852 if (phone == null) {
2853 loge("getCarrierPrivilegeStatus: Invalid subId");
2854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2855 }
2856 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002857 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002858 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002859 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2860 }
2861 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002862 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002863 }
Junda Liu29340342014-07-10 15:23:27 -07002864
2865 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002866 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002867 if (TextUtils.isEmpty(pkgName))
2868 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002869 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002870 if (card == null) {
2871 loge("checkCarrierPrivilegesForPackage: No UICC");
2872 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2873 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002874 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2875 }
2876
2877 @Override
2878 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002879 if (TextUtils.isEmpty(pkgName))
2880 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002881 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2882 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2883 UiccCard card = UiccController.getInstance().getUiccCard(i);
2884 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002885 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002886 continue;
2887 }
2888
2889 result = card.getCarrierPrivilegeStatus(
2890 mPhone.getContext().getPackageManager(), pkgName);
2891 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2892 break;
2893 }
2894 }
2895
2896 return result;
Junda Liu29340342014-07-10 15:23:27 -07002897 }
Derek Tan89e89d42014-07-08 17:00:10 -07002898
2899 @Override
Junda Liue64de782015-04-16 17:19:16 -07002900 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2901 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2902 loge("phoneId " + phoneId + " is not valid.");
2903 return null;
2904 }
2905 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002906 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002907 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002908 return null ;
2909 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002910 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002911 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002912 }
2913
Amith Yamasani6e118872016-02-19 12:53:51 -08002914 @Override
2915 public List<String> getPackagesWithCarrierPrivileges() {
2916 PackageManager pm = mPhone.getContext().getPackageManager();
2917 List<String> privilegedPackages = new ArrayList<>();
2918 List<PackageInfo> packages = null;
2919 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2920 UiccCard card = UiccController.getInstance().getUiccCard(i);
2921 if (card == null) {
2922 // No UICC in that slot.
2923 continue;
2924 }
2925 if (card.hasCarrierPrivilegeRules()) {
2926 if (packages == null) {
2927 // Only check packages in user 0 for now
2928 packages = pm.getInstalledPackagesAsUser(
2929 PackageManager.MATCH_DISABLED_COMPONENTS
2930 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2931 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2932 }
2933 for (int p = packages.size() - 1; p >= 0; p--) {
2934 PackageInfo pkgInfo = packages.get(p);
2935 if (pkgInfo != null && pkgInfo.packageName != null
2936 && card.getCarrierPrivilegeStatus(pkgInfo)
2937 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2938 privilegedPackages.add(pkgInfo.packageName);
2939 }
2940 }
2941 }
2942 }
2943 return privilegedPackages;
2944 }
2945
Wink Savilleb564aae2014-10-23 10:18:09 -07002946 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002947 final Phone phone = getPhone(subId);
2948 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002949 if (card == null) {
2950 loge("getIccId: No UICC");
2951 return null;
2952 }
2953 String iccId = card.getIccId();
2954 if (TextUtils.isEmpty(iccId)) {
2955 loge("getIccId: ICC ID is null or empty.");
2956 return null;
2957 }
2958 return iccId;
2959 }
2960
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002961 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002962 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2963 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002964 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002965
Jeff Sharkey85190e62014-12-05 09:40:12 -08002966 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002967 final Phone phone = getPhone(subId);
2968 if (phone == null) {
2969 return false;
2970 }
2971 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002972
2973 if (DBG_MERGE) {
2974 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2975 + subscriberId + " to " + number);
2976 }
2977
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002978 if (TextUtils.isEmpty(iccId)) {
2979 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002980 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002981
Jeff Sharkey85190e62014-12-05 09:40:12 -08002982 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2983
2984 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002985 if (alphaTag == null) {
2986 editor.remove(alphaTagPrefKey);
2987 } else {
2988 editor.putString(alphaTagPrefKey, alphaTag);
2989 }
2990
Jeff Sharkey85190e62014-12-05 09:40:12 -08002991 // Record both the line number and IMSI for this ICCID, since we need to
2992 // track all merged IMSIs based on line number
2993 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2994 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002995 if (number == null) {
2996 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002997 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002998 } else {
2999 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003000 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003001 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003002
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003003 editor.commit();
3004 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003005 }
3006
3007 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003008 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003009 // This is open to apps with WRITE_SMS.
3010 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003011 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003012 return null;
3013 }
Derek Tan97ebb422014-09-05 16:55:38 -07003014
3015 String iccId = getIccId(subId);
3016 if (iccId != null) {
3017 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003018 if (DBG_MERGE) {
3019 log("getLine1NumberForDisplay returning " +
3020 mTelephonySharedPreferences.getString(numberPrefKey, null));
3021 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003022 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003023 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003024 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003025 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003026 }
3027
3028 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003029 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3030 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3031 return null;
3032 }
Derek Tan97ebb422014-09-05 16:55:38 -07003033
3034 String iccId = getIccId(subId);
3035 if (iccId != null) {
3036 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003037 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003038 }
Derek Tan97ebb422014-09-05 16:55:38 -07003039 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003040 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003041
3042 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003043 public String[] getMergedSubscriberIds(String callingPackage) {
3044 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3045 return null;
3046 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003047 final Context context = mPhone.getContext();
3048 final TelephonyManager tele = TelephonyManager.from(context);
3049 final SubscriptionManager sub = SubscriptionManager.from(context);
3050
3051 // Figure out what subscribers are currently active
3052 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003053 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3054 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 final int[] subIds = sub.getActiveSubscriptionIdList();
3058 for (int subId : subIds) {
3059 activeSubscriberIds.add(tele.getSubscriberId(subId));
3060 }
3061 } finally {
3062 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003063 }
3064
3065 // First pass, find a number override for an active subscriber
3066 String mergeNumber = null;
3067 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3068 for (String key : prefs.keySet()) {
3069 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3070 final String subscriberId = (String) prefs.get(key);
3071 if (activeSubscriberIds.contains(subscriberId)) {
3072 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3073 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3074 mergeNumber = (String) prefs.get(numberKey);
3075 if (DBG_MERGE) {
3076 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3077 + " for active subscriber " + subscriberId);
3078 }
3079 if (!TextUtils.isEmpty(mergeNumber)) {
3080 break;
3081 }
3082 }
3083 }
3084 }
3085
3086 // Shortcut when no active merged subscribers
3087 if (TextUtils.isEmpty(mergeNumber)) {
3088 return null;
3089 }
3090
3091 // Second pass, find all subscribers under that line override
3092 final ArraySet<String> result = new ArraySet<>();
3093 for (String key : prefs.keySet()) {
3094 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3095 final String number = (String) prefs.get(key);
3096 if (mergeNumber.equals(number)) {
3097 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3098 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3099 final String subscriberId = (String) prefs.get(subscriberKey);
3100 if (!TextUtils.isEmpty(subscriberId)) {
3101 result.add(subscriberId);
3102 }
3103 }
3104 }
3105 }
3106
3107 final String[] resultArray = result.toArray(new String[result.size()]);
3108 Arrays.sort(resultArray);
3109 if (DBG_MERGE) {
3110 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3111 }
3112 return resultArray;
3113 }
3114
3115 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003116 public boolean setOperatorBrandOverride(int subId, String brand) {
3117 enforceCarrierPrivilege(subId);
3118 final Phone phone = getPhone(subId);
3119 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003120 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003121
3122 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003123 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003124 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3125 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003126 enforceCarrierPrivilege(subId);
3127 final Phone phone = getPhone(subId);
3128 if (phone == null) {
3129 return false;
3130 }
3131 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003132 cdmaNonRoamingList);
3133 }
3134
3135 @Override
Amit Mahajanf43fe462017-02-23 12:08:31 -08003136 @Deprecated
Steven Liu4bf01bc2014-07-17 11:05:29 -05003137 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3138 enforceModifyPermission();
3139
3140 int returnValue = 0;
3141 try {
3142 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3143 if(result.exception == null) {
3144 if (result.result != null) {
3145 byte[] responseData = (byte[])(result.result);
3146 if(responseData.length > oemResp.length) {
3147 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3148 responseData.length + "bytes. Buffer Size is " +
3149 oemResp.length + "bytes.");
3150 }
3151 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3152 returnValue = responseData.length;
3153 }
3154 } else {
3155 CommandException ex = (CommandException) result.exception;
3156 returnValue = ex.getCommandError().ordinal();
3157 if(returnValue > 0) returnValue *= -1;
3158 }
3159 } catch (RuntimeException e) {
3160 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3161 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3162 if(returnValue > 0) returnValue *= -1;
3163 }
3164
3165 return returnValue;
3166 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003167
3168 @Override
3169 public void setRadioCapability(RadioAccessFamily[] rafs) {
3170 try {
3171 ProxyController.getInstance().setRadioCapability(rafs);
3172 } catch (RuntimeException e) {
3173 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3174 }
3175 }
3176
3177 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003178 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3179 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3180 return RadioAccessFamily.RAF_UNKNOWN;
3181 }
3182
Wink Saville5d475dd2014-10-17 15:00:58 -07003183 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3184 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003185
3186 @Override
3187 public void enableVideoCalling(boolean enable) {
3188 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003189 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003190 }
3191
3192 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003193 public boolean isVideoCallingEnabled(String callingPackage) {
3194 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3195 return false;
3196 }
3197
Andrew Lee77527ac2014-10-21 16:57:39 -07003198 // Check the user preference and the system-level IMS setting. Even if the user has
3199 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3200 // In the long run, we may instead need to check if there exists a connection service
3201 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003202 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3203 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003204 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003205 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003206
Andrew Leea1239f22015-03-02 17:44:07 -08003207 @Override
3208 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003209 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003210 }
3211
3212 @Override
3213 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003214 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003215 }
3216
Andrew Lee9431b832015-03-09 18:46:45 -07003217 @Override
3218 public boolean isTtyModeSupported() {
3219 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3220 TelephonyManager telephonyManager =
3221 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003222 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003223 }
3224
3225 @Override
3226 public boolean isHearingAidCompatibilitySupported() {
3227 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3228 }
3229
Sanket Padawe7310cc72015-01-14 09:53:20 -08003230 /**
3231 * Returns the unique device ID of phone, for example, the IMEI for
3232 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3233 *
3234 * <p>Requires Permission:
3235 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3236 */
3237 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003238 public String getDeviceId(String callingPackage) {
3239 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3240 return null;
3241 }
3242
Sanket Padawe7310cc72015-01-14 09:53:20 -08003243 final Phone phone = PhoneFactory.getPhone(0);
3244 if (phone != null) {
3245 return phone.getDeviceId();
3246 } else {
3247 return null;
3248 }
3249 }
3250
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003251 /*
3252 * {@hide}
3253 * Returns the IMS Registration Status
3254 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003255 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003256 public boolean isImsRegistered() {
3257 return mPhone.isImsRegistered();
3258 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003259
3260 @Override
3261 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3262 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3263 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003264
Nathan Haroldc55097a2015-03-11 18:14:50 -07003265 /*
3266 * {@hide}
3267 * Returns the IMS Registration Status
3268 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003269 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003270 return mPhone.isWifiCallingEnabled();
3271 }
3272
3273 /*
3274 * {@hide}
3275 * Returns the IMS Registration Status
3276 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003277 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003278 return mPhone.isVolteEnabled();
3279 }
Svet Ganovb320e182015-04-16 12:30:10 -07003280
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003281 /*
3282 * {@hide} Returns the IMS Registration Status
3283 */
3284 public boolean isVideoTelephonyAvailable() {
3285 return mPhone.isVideoEnabled();
3286 }
3287
Svet Ganovb320e182015-04-16 12:30:10 -07003288 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003289 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003290 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003291 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3292
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003293 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003294 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003295 } catch (SecurityException e) {
3296 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3297 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003298 }
Svet Ganovb320e182015-04-16 12:30:10 -07003299
3300 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3301 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3302 return false;
3303 }
3304
3305 return true;
3306 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003307
Makoto Onukifee69342015-06-29 14:44:50 -07003308 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003309 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003310 */
3311 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003312 // Default SMS app can always read it.
3313 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3314 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3315 return true;
3316 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003317
Makoto Onukie4072d12015-08-03 15:12:23 -07003318 try {
3319 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003320 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003321 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003322 // Can be read with READ_SMS too.
3323 try {
3324 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3325 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3326 if (opCode != AppOpsManager.OP_NONE) {
3327 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3328 == AppOpsManager.MODE_ALLOWED;
3329 } else {
3330 return true;
3331 }
3332 } catch (SecurityException readSmsSecurityException) {
3333 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003334 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003335 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003336 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003337 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003338 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003339 if (opCode != AppOpsManager.OP_NONE) {
3340 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3341 == AppOpsManager.MODE_ALLOWED;
3342 } else {
3343 return true;
3344 }
3345 } catch (SecurityException readPhoneNumberSecurityException) {
3346 }
3347
3348 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3349 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3350 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003351 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003352 }
3353
Stuart Scott8eef64f2015-04-08 15:13:54 -07003354 @Override
3355 public void factoryReset(int subId) {
3356 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003357 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3358 return;
3359 }
3360
Svet Ganovcc087f82015-05-12 20:35:54 -07003361 final long identity = Binder.clearCallingIdentity();
3362 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003363 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3364 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003365 // Enable data
3366 setDataEnabled(subId, true);
3367 // Set network selection mode to automatic
3368 setNetworkSelectionModeAutomatic(subId);
3369 // Set preferred mobile network type to the best available
3370 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3371 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003372 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003373 }
3374 } finally {
3375 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003376 }
3377 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003378
3379 @Override
3380 public String getLocaleFromDefaultSim() {
3381 // We query all subscriptions instead of just the active ones, because
3382 // this might be called early on in the provisioning flow when the
3383 // subscriptions potentially aren't active yet.
3384 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3385 if (slist == null || slist.isEmpty()) {
3386 return null;
3387 }
3388
3389 // This function may be called very early, say, from the setup wizard, at
3390 // which point we won't have a default subscription set. If that's the case
3391 // we just choose the first, which will be valid in "most cases".
3392 final int defaultSubId = getDefaultSubscription();
3393 SubscriptionInfo info = null;
3394 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3395 info = slist.get(0);
3396 } else {
3397 for (SubscriptionInfo item : slist) {
3398 if (item.getSubscriptionId() == defaultSubId) {
3399 info = item;
3400 break;
3401 }
3402 }
3403
3404 if (info == null) {
3405 return null;
3406 }
3407 }
3408
3409 // Try and fetch the locale from the carrier properties or from the SIM language
3410 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003411 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003412 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003413 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003414 if (defaultPhone != null) {
3415 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3416 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003417 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003418 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3419 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003420 } else {
3421 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003422 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003423 }
3424 }
3425
Narayan Kamath011676f2015-07-29 12:04:08 +01003426 // The SIM language preferences only store a language (e.g. fr = French), not an
3427 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3428 // the SIM and carrier preferences does not include a country we add the country
3429 // determined from the SIM MCC to provide an exact locale.
3430 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003431 if (mccLocale != null) {
3432 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3433 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003434 }
3435
Tony Hill183b2de2015-06-24 14:53:58 +01003436 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003437 return null;
3438 }
3439
3440 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 return mSubscriptionController.getAllSubInfoList(
3444 mPhone.getContext().getOpPackageName());
3445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
3450 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 return mSubscriptionController.getActiveSubscriptionInfoList(
3454 mPhone.getContext().getOpPackageName());
3455 } finally {
3456 Binder.restoreCallingIdentity(identity);
3457 }
3458 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003459
3460 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003461 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3462 * representing the state of the modem.
3463 *
3464 * NOTE: This clears the modem state, so there should only every be one caller.
3465 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003466 */
3467 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003468 public void requestModemActivityInfo(ResultReceiver result) {
3469 enforceModifyPermission();
3470
3471 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3472 Bundle bundle = new Bundle();
3473 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3474 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003475 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003476
3477 /**
3478 * {@hide}
3479 * Returns the service state information on specified subscription.
3480 */
3481 @Override
3482 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3483
3484 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3485 return null;
3486 }
3487
3488 final Phone phone = getPhone(subId);
3489 if (phone == null) {
3490 return null;
3491 }
3492
3493 return phone.getServiceState();
3494 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003495
3496 /**
3497 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3498 *
3499 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3500 * voicemail ringtone.
3501 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3502 * PhoneAccount.
3503 */
3504 @Override
3505 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003506 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003507 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003508 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003509 }
3510
fionaxu7ed723d2017-05-30 18:58:54 -07003511 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003512 }
3513
3514 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003515 * Sets the per-account voicemail ringtone.
3516 *
3517 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3518 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3519 *
3520 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3521 * voicemail ringtone.
3522 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3523 * PhoneAccount.
3524 */
3525 @Override
3526 public void setVoicemailRingtoneUri(String callingPackage,
3527 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3529 if (!TextUtils.equals(callingPackage,
3530 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3531 enforceModifyPermissionOrCarrierPrivilege(
3532 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3533 }
3534 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3535 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003536 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003537 }
fionaxu7ed723d2017-05-30 18:58:54 -07003538 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003539 }
3540
3541 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003542 * Returns whether vibration is set for voicemail notification in Phone settings.
3543 *
3544 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3545 * voicemail vibration setting.
3546 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3547 */
3548 @Override
3549 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003550 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003551 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003552 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003553 }
3554
fionaxu7ed723d2017-05-30 18:58:54 -07003555 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003556 }
3557
Youhan Wange64578a2016-05-02 15:32:42 -07003558 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003559 * Sets the per-account voicemail vibration.
3560 *
3561 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3562 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3563 *
3564 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3565 * voicemail vibration setting.
3566 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3567 * specific PhoneAccount.
3568 */
3569 @Override
3570 public void setVoicemailVibrationEnabled(String callingPackage,
3571 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3572 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3573 if (!TextUtils.equals(callingPackage,
3574 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3575 enforceModifyPermissionOrCarrierPrivilege(
3576 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3577 }
3578
3579 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3580 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003581 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003582 }
fionaxu7ed723d2017-05-30 18:58:54 -07003583 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003584 }
3585
3586 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003587 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3588 *
3589 * @throws SecurityException if the caller does not have the required permission
3590 */
3591 private void enforceReadPrivilegedPermission() {
3592 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3593 null);
3594 }
3595
3596 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003597 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3598 * permission.
3599 *
3600 * @throws SecurityException if the caller does not have the required permission
3601 */
3602 private void enforceSendSmsPermission() {
3603 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3604 }
3605
3606 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003607 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003608 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003609 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003610 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003611 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003612 ComponentName componentName =
3613 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3614 if(componentName == null) {
3615 throw new SecurityException("Caller not current active visual voicemail package[null]");
3616 }
3617 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003618 if (!callingPackage.equals(vvmPackage)) {
3619 throw new SecurityException("Caller not current active visual voicemail package[" +
3620 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003621 }
3622 }
3623
3624 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003625 * Return the application ID for the app type.
3626 *
3627 * @param subId the subscription ID that this request applies to.
3628 * @param appType the uicc app type.
3629 * @return Application ID for specificied app type, or null if no uicc.
3630 */
3631 @Override
3632 public String getAidForAppType(int subId, int appType) {
3633 enforceReadPrivilegedPermission();
3634 Phone phone = getPhone(subId);
3635 if (phone == null) {
3636 return null;
3637 }
3638 String aid = null;
3639 try {
3640 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3641 .getApplicationByType(appType).getAid();
3642 } catch (Exception e) {
3643 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3644 }
3645 return aid;
3646 }
3647
Youhan Wang4001d252016-05-11 10:29:41 -07003648 /**
3649 * Return the Electronic Serial Number.
3650 *
3651 * @param subId the subscription ID that this request applies to.
3652 * @return ESN or null if error.
3653 */
3654 @Override
3655 public String getEsn(int subId) {
3656 enforceReadPrivilegedPermission();
3657 Phone phone = getPhone(subId);
3658 if (phone == null) {
3659 return null;
3660 }
3661 String esn = null;
3662 try {
3663 esn = phone.getEsn();
3664 } catch (Exception e) {
3665 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3666 }
3667 return esn;
3668 }
3669
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003670 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003671 * Return the Preferred Roaming List Version.
3672 *
3673 * @param subId the subscription ID that this request applies to.
3674 * @return PRLVersion or null if error.
3675 */
3676 @Override
3677 public String getCdmaPrlVersion(int subId) {
3678 enforceReadPrivilegedPermission();
3679 Phone phone = getPhone(subId);
3680 if (phone == null) {
3681 return null;
3682 }
3683 String cdmaPrlVersion = null;
3684 try {
3685 cdmaPrlVersion = phone.getCdmaPrlVersion();
3686 } catch (Exception e) {
3687 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3688 }
3689 return cdmaPrlVersion;
3690 }
3691
3692 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003693 * Get snapshot of Telephony histograms
3694 * @return List of Telephony histograms
3695 * @hide
3696 */
3697 @Override
3698 public List<TelephonyHistogram> getTelephonyHistograms() {
3699 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3700 return RIL.getTelephonyRILTimingHistograms();
3701 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003702
3703 /**
3704 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003705 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003706 * Require system privileges. In the future we may add this to carrier APIs.
3707 *
3708 * @return The number of carriers set successfully, should match length of carriers
3709 */
3710 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003711 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003712 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003713
Meng Wang9b7c4e92017-02-17 11:41:27 -08003714 if (carriers == null) {
3715 throw new NullPointerException("carriers cannot be null");
3716 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003717
3718 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003719 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3720 return retVal[0];
3721 }
3722
3723 /**
3724 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003725 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003726 * Require system privileges. In the future we may add this to carrier APIs.
3727 *
3728 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3729 * means all carriers are allowed.
3730 */
3731 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003732 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003733 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003734 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003735 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3736 }
3737
fionaxu59545b42016-05-25 15:53:37 -07003738 /**
3739 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3740 * @param subId the subscription ID that this action applies to.
3741 * @param enabled control enable or disable metered apns.
3742 * {@hide}
3743 */
3744 @Override
3745 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3746 enforceModifyPermission();
3747 final Phone phone = getPhone(subId);
3748 if (phone == null) {
3749 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3750 return;
3751 }
3752 try {
3753 phone.carrierActionSetMeteredApnsEnabled(enabled);
3754 } catch (Exception e) {
3755 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3756 }
3757 }
3758
3759 /**
3760 * Action set from carrier signalling broadcast receivers to enable/disable radio
3761 * @param subId the subscription ID that this action applies to.
3762 * @param enabled control enable or disable radio.
3763 * {@hide}
3764 */
3765 @Override
3766 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3767 enforceModifyPermission();
3768 final Phone phone = getPhone(subId);
3769 if (phone == null) {
3770 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3771 return;
3772 }
3773 try {
3774 phone.carrierActionSetRadioEnabled(enabled);
3775 } catch (Exception e) {
3776 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3777 }
3778 }
3779
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003780 /**
3781 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3782 * bug report is being generated.
3783 */
3784 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003785 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003786 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3787 != PackageManager.PERMISSION_GRANTED) {
3788 writer.println("Permission Denial: can't dump Phone from pid="
3789 + Binder.getCallingPid()
3790 + ", uid=" + Binder.getCallingUid()
3791 + "without permission "
3792 + android.Manifest.permission.DUMP);
3793 return;
3794 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003795 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003796 }
Jack Yueb89b242016-06-22 13:27:47 -07003797
3798 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003799 * Get aggregated video call data usage since boot.
3800 *
3801 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3802 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003803 * {@hide}
3804 */
3805 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003806 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003807 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3808 null);
3809
Jack Yu84291ec2017-05-26 16:07:50 -07003810 // NetworkStatsService keeps tracking the active network interface and identity. It
3811 // records the delta with the corresponding network identity. We just return the total video
3812 // call data usage snapshot since boot.
3813 Phone phone = getPhone(subId);
3814 if (phone != null) {
3815 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003816 }
Jack Yu84291ec2017-05-26 16:07:50 -07003817 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003818 }
Jack Yu75ab2952016-07-08 14:29:33 -07003819
3820 /**
3821 * Policy control of data connection. Usually used when data limit is passed.
3822 * @param enabled True if enabling the data, otherwise disabling.
3823 * @param subId Subscription index
3824 * {@hide}
3825 */
3826 @Override
3827 public void setPolicyDataEnabled(boolean enabled, int subId) {
3828 enforceModifyPermission();
3829 Phone phone = getPhone(subId);
3830 if (phone != null) {
3831 phone.setPolicyDataEnabled(enabled);
3832 }
3833 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003834
3835 /**
3836 * Get Client request stats
3837 * @return List of Client Request Stats
3838 * @hide
3839 */
3840 @Override
3841 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3842 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3843 return null;
3844 }
3845
3846 Phone phone = getPhone(subId);
3847 if (phone != null) {
3848 return phone.getClientRequestStats();
3849 }
3850
3851 return null;
3852 }
3853
3854 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3855 if (workSource != null) {
3856 return workSource;
3857 }
3858
3859 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3860 workSource = new WorkSource(uid, packageName);
3861 return workSource;
3862 }
Jack Yueb4124c2017-02-16 15:32:43 -08003863
3864 /**
Grace Chen70990072017-03-24 17:21:30 -07003865 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003866 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003867 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003868 * @param state State of SIM (power down, power up, pass through)
3869 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3870 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3871 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003872 *
3873 **/
3874 @Override
Grace Chen70990072017-03-24 17:21:30 -07003875 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003876 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003877 Phone phone = PhoneFactory.getPhone(slotIndex);
3878
Jack Yueb4124c2017-02-16 15:32:43 -08003879 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003880 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003881 }
3882 }
Shuo Qiandd210312017-04-12 22:11:33 +00003883
Tyler Gunn65d45c22017-06-05 11:22:26 -07003884 private boolean isUssdApiAllowed(int subId) {
3885 CarrierConfigManager configManager =
3886 (CarrierConfigManager) mPhone.getContext().getSystemService(
3887 Context.CARRIER_CONFIG_SERVICE);
3888 if (configManager == null) {
3889 return false;
3890 }
3891 PersistableBundle pb = configManager.getConfigForSubId(subId);
3892 if (pb == null) {
3893 return false;
3894 }
3895 return pb.getBoolean(
3896 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3897 }
3898
Shuo Qiandd210312017-04-12 22:11:33 +00003899 /**
3900 * Check if phone is in emergency callback mode
3901 * @return true if phone is in emergency callback mode
3902 * @param subId sub id
3903 */
3904 public boolean getEmergencyCallbackMode(int subId) {
3905 final Phone phone = getPhone(subId);
3906 if (phone != null) {
3907 return phone.isInEcm();
3908 } else {
3909 return false;
3910 }
3911 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003912
3913 /**
3914 * Get the current signal strength information for the given subscription.
3915 * Because this information is not updated when the device is in a low power state
3916 * it should not be relied-upon to be current.
3917 * @param subId Subscription index
3918 * @return the most recent cached signal strength info from the modem
3919 */
3920 @Override
3921 public SignalStrength getSignalStrength(int subId) {
3922 Phone p = getPhone(subId);
3923 if (p == null) {
3924 return null;
3925 }
3926
3927 return p.getSignalStrength();
3928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003929}