blob: 52c5621adaf995c92ed936f1594eed92280b164e [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;
Ta-wei Yendca928f2017-01-10 16:17:08 -080022import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.app.ActivityManager;
24import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
37import android.os.Looper;
38import android.os.Message;
39import android.os.Process;
Adam Lesinski903a54c2016-04-11 14:49:52 -070040import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.ServiceManager;
42import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070043import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070044import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070045import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080046import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070047import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080048import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080049import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070050import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070051import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070053import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070054import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070055import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080056import android.telephony.NeighboringCellInfo;
Wink Saville5d475dd2014-10-17 15:00:58 -070057import android.telephony.RadioAccessFamily;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.ServiceState;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080059import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080060import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080061import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070062import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070063import android.telephony.TelephonyManager;
64import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080066import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080068import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080069import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080070
Andrew Lee312e8172014-10-23 17:01:36 -070071import com.android.ims.ImsManager;
Brad Ebinger51f743a2017-01-23 13:50:20 -080072import com.android.ims.internal.IImsServiceController;
73import com.android.ims.internal.IImsServiceFeatureListener;
Shishir Agrawal566b7612013-10-28 14:41:00 -070074import com.android.internal.telephony.CallManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070075import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070076import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080079import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010080import com.android.internal.telephony.MccTable;
Shishir Agrawal302c8692015-06-19 13:49:39 -070081import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import com.android.internal.telephony.Phone;
Ta-wei Yen87c49842016-05-13 21:19:52 -070083import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070084import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070086import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070087import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080088import com.android.internal.telephony.SubscriptionController;
Shishir Agrawal566b7612013-10-28 14:41:00 -070089import com.android.internal.telephony.uicc.IccIoResult;
90import com.android.internal.telephony.uicc.IccUtils;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -070091import com.android.internal.telephony.uicc.UiccCard;
Shishir Agrawal566b7612013-10-28 14:41:00 -070092import com.android.internal.telephony.uicc.UiccController;
Jake Hambye994d462014-02-03 13:10:13 -080093import com.android.internal.util.HexDump;
Ta-wei Yenb0f695b2016-08-08 17:33:11 -070094import com.android.phone.settings.VisualVoicemailSettingsUtil;
Nancy Chen31f9ba12016-01-06 11:42:12 -080095import com.android.phone.settings.VoicemailNotificationSettingsUtil;
Ta-wei Yen527a9c02017-01-06 15:29:25 -080096import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080097
Ta-wei Yenc236d6b2016-06-21 13:33:12 -070098import java.io.FileDescriptor;
99import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800100import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700101import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800102import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800103import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100104import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800105import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106
107/**
108 * Implementation of the ITelephony interface.
109 */
Santos Cordon117fee72014-05-16 17:56:12 -0700110public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111 private static final String LOG_TAG = "PhoneInterfaceManager";
112 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
113 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800114 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115
116 // Message codes used with mMainThreadHandler
117 private static final int CMD_HANDLE_PIN_MMI = 1;
118 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
119 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
120 private static final int CMD_ANSWER_RINGING_CALL = 4;
121 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700122 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
123 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124 private static final int CMD_OPEN_CHANNEL = 9;
125 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
126 private static final int CMD_CLOSE_CHANNEL = 11;
127 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800128 private static final int CMD_NV_READ_ITEM = 13;
129 private static final int EVENT_NV_READ_ITEM_DONE = 14;
130 private static final int CMD_NV_WRITE_ITEM = 15;
131 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
132 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
133 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
134 private static final int CMD_NV_RESET_CONFIG = 19;
135 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800136 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
137 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
138 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
139 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800140 private static final int CMD_SEND_ENVELOPE = 25;
141 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700142 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
143 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
144 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
145 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
146 private static final int CMD_EXCHANGE_SIM_IO = 31;
147 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800148 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
149 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700150 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
151 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700152 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
153 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
155 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
156 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
157 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700158 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
159 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
160 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
161 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700162 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163
164 /** The singleton instance. */
165 private static PhoneInterfaceManager sInstance;
166
Wink Saville3ab207e2014-11-20 13:07:20 -0800167 private PhoneGlobals mApp;
168 private Phone mPhone;
169 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700170 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800171 private AppOpsManager mAppOps;
172 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800173 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800174 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175
Derek Tan97ebb422014-09-05 16:55:38 -0700176 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
177 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700179
180 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700181 * A request object to use for transmitting data to an ICC.
182 */
183 private static final class IccAPDUArgument {
184 public int channel, cla, command, p1, p2, p3;
185 public String data;
186
187 public IccAPDUArgument(int channel, int cla, int command,
188 int p1, int p2, int p3, String data) {
189 this.channel = channel;
190 this.cla = cla;
191 this.command = command;
192 this.p1 = p1;
193 this.p2 = p2;
194 this.p3 = p3;
195 this.data = data;
196 }
197 }
198
199 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700200 * A request object to use for transmitting data to an ICC.
201 */
202 private static final class ManualNetworkSelectionArgument {
203 public OperatorInfo operatorInfo;
204 public boolean persistSelection;
205
206 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
207 this.operatorInfo = operatorInfo;
208 this.persistSelection = persistSelection;
209 }
210 }
211
212 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
214 * request after sending. The main thread will notify the request when it is complete.
215 */
216 private static final class MainThreadRequest {
217 /** The argument to use for the request */
218 public Object argument;
219 /** The result of the request that is run on the main thread */
220 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800221 // The subscriber id that this request applies to. Defaults to
222 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
223 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224
225 public MainThreadRequest(Object argument) {
226 this.argument = argument;
227 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800228
229 public MainThreadRequest(Object argument, Integer subId) {
230 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800231 if (subId != null) {
232 this.subId = subId;
233 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 }
236
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800237 private static final class IncomingThirdPartyCallArgs {
238 public final ComponentName component;
239 public final String callId;
240 public final String callerDisplayName;
241
242 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
243 String callerDisplayName) {
244 this.component = component;
245 this.callId = callId;
246 this.callerDisplayName = callerDisplayName;
247 }
248 }
249
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250 /**
251 * A handler that processes messages on the main thread in the phone process. Since many
252 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
253 * inbound binder threads to the main thread in the phone process. The Binder thread
254 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
255 * on, which will be notified when the operation completes and will contain the result of the
256 * request.
257 *
258 * <p>If a MainThreadRequest object is provided in the msg.obj field,
259 * note that request.result must be set to something non-null for the calling thread to
260 * unblock.
261 */
262 private final class MainThreadHandler extends Handler {
263 @Override
264 public void handleMessage(Message msg) {
265 MainThreadRequest request;
266 Message onCompleted;
267 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800268 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700269 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
271 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700272 case CMD_HANDLE_USSD_REQUEST: {
273 request = (MainThreadRequest) msg.obj;
274 final Phone phone = getPhoneFromRequest(request);
275 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
276 String ussdRequest = ussdObject.first;
277 ResultReceiver wrappedCallback = ussdObject.second;
278 request.result = phone != null ?
279 phone.handleUssdRequest(ussdRequest, wrappedCallback)
280 :false;
281 // Wake up the requesting thread
282 synchronized (request) {
283 request.notifyAll();
284 }
285 break;
286 }
287
Yorke Lee716f67e2015-06-17 15:39:16 -0700288 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700290 final Phone phone = getPhoneFromRequest(request);
291 request.result = phone != null ?
292 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
293 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294 // Wake up the requesting thread
295 synchronized (request) {
296 request.notifyAll();
297 }
298 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700300
301 case CMD_HANDLE_NEIGHBORING_CELL:
302 request = (MainThreadRequest) msg.obj;
303 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
304 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700305 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306 break;
307
308 case EVENT_NEIGHBORING_CELL_DONE:
309 ar = (AsyncResult) msg.obj;
310 request = (MainThreadRequest) ar.userObj;
311 if (ar.exception == null && ar.result != null) {
312 request.result = ar.result;
313 } else {
314 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800315 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 }
317 // Wake up the requesting thread
318 synchronized (request) {
319 request.notifyAll();
320 }
321 break;
322
323 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700324 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800325 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700326 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327 break;
328
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 case CMD_END_CALL:
330 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800331 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700332 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700333 Phone phone = getPhone(end_subId);
334 if (phone == null) {
335 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
336 break;
337 }
338 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
340 // CDMA: If the user presses the Power button we treat it as
341 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700342 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
344 // GSM: End the call as per the Phone state
345 hungUp = PhoneUtils.hangup(mCM);
346 } else {
347 throw new IllegalStateException("Unexpected phone type: " + phoneType);
348 }
349 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
350 request.result = hungUp;
351 // Wake up the requesting thread
352 synchronized (request) {
353 request.notifyAll();
354 }
355 break;
356
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700357 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700358 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700359 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800360 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700361 if (uiccCard == null) {
362 loge("iccTransmitApduLogicalChannel: No UICC");
363 request.result = new IccIoResult(0x6F, 0, (byte[])null);
364 synchronized (request) {
365 request.notifyAll();
366 }
367 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700368 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
369 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700370 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700371 iccArgument.channel, iccArgument.cla, iccArgument.command,
372 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700373 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700374 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700375 break;
376
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700377 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700378 ar = (AsyncResult) msg.obj;
379 request = (MainThreadRequest) ar.userObj;
380 if (ar.exception == null && ar.result != null) {
381 request.result = ar.result;
382 } else {
383 request.result = new IccIoResult(0x6F, 0, (byte[])null);
384 if (ar.result == null) {
385 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800386 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700387 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800388 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700389 } else {
390 loge("iccTransmitApduLogicalChannel: Unknown exception");
391 }
392 }
393 synchronized (request) {
394 request.notifyAll();
395 }
396 break;
397
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700398 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
399 request = (MainThreadRequest) msg.obj;
400 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800401 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700402 if (uiccCard == null) {
403 loge("iccTransmitApduBasicChannel: No UICC");
404 request.result = new IccIoResult(0x6F, 0, (byte[])null);
405 synchronized (request) {
406 request.notifyAll();
407 }
408 } else {
409 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
410 request);
411 uiccCard.iccTransmitApduBasicChannel(
412 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
413 iccArgument.p3, iccArgument.data, onCompleted);
414 }
415 break;
416
417 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
418 ar = (AsyncResult) msg.obj;
419 request = (MainThreadRequest) ar.userObj;
420 if (ar.exception == null && ar.result != null) {
421 request.result = ar.result;
422 } else {
423 request.result = new IccIoResult(0x6F, 0, (byte[])null);
424 if (ar.result == null) {
425 loge("iccTransmitApduBasicChannel: Empty response");
426 } else if (ar.exception instanceof CommandException) {
427 loge("iccTransmitApduBasicChannel: CommandException: " +
428 ar.exception);
429 } else {
430 loge("iccTransmitApduBasicChannel: Unknown exception");
431 }
432 }
433 synchronized (request) {
434 request.notifyAll();
435 }
436 break;
437
438 case CMD_EXCHANGE_SIM_IO:
439 request = (MainThreadRequest) msg.obj;
440 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800441 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 if (uiccCard == null) {
443 loge("iccExchangeSimIO: No UICC");
444 request.result = new IccIoResult(0x6F, 0, (byte[])null);
445 synchronized (request) {
446 request.notifyAll();
447 }
448 } else {
449 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
450 request);
451 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
452 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
453 iccArgument.data, onCompleted);
454 }
455 break;
456
457 case EVENT_EXCHANGE_SIM_IO_DONE:
458 ar = (AsyncResult) msg.obj;
459 request = (MainThreadRequest) ar.userObj;
460 if (ar.exception == null && ar.result != null) {
461 request.result = ar.result;
462 } else {
463 request.result = new IccIoResult(0x6f, 0, (byte[])null);
464 }
465 synchronized (request) {
466 request.notifyAll();
467 }
468 break;
469
Derek Tan4d5e5c12014-02-04 11:54:58 -0800470 case CMD_SEND_ENVELOPE:
471 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800472 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 if (uiccCard == null) {
474 loge("sendEnvelopeWithStatus: No UICC");
475 request.result = new IccIoResult(0x6F, 0, (byte[])null);
476 synchronized (request) {
477 request.notifyAll();
478 }
479 } else {
480 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
481 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
482 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800483 break;
484
485 case EVENT_SEND_ENVELOPE_DONE:
486 ar = (AsyncResult) msg.obj;
487 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700488 if (ar.exception == null && ar.result != null) {
489 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800490 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700491 request.result = new IccIoResult(0x6F, 0, (byte[])null);
492 if (ar.result == null) {
493 loge("sendEnvelopeWithStatus: Empty response");
494 } else if (ar.exception instanceof CommandException) {
495 loge("sendEnvelopeWithStatus: CommandException: " +
496 ar.exception);
497 } else {
498 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
499 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800500 }
501 synchronized (request) {
502 request.notifyAll();
503 }
504 break;
505
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 case CMD_OPEN_CHANNEL:
507 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800508 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700509 if (uiccCard == null) {
510 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800511 request.result = new IccOpenLogicalChannelResponse(-1,
512 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700513 synchronized (request) {
514 request.notifyAll();
515 }
516 } else {
517 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
518 uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted);
519 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700520 break;
521
522 case EVENT_OPEN_CHANNEL_DONE:
523 ar = (AsyncResult) msg.obj;
524 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 int[] result = (int[]) ar.result;
528 int channelId = result[0];
529 byte[] selectResponse = null;
530 if (result.length > 1) {
531 selectResponse = new byte[result.length - 1];
532 for (int i = 1; i < result.length; ++i) {
533 selectResponse[i - 1] = (byte) result[i];
534 }
535 }
536 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700537 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700538 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 if (ar.result == null) {
540 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 if (ar.exception != null) {
543 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
544 }
545
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700546 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700547 if (ar.exception instanceof CommandException) {
548 CommandException.Error error =
549 ((CommandException) (ar.exception)).getCommandError();
550 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700551 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700552 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700553 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 }
555 }
556 openChannelResp = new IccOpenLogicalChannelResponse(
557 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700559 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 synchronized (request) {
561 request.notifyAll();
562 }
563 break;
564
565 case CMD_CLOSE_CHANNEL:
566 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800567 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 if (uiccCard == null) {
569 loge("iccCloseLogicalChannel: No UICC");
570 request.result = new IccIoResult(0x6F, 0, (byte[])null);
571 synchronized (request) {
572 request.notifyAll();
573 }
574 } else {
575 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
576 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
577 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 break;
579
580 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800581 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
582 break;
583
584 case CMD_NV_READ_ITEM:
585 request = (MainThreadRequest) msg.obj;
586 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
587 mPhone.nvReadItem((Integer) request.argument, onCompleted);
588 break;
589
590 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 ar = (AsyncResult) msg.obj;
592 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800593 if (ar.exception == null && ar.result != null) {
594 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800596 request.result = "";
597 if (ar.result == null) {
598 loge("nvReadItem: Empty response");
599 } else if (ar.exception instanceof CommandException) {
600 loge("nvReadItem: CommandException: " +
601 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800603 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 }
605 }
606 synchronized (request) {
607 request.notifyAll();
608 }
609 break;
610
Jake Hambye994d462014-02-03 13:10:13 -0800611 case CMD_NV_WRITE_ITEM:
612 request = (MainThreadRequest) msg.obj;
613 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
614 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
615 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
616 break;
617
618 case EVENT_NV_WRITE_ITEM_DONE:
619 handleNullReturnEvent(msg, "nvWriteItem");
620 break;
621
622 case CMD_NV_WRITE_CDMA_PRL:
623 request = (MainThreadRequest) msg.obj;
624 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
625 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
626 break;
627
628 case EVENT_NV_WRITE_CDMA_PRL_DONE:
629 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
630 break;
631
632 case CMD_NV_RESET_CONFIG:
633 request = (MainThreadRequest) msg.obj;
634 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
635 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
636 break;
637
638 case EVENT_NV_RESET_CONFIG_DONE:
639 handleNullReturnEvent(msg, "nvResetConfig");
640 break;
641
Jake Hamby7c27be32014-03-03 13:25:59 -0800642 case CMD_GET_PREFERRED_NETWORK_TYPE:
643 request = (MainThreadRequest) msg.obj;
644 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700645 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800646 break;
647
648 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
649 ar = (AsyncResult) msg.obj;
650 request = (MainThreadRequest) ar.userObj;
651 if (ar.exception == null && ar.result != null) {
652 request.result = ar.result; // Integer
653 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800654 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800655 if (ar.result == null) {
656 loge("getPreferredNetworkType: Empty response");
657 } else if (ar.exception instanceof CommandException) {
658 loge("getPreferredNetworkType: CommandException: " +
659 ar.exception);
660 } else {
661 loge("getPreferredNetworkType: Unknown exception");
662 }
663 }
664 synchronized (request) {
665 request.notifyAll();
666 }
667 break;
668
669 case CMD_SET_PREFERRED_NETWORK_TYPE:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
672 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700673 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800674 break;
675
676 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
677 handleNullReturnEvent(msg, "setPreferredNetworkType");
678 break;
679
Steven Liu4bf01bc2014-07-17 11:05:29 -0500680 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
681 request = (MainThreadRequest)msg.obj;
682 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
683 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
684 break;
685
686 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
687 ar = (AsyncResult)msg.obj;
688 request = (MainThreadRequest)ar.userObj;
689 request.result = ar;
690 synchronized (request) {
691 request.notifyAll();
692 }
693 break;
694
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800695 case CMD_SET_VOICEMAIL_NUMBER:
696 request = (MainThreadRequest) msg.obj;
697 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
698 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800699 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
700 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800701 break;
702
703 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
704 handleNullReturnEvent(msg, "setVoicemailNumber");
705 break;
706
Stuart Scott54788802015-03-30 13:18:01 -0700707 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
708 request = (MainThreadRequest) msg.obj;
709 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
710 request);
711 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
712 break;
713
714 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
715 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
716 break;
717
Shishir Agrawal302c8692015-06-19 13:49:39 -0700718 case CMD_PERFORM_NETWORK_SCAN:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
721 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
722 break;
723
724 case EVENT_PERFORM_NETWORK_SCAN_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
727 CellNetworkScanResult cellScanResult;
728 if (ar.exception == null && ar.result != null) {
729 cellScanResult = new CellNetworkScanResult(
730 CellNetworkScanResult.STATUS_SUCCESS,
731 (List<OperatorInfo>) ar.result);
732 } else {
733 if (ar.result == null) {
734 loge("getCellNetworkScanResults: Empty response");
735 }
736 if (ar.exception != null) {
737 loge("getCellNetworkScanResults: Exception: " + ar.exception);
738 }
739 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
740 if (ar.exception instanceof CommandException) {
741 CommandException.Error error =
742 ((CommandException) (ar.exception)).getCommandError();
743 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
744 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
745 } else if (error == CommandException.Error.GENERIC_FAILURE) {
746 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
747 }
748 }
749 cellScanResult = new CellNetworkScanResult(errorCode, null);
750 }
751 request.result = cellScanResult;
752 synchronized (request) {
753 request.notifyAll();
754 }
755 break;
756
757 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
758 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700759 ManualNetworkSelectionArgument selArg =
760 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700761 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
762 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700763 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
764 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700765 break;
766
767 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
768 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
769 break;
770
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700771 case CMD_GET_MODEM_ACTIVITY_INFO:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700774 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700775 break;
776
777 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
778 ar = (AsyncResult) msg.obj;
779 request = (MainThreadRequest) ar.userObj;
780 if (ar.exception == null && ar.result != null) {
781 request.result = ar.result;
782 } else {
783 if (ar.result == null) {
784 loge("queryModemActivityInfo: Empty response");
785 } else if (ar.exception instanceof CommandException) {
786 loge("queryModemActivityInfo: CommandException: " +
787 ar.exception);
788 } else {
789 loge("queryModemActivityInfo: Unknown exception");
790 }
791 }
Amit Mahajand4766222016-01-28 15:28:28 -0800792 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
793 if (request.result == null) {
794 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
795 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700796 synchronized (request) {
797 request.notifyAll();
798 }
799 break;
800
Meng Wang1a7c35a2016-05-05 20:56:15 -0700801 case CMD_SET_ALLOWED_CARRIERS:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
804 mPhone.setAllowedCarriers(
805 (List<CarrierIdentifier>) request.argument,
806 onCompleted);
807 break;
808
809 case EVENT_SET_ALLOWED_CARRIERS_DONE:
810 ar = (AsyncResult) msg.obj;
811 request = (MainThreadRequest) ar.userObj;
812 if (ar.exception == null && ar.result != null) {
813 request.result = ar.result;
814 } else {
815 if (ar.result == null) {
816 loge("setAllowedCarriers: Empty response");
817 } else if (ar.exception instanceof CommandException) {
818 loge("setAllowedCarriers: CommandException: " +
819 ar.exception);
820 } else {
821 loge("setAllowedCarriers: Unknown exception");
822 }
823 }
824 // Result cannot be null. Return -1 on error.
825 if (request.result == null) {
826 request.result = new int[]{-1};
827 }
828 synchronized (request) {
829 request.notifyAll();
830 }
831 break;
832
833 case CMD_GET_ALLOWED_CARRIERS:
834 request = (MainThreadRequest) msg.obj;
835 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
836 mPhone.getAllowedCarriers(onCompleted);
837 break;
838
839 case EVENT_GET_ALLOWED_CARRIERS_DONE:
840 ar = (AsyncResult) msg.obj;
841 request = (MainThreadRequest) ar.userObj;
842 if (ar.exception == null && ar.result != null) {
843 request.result = ar.result;
844 } else {
845 if (ar.result == null) {
846 loge("getAllowedCarriers: Empty response");
847 } else if (ar.exception instanceof CommandException) {
848 loge("getAllowedCarriers: CommandException: " +
849 ar.exception);
850 } else {
851 loge("getAllowedCarriers: Unknown exception");
852 }
853 }
854 // Result cannot be null. Return empty list of CarrierIdentifier.
855 if (request.result == null) {
856 request.result = new ArrayList<CarrierIdentifier>(0);
857 }
858 synchronized (request) {
859 request.notifyAll();
860 }
861 break;
862
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700863 default:
864 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
865 break;
866 }
867 }
Jake Hambye994d462014-02-03 13:10:13 -0800868
869 private void handleNullReturnEvent(Message msg, String command) {
870 AsyncResult ar = (AsyncResult) msg.obj;
871 MainThreadRequest request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null) {
873 request.result = true;
874 } else {
875 request.result = false;
876 if (ar.exception instanceof CommandException) {
877 loge(command + ": CommandException: " + ar.exception);
878 } else {
879 loge(command + ": Unknown exception");
880 }
881 }
882 synchronized (request) {
883 request.notifyAll();
884 }
885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700886 }
887
888 /**
889 * Posts the specified command to be executed on the main thread,
890 * waits for the request to complete, and returns the result.
891 * @see #sendRequestAsync
892 */
893 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800894 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700895 }
896
897 /**
898 * Posts the specified command to be executed on the main thread,
899 * waits for the request to complete, and returns the result.
900 * @see #sendRequestAsync
901 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800902 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700903 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
904 throw new RuntimeException("This method will deadlock if called from the main thread.");
905 }
906
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800907 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700908 Message msg = mMainThreadHandler.obtainMessage(command, request);
909 msg.sendToTarget();
910
911 // Wait for the request to complete
912 synchronized (request) {
913 while (request.result == null) {
914 try {
915 request.wait();
916 } catch (InterruptedException e) {
917 // Do nothing, go back and wait until the request is complete
918 }
919 }
920 }
921 return request.result;
922 }
923
924 /**
925 * Asynchronous ("fire and forget") version of sendRequest():
926 * Posts the specified command to be executed on the main thread, and
927 * returns immediately.
928 * @see #sendRequest
929 */
930 private void sendRequestAsync(int command) {
931 mMainThreadHandler.sendEmptyMessage(command);
932 }
933
934 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -0700935 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
936 * @see {@link #sendRequest(int,Object)}
937 */
938 private void sendRequestAsync(int command, Object argument) {
939 MainThreadRequest request = new MainThreadRequest(argument);
940 Message msg = mMainThreadHandler.obtainMessage(command, request);
941 msg.sendToTarget();
942 }
943
944 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700945 * Initialize the singleton PhoneInterfaceManager instance.
946 * This is only done once, at startup, from PhoneApp.onCreate().
947 */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700948 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700949 synchronized (PhoneInterfaceManager.class) {
950 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -0700951 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700952 } else {
953 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
954 }
955 return sInstance;
956 }
957 }
958
959 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700960 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700961 mApp = app;
962 mPhone = phone;
963 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700964 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700965 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
966 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -0700967 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -0700968 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800969 mSubscriptionController = SubscriptionController.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -0800970
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700971 publish();
972 }
973
974 private void publish() {
975 if (DBG) log("publish: " + this);
976
977 ServiceManager.addService("phone", this);
978 }
979
Stuart Scott584921c2015-01-15 17:10:34 -0800980 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800981 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
982 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -0800983 }
984
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800985 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
986 Phone phone = getPhoneFromRequest(request);
987 return phone == null ? null :
988 UiccController.getInstance().getUiccCard(phone.getPhoneId());
989 }
990
Wink Saville36469e72014-06-11 15:17:00 -0700991 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -0700992 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800993 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -0700994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700995 //
996 // Implementation of the ITelephony interface.
997 //
998
999 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001000 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001001 }
1002
Wink Savilleb564aae2014-10-23 10:18:09 -07001003 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001004 if (DBG) log("dial: " + number);
1005 // No permission check needed here: This is just a wrapper around the
1006 // ACTION_DIAL intent, which is available to any app since it puts up
1007 // the UI before it does anything.
1008
1009 String url = createTelUrl(number);
1010 if (url == null) {
1011 return;
1012 }
1013
1014 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001015 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001016 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1017 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1018 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1019 mApp.startActivity(intent);
1020 }
1021 }
1022
1023 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001024 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001025 }
1026
Wink Savilleb564aae2014-10-23 10:18:09 -07001027 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001028 if (DBG) log("call: " + number);
1029
1030 // This is just a wrapper around the ACTION_CALL intent, but we still
1031 // need to do a permission check since we're calling startActivity()
1032 // from the context of the phone app.
1033 enforceCallPermission();
1034
1035 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1036 != AppOpsManager.MODE_ALLOWED) {
1037 return;
1038 }
1039
1040 String url = createTelUrl(number);
1041 if (url == null) {
1042 return;
1043 }
1044
Wink Saville08874612014-08-31 19:19:58 -07001045 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001046 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001047 if (slist != null) {
1048 for (SubscriptionInfo subInfoRecord : slist) {
1049 if (subInfoRecord.getSubscriptionId() == subId) {
1050 isValid = true;
1051 break;
1052 }
Wink Saville08874612014-08-31 19:19:58 -07001053 }
1054 }
1055 if (isValid == false) {
1056 return;
1057 }
1058
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001059 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001060 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001061 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1062 mApp.startActivity(intent);
1063 }
1064
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001065 /**
1066 * End a call based on call state
1067 * @return true is a call was ended
1068 */
1069 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001070 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001071 }
1072
1073 /**
1074 * End a call based on the call state of the subId
1075 * @return true is a call was ended
1076 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001077 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001079 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001080 }
1081
1082 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001083 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001084 }
1085
Wink Savilleb564aae2014-10-23 10:18:09 -07001086 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 if (DBG) log("answerRingingCall...");
1088 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1089 // but that can probably wait till the big TelephonyManager API overhaul.
1090 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1091 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001092 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001093 }
1094
1095 /**
1096 * Make the actual telephony calls to implement answerRingingCall().
1097 * This should only be called from the main thread of the Phone app.
1098 * @see #answerRingingCall
1099 *
1100 * TODO: it would be nice to return true if we answered the call, or
1101 * false if there wasn't actually a ringing incoming call, or some
1102 * other error occurred. (In other words, pass back the return value
1103 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1104 * But that would require calling this method via sendRequest() rather
1105 * than sendRequestAsync(), and right now we don't actually *need* that
1106 * return value, so let's just return void for now.
1107 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001108 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001109 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001111 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1112 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001113 if (hasActiveCall && hasHoldingCall) {
1114 // Both lines are in use!
1115 // TODO: provide a flag to let the caller specify what
1116 // policy to use if both lines are in use. (The current
1117 // behavior is hardwired to "answer incoming, end ongoing",
1118 // which is how the CALL button is specced to behave.)
1119 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1120 return;
1121 } else {
1122 // answerCall() will automatically hold the current active
1123 // call, if there is one.
1124 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1125 return;
1126 }
1127 } else {
1128 // No call was ringing.
1129 return;
1130 }
1131 }
1132
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001133 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001134 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001136 public void silenceRinger() {
1137 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 }
1139
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001140 @Override
1141 public boolean isOffhook(String callingPackage) {
1142 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001143 }
1144
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001145 @Override
1146 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1147 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1148 return false;
1149 }
1150
Sanket Padawe356d7632015-06-22 14:03:32 -07001151 final Phone phone = getPhone(subId);
1152 if (phone != null) {
1153 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1154 } else {
1155 return false;
1156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001157 }
1158
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001159 @Override
1160 public boolean isRinging(String callingPackage) {
1161 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001162 }
1163
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001164 @Override
1165 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1166 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1167 return false;
1168 }
1169
Sanket Padawe356d7632015-06-22 14:03:32 -07001170 final Phone phone = getPhone(subId);
1171 if (phone != null) {
1172 return (phone.getState() == PhoneConstants.State.RINGING);
1173 } else {
1174 return false;
1175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001176 }
1177
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001178 @Override
1179 public boolean isIdle(String callingPackage) {
1180 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001181 }
1182
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001183 @Override
1184 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1185 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1186 return false;
1187 }
1188
Sanket Padawe356d7632015-06-22 14:03:32 -07001189 final Phone phone = getPhone(subId);
1190 if (phone != null) {
1191 return (phone.getState() == PhoneConstants.State.IDLE);
1192 } else {
1193 return false;
1194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 }
1196
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001198 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001199 }
1200
Wink Savilleb564aae2014-10-23 10:18:09 -07001201 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001202 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001203 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1204 }
1205
1206 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001207 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001208 }
1209
Wink Savilleb564aae2014-10-23 10:18:09 -07001210 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001211 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001212 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1213 }
1214
1215 /** {@hide} */
1216 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001217 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001218 }
1219
Wink Savilleb564aae2014-10-23 10:18:09 -07001220 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001222 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 checkSimPin.start();
1224 return checkSimPin.unlockSim(null, pin);
1225 }
1226
Wink Saville9de0f752013-10-22 19:04:03 -07001227 /** {@hide} */
1228 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001229 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001230 }
1231
Wink Savilleb564aae2014-10-23 10:18:09 -07001232 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001234 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 checkSimPuk.start();
1236 return checkSimPuk.unlockSim(puk, pin);
1237 }
1238
1239 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001240 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 * a synchronous one.
1242 */
1243 private static class UnlockSim extends Thread {
1244
1245 private final IccCard mSimCard;
1246
1247 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001248 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1249 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250
1251 // For replies from SimCard interface
1252 private Handler mHandler;
1253
1254 // For async handler to identify request type
1255 private static final int SUPPLY_PIN_COMPLETE = 100;
1256
1257 public UnlockSim(IccCard simCard) {
1258 mSimCard = simCard;
1259 }
1260
1261 @Override
1262 public void run() {
1263 Looper.prepare();
1264 synchronized (UnlockSim.this) {
1265 mHandler = new Handler() {
1266 @Override
1267 public void handleMessage(Message msg) {
1268 AsyncResult ar = (AsyncResult) msg.obj;
1269 switch (msg.what) {
1270 case SUPPLY_PIN_COMPLETE:
1271 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1272 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001273 mRetryCount = msg.arg1;
1274 if (ar.exception != null) {
1275 if (ar.exception instanceof CommandException &&
1276 ((CommandException)(ar.exception)).getCommandError()
1277 == CommandException.Error.PASSWORD_INCORRECT) {
1278 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1279 } else {
1280 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1281 }
1282 } else {
1283 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 mDone = true;
1286 UnlockSim.this.notifyAll();
1287 }
1288 break;
1289 }
1290 }
1291 };
1292 UnlockSim.this.notifyAll();
1293 }
1294 Looper.loop();
1295 }
1296
1297 /*
1298 * Use PIN or PUK to unlock SIM card
1299 *
1300 * If PUK is null, unlock SIM card with PIN
1301 *
1302 * If PUK is not null, unlock SIM card with PUK and set PIN code
1303 */
Wink Saville9de0f752013-10-22 19:04:03 -07001304 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305
1306 while (mHandler == null) {
1307 try {
1308 wait();
1309 } catch (InterruptedException e) {
1310 Thread.currentThread().interrupt();
1311 }
1312 }
1313 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1314
1315 if (puk == null) {
1316 mSimCard.supplyPin(pin, callback);
1317 } else {
1318 mSimCard.supplyPuk(puk, pin, callback);
1319 }
1320
1321 while (!mDone) {
1322 try {
1323 Log.d(LOG_TAG, "wait for done");
1324 wait();
1325 } catch (InterruptedException e) {
1326 // Restore the interrupted status
1327 Thread.currentThread().interrupt();
1328 }
1329 }
1330 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001331 int[] resultArray = new int[2];
1332 resultArray[0] = mResult;
1333 resultArray[1] = mRetryCount;
1334 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 }
1336 }
1337
1338 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001339 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001340
1341 }
1342
Wink Savilleb564aae2014-10-23 10:18:09 -07001343 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 // No permission check needed here: this call is harmless, and it's
1345 // needed for the ServiceState.requestStateUpdate() call (which is
1346 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001347 final Phone phone = getPhone(subId);
1348 if (phone != null) {
1349 phone.updateServiceLocation();
1350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351 }
1352
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001353 @Override
1354 public boolean isRadioOn(String callingPackage) {
1355 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001356 }
1357
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001358 @Override
1359 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1360 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1361 return false;
1362 }
1363 return isRadioOnForSubscriber(subId);
1364 }
1365
1366 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001367 final Phone phone = getPhone(subId);
1368 if (phone != null) {
1369 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1370 } else {
1371 return false;
1372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373 }
1374
1375 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001376 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001377
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 }
Wink Saville36469e72014-06-11 15:17:00 -07001379
Wink Savilleb564aae2014-10-23 10:18:09 -07001380 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001382 final Phone phone = getPhone(subId);
1383 if (phone != null) {
1384 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1385 }
Wink Saville36469e72014-06-11 15:17:00 -07001386 }
1387
1388 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001389 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001390 }
1391
Wink Savilleb564aae2014-10-23 10:18:09 -07001392 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001393 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001394 final Phone phone = getPhone(subId);
1395 if (phone == null) {
1396 return false;
1397 }
1398 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001399 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001400 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 }
1402 return true;
1403 }
Wink Saville36469e72014-06-11 15:17:00 -07001404
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001405 public boolean needMobileRadioShutdown() {
1406 /*
1407 * If any of the Radios are available, it will need to be
1408 * shutdown. So return true if any Radio is available.
1409 */
1410 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1411 Phone phone = PhoneFactory.getPhone(i);
1412 if (phone != null && phone.isRadioAvailable()) return true;
1413 }
1414 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1415 return false;
1416 }
1417
1418 public void shutdownMobileRadios() {
1419 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1420 logv("Shutting down Phone " + i);
1421 shutdownRadioUsingPhoneId(i);
1422 }
1423 }
1424
1425 private void shutdownRadioUsingPhoneId(int phoneId) {
1426 enforceModifyPermission();
1427 Phone phone = PhoneFactory.getPhone(phoneId);
1428 if (phone != null && phone.isRadioAvailable()) {
1429 phone.shutdownRadio();
1430 }
1431 }
1432
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433 public boolean setRadioPower(boolean turnOn) {
Wei Liu9ae2a062016-08-08 11:09:34 -07001434 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1435 if (defaultPhone != null) {
1436 defaultPhone.setRadioPower(turnOn);
1437 return true;
1438 } else {
1439 loge("There's no default phone.");
1440 return false;
1441 }
Wink Saville36469e72014-06-11 15:17:00 -07001442 }
1443
Wink Savilleb564aae2014-10-23 10:18:09 -07001444 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001446 final Phone phone = getPhone(subId);
1447 if (phone != null) {
1448 phone.setRadioPower(turnOn);
1449 return true;
1450 } else {
1451 return false;
1452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 }
1454
Wink Saville36469e72014-06-11 15:17:00 -07001455 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001456 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 public boolean enableDataConnectivity() {
1458 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001459 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001460 final Phone phone = getPhone(subId);
1461 if (phone != null) {
1462 phone.setDataEnabled(true);
1463 return true;
1464 } else {
1465 return false;
1466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001467 }
1468
Wink Saville36469e72014-06-11 15:17:00 -07001469 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001470 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 public boolean disableDataConnectivity() {
1472 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001473 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001474 final Phone phone = getPhone(subId);
1475 if (phone != null) {
1476 phone.setDataEnabled(false);
1477 return true;
1478 } else {
1479 return false;
1480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482
Wink Saville36469e72014-06-11 15:17:00 -07001483 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001484 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485 public boolean isDataConnectivityPossible() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001486 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001487 final Phone phone = getPhone(subId);
1488 if (phone != null) {
1489 return phone.isDataConnectivityPossible();
1490 } else {
1491 return false;
1492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 }
1494
1495 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001496 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001497 }
1498
pkanwarae03a6b2016-11-06 20:37:09 -08001499 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001500 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001501 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1502 return;
1503 }
1504 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1505 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1506 };
1507
1508
Wink Savilleb564aae2014-10-23 10:18:09 -07001509 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001511 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1512 return false;
1513 }
Wink Saville36469e72014-06-11 15:17:00 -07001514 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515 }
1516
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001517 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001518 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001519 }
1520
Shishir Agrawala9f32182016-04-12 12:00:16 -07001521 public int getCallStateForSlot(int slotId) {
1522 Phone phone = PhoneFactory.getPhone(slotId);
1523 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1524 DefaultPhoneNotifier.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 }
1526
Sanket Padawe356d7632015-06-22 14:03:32 -07001527 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001529 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001530 if (phone != null) {
1531 return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
1532 } else {
1533 return DefaultPhoneNotifier.convertDataState(PhoneConstants.DataState.DISCONNECTED);
1534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 }
1536
Sanket Padawe356d7632015-06-22 14:03:32 -07001537 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001538 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001539 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001540 if (phone != null) {
1541 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1542 } else {
1543 return TelephonyManager.DATA_ACTIVITY_NONE;
1544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 }
1546
1547 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001548 public Bundle getCellLocation(String callingPackage) {
1549 enforceFineOrCoarseLocationPermission("getCellLocation");
1550
1551 // OP_COARSE_LOCATION controls both fine and coarse location.
1552 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1553 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001554 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001555 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001558 if (checkIfCallerIsSelfOrForegroundUser() ||
1559 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 if (DBG_LOC) log("getCellLocation: is active user");
1561 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001562 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 if (phone == null) {
1564 return null;
1565 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001566
1567 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1568 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 return data;
1570 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001571 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 return null;
1573 }
1574 }
1575
Svetoslav64fad262015-04-14 14:35:21 -07001576 private void enforceFineOrCoarseLocationPermission(String message) {
1577 try {
1578 mApp.enforceCallingOrSelfPermission(
1579 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1580 } catch (SecurityException e) {
1581 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1582 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1583 // is the weaker precondition
1584 mApp.enforceCallingOrSelfPermission(
1585 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1586 }
1587 }
1588
1589
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 @Override
1591 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001592 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001593 }
1594
Sanket Padawe356d7632015-06-22 14:03:32 -07001595 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001596 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 mApp.enforceCallingOrSelfPermission(
1598 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 final Phone phone = getPhone(subId);
1600 if (phone != null) {
1601 phone.enableLocationUpdates();
1602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 }
1604
1605 @Override
1606 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001607 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001608 }
1609
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001611 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 mApp.enforceCallingOrSelfPermission(
1613 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 final Phone phone = getPhone(subId);
1615 if (phone != null) {
1616 phone.disableLocationUpdates();
1617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 }
1619
1620 @Override
1621 @SuppressWarnings("unchecked")
1622 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001623 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1624
1625 // OP_COARSE_LOCATION controls both fine and coarse location.
1626 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1627 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1628 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
1630
1631 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1632 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1633 return null;
1634 }
Svetoslav64fad262015-04-14 14:35:21 -07001635
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001636 if (checkIfCallerIsSelfOrForegroundUser() ||
1637 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1639
1640 ArrayList<NeighboringCellInfo> cells = null;
1641
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001642 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 try {
1644 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001645 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001646 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001648 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 }
1650 return cells;
1651 } else {
1652 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1653 return null;
1654 }
1655 }
1656
1657
1658 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001659 public List<CellInfo> getAllCellInfo(String callingPackage) {
1660 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1661
1662 // OP_COARSE_LOCATION controls both fine and coarse location.
1663 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1664 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1665 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 }
1667
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001668 if (checkIfCallerIsSelfOrForegroundUser() ||
1669 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001671 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001672 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1673 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001674 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1675 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001676 }
1677 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 } else {
1679 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1680 return null;
1681 }
1682 }
1683
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001684 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001686 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001687 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1688 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 }
1690
Shishir Agrawala9f32182016-04-12 12:00:16 -07001691 @Override
1692 public String getImeiForSlot(int slotId, String callingPackage) {
1693 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1694 return null;
1695 }
1696 Phone phone = PhoneFactory.getPhone(slotId);
1697 return phone == null ? null : phone.getImei();
1698 }
1699
1700 @Override
1701 public String getDeviceSoftwareVersionForSlot(int slotId, String callingPackage) {
1702 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1703 return null;
1704 }
1705 Phone phone = PhoneFactory.getPhone(slotId);
1706 return phone == null ? null : phone.getDeviceSvn();
1707 }
1708
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 //
1710 // Internal helper methods.
1711 //
1712
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001713 /**
1714 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1715 */
1716 private boolean checkCallerInteractAcrossUsersFull() {
1717 return mPhone.getContext().checkCallingOrSelfPermission(
1718 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1719 == PackageManager.PERMISSION_GRANTED;
1720 }
1721
Jake Hambye994d462014-02-03 13:10:13 -08001722 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 boolean ok;
1724
1725 boolean self = Binder.getCallingUid() == Process.myUid();
1726 if (!self) {
1727 // Get the caller's user id then clear the calling identity
1728 // which will be restored in the finally clause.
1729 int callingUser = UserHandle.getCallingUserId();
1730 long ident = Binder.clearCallingIdentity();
1731
1732 try {
1733 // With calling identity cleared the current user is the foreground user.
1734 int foregroundUser = ActivityManager.getCurrentUser();
1735 ok = (foregroundUser == callingUser);
1736 if (DBG_LOC) {
1737 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1738 + " callingUser=" + callingUser + " ok=" + ok);
1739 }
1740 } catch (Exception ex) {
1741 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1742 ok = false;
1743 } finally {
1744 Binder.restoreCallingIdentity(ident);
1745 }
1746 } else {
1747 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1748 ok = true;
1749 }
1750 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1751 return ok;
1752 }
1753
1754 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1756 *
1757 * @throws SecurityException if the caller does not have the required permission
1758 */
1759 private void enforceModifyPermission() {
1760 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1761 }
1762
1763 /**
Junda Liua2e36012014-07-09 18:30:01 -07001764 * Make sure either system app or the caller has carrier privilege.
1765 *
1766 * @throws SecurityException if the caller does not have the required permission/privilege
1767 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001768 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001769 int permission = mApp.checkCallingOrSelfPermission(
1770 android.Manifest.permission.MODIFY_PHONE_STATE);
1771 if (permission == PackageManager.PERMISSION_GRANTED) {
1772 return;
1773 }
1774
1775 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001776 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001777 }
1778
1779 /**
1780 * Make sure the caller has carrier privilege.
1781 *
1782 * @throws SecurityException if the caller does not have the required permission
1783 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001784 private void enforceCarrierPrivilege(int subId) {
1785 if (getCarrierPrivilegeStatus(subId) !=
1786 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001787 loge("No Carrier Privilege.");
1788 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001789 }
1790 }
1791
1792 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 * Make sure the caller has the CALL_PHONE permission.
1794 *
1795 * @throws SecurityException if the caller does not have the required permission
1796 */
1797 private void enforceCallPermission() {
1798 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1799 }
1800
Stuart Scott8eef64f2015-04-08 15:13:54 -07001801 private void enforceConnectivityInternalPermission() {
1802 mApp.enforceCallingOrSelfPermission(
1803 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1804 "ConnectivityService");
1805 }
1806
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 private String createTelUrl(String number) {
1808 if (TextUtils.isEmpty(number)) {
1809 return null;
1810 }
1811
Jake Hambye994d462014-02-03 13:10:13 -08001812 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
Ihab Awadf9e92732013-12-05 18:02:52 -08001815 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1817 }
1818
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001819 private static void logv(String msg) {
1820 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1821 }
1822
Ihab Awadf9e92732013-12-05 18:02:52 -08001823 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1825 }
1826
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001827 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001829 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001830 }
1831
Sanket Padawe356d7632015-06-22 14:03:32 -07001832 @Override
Shishir Agrawala9f32182016-04-12 12:00:16 -07001833 public int getActivePhoneTypeForSlot(int slotId) {
1834 final Phone phone = PhoneFactory.getPhone(slotId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001835 if (phone == null) {
1836 return PhoneConstants.PHONE_TYPE_NONE;
1837 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001838 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 }
1841
1842 /**
1843 * Returns the CDMA ERI icon index to display
1844 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001845 @Override
1846 public int getCdmaEriIconIndex(String callingPackage) {
1847 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
Sanket Padawe356d7632015-06-22 14:03:32 -07001850 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001851 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1852 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1853 return -1;
1854 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 final Phone phone = getPhone(subId);
1856 if (phone != null) {
1857 return phone.getCdmaEriIconIndex();
1858 } else {
1859 return -1;
1860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
1863 /**
1864 * Returns the CDMA ERI icon mode,
1865 * 0 - ON
1866 * 1 - FLASHING
1867 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001868 @Override
1869 public int getCdmaEriIconMode(String callingPackage) {
1870 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001871 }
1872
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001874 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1875 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1876 return -1;
1877 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001878 final Phone phone = getPhone(subId);
1879 if (phone != null) {
1880 return phone.getCdmaEriIconMode();
1881 } else {
1882 return -1;
1883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
1886 /**
1887 * Returns the CDMA ERI text,
1888 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001889 @Override
1890 public String getCdmaEriText(String callingPackage) {
1891 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001895 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1896 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1897 return null;
1898 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 final Phone phone = getPhone(subId);
1900 if (phone != null) {
1901 return phone.getCdmaEriText();
1902 } else {
1903 return null;
1904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
1907 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001908 * Returns the CDMA MDN.
1909 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001910 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001911 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001912 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 final Phone phone = getPhone(subId);
1914 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1915 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001916 } else {
1917 return null;
1918 }
1919 }
1920
1921 /**
1922 * Returns the CDMA MIN.
1923 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001925 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001926 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 final Phone phone = getPhone(subId);
1928 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1929 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001930 } else {
1931 return null;
1932 }
1933 }
1934
1935 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 * Returns true if CDMA provisioning needs to run.
1937 */
1938 public boolean needsOtaServiceProvisioning() {
1939 return mPhone.needsOtaServiceProvisioning();
1940 }
1941
1942 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001943 * Sets the voice mail number of a given subId.
1944 */
1945 @Override
1946 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001947 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001948 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1949 new Pair<String, String>(alphaTag, number), new Integer(subId));
1950 return success;
1951 }
1952
Ta-wei Yen87c49842016-05-13 21:19:52 -07001953 @Override
Ta-wei Yenb0f695b2016-08-08 17:33:11 -07001954 public void setVisualVoicemailEnabled(String callingPackage,
1955 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
1956 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1957 if (!TextUtils.equals(callingPackage,
1958 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
1959 enforceModifyPermissionOrCarrierPrivilege(
1960 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
1961 }
1962 VisualVoicemailSettingsUtil.setEnabled(mPhone.getContext(), phoneAccountHandle, enabled);
1963 }
1964
1965 @Override
1966 public boolean isVisualVoicemailEnabled(String callingPackage,
1967 PhoneAccountHandle phoneAccountHandle) {
1968 if (!canReadPhoneState(callingPackage, "isVisualVoicemailEnabled")) {
1969 return false;
1970 }
1971 return VisualVoicemailSettingsUtil.isEnabled(mPhone.getContext(), phoneAccountHandle);
1972 }
1973
1974 @Override
Ta-wei Yendca928f2017-01-10 16:17:08 -08001975 public String getVisualVoicemailPackageName(String callingPackage,
1976 @Nullable PhoneAccountHandle phoneAccountHandle) {
1977 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1978 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
1979 return null;
1980 }
1981 int subId = PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
1982 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
1983 }
1984
1985 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001986 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
1987 VisualVoicemailSmsFilterSettings settings) {
1988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001989 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001990 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
1991 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001992 }
1993
1994 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001995 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
1996 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001997 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001998 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001999 }
2000
2001 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002002 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2003 String callingPackage, int subId) {
2004 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002005 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002006 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002007 }
2008
2009 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002010 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002011 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002012 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002013 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2014 }
2015
2016 @Override
2017 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2018 String number, int port, String text, PendingIntent sentIntent) {
2019 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002020 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002021 enforceSendSmsPermission();
2022 // Make the calls as the phone process.
2023 final long identity = Binder.clearCallingIdentity();
2024 try {
2025 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2026 if (port == 0) {
2027 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2028 sentIntent, null, false);
2029 } else {
2030 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2031 smsManager.sendDataMessageWithSelfPermissions(number, null,
2032 (short) port, data, sentIntent, null);
2033 }
2034 } finally {
2035 Binder.restoreCallingIdentity(identity);
2036 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002037 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002038 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 * Returns the unread count of voicemails
2040 */
2041 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002042 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002043 }
2044
2045 /**
2046 * Returns the unread count of voicemails for a subId
2047 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002048 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002049 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002050 final Phone phone = getPhone(subId);
2051 if (phone != null) {
2052 return phone.getVoiceMessageCount();
2053 } else {
2054 return 0;
2055 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 }
2057
2058 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002059 * returns true, if the device is in a state where both voice and data
2060 * are supported simultaneously. This can change based on location or network condition.
2061 */
2062 @Override
2063 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2064 final Phone phone = getPhone(subId);
2065 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2066 }
2067
2068 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002069 * Returns the data network type.
2070 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 *
2072 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2073 */
2074 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002075 public int getNetworkType() {
2076 final Phone phone = getPhone(getDefaultSubscription());
2077 if (phone != null) {
2078 return phone.getServiceState().getDataNetworkType();
2079 } else {
2080 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2081 }
Wink Saville36469e72014-06-11 15:17:00 -07002082 }
2083
2084 /**
2085 * Returns the network type for a subId
2086 */
2087 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002088 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2089 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2090 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2091 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002092
Sanket Padawe356d7632015-06-22 14:03:32 -07002093 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002094 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002095 return phone.getServiceState().getDataNetworkType();
2096 } else {
2097 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2098 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 }
2100
2101 /**
2102 * Returns the data network type
2103 */
2104 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002105 public int getDataNetworkType(String callingPackage) {
2106 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002107 }
2108
2109 /**
2110 * Returns the data network type for a subId
2111 */
2112 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002113 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2114 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2115 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2116 }
2117
Sanket Padawe356d7632015-06-22 14:03:32 -07002118 final Phone phone = getPhone(subId);
2119 if (phone != null) {
2120 return phone.getServiceState().getDataNetworkType();
2121 } else {
2122 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 }
2125
2126 /**
Wink Saville36469e72014-06-11 15:17:00 -07002127 * Returns the Voice network type for a subId
2128 */
2129 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002130 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2131 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2132 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2133 }
2134
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 final Phone phone = getPhone(subId);
2136 if (phone != null) {
2137 return phone.getServiceState().getVoiceNetworkType();
2138 } else {
2139 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 }
2142
2143 /**
2144 * @return true if a ICC card is present
2145 */
2146 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002147 // FIXME Make changes to pass defaultSimId of type int
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002148 return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002149 }
2150
2151 /**
2152 * @return true if a ICC card is present for a slotId
2153 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002154 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002155 public boolean hasIccCardUsingSlotId(int slotId) {
fionaxu6e6c68b2016-06-23 13:31:32 -07002156 final Phone phone = PhoneFactory.getPhone(slotId);
2157 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002158 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002159 } else {
2160 return false;
2161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 }
2163
2164 /**
2165 * Return if the current radio is LTE on CDMA. This
2166 * is a tri-state return value as for a period of time
2167 * the mode may be unknown.
2168 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002169 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002171 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002173 @Override
2174 public int getLteOnCdmaMode(String callingPackage) {
2175 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002176 }
2177
Sanket Padawe356d7632015-06-22 14:03:32 -07002178 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002179 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2180 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2181 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2182 }
2183
Sanket Padawe356d7632015-06-22 14:03:32 -07002184 final Phone phone = getPhone(subId);
2185 if (phone == null) {
2186 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2187 } else {
2188 return phone.getLteOnCdmaMode();
2189 }
Wink Saville36469e72014-06-11 15:17:00 -07002190 }
2191
2192 public void setPhone(Phone phone) {
2193 mPhone = phone;
2194 }
2195
2196 /**
2197 * {@hide}
2198 * Returns Default subId, 0 in the case of single standby.
2199 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002200 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002201 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002202 }
2203
Shishir Agrawala9f32182016-04-12 12:00:16 -07002204 private int getSlotForDefaultSubscription() {
2205 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2206 }
2207
Wink Savilleb564aae2014-10-23 10:18:09 -07002208 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002209 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002211
2212 /**
2213 * @see android.telephony.TelephonyManager.WifiCallingChoices
2214 */
2215 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002216 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2217 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002218 }
2219
2220 /**
2221 * @see android.telephony.TelephonyManager.WifiCallingChoices
2222 */
2223 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002224 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2225 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2226 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002227 }
2228
Sailesh Nepald1e68152013-12-12 19:08:02 -08002229 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002230 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002231 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002232 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002233
Shishir Agrawal566b7612013-10-28 14:41:00 -07002234 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002235 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID) {
2236 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002237
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002238 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002239 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002240 CMD_OPEN_CHANNEL, AID, subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002241 if (DBG) log("iccOpenLogicalChannel: " + response);
2242 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002243 }
2244
2245 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002246 public boolean iccCloseLogicalChannel(int subId, int channel) {
2247 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002248
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002249 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002250 if (channel < 0) {
2251 return false;
2252 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002253 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002254 if (DBG) log("iccCloseLogicalChannel: " + success);
2255 return success;
2256 }
2257
2258 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002259 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002260 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002261 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002262
2263 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002264 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2265 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002266 " data=" + data);
2267 }
2268
2269 if (channel < 0) {
2270 return "";
2271 }
2272
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002273 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002274 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002275 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2276
Shishir Agrawal566b7612013-10-28 14:41:00 -07002277 // Append the returned status code to the end of the response payload.
2278 String s = Integer.toHexString(
2279 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002280 if (response.payload != null) {
2281 s = IccUtils.bytesToHexString(response.payload) + s;
2282 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002283 return s;
2284 }
Jake Hambye994d462014-02-03 13:10:13 -08002285
Evan Charltonc66da362014-05-16 14:06:40 -07002286 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002287 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002288 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002289 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002290
2291 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002292 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2293 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002294 }
2295
2296 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002297 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002298 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2299
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002300 // Append the returned status code to the end of the response payload.
2301 String s = Integer.toHexString(
2302 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002303 if (response.payload != null) {
2304 s = IccUtils.bytesToHexString(response.payload) + s;
2305 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002306 return s;
2307 }
2308
2309 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002310 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002311 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002312 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002313
2314 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002315 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002316 p1 + " " + p2 + " " + p3 + ":" + filePath);
2317 }
2318
2319 IccIoResult response =
2320 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002321 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2322 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002323
2324 if (DBG) {
2325 log("Exchange SIM_IO [R]" + response);
2326 }
2327
2328 byte[] result = null;
2329 int length = 2;
2330 if (response.payload != null) {
2331 length = 2 + response.payload.length;
2332 result = new byte[length];
2333 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2334 } else {
2335 result = new byte[length];
2336 }
2337
2338 result[length - 1] = (byte) response.sw2;
2339 result[length - 2] = (byte) response.sw1;
2340 return result;
2341 }
2342
2343 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002344 public String sendEnvelopeWithStatus(int subId, String content) {
2345 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002346
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002347 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002348 if (response.payload == null) {
2349 return "";
2350 }
2351
2352 // Append the returned status code to the end of the response payload.
2353 String s = Integer.toHexString(
2354 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2355 s = IccUtils.bytesToHexString(response.payload) + s;
2356 return s;
2357 }
2358
Jake Hambye994d462014-02-03 13:10:13 -08002359 /**
2360 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2361 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2362 *
2363 * @param itemID the ID of the item to read
2364 * @return the NV item as a String, or null on error.
2365 */
2366 @Override
2367 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002368 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002369 if (DBG) log("nvReadItem: item " + itemID);
2370 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2371 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2372 return value;
2373 }
2374
2375 /**
2376 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2377 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2378 *
2379 * @param itemID the ID of the item to read
2380 * @param itemValue the value to write, as a String
2381 * @return true on success; false on any failure
2382 */
2383 @Override
2384 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002385 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002386 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2387 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2388 new Pair<Integer, String>(itemID, itemValue));
2389 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2390 return success;
2391 }
2392
2393 /**
2394 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2395 * Used for device configuration by some CDMA operators.
2396 *
2397 * @param preferredRoamingList byte array containing the new PRL
2398 * @return true on success; false on any failure
2399 */
2400 @Override
2401 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002402 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002403 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2404 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2405 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2406 return success;
2407 }
2408
2409 /**
2410 * Perform the specified type of NV config reset.
2411 * Used for device configuration by some CDMA operators.
2412 *
2413 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2414 * @return true on success; false on any failure
2415 */
2416 @Override
2417 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002418 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002419 if (DBG) log("nvResetConfig: type " + resetType);
2420 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2421 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2422 return success;
2423 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002424
2425 /**
Wink Saville36469e72014-06-11 15:17:00 -07002426 * {@hide}
2427 * Returns Default sim, 0 in the case of single standby.
2428 */
2429 public int getDefaultSim() {
2430 //TODO Need to get it from Telephony Devcontroller
2431 return 0;
2432 }
2433
Svet Ganovb320e182015-04-16 12:30:10 -07002434 public String[] getPcscfAddress(String apnType, String callingPackage) {
2435 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2436 return new String[0];
2437 }
2438
2439
ram87fca6f2014-07-18 18:58:44 +05302440 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002441 }
2442
Brad Ebinger51f743a2017-01-23 13:50:20 -08002443 /**
2444 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2445 * feature or {@link null} if the service is not available. If an ImsServiceController is
2446 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2447 * feature updates.
2448 */
2449 public IImsServiceController getImsServiceControllerAndListen(int slotId, int feature,
2450 IImsServiceFeatureListener callback) {
2451 enforceModifyPermission();
2452 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotId, feature,
2453 callback);
2454 }
2455
Wink Saville36469e72014-06-11 15:17:00 -07002456 public void setImsRegistrationState(boolean registered) {
2457 enforceModifyPermission();
2458 mPhone.setImsRegistrationState(registered);
2459 }
2460
2461 /**
Stuart Scott54788802015-03-30 13:18:01 -07002462 * Set the network selection mode to automatic.
2463 *
2464 */
2465 @Override
2466 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002467 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002468 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2469 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2470 }
2471
2472 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002473 * Set the network selection mode to manual with the selected carrier.
2474 */
2475 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002476 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2477 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002478 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002479 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002480 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2481 persistSelection);
2482 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002483 }
2484
2485 /**
2486 * Scans for available networks.
2487 */
2488 @Override
2489 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002490 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002491 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2492 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2493 CMD_PERFORM_NETWORK_SCAN, null, subId);
2494 return result;
2495 }
2496
2497 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002498 * Get the calculated preferred network type.
2499 * Used for debugging incorrect network type.
2500 *
2501 * @return the preferred network type, defined in RILConstants.java.
2502 */
2503 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002504 public int getCalculatedPreferredNetworkType(String callingPackage) {
2505 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2506 return RILConstants.PREFERRED_NETWORK_MODE;
2507 }
2508
Amit Mahajan43330e02014-11-18 11:54:45 -08002509 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002510 }
2511
2512 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002513 * Get the preferred network type.
2514 * Used for device configuration by some CDMA operators.
2515 *
2516 * @return the preferred network type, defined in RILConstants.java.
2517 */
2518 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002519 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002520 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002521 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002522 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002523 int networkType = (result != null ? result[0] : -1);
2524 if (DBG) log("getPreferredNetworkType: " + networkType);
2525 return networkType;
2526 }
2527
2528 /**
2529 * Set the preferred network type.
2530 * Used for device configuration by some CDMA operators.
2531 *
2532 * @param networkType the preferred network type, defined in RILConstants.java.
2533 * @return true on success; false on any failure.
2534 */
2535 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002536 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002537 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002538 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2539 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002540 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002541 if (success) {
2542 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002543 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002544 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002545 return success;
2546 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002547
2548 /**
Junda Liu475951f2014-11-07 16:45:03 -08002549 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2550 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2551 * tethering.
2552 *
2553 * @return 0: Not required. 1: required. 2: Not set.
2554 * @hide
2555 */
2556 @Override
2557 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002558 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002559 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2560 Settings.Global.TETHER_DUN_REQUIRED, 2);
2561 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2562 // config_tether_apndata.
2563 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2564 dunRequired = 1;
2565 }
2566 return dunRequired;
2567 }
2568
2569 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002570 * Set mobile data enabled
2571 * Used by the user through settings etc to turn on/off mobile data
2572 *
2573 * @param enable {@code true} turn turn data on, else {@code false}
2574 */
2575 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002576 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002577 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002578 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002579 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002580 Phone phone = PhoneFactory.getPhone(phoneId);
2581 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002582 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002583 phone.setDataEnabled(enable);
2584 } else {
2585 loge("setDataEnabled: no phone for subId=" + subId);
2586 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002587 }
2588
2589 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002590 * Get whether mobile data is enabled.
2591 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002592 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002593 *
2594 * @return {@code true} if data is enabled else {@code false}
2595 */
2596 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002597 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002598 try {
2599 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2600 null);
2601 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002602 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002603 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002604 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002605 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002606 Phone phone = PhoneFactory.getPhone(phoneId);
2607 if (phone != null) {
2608 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002609 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002610 return retVal;
2611 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002612 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002613 return false;
2614 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002615 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002616
2617 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002618 public int getCarrierPrivilegeStatus(int subId) {
2619 final Phone phone = getPhone(subId);
2620 if (phone == null) {
2621 loge("getCarrierPrivilegeStatus: Invalid subId");
2622 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2623 }
2624 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002625 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002626 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002627 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2628 }
2629 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002630 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002631 }
Junda Liu29340342014-07-10 15:23:27 -07002632
2633 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002634 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002635 if (TextUtils.isEmpty(pkgName))
2636 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002637 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002638 if (card == null) {
2639 loge("checkCarrierPrivilegesForPackage: No UICC");
2640 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2641 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002642 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2643 }
2644
2645 @Override
2646 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002647 if (TextUtils.isEmpty(pkgName))
2648 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002649 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2650 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2651 UiccCard card = UiccController.getInstance().getUiccCard(i);
2652 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002653 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002654 continue;
2655 }
2656
2657 result = card.getCarrierPrivilegeStatus(
2658 mPhone.getContext().getPackageManager(), pkgName);
2659 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2660 break;
2661 }
2662 }
2663
2664 return result;
Junda Liu29340342014-07-10 15:23:27 -07002665 }
Derek Tan89e89d42014-07-08 17:00:10 -07002666
2667 @Override
Junda Liue64de782015-04-16 17:19:16 -07002668 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2669 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2670 loge("phoneId " + phoneId + " is not valid.");
2671 return null;
2672 }
2673 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002674 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002675 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002676 return null ;
2677 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002678 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002679 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002680 }
2681
Amith Yamasani6e118872016-02-19 12:53:51 -08002682 @Override
2683 public List<String> getPackagesWithCarrierPrivileges() {
2684 PackageManager pm = mPhone.getContext().getPackageManager();
2685 List<String> privilegedPackages = new ArrayList<>();
2686 List<PackageInfo> packages = null;
2687 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2688 UiccCard card = UiccController.getInstance().getUiccCard(i);
2689 if (card == null) {
2690 // No UICC in that slot.
2691 continue;
2692 }
2693 if (card.hasCarrierPrivilegeRules()) {
2694 if (packages == null) {
2695 // Only check packages in user 0 for now
2696 packages = pm.getInstalledPackagesAsUser(
2697 PackageManager.MATCH_DISABLED_COMPONENTS
2698 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2699 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2700 }
2701 for (int p = packages.size() - 1; p >= 0; p--) {
2702 PackageInfo pkgInfo = packages.get(p);
2703 if (pkgInfo != null && pkgInfo.packageName != null
2704 && card.getCarrierPrivilegeStatus(pkgInfo)
2705 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2706 privilegedPackages.add(pkgInfo.packageName);
2707 }
2708 }
2709 }
2710 }
2711 return privilegedPackages;
2712 }
2713
Wink Savilleb564aae2014-10-23 10:18:09 -07002714 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 final Phone phone = getPhone(subId);
2716 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002717 if (card == null) {
2718 loge("getIccId: No UICC");
2719 return null;
2720 }
2721 String iccId = card.getIccId();
2722 if (TextUtils.isEmpty(iccId)) {
2723 loge("getIccId: ICC ID is null or empty.");
2724 return null;
2725 }
2726 return iccId;
2727 }
2728
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002729 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002730 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2731 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002732 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002733
Jeff Sharkey85190e62014-12-05 09:40:12 -08002734 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002735 final Phone phone = getPhone(subId);
2736 if (phone == null) {
2737 return false;
2738 }
2739 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002740
2741 if (DBG_MERGE) {
2742 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2743 + subscriberId + " to " + number);
2744 }
2745
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002746 if (TextUtils.isEmpty(iccId)) {
2747 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002748 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002749
Jeff Sharkey85190e62014-12-05 09:40:12 -08002750 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2751
2752 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002753 if (alphaTag == null) {
2754 editor.remove(alphaTagPrefKey);
2755 } else {
2756 editor.putString(alphaTagPrefKey, alphaTag);
2757 }
2758
Jeff Sharkey85190e62014-12-05 09:40:12 -08002759 // Record both the line number and IMSI for this ICCID, since we need to
2760 // track all merged IMSIs based on line number
2761 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2762 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002763 if (number == null) {
2764 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002765 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002766 } else {
2767 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002768 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002769 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002770
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002771 editor.commit();
2772 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002773 }
2774
2775 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002776 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002777 // This is open to apps with WRITE_SMS.
2778 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002779 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002780 return null;
2781 }
Derek Tan97ebb422014-09-05 16:55:38 -07002782
2783 String iccId = getIccId(subId);
2784 if (iccId != null) {
2785 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002786 if (DBG_MERGE) {
2787 log("getLine1NumberForDisplay returning " +
2788 mTelephonySharedPreferences.getString(numberPrefKey, null));
2789 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002790 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002791 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002792 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002793 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002794 }
2795
2796 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002797 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2798 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2799 return null;
2800 }
Derek Tan97ebb422014-09-05 16:55:38 -07002801
2802 String iccId = getIccId(subId);
2803 if (iccId != null) {
2804 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002805 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002806 }
Derek Tan97ebb422014-09-05 16:55:38 -07002807 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002808 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002809
2810 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002811 public String[] getMergedSubscriberIds(String callingPackage) {
2812 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2813 return null;
2814 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002815 final Context context = mPhone.getContext();
2816 final TelephonyManager tele = TelephonyManager.from(context);
2817 final SubscriptionManager sub = SubscriptionManager.from(context);
2818
2819 // Figure out what subscribers are currently active
2820 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002821 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2822 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 final int[] subIds = sub.getActiveSubscriptionIdList();
2826 for (int subId : subIds) {
2827 activeSubscriberIds.add(tele.getSubscriberId(subId));
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002831 }
2832
2833 // First pass, find a number override for an active subscriber
2834 String mergeNumber = null;
2835 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2836 for (String key : prefs.keySet()) {
2837 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2838 final String subscriberId = (String) prefs.get(key);
2839 if (activeSubscriberIds.contains(subscriberId)) {
2840 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2841 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2842 mergeNumber = (String) prefs.get(numberKey);
2843 if (DBG_MERGE) {
2844 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2845 + " for active subscriber " + subscriberId);
2846 }
2847 if (!TextUtils.isEmpty(mergeNumber)) {
2848 break;
2849 }
2850 }
2851 }
2852 }
2853
2854 // Shortcut when no active merged subscribers
2855 if (TextUtils.isEmpty(mergeNumber)) {
2856 return null;
2857 }
2858
2859 // Second pass, find all subscribers under that line override
2860 final ArraySet<String> result = new ArraySet<>();
2861 for (String key : prefs.keySet()) {
2862 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2863 final String number = (String) prefs.get(key);
2864 if (mergeNumber.equals(number)) {
2865 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2866 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2867 final String subscriberId = (String) prefs.get(subscriberKey);
2868 if (!TextUtils.isEmpty(subscriberId)) {
2869 result.add(subscriberId);
2870 }
2871 }
2872 }
2873 }
2874
2875 final String[] resultArray = result.toArray(new String[result.size()]);
2876 Arrays.sort(resultArray);
2877 if (DBG_MERGE) {
2878 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2879 }
2880 return resultArray;
2881 }
2882
2883 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002884 public boolean setOperatorBrandOverride(int subId, String brand) {
2885 enforceCarrierPrivilege(subId);
2886 final Phone phone = getPhone(subId);
2887 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002888 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002889
2890 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002891 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002892 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2893 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002894 enforceCarrierPrivilege(subId);
2895 final Phone phone = getPhone(subId);
2896 if (phone == null) {
2897 return false;
2898 }
2899 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002900 cdmaNonRoamingList);
2901 }
2902
2903 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002904 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2905 enforceModifyPermission();
2906
2907 int returnValue = 0;
2908 try {
2909 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2910 if(result.exception == null) {
2911 if (result.result != null) {
2912 byte[] responseData = (byte[])(result.result);
2913 if(responseData.length > oemResp.length) {
2914 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2915 responseData.length + "bytes. Buffer Size is " +
2916 oemResp.length + "bytes.");
2917 }
2918 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2919 returnValue = responseData.length;
2920 }
2921 } else {
2922 CommandException ex = (CommandException) result.exception;
2923 returnValue = ex.getCommandError().ordinal();
2924 if(returnValue > 0) returnValue *= -1;
2925 }
2926 } catch (RuntimeException e) {
2927 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2928 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2929 if(returnValue > 0) returnValue *= -1;
2930 }
2931
2932 return returnValue;
2933 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002934
2935 @Override
2936 public void setRadioCapability(RadioAccessFamily[] rafs) {
2937 try {
2938 ProxyController.getInstance().setRadioCapability(rafs);
2939 } catch (RuntimeException e) {
2940 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2941 }
2942 }
2943
2944 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002945 public int getRadioAccessFamily(int phoneId, String callingPackage) {
2946 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
2947 return RadioAccessFamily.RAF_UNKNOWN;
2948 }
2949
Wink Saville5d475dd2014-10-17 15:00:58 -07002950 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2951 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002952
2953 @Override
2954 public void enableVideoCalling(boolean enable) {
2955 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002956 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07002957 }
2958
2959 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002960 public boolean isVideoCallingEnabled(String callingPackage) {
2961 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
2962 return false;
2963 }
2964
Andrew Lee77527ac2014-10-21 16:57:39 -07002965 // Check the user preference and the system-level IMS setting. Even if the user has
2966 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2967 // In the long run, we may instead need to check if there exists a connection service
2968 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002969 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2970 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002971 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07002972 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002973
Andrew Leea1239f22015-03-02 17:44:07 -08002974 @Override
2975 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002976 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002977 }
2978
2979 @Override
2980 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002981 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002982 }
2983
Andrew Lee9431b832015-03-09 18:46:45 -07002984 @Override
2985 public boolean isTtyModeSupported() {
2986 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
2987 TelephonyManager telephonyManager =
2988 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08002989 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07002990 }
2991
2992 @Override
2993 public boolean isHearingAidCompatibilitySupported() {
2994 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
2995 }
2996
Sanket Padawe7310cc72015-01-14 09:53:20 -08002997 /**
2998 * Returns the unique device ID of phone, for example, the IMEI for
2999 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3000 *
3001 * <p>Requires Permission:
3002 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3003 */
3004 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003005 public String getDeviceId(String callingPackage) {
3006 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3007 return null;
3008 }
3009
Sanket Padawe7310cc72015-01-14 09:53:20 -08003010 final Phone phone = PhoneFactory.getPhone(0);
3011 if (phone != null) {
3012 return phone.getDeviceId();
3013 } else {
3014 return null;
3015 }
3016 }
3017
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003018 /*
3019 * {@hide}
3020 * Returns the IMS Registration Status
3021 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003022 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003023 public boolean isImsRegistered() {
3024 return mPhone.isImsRegistered();
3025 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003026
3027 @Override
3028 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3029 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3030 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003031
Nathan Haroldc55097a2015-03-11 18:14:50 -07003032 /*
3033 * {@hide}
3034 * Returns the IMS Registration Status
3035 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003036 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003037 return mPhone.isWifiCallingEnabled();
3038 }
3039
3040 /*
3041 * {@hide}
3042 * Returns the IMS Registration Status
3043 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003044 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003045 return mPhone.isVolteEnabled();
3046 }
Svet Ganovb320e182015-04-16 12:30:10 -07003047
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003048 /*
3049 * {@hide} Returns the IMS Registration Status
3050 */
3051 public boolean isVideoTelephonyAvailable() {
3052 return mPhone.isVideoEnabled();
3053 }
3054
Svet Ganovb320e182015-04-16 12:30:10 -07003055 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003056 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003057 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003058 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3059
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003060 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003061 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003062 } catch (SecurityException e) {
3063 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3064 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003065 }
Svet Ganovb320e182015-04-16 12:30:10 -07003066
3067 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3068 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3069 return false;
3070 }
3071
3072 return true;
3073 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003074
Makoto Onukifee69342015-06-29 14:44:50 -07003075 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003076 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003077 */
3078 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003079 // Default SMS app can always read it.
3080 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3081 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3082 return true;
3083 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003084
Makoto Onukie4072d12015-08-03 15:12:23 -07003085 try {
3086 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003087 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003088 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003089 // Can be read with READ_SMS too.
3090 try {
3091 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3092 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3093 if (opCode != AppOpsManager.OP_NONE) {
3094 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3095 == AppOpsManager.MODE_ALLOWED;
3096 } else {
3097 return true;
3098 }
3099 } catch (SecurityException readSmsSecurityException) {
3100 }
3101 // Can be read with READ_PHONE_NUMBER too.
3102 try {
3103 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBER,
3104 message);
3105 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBER);
3106 if (opCode != AppOpsManager.OP_NONE) {
3107 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3108 == AppOpsManager.MODE_ALLOWED;
3109 } else {
3110 return true;
3111 }
3112 } catch (SecurityException readPhoneNumberSecurityException) {
3113 }
3114
3115 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3116 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3117 ", " + android.Manifest.permission.READ_SMS + ", or " +
3118 android.Manifest.permission.READ_PHONE_NUMBER);
Makoto Onukifee69342015-06-29 14:44:50 -07003119 }
3120
Stuart Scott8eef64f2015-04-08 15:13:54 -07003121 @Override
3122 public void factoryReset(int subId) {
3123 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003124 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3125 return;
3126 }
3127
Svet Ganovcc087f82015-05-12 20:35:54 -07003128 final long identity = Binder.clearCallingIdentity();
3129 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003130 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3131 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003132 // Enable data
3133 setDataEnabled(subId, true);
3134 // Set network selection mode to automatic
3135 setNetworkSelectionModeAutomatic(subId);
3136 // Set preferred mobile network type to the best available
3137 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3138 // Turn off roaming
3139 SubscriptionManager.from(mApp).setDataRoaming(0, subId);
3140 }
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003143 }
3144 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003145
3146 @Override
3147 public String getLocaleFromDefaultSim() {
3148 // We query all subscriptions instead of just the active ones, because
3149 // this might be called early on in the provisioning flow when the
3150 // subscriptions potentially aren't active yet.
3151 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3152 if (slist == null || slist.isEmpty()) {
3153 return null;
3154 }
3155
3156 // This function may be called very early, say, from the setup wizard, at
3157 // which point we won't have a default subscription set. If that's the case
3158 // we just choose the first, which will be valid in "most cases".
3159 final int defaultSubId = getDefaultSubscription();
3160 SubscriptionInfo info = null;
3161 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3162 info = slist.get(0);
3163 } else {
3164 for (SubscriptionInfo item : slist) {
3165 if (item.getSubscriptionId() == defaultSubId) {
3166 info = item;
3167 break;
3168 }
3169 }
3170
3171 if (info == null) {
3172 return null;
3173 }
3174 }
3175
3176 // Try and fetch the locale from the carrier properties or from the SIM language
3177 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003178 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003179 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003180 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003181 if (defaultPhone != null) {
3182 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3183 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003184 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003185 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3186 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003187 } else {
3188 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003189 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003190 }
3191 }
3192
Narayan Kamath011676f2015-07-29 12:04:08 +01003193 // The SIM language preferences only store a language (e.g. fr = French), not an
3194 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3195 // the SIM and carrier preferences does not include a country we add the country
3196 // determined from the SIM MCC to provide an exact locale.
3197 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003198 if (mccLocale != null) {
3199 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3200 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003201 }
3202
Tony Hill183b2de2015-06-24 14:53:58 +01003203 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003204 return null;
3205 }
3206
3207 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 return mSubscriptionController.getAllSubInfoList(
3211 mPhone.getContext().getOpPackageName());
3212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
3215 }
3216
3217 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3218 final long identity = Binder.clearCallingIdentity();
3219 try {
3220 return mSubscriptionController.getActiveSubscriptionInfoList(
3221 mPhone.getContext().getOpPackageName());
3222 } finally {
3223 Binder.restoreCallingIdentity(identity);
3224 }
3225 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003226
3227 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003228 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3229 * representing the state of the modem.
3230 *
3231 * NOTE: This clears the modem state, so there should only every be one caller.
3232 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003233 */
3234 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003235 public void requestModemActivityInfo(ResultReceiver result) {
3236 enforceModifyPermission();
3237
3238 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3239 Bundle bundle = new Bundle();
3240 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3241 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003242 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003243
3244 /**
3245 * {@hide}
3246 * Returns the service state information on specified subscription.
3247 */
3248 @Override
3249 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3250
3251 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3252 return null;
3253 }
3254
3255 final Phone phone = getPhone(subId);
3256 if (phone == null) {
3257 return null;
3258 }
3259
3260 return phone.getServiceState();
3261 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003262
3263 /**
3264 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3265 *
3266 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3267 * voicemail ringtone.
3268 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3269 * PhoneAccount.
3270 */
3271 @Override
3272 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
3273 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3274 if (phone == null) {
3275 return null;
3276 }
3277
3278 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
3279 }
3280
3281 /**
3282 * Returns whether vibration is set for voicemail notification in Phone settings.
3283 *
3284 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3285 * voicemail vibration setting.
3286 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3287 */
3288 @Override
3289 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
3290 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3291 if (phone == null) {
3292 return false;
3293 }
3294
3295 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone);
3296 }
3297
Youhan Wange64578a2016-05-02 15:32:42 -07003298 /**
3299 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3300 *
3301 * @throws SecurityException if the caller does not have the required permission
3302 */
3303 private void enforceReadPrivilegedPermission() {
3304 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3305 null);
3306 }
3307
3308 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003309 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3310 * permission.
3311 *
3312 * @throws SecurityException if the caller does not have the required permission
3313 */
3314 private void enforceSendSmsPermission() {
3315 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3316 }
3317
3318 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003319 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003320 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003321 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003322 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003323 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
3324 String vvmPackage = RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId)
3325 .getPackageName();
3326 if (!callingPackage.equals(vvmPackage)) {
3327 throw new SecurityException("Caller not current active visual voicemail package[" +
3328 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003329 }
3330 }
3331
3332 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003333 * Return the application ID for the app type.
3334 *
3335 * @param subId the subscription ID that this request applies to.
3336 * @param appType the uicc app type.
3337 * @return Application ID for specificied app type, or null if no uicc.
3338 */
3339 @Override
3340 public String getAidForAppType(int subId, int appType) {
3341 enforceReadPrivilegedPermission();
3342 Phone phone = getPhone(subId);
3343 if (phone == null) {
3344 return null;
3345 }
3346 String aid = null;
3347 try {
3348 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3349 .getApplicationByType(appType).getAid();
3350 } catch (Exception e) {
3351 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3352 }
3353 return aid;
3354 }
3355
Youhan Wang4001d252016-05-11 10:29:41 -07003356 /**
3357 * Return the Electronic Serial Number.
3358 *
3359 * @param subId the subscription ID that this request applies to.
3360 * @return ESN or null if error.
3361 */
3362 @Override
3363 public String getEsn(int subId) {
3364 enforceReadPrivilegedPermission();
3365 Phone phone = getPhone(subId);
3366 if (phone == null) {
3367 return null;
3368 }
3369 String esn = null;
3370 try {
3371 esn = phone.getEsn();
3372 } catch (Exception e) {
3373 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3374 }
3375 return esn;
3376 }
3377
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003378 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003379 * Return the Preferred Roaming List Version.
3380 *
3381 * @param subId the subscription ID that this request applies to.
3382 * @return PRLVersion or null if error.
3383 */
3384 @Override
3385 public String getCdmaPrlVersion(int subId) {
3386 enforceReadPrivilegedPermission();
3387 Phone phone = getPhone(subId);
3388 if (phone == null) {
3389 return null;
3390 }
3391 String cdmaPrlVersion = null;
3392 try {
3393 cdmaPrlVersion = phone.getCdmaPrlVersion();
3394 } catch (Exception e) {
3395 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3396 }
3397 return cdmaPrlVersion;
3398 }
3399
3400 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003401 * Get snapshot of Telephony histograms
3402 * @return List of Telephony histograms
3403 * @hide
3404 */
3405 @Override
3406 public List<TelephonyHistogram> getTelephonyHistograms() {
3407 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3408 return RIL.getTelephonyRILTimingHistograms();
3409 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003410
3411 /**
3412 * {@hide}
3413 * Set the allowed carrier list for slotId
3414 * Require system privileges. In the future we may add this to carrier APIs.
3415 *
3416 * @return The number of carriers set successfully, should match length of carriers
3417 */
3418 @Override
3419 public int setAllowedCarriers(int slotId, List<CarrierIdentifier> carriers) {
3420 enforceModifyPermission();
3421 int subId = SubscriptionManager.getSubId(slotId)[0];
3422 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3423 return retVal[0];
3424 }
3425
3426 /**
3427 * {@hide}
3428 * Get the allowed carrier list for slotId.
3429 * Require system privileges. In the future we may add this to carrier APIs.
3430 *
3431 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3432 * means all carriers are allowed.
3433 */
3434 @Override
3435 public List<CarrierIdentifier> getAllowedCarriers(int slotId) {
3436 enforceReadPrivilegedPermission();
3437 int subId = SubscriptionManager.getSubId(slotId)[0];
3438 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3439 }
3440
fionaxu59545b42016-05-25 15:53:37 -07003441 /**
3442 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3443 * @param subId the subscription ID that this action applies to.
3444 * @param enabled control enable or disable metered apns.
3445 * {@hide}
3446 */
3447 @Override
3448 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3449 enforceModifyPermission();
3450 final Phone phone = getPhone(subId);
3451 if (phone == null) {
3452 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3453 return;
3454 }
3455 try {
3456 phone.carrierActionSetMeteredApnsEnabled(enabled);
3457 } catch (Exception e) {
3458 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3459 }
3460 }
3461
3462 /**
3463 * Action set from carrier signalling broadcast receivers to enable/disable radio
3464 * @param subId the subscription ID that this action applies to.
3465 * @param enabled control enable or disable radio.
3466 * {@hide}
3467 */
3468 @Override
3469 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3470 enforceModifyPermission();
3471 final Phone phone = getPhone(subId);
3472 if (phone == null) {
3473 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3474 return;
3475 }
3476 try {
3477 phone.carrierActionSetRadioEnabled(enabled);
3478 } catch (Exception e) {
3479 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3480 }
3481 }
3482
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003483 /**
3484 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3485 * bug report is being generated.
3486 */
3487 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003488 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003489 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3490 != PackageManager.PERMISSION_GRANTED) {
3491 writer.println("Permission Denial: can't dump Phone from pid="
3492 + Binder.getCallingPid()
3493 + ", uid=" + Binder.getCallingUid()
3494 + "without permission "
3495 + android.Manifest.permission.DUMP);
3496 return;
3497 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003498 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003499 }
Jack Yueb89b242016-06-22 13:27:47 -07003500
3501 /**
3502 * Get aggregated video call data usage from all subscriptions since boot.
3503 * @return total data usage in bytes
3504 * {@hide}
3505 */
3506 @Override
3507 public long getVtDataUsage() {
3508 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3509 null);
3510
3511 // NetworkStatsService keeps tracking the active network interface and identity. It will
3512 // record the delta with the corresponding network identity. What we need to do here is
3513 // returning total video call data usage from all subscriptions since boot.
3514
3515 // TODO: Add sub id support in the future. We'll need it when we support DSDA and
3516 // simultaneous VT calls.
3517 final Phone[] phones = PhoneFactory.getPhones();
3518 long total = 0;
3519 for (Phone phone : phones) {
3520 total += phone.getVtDataUsage();
3521 }
3522 return total;
3523 }
Jack Yu75ab2952016-07-08 14:29:33 -07003524
3525 /**
3526 * Policy control of data connection. Usually used when data limit is passed.
3527 * @param enabled True if enabling the data, otherwise disabling.
3528 * @param subId Subscription index
3529 * {@hide}
3530 */
3531 @Override
3532 public void setPolicyDataEnabled(boolean enabled, int subId) {
3533 enforceModifyPermission();
3534 Phone phone = getPhone(subId);
3535 if (phone != null) {
3536 phone.setPolicyDataEnabled(enabled);
3537 }
3538 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003539
3540 /**
3541 * Get Client request stats
3542 * @return List of Client Request Stats
3543 * @hide
3544 */
3545 @Override
3546 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3547 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3548 return null;
3549 }
3550
3551 Phone phone = getPhone(subId);
3552 if (phone != null) {
3553 return phone.getClientRequestStats();
3554 }
3555
3556 return null;
3557 }
3558
3559 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3560 if (workSource != null) {
3561 return workSource;
3562 }
3563
3564 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3565 workSource = new WorkSource(uid, packageName);
3566 return workSource;
3567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003568}