blob: 81e6abc50f60ded58818d63f6779a92c565f3e2f [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;
Shishir Agrawal566b7612013-10-28 14:41:00 -070072import com.android.internal.telephony.CallManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070073import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070074import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080077import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010078import com.android.internal.telephony.MccTable;
Shishir Agrawal302c8692015-06-19 13:49:39 -070079import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import com.android.internal.telephony.Phone;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070082import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070083import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070084import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070085import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080086import com.android.internal.telephony.SubscriptionController;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.uicc.IccIoResult;
88import com.android.internal.telephony.uicc.IccUtils;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -070089import com.android.internal.telephony.uicc.UiccCard;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.uicc.UiccController;
Jake Hambye994d462014-02-03 13:10:13 -080091import com.android.internal.util.HexDump;
Ta-wei Yenb0f695b2016-08-08 17:33:11 -070092import com.android.phone.settings.VisualVoicemailSettingsUtil;
Nancy Chen31f9ba12016-01-06 11:42:12 -080093import com.android.phone.settings.VoicemailNotificationSettingsUtil;
Ta-wei Yen527a9c02017-01-06 15:29:25 -080094import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080095
Ta-wei Yenc236d6b2016-06-21 13:33:12 -070096import java.io.FileDescriptor;
97import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080098import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800101import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100102import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104
105/**
106 * Implementation of the ITelephony interface.
107 */
Santos Cordon117fee72014-05-16 17:56:12 -0700108public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109 private static final String LOG_TAG = "PhoneInterfaceManager";
110 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
111 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800112 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113
114 // Message codes used with mMainThreadHandler
115 private static final int CMD_HANDLE_PIN_MMI = 1;
116 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
117 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
118 private static final int CMD_ANSWER_RINGING_CALL = 4;
119 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700120 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
121 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122 private static final int CMD_OPEN_CHANNEL = 9;
123 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
124 private static final int CMD_CLOSE_CHANNEL = 11;
125 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800126 private static final int CMD_NV_READ_ITEM = 13;
127 private static final int EVENT_NV_READ_ITEM_DONE = 14;
128 private static final int CMD_NV_WRITE_ITEM = 15;
129 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
130 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
131 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
132 private static final int CMD_NV_RESET_CONFIG = 19;
133 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800134 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
135 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
136 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
137 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800138 private static final int CMD_SEND_ENVELOPE = 25;
139 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700140 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
141 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
142 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
143 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
144 private static final int CMD_EXCHANGE_SIM_IO = 31;
145 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800146 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
147 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700148 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
149 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700150 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
151 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700152 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
153 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
154 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
155 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700156 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
157 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
158 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
159 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700160 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161
162 /** The singleton instance. */
163 private static PhoneInterfaceManager sInstance;
164
Wink Saville3ab207e2014-11-20 13:07:20 -0800165 private PhoneGlobals mApp;
166 private Phone mPhone;
167 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700168 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800169 private AppOpsManager mAppOps;
170 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800171 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800172 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173
Derek Tan97ebb422014-09-05 16:55:38 -0700174 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
175 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800176 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700177
178 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179 * A request object to use for transmitting data to an ICC.
180 */
181 private static final class IccAPDUArgument {
182 public int channel, cla, command, p1, p2, p3;
183 public String data;
184
185 public IccAPDUArgument(int channel, int cla, int command,
186 int p1, int p2, int p3, String data) {
187 this.channel = channel;
188 this.cla = cla;
189 this.command = command;
190 this.p1 = p1;
191 this.p2 = p2;
192 this.p3 = p3;
193 this.data = data;
194 }
195 }
196
197 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700198 * A request object to use for transmitting data to an ICC.
199 */
200 private static final class ManualNetworkSelectionArgument {
201 public OperatorInfo operatorInfo;
202 public boolean persistSelection;
203
204 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
205 this.operatorInfo = operatorInfo;
206 this.persistSelection = persistSelection;
207 }
208 }
209
210 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
212 * request after sending. The main thread will notify the request when it is complete.
213 */
214 private static final class MainThreadRequest {
215 /** The argument to use for the request */
216 public Object argument;
217 /** The result of the request that is run on the main thread */
218 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800219 // The subscriber id that this request applies to. Defaults to
220 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
221 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222
223 public MainThreadRequest(Object argument) {
224 this.argument = argument;
225 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800226
227 public MainThreadRequest(Object argument, Integer subId) {
228 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800229 if (subId != null) {
230 this.subId = subId;
231 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 }
234
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800235 private static final class IncomingThirdPartyCallArgs {
236 public final ComponentName component;
237 public final String callId;
238 public final String callerDisplayName;
239
240 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
241 String callerDisplayName) {
242 this.component = component;
243 this.callId = callId;
244 this.callerDisplayName = callerDisplayName;
245 }
246 }
247
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 /**
249 * A handler that processes messages on the main thread in the phone process. Since many
250 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
251 * inbound binder threads to the main thread in the phone process. The Binder thread
252 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
253 * on, which will be notified when the operation completes and will contain the result of the
254 * request.
255 *
256 * <p>If a MainThreadRequest object is provided in the msg.obj field,
257 * note that request.result must be set to something non-null for the calling thread to
258 * unblock.
259 */
260 private final class MainThreadHandler extends Handler {
261 @Override
262 public void handleMessage(Message msg) {
263 MainThreadRequest request;
264 Message onCompleted;
265 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800266 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700267 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
269 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700270 case CMD_HANDLE_USSD_REQUEST: {
271 request = (MainThreadRequest) msg.obj;
272 final Phone phone = getPhoneFromRequest(request);
273 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
274 String ussdRequest = ussdObject.first;
275 ResultReceiver wrappedCallback = ussdObject.second;
276 request.result = phone != null ?
277 phone.handleUssdRequest(ussdRequest, wrappedCallback)
278 :false;
279 // Wake up the requesting thread
280 synchronized (request) {
281 request.notifyAll();
282 }
283 break;
284 }
285
Yorke Lee716f67e2015-06-17 15:39:16 -0700286 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700288 final Phone phone = getPhoneFromRequest(request);
289 request.result = phone != null ?
290 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
291 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 // Wake up the requesting thread
293 synchronized (request) {
294 request.notifyAll();
295 }
296 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298
299 case CMD_HANDLE_NEIGHBORING_CELL:
300 request = (MainThreadRequest) msg.obj;
301 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
302 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700303 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304 break;
305
306 case EVENT_NEIGHBORING_CELL_DONE:
307 ar = (AsyncResult) msg.obj;
308 request = (MainThreadRequest) ar.userObj;
309 if (ar.exception == null && ar.result != null) {
310 request.result = ar.result;
311 } else {
312 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800313 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314 }
315 // Wake up the requesting thread
316 synchronized (request) {
317 request.notifyAll();
318 }
319 break;
320
321 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700322 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800323 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700324 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 break;
326
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327 case CMD_END_CALL:
328 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800329 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700330 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700331 Phone phone = getPhone(end_subId);
332 if (phone == null) {
333 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
334 break;
335 }
336 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
338 // CDMA: If the user presses the Power button we treat it as
339 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700340 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
342 // GSM: End the call as per the Phone state
343 hungUp = PhoneUtils.hangup(mCM);
344 } else {
345 throw new IllegalStateException("Unexpected phone type: " + phoneType);
346 }
347 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
348 request.result = hungUp;
349 // Wake up the requesting thread
350 synchronized (request) {
351 request.notifyAll();
352 }
353 break;
354
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700355 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700356 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700357 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800358 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700359 if (uiccCard == null) {
360 loge("iccTransmitApduLogicalChannel: No UICC");
361 request.result = new IccIoResult(0x6F, 0, (byte[])null);
362 synchronized (request) {
363 request.notifyAll();
364 }
365 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700366 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
367 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700368 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700369 iccArgument.channel, iccArgument.cla, iccArgument.command,
370 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700371 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700373 break;
374
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700375 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700376 ar = (AsyncResult) msg.obj;
377 request = (MainThreadRequest) ar.userObj;
378 if (ar.exception == null && ar.result != null) {
379 request.result = ar.result;
380 } else {
381 request.result = new IccIoResult(0x6F, 0, (byte[])null);
382 if (ar.result == null) {
383 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800384 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700385 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800386 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700387 } else {
388 loge("iccTransmitApduLogicalChannel: Unknown exception");
389 }
390 }
391 synchronized (request) {
392 request.notifyAll();
393 }
394 break;
395
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700396 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
397 request = (MainThreadRequest) msg.obj;
398 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800399 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 if (uiccCard == null) {
401 loge("iccTransmitApduBasicChannel: No UICC");
402 request.result = new IccIoResult(0x6F, 0, (byte[])null);
403 synchronized (request) {
404 request.notifyAll();
405 }
406 } else {
407 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
408 request);
409 uiccCard.iccTransmitApduBasicChannel(
410 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
411 iccArgument.p3, iccArgument.data, onCompleted);
412 }
413 break;
414
415 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
416 ar = (AsyncResult) msg.obj;
417 request = (MainThreadRequest) ar.userObj;
418 if (ar.exception == null && ar.result != null) {
419 request.result = ar.result;
420 } else {
421 request.result = new IccIoResult(0x6F, 0, (byte[])null);
422 if (ar.result == null) {
423 loge("iccTransmitApduBasicChannel: Empty response");
424 } else if (ar.exception instanceof CommandException) {
425 loge("iccTransmitApduBasicChannel: CommandException: " +
426 ar.exception);
427 } else {
428 loge("iccTransmitApduBasicChannel: Unknown exception");
429 }
430 }
431 synchronized (request) {
432 request.notifyAll();
433 }
434 break;
435
436 case CMD_EXCHANGE_SIM_IO:
437 request = (MainThreadRequest) msg.obj;
438 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800439 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 if (uiccCard == null) {
441 loge("iccExchangeSimIO: No UICC");
442 request.result = new IccIoResult(0x6F, 0, (byte[])null);
443 synchronized (request) {
444 request.notifyAll();
445 }
446 } else {
447 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
448 request);
449 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
450 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
451 iccArgument.data, onCompleted);
452 }
453 break;
454
455 case EVENT_EXCHANGE_SIM_IO_DONE:
456 ar = (AsyncResult) msg.obj;
457 request = (MainThreadRequest) ar.userObj;
458 if (ar.exception == null && ar.result != null) {
459 request.result = ar.result;
460 } else {
461 request.result = new IccIoResult(0x6f, 0, (byte[])null);
462 }
463 synchronized (request) {
464 request.notifyAll();
465 }
466 break;
467
Derek Tan4d5e5c12014-02-04 11:54:58 -0800468 case CMD_SEND_ENVELOPE:
469 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800470 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700471 if (uiccCard == null) {
472 loge("sendEnvelopeWithStatus: No UICC");
473 request.result = new IccIoResult(0x6F, 0, (byte[])null);
474 synchronized (request) {
475 request.notifyAll();
476 }
477 } else {
478 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
479 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
480 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800481 break;
482
483 case EVENT_SEND_ENVELOPE_DONE:
484 ar = (AsyncResult) msg.obj;
485 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700486 if (ar.exception == null && ar.result != null) {
487 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800488 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
490 if (ar.result == null) {
491 loge("sendEnvelopeWithStatus: Empty response");
492 } else if (ar.exception instanceof CommandException) {
493 loge("sendEnvelopeWithStatus: CommandException: " +
494 ar.exception);
495 } else {
496 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
497 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800498 }
499 synchronized (request) {
500 request.notifyAll();
501 }
502 break;
503
Shishir Agrawal566b7612013-10-28 14:41:00 -0700504 case CMD_OPEN_CHANNEL:
505 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700507 if (uiccCard == null) {
508 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800509 request.result = new IccOpenLogicalChannelResponse(-1,
510 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700511 synchronized (request) {
512 request.notifyAll();
513 }
514 } else {
515 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
516 uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted);
517 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700518 break;
519
520 case EVENT_OPEN_CHANNEL_DONE:
521 ar = (AsyncResult) msg.obj;
522 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 int[] result = (int[]) ar.result;
526 int channelId = result[0];
527 byte[] selectResponse = null;
528 if (result.length > 1) {
529 selectResponse = new byte[result.length - 1];
530 for (int i = 1; i < result.length; ++i) {
531 selectResponse[i - 1] = (byte) result[i];
532 }
533 }
534 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700535 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700536 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 if (ar.result == null) {
538 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 if (ar.exception != null) {
541 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
542 }
543
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700544 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700545 if (ar.exception instanceof CommandException) {
546 CommandException.Error error =
547 ((CommandException) (ar.exception)).getCommandError();
548 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700549 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700550 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700551 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 }
553 }
554 openChannelResp = new IccOpenLogicalChannelResponse(
555 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700557 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 synchronized (request) {
559 request.notifyAll();
560 }
561 break;
562
563 case CMD_CLOSE_CHANNEL:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("iccCloseLogicalChannel: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
569 synchronized (request) {
570 request.notifyAll();
571 }
572 } else {
573 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
574 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
575 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 break;
577
578 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800579 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
580 break;
581
582 case CMD_NV_READ_ITEM:
583 request = (MainThreadRequest) msg.obj;
584 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
585 mPhone.nvReadItem((Integer) request.argument, onCompleted);
586 break;
587
588 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 ar = (AsyncResult) msg.obj;
590 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800591 if (ar.exception == null && ar.result != null) {
592 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800594 request.result = "";
595 if (ar.result == null) {
596 loge("nvReadItem: Empty response");
597 } else if (ar.exception instanceof CommandException) {
598 loge("nvReadItem: CommandException: " +
599 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800601 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 }
603 }
604 synchronized (request) {
605 request.notifyAll();
606 }
607 break;
608
Jake Hambye994d462014-02-03 13:10:13 -0800609 case CMD_NV_WRITE_ITEM:
610 request = (MainThreadRequest) msg.obj;
611 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
612 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
613 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
614 break;
615
616 case EVENT_NV_WRITE_ITEM_DONE:
617 handleNullReturnEvent(msg, "nvWriteItem");
618 break;
619
620 case CMD_NV_WRITE_CDMA_PRL:
621 request = (MainThreadRequest) msg.obj;
622 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
623 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
624 break;
625
626 case EVENT_NV_WRITE_CDMA_PRL_DONE:
627 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
628 break;
629
630 case CMD_NV_RESET_CONFIG:
631 request = (MainThreadRequest) msg.obj;
632 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
633 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
634 break;
635
636 case EVENT_NV_RESET_CONFIG_DONE:
637 handleNullReturnEvent(msg, "nvResetConfig");
638 break;
639
Jake Hamby7c27be32014-03-03 13:25:59 -0800640 case CMD_GET_PREFERRED_NETWORK_TYPE:
641 request = (MainThreadRequest) msg.obj;
642 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700643 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800644 break;
645
646 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
647 ar = (AsyncResult) msg.obj;
648 request = (MainThreadRequest) ar.userObj;
649 if (ar.exception == null && ar.result != null) {
650 request.result = ar.result; // Integer
651 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800652 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800653 if (ar.result == null) {
654 loge("getPreferredNetworkType: Empty response");
655 } else if (ar.exception instanceof CommandException) {
656 loge("getPreferredNetworkType: CommandException: " +
657 ar.exception);
658 } else {
659 loge("getPreferredNetworkType: Unknown exception");
660 }
661 }
662 synchronized (request) {
663 request.notifyAll();
664 }
665 break;
666
667 case CMD_SET_PREFERRED_NETWORK_TYPE:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
670 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700671 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800672 break;
673
674 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
675 handleNullReturnEvent(msg, "setPreferredNetworkType");
676 break;
677
Steven Liu4bf01bc2014-07-17 11:05:29 -0500678 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
679 request = (MainThreadRequest)msg.obj;
680 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
681 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
682 break;
683
684 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
685 ar = (AsyncResult)msg.obj;
686 request = (MainThreadRequest)ar.userObj;
687 request.result = ar;
688 synchronized (request) {
689 request.notifyAll();
690 }
691 break;
692
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800693 case CMD_SET_VOICEMAIL_NUMBER:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
696 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800697 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
698 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800699 break;
700
701 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
702 handleNullReturnEvent(msg, "setVoicemailNumber");
703 break;
704
Stuart Scott54788802015-03-30 13:18:01 -0700705 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
706 request = (MainThreadRequest) msg.obj;
707 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
708 request);
709 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
710 break;
711
712 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
713 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
714 break;
715
Shishir Agrawal302c8692015-06-19 13:49:39 -0700716 case CMD_PERFORM_NETWORK_SCAN:
717 request = (MainThreadRequest) msg.obj;
718 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
719 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
720 break;
721
722 case EVENT_PERFORM_NETWORK_SCAN_DONE:
723 ar = (AsyncResult) msg.obj;
724 request = (MainThreadRequest) ar.userObj;
725 CellNetworkScanResult cellScanResult;
726 if (ar.exception == null && ar.result != null) {
727 cellScanResult = new CellNetworkScanResult(
728 CellNetworkScanResult.STATUS_SUCCESS,
729 (List<OperatorInfo>) ar.result);
730 } else {
731 if (ar.result == null) {
732 loge("getCellNetworkScanResults: Empty response");
733 }
734 if (ar.exception != null) {
735 loge("getCellNetworkScanResults: Exception: " + ar.exception);
736 }
737 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
738 if (ar.exception instanceof CommandException) {
739 CommandException.Error error =
740 ((CommandException) (ar.exception)).getCommandError();
741 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
742 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
743 } else if (error == CommandException.Error.GENERIC_FAILURE) {
744 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
745 }
746 }
747 cellScanResult = new CellNetworkScanResult(errorCode, null);
748 }
749 request.result = cellScanResult;
750 synchronized (request) {
751 request.notifyAll();
752 }
753 break;
754
755 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
756 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700757 ManualNetworkSelectionArgument selArg =
758 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700759 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
760 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700761 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
762 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700763 break;
764
765 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
766 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
767 break;
768
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700769 case CMD_GET_MODEM_ACTIVITY_INFO:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700772 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700773 break;
774
775 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
776 ar = (AsyncResult) msg.obj;
777 request = (MainThreadRequest) ar.userObj;
778 if (ar.exception == null && ar.result != null) {
779 request.result = ar.result;
780 } else {
781 if (ar.result == null) {
782 loge("queryModemActivityInfo: Empty response");
783 } else if (ar.exception instanceof CommandException) {
784 loge("queryModemActivityInfo: CommandException: " +
785 ar.exception);
786 } else {
787 loge("queryModemActivityInfo: Unknown exception");
788 }
789 }
Amit Mahajand4766222016-01-28 15:28:28 -0800790 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
791 if (request.result == null) {
792 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
793 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700794 synchronized (request) {
795 request.notifyAll();
796 }
797 break;
798
Meng Wang1a7c35a2016-05-05 20:56:15 -0700799 case CMD_SET_ALLOWED_CARRIERS:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
802 mPhone.setAllowedCarriers(
803 (List<CarrierIdentifier>) request.argument,
804 onCompleted);
805 break;
806
807 case EVENT_SET_ALLOWED_CARRIERS_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
810 if (ar.exception == null && ar.result != null) {
811 request.result = ar.result;
812 } else {
813 if (ar.result == null) {
814 loge("setAllowedCarriers: Empty response");
815 } else if (ar.exception instanceof CommandException) {
816 loge("setAllowedCarriers: CommandException: " +
817 ar.exception);
818 } else {
819 loge("setAllowedCarriers: Unknown exception");
820 }
821 }
822 // Result cannot be null. Return -1 on error.
823 if (request.result == null) {
824 request.result = new int[]{-1};
825 }
826 synchronized (request) {
827 request.notifyAll();
828 }
829 break;
830
831 case CMD_GET_ALLOWED_CARRIERS:
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
834 mPhone.getAllowedCarriers(onCompleted);
835 break;
836
837 case EVENT_GET_ALLOWED_CARRIERS_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result;
842 } else {
843 if (ar.result == null) {
844 loge("getAllowedCarriers: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("getAllowedCarriers: CommandException: " +
847 ar.exception);
848 } else {
849 loge("getAllowedCarriers: Unknown exception");
850 }
851 }
852 // Result cannot be null. Return empty list of CarrierIdentifier.
853 if (request.result == null) {
854 request.result = new ArrayList<CarrierIdentifier>(0);
855 }
856 synchronized (request) {
857 request.notifyAll();
858 }
859 break;
860
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700861 default:
862 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
863 break;
864 }
865 }
Jake Hambye994d462014-02-03 13:10:13 -0800866
867 private void handleNullReturnEvent(Message msg, String command) {
868 AsyncResult ar = (AsyncResult) msg.obj;
869 MainThreadRequest request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null) {
871 request.result = true;
872 } else {
873 request.result = false;
874 if (ar.exception instanceof CommandException) {
875 loge(command + ": CommandException: " + ar.exception);
876 } else {
877 loge(command + ": Unknown exception");
878 }
879 }
880 synchronized (request) {
881 request.notifyAll();
882 }
883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700884 }
885
886 /**
887 * Posts the specified command to be executed on the main thread,
888 * waits for the request to complete, and returns the result.
889 * @see #sendRequestAsync
890 */
891 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800892 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700893 }
894
895 /**
896 * Posts the specified command to be executed on the main thread,
897 * waits for the request to complete, and returns the result.
898 * @see #sendRequestAsync
899 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800900 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700901 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
902 throw new RuntimeException("This method will deadlock if called from the main thread.");
903 }
904
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800905 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700906 Message msg = mMainThreadHandler.obtainMessage(command, request);
907 msg.sendToTarget();
908
909 // Wait for the request to complete
910 synchronized (request) {
911 while (request.result == null) {
912 try {
913 request.wait();
914 } catch (InterruptedException e) {
915 // Do nothing, go back and wait until the request is complete
916 }
917 }
918 }
919 return request.result;
920 }
921
922 /**
923 * Asynchronous ("fire and forget") version of sendRequest():
924 * Posts the specified command to be executed on the main thread, and
925 * returns immediately.
926 * @see #sendRequest
927 */
928 private void sendRequestAsync(int command) {
929 mMainThreadHandler.sendEmptyMessage(command);
930 }
931
932 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -0700933 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
934 * @see {@link #sendRequest(int,Object)}
935 */
936 private void sendRequestAsync(int command, Object argument) {
937 MainThreadRequest request = new MainThreadRequest(argument);
938 Message msg = mMainThreadHandler.obtainMessage(command, request);
939 msg.sendToTarget();
940 }
941
942 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700943 * Initialize the singleton PhoneInterfaceManager instance.
944 * This is only done once, at startup, from PhoneApp.onCreate().
945 */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700946 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700947 synchronized (PhoneInterfaceManager.class) {
948 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -0700949 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700950 } else {
951 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
952 }
953 return sInstance;
954 }
955 }
956
957 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700958 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700959 mApp = app;
960 mPhone = phone;
961 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700962 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700963 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
964 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -0700965 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -0700966 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800967 mSubscriptionController = SubscriptionController.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -0800968
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700969 publish();
970 }
971
972 private void publish() {
973 if (DBG) log("publish: " + this);
974
975 ServiceManager.addService("phone", this);
976 }
977
Stuart Scott584921c2015-01-15 17:10:34 -0800978 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800979 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
980 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -0800981 }
982
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800983 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
984 Phone phone = getPhoneFromRequest(request);
985 return phone == null ? null :
986 UiccController.getInstance().getUiccCard(phone.getPhoneId());
987 }
988
Wink Saville36469e72014-06-11 15:17:00 -0700989 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -0700990 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800991 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -0700992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700993 //
994 // Implementation of the ITelephony interface.
995 //
996
997 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700998 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -0700999 }
1000
Wink Savilleb564aae2014-10-23 10:18:09 -07001001 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001002 if (DBG) log("dial: " + number);
1003 // No permission check needed here: This is just a wrapper around the
1004 // ACTION_DIAL intent, which is available to any app since it puts up
1005 // the UI before it does anything.
1006
1007 String url = createTelUrl(number);
1008 if (url == null) {
1009 return;
1010 }
1011
1012 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001013 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001014 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1015 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1016 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1017 mApp.startActivity(intent);
1018 }
1019 }
1020
1021 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001022 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001023 }
1024
Wink Savilleb564aae2014-10-23 10:18:09 -07001025 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 if (DBG) log("call: " + number);
1027
1028 // This is just a wrapper around the ACTION_CALL intent, but we still
1029 // need to do a permission check since we're calling startActivity()
1030 // from the context of the phone app.
1031 enforceCallPermission();
1032
1033 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1034 != AppOpsManager.MODE_ALLOWED) {
1035 return;
1036 }
1037
1038 String url = createTelUrl(number);
1039 if (url == null) {
1040 return;
1041 }
1042
Wink Saville08874612014-08-31 19:19:58 -07001043 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001044 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001045 if (slist != null) {
1046 for (SubscriptionInfo subInfoRecord : slist) {
1047 if (subInfoRecord.getSubscriptionId() == subId) {
1048 isValid = true;
1049 break;
1050 }
Wink Saville08874612014-08-31 19:19:58 -07001051 }
1052 }
1053 if (isValid == false) {
1054 return;
1055 }
1056
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001057 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001058 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001059 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1060 mApp.startActivity(intent);
1061 }
1062
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001063 /**
1064 * End a call based on call state
1065 * @return true is a call was ended
1066 */
1067 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001068 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001069 }
1070
1071 /**
1072 * End a call based on the call state of the subId
1073 * @return true is a call was ended
1074 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001075 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001076 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001077 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 }
1079
1080 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001081 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001082 }
1083
Wink Savilleb564aae2014-10-23 10:18:09 -07001084 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 if (DBG) log("answerRingingCall...");
1086 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1087 // but that can probably wait till the big TelephonyManager API overhaul.
1088 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1089 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001090 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 }
1092
1093 /**
1094 * Make the actual telephony calls to implement answerRingingCall().
1095 * This should only be called from the main thread of the Phone app.
1096 * @see #answerRingingCall
1097 *
1098 * TODO: it would be nice to return true if we answered the call, or
1099 * false if there wasn't actually a ringing incoming call, or some
1100 * other error occurred. (In other words, pass back the return value
1101 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1102 * But that would require calling this method via sendRequest() rather
1103 * than sendRequestAsync(), and right now we don't actually *need* that
1104 * return value, so let's just return void for now.
1105 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001106 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001107 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001108 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001109 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1110 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001111 if (hasActiveCall && hasHoldingCall) {
1112 // Both lines are in use!
1113 // TODO: provide a flag to let the caller specify what
1114 // policy to use if both lines are in use. (The current
1115 // behavior is hardwired to "answer incoming, end ongoing",
1116 // which is how the CALL button is specced to behave.)
1117 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1118 return;
1119 } else {
1120 // answerCall() will automatically hold the current active
1121 // call, if there is one.
1122 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1123 return;
1124 }
1125 } else {
1126 // No call was ringing.
1127 return;
1128 }
1129 }
1130
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001131 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001132 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001133 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001134 public void silenceRinger() {
1135 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 }
1137
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001138 @Override
1139 public boolean isOffhook(String callingPackage) {
1140 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001141 }
1142
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001143 @Override
1144 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1145 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1146 return false;
1147 }
1148
Sanket Padawe356d7632015-06-22 14:03:32 -07001149 final Phone phone = getPhone(subId);
1150 if (phone != null) {
1151 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1152 } else {
1153 return false;
1154 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001155 }
1156
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001157 @Override
1158 public boolean isRinging(String callingPackage) {
1159 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001160 }
1161
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001162 @Override
1163 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1164 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1165 return false;
1166 }
1167
Sanket Padawe356d7632015-06-22 14:03:32 -07001168 final Phone phone = getPhone(subId);
1169 if (phone != null) {
1170 return (phone.getState() == PhoneConstants.State.RINGING);
1171 } else {
1172 return false;
1173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 }
1175
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001176 @Override
1177 public boolean isIdle(String callingPackage) {
1178 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001179 }
1180
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001181 @Override
1182 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1183 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1184 return false;
1185 }
1186
Sanket Padawe356d7632015-06-22 14:03:32 -07001187 final Phone phone = getPhone(subId);
1188 if (phone != null) {
1189 return (phone.getState() == PhoneConstants.State.IDLE);
1190 } else {
1191 return false;
1192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001193 }
1194
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001196 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001197 }
1198
Wink Savilleb564aae2014-10-23 10:18:09 -07001199 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001200 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001201 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1202 }
1203
1204 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001205 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001206 }
1207
Wink Savilleb564aae2014-10-23 10:18:09 -07001208 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001209 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001210 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1211 }
1212
1213 /** {@hide} */
1214 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001215 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001216 }
1217
Wink Savilleb564aae2014-10-23 10:18:09 -07001218 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001220 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 checkSimPin.start();
1222 return checkSimPin.unlockSim(null, pin);
1223 }
1224
Wink Saville9de0f752013-10-22 19:04:03 -07001225 /** {@hide} */
1226 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001227 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001228 }
1229
Wink Savilleb564aae2014-10-23 10:18:09 -07001230 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001232 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 checkSimPuk.start();
1234 return checkSimPuk.unlockSim(puk, pin);
1235 }
1236
1237 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001238 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001239 * a synchronous one.
1240 */
1241 private static class UnlockSim extends Thread {
1242
1243 private final IccCard mSimCard;
1244
1245 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001246 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1247 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248
1249 // For replies from SimCard interface
1250 private Handler mHandler;
1251
1252 // For async handler to identify request type
1253 private static final int SUPPLY_PIN_COMPLETE = 100;
1254
1255 public UnlockSim(IccCard simCard) {
1256 mSimCard = simCard;
1257 }
1258
1259 @Override
1260 public void run() {
1261 Looper.prepare();
1262 synchronized (UnlockSim.this) {
1263 mHandler = new Handler() {
1264 @Override
1265 public void handleMessage(Message msg) {
1266 AsyncResult ar = (AsyncResult) msg.obj;
1267 switch (msg.what) {
1268 case SUPPLY_PIN_COMPLETE:
1269 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1270 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001271 mRetryCount = msg.arg1;
1272 if (ar.exception != null) {
1273 if (ar.exception instanceof CommandException &&
1274 ((CommandException)(ar.exception)).getCommandError()
1275 == CommandException.Error.PASSWORD_INCORRECT) {
1276 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1277 } else {
1278 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1279 }
1280 } else {
1281 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 mDone = true;
1284 UnlockSim.this.notifyAll();
1285 }
1286 break;
1287 }
1288 }
1289 };
1290 UnlockSim.this.notifyAll();
1291 }
1292 Looper.loop();
1293 }
1294
1295 /*
1296 * Use PIN or PUK to unlock SIM card
1297 *
1298 * If PUK is null, unlock SIM card with PIN
1299 *
1300 * If PUK is not null, unlock SIM card with PUK and set PIN code
1301 */
Wink Saville9de0f752013-10-22 19:04:03 -07001302 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303
1304 while (mHandler == null) {
1305 try {
1306 wait();
1307 } catch (InterruptedException e) {
1308 Thread.currentThread().interrupt();
1309 }
1310 }
1311 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1312
1313 if (puk == null) {
1314 mSimCard.supplyPin(pin, callback);
1315 } else {
1316 mSimCard.supplyPuk(puk, pin, callback);
1317 }
1318
1319 while (!mDone) {
1320 try {
1321 Log.d(LOG_TAG, "wait for done");
1322 wait();
1323 } catch (InterruptedException e) {
1324 // Restore the interrupted status
1325 Thread.currentThread().interrupt();
1326 }
1327 }
1328 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001329 int[] resultArray = new int[2];
1330 resultArray[0] = mResult;
1331 resultArray[1] = mRetryCount;
1332 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 }
1334 }
1335
1336 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001337 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001338
1339 }
1340
Wink Savilleb564aae2014-10-23 10:18:09 -07001341 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 // No permission check needed here: this call is harmless, and it's
1343 // needed for the ServiceState.requestStateUpdate() call (which is
1344 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001345 final Phone phone = getPhone(subId);
1346 if (phone != null) {
1347 phone.updateServiceLocation();
1348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 }
1350
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001351 @Override
1352 public boolean isRadioOn(String callingPackage) {
1353 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001354 }
1355
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001356 @Override
1357 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1358 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1359 return false;
1360 }
1361 return isRadioOnForSubscriber(subId);
1362 }
1363
1364 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001365 final Phone phone = getPhone(subId);
1366 if (phone != null) {
1367 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1368 } else {
1369 return false;
1370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371 }
1372
1373 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001375
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 }
Wink Saville36469e72014-06-11 15:17:00 -07001377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001380 final Phone phone = getPhone(subId);
1381 if (phone != null) {
1382 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1383 }
Wink Saville36469e72014-06-11 15:17:00 -07001384 }
1385
1386 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001387 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001388 }
1389
Wink Savilleb564aae2014-10-23 10:18:09 -07001390 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001391 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001392 final Phone phone = getPhone(subId);
1393 if (phone == null) {
1394 return false;
1395 }
1396 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001397 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 }
1400 return true;
1401 }
Wink Saville36469e72014-06-11 15:17:00 -07001402
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001403 public boolean needMobileRadioShutdown() {
1404 /*
1405 * If any of the Radios are available, it will need to be
1406 * shutdown. So return true if any Radio is available.
1407 */
1408 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1409 Phone phone = PhoneFactory.getPhone(i);
1410 if (phone != null && phone.isRadioAvailable()) return true;
1411 }
1412 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1413 return false;
1414 }
1415
1416 public void shutdownMobileRadios() {
1417 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1418 logv("Shutting down Phone " + i);
1419 shutdownRadioUsingPhoneId(i);
1420 }
1421 }
1422
1423 private void shutdownRadioUsingPhoneId(int phoneId) {
1424 enforceModifyPermission();
1425 Phone phone = PhoneFactory.getPhone(phoneId);
1426 if (phone != null && phone.isRadioAvailable()) {
1427 phone.shutdownRadio();
1428 }
1429 }
1430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 public boolean setRadioPower(boolean turnOn) {
Wei Liu9ae2a062016-08-08 11:09:34 -07001432 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1433 if (defaultPhone != null) {
1434 defaultPhone.setRadioPower(turnOn);
1435 return true;
1436 } else {
1437 loge("There's no default phone.");
1438 return false;
1439 }
Wink Saville36469e72014-06-11 15:17:00 -07001440 }
1441
Wink Savilleb564aae2014-10-23 10:18:09 -07001442 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001444 final Phone phone = getPhone(subId);
1445 if (phone != null) {
1446 phone.setRadioPower(turnOn);
1447 return true;
1448 } else {
1449 return false;
1450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 }
1452
Wink Saville36469e72014-06-11 15:17:00 -07001453 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001454 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 public boolean enableDataConnectivity() {
1456 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001457 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001458 final Phone phone = getPhone(subId);
1459 if (phone != null) {
1460 phone.setDataEnabled(true);
1461 return true;
1462 } else {
1463 return false;
1464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 }
1466
Wink Saville36469e72014-06-11 15:17:00 -07001467 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001468 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 public boolean disableDataConnectivity() {
1470 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001471 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001472 final Phone phone = getPhone(subId);
1473 if (phone != null) {
1474 phone.setDataEnabled(false);
1475 return true;
1476 } else {
1477 return false;
1478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480
Wink Saville36469e72014-06-11 15:17:00 -07001481 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001482 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 public boolean isDataConnectivityPossible() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001484 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001485 final Phone phone = getPhone(subId);
1486 if (phone != null) {
1487 return phone.isDataConnectivityPossible();
1488 } else {
1489 return false;
1490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 }
1492
1493 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001494 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001495 }
1496
pkanwarae03a6b2016-11-06 20:37:09 -08001497 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001498 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001499 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1500 return;
1501 }
1502 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1503 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1504 };
1505
1506
Wink Savilleb564aae2014-10-23 10:18:09 -07001507 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001509 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1510 return false;
1511 }
Wink Saville36469e72014-06-11 15:17:00 -07001512 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513 }
1514
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001516 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001517 }
1518
Shishir Agrawala9f32182016-04-12 12:00:16 -07001519 public int getCallStateForSlot(int slotId) {
1520 Phone phone = PhoneFactory.getPhone(slotId);
1521 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1522 DefaultPhoneNotifier.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523 }
1524
Sanket Padawe356d7632015-06-22 14:03:32 -07001525 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001527 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001528 if (phone != null) {
1529 return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
1530 } else {
1531 return DefaultPhoneNotifier.convertDataState(PhoneConstants.DataState.DISCONNECTED);
1532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 }
1534
Sanket Padawe356d7632015-06-22 14:03:32 -07001535 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001537 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001538 if (phone != null) {
1539 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1540 } else {
1541 return TelephonyManager.DATA_ACTIVITY_NONE;
1542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 }
1544
1545 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001546 public Bundle getCellLocation(String callingPackage) {
1547 enforceFineOrCoarseLocationPermission("getCellLocation");
1548
1549 // OP_COARSE_LOCATION controls both fine and coarse location.
1550 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1551 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001552 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001553 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001556 if (checkIfCallerIsSelfOrForegroundUser() ||
1557 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 if (DBG_LOC) log("getCellLocation: is active user");
1559 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001560 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001561 if (phone == null) {
1562 return null;
1563 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001564
1565 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1566 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 return data;
1568 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001569 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 return null;
1571 }
1572 }
1573
Svetoslav64fad262015-04-14 14:35:21 -07001574 private void enforceFineOrCoarseLocationPermission(String message) {
1575 try {
1576 mApp.enforceCallingOrSelfPermission(
1577 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1578 } catch (SecurityException e) {
1579 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1580 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1581 // is the weaker precondition
1582 mApp.enforceCallingOrSelfPermission(
1583 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1584 }
1585 }
1586
1587
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 @Override
1589 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001590 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001591 }
1592
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001594 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 mApp.enforceCallingOrSelfPermission(
1596 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001597 final Phone phone = getPhone(subId);
1598 if (phone != null) {
1599 phone.enableLocationUpdates();
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
1603 @Override
1604 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001605 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001606 }
1607
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001609 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 mApp.enforceCallingOrSelfPermission(
1611 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 final Phone phone = getPhone(subId);
1613 if (phone != null) {
1614 phone.disableLocationUpdates();
1615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 }
1617
1618 @Override
1619 @SuppressWarnings("unchecked")
1620 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001621 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1622
1623 // OP_COARSE_LOCATION controls both fine and coarse location.
1624 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1625 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1626 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 }
1628
1629 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1630 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1631 return null;
1632 }
Svetoslav64fad262015-04-14 14:35:21 -07001633
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001634 if (checkIfCallerIsSelfOrForegroundUser() ||
1635 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1637
1638 ArrayList<NeighboringCellInfo> cells = null;
1639
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001640 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 try {
1642 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001643 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001644 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001646 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 }
1648 return cells;
1649 } else {
1650 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1651 return null;
1652 }
1653 }
1654
1655
1656 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001657 public List<CellInfo> getAllCellInfo(String callingPackage) {
1658 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1659
1660 // OP_COARSE_LOCATION controls both fine and coarse location.
1661 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1662 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1663 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 }
1665
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001666 if (checkIfCallerIsSelfOrForegroundUser() ||
1667 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001669 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001670 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1671 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001672 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1673 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001674 }
1675 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 } else {
1677 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1678 return null;
1679 }
1680 }
1681
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001682 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 public void setCellInfoListRate(int rateInMillis) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001684 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1685 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687
Shishir Agrawala9f32182016-04-12 12:00:16 -07001688 @Override
1689 public String getImeiForSlot(int slotId, String callingPackage) {
1690 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1691 return null;
1692 }
1693 Phone phone = PhoneFactory.getPhone(slotId);
1694 return phone == null ? null : phone.getImei();
1695 }
1696
1697 @Override
1698 public String getDeviceSoftwareVersionForSlot(int slotId, String callingPackage) {
1699 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1700 return null;
1701 }
1702 Phone phone = PhoneFactory.getPhone(slotId);
1703 return phone == null ? null : phone.getDeviceSvn();
1704 }
1705
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 //
1707 // Internal helper methods.
1708 //
1709
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001710 /**
1711 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1712 */
1713 private boolean checkCallerInteractAcrossUsersFull() {
1714 return mPhone.getContext().checkCallingOrSelfPermission(
1715 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1716 == PackageManager.PERMISSION_GRANTED;
1717 }
1718
Jake Hambye994d462014-02-03 13:10:13 -08001719 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 boolean ok;
1721
1722 boolean self = Binder.getCallingUid() == Process.myUid();
1723 if (!self) {
1724 // Get the caller's user id then clear the calling identity
1725 // which will be restored in the finally clause.
1726 int callingUser = UserHandle.getCallingUserId();
1727 long ident = Binder.clearCallingIdentity();
1728
1729 try {
1730 // With calling identity cleared the current user is the foreground user.
1731 int foregroundUser = ActivityManager.getCurrentUser();
1732 ok = (foregroundUser == callingUser);
1733 if (DBG_LOC) {
1734 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1735 + " callingUser=" + callingUser + " ok=" + ok);
1736 }
1737 } catch (Exception ex) {
1738 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1739 ok = false;
1740 } finally {
1741 Binder.restoreCallingIdentity(ident);
1742 }
1743 } else {
1744 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1745 ok = true;
1746 }
1747 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1748 return ok;
1749 }
1750
1751 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1753 *
1754 * @throws SecurityException if the caller does not have the required permission
1755 */
1756 private void enforceModifyPermission() {
1757 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1758 }
1759
1760 /**
Junda Liua2e36012014-07-09 18:30:01 -07001761 * Make sure either system app or the caller has carrier privilege.
1762 *
1763 * @throws SecurityException if the caller does not have the required permission/privilege
1764 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001765 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001766 int permission = mApp.checkCallingOrSelfPermission(
1767 android.Manifest.permission.MODIFY_PHONE_STATE);
1768 if (permission == PackageManager.PERMISSION_GRANTED) {
1769 return;
1770 }
1771
1772 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001773 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001774 }
1775
1776 /**
1777 * Make sure the caller has carrier privilege.
1778 *
1779 * @throws SecurityException if the caller does not have the required permission
1780 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001781 private void enforceCarrierPrivilege(int subId) {
1782 if (getCarrierPrivilegeStatus(subId) !=
1783 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001784 loge("No Carrier Privilege.");
1785 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001786 }
1787 }
1788
1789 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 * Make sure the caller has the CALL_PHONE permission.
1791 *
1792 * @throws SecurityException if the caller does not have the required permission
1793 */
1794 private void enforceCallPermission() {
1795 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1796 }
1797
Stuart Scott8eef64f2015-04-08 15:13:54 -07001798 private void enforceConnectivityInternalPermission() {
1799 mApp.enforceCallingOrSelfPermission(
1800 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1801 "ConnectivityService");
1802 }
1803
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 private String createTelUrl(String number) {
1805 if (TextUtils.isEmpty(number)) {
1806 return null;
1807 }
1808
Jake Hambye994d462014-02-03 13:10:13 -08001809 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 }
1811
Ihab Awadf9e92732013-12-05 18:02:52 -08001812 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1814 }
1815
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001816 private static void logv(String msg) {
1817 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1818 }
1819
Ihab Awadf9e92732013-12-05 18:02:52 -08001820 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1822 }
1823
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001824 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001826 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001827 }
1828
Sanket Padawe356d7632015-06-22 14:03:32 -07001829 @Override
Shishir Agrawala9f32182016-04-12 12:00:16 -07001830 public int getActivePhoneTypeForSlot(int slotId) {
1831 final Phone phone = PhoneFactory.getPhone(slotId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001832 if (phone == null) {
1833 return PhoneConstants.PHONE_TYPE_NONE;
1834 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001835 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 }
1838
1839 /**
1840 * Returns the CDMA ERI icon index to display
1841 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001842 @Override
1843 public int getCdmaEriIconIndex(String callingPackage) {
1844 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001845 }
1846
Sanket Padawe356d7632015-06-22 14:03:32 -07001847 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001848 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1849 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1850 return -1;
1851 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 final Phone phone = getPhone(subId);
1853 if (phone != null) {
1854 return phone.getCdmaEriIconIndex();
1855 } else {
1856 return -1;
1857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
1860 /**
1861 * Returns the CDMA ERI icon mode,
1862 * 0 - ON
1863 * 1 - FLASHING
1864 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001865 @Override
1866 public int getCdmaEriIconMode(String callingPackage) {
1867 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001868 }
1869
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001871 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1872 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1873 return -1;
1874 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
1877 return phone.getCdmaEriIconMode();
1878 } else {
1879 return -1;
1880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 }
1882
1883 /**
1884 * Returns the CDMA ERI text,
1885 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001886 @Override
1887 public String getCdmaEriText(String callingPackage) {
1888 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001889 }
1890
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001892 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1893 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1894 return null;
1895 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
1898 return phone.getCdmaEriText();
1899 } else {
1900 return null;
1901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
1904 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001905 * Returns the CDMA MDN.
1906 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001908 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001909 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001910 final Phone phone = getPhone(subId);
1911 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1912 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001913 } else {
1914 return null;
1915 }
1916 }
1917
1918 /**
1919 * Returns the CDMA MIN.
1920 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001921 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001922 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001923 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 final Phone phone = getPhone(subId);
1925 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1926 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001927 } else {
1928 return null;
1929 }
1930 }
1931
1932 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 * Returns true if CDMA provisioning needs to run.
1934 */
1935 public boolean needsOtaServiceProvisioning() {
1936 return mPhone.needsOtaServiceProvisioning();
1937 }
1938
1939 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001940 * Sets the voice mail number of a given subId.
1941 */
1942 @Override
1943 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001944 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001945 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1946 new Pair<String, String>(alphaTag, number), new Integer(subId));
1947 return success;
1948 }
1949
Ta-wei Yen87c49842016-05-13 21:19:52 -07001950 @Override
Ta-wei Yenb0f695b2016-08-08 17:33:11 -07001951 public void setVisualVoicemailEnabled(String callingPackage,
1952 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
1953 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1954 if (!TextUtils.equals(callingPackage,
1955 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
1956 enforceModifyPermissionOrCarrierPrivilege(
1957 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
1958 }
1959 VisualVoicemailSettingsUtil.setEnabled(mPhone.getContext(), phoneAccountHandle, enabled);
1960 }
1961
1962 @Override
1963 public boolean isVisualVoicemailEnabled(String callingPackage,
1964 PhoneAccountHandle phoneAccountHandle) {
1965 if (!canReadPhoneState(callingPackage, "isVisualVoicemailEnabled")) {
1966 return false;
1967 }
1968 return VisualVoicemailSettingsUtil.isEnabled(mPhone.getContext(), phoneAccountHandle);
1969 }
1970
1971 @Override
Ta-wei Yendca928f2017-01-10 16:17:08 -08001972 public String getVisualVoicemailPackageName(String callingPackage,
1973 @Nullable PhoneAccountHandle phoneAccountHandle) {
1974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1975 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
1976 return null;
1977 }
1978 int subId = PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
1979 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
1980 }
1981
1982 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001983 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
1984 VisualVoicemailSmsFilterSettings settings) {
1985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001986 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001987 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
1988 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001989 }
1990
1991 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001992 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
1993 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001994 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001995 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001996 }
1997
1998 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001999 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2000 String callingPackage, int subId) {
2001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002002 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002003 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002004 }
2005
2006 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002007 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002008 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002009 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002010 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2011 }
2012
2013 @Override
2014 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2015 String number, int port, String text, PendingIntent sentIntent) {
2016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002017 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002018 enforceSendSmsPermission();
2019 // Make the calls as the phone process.
2020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2023 if (port == 0) {
2024 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2025 sentIntent, null, false);
2026 } else {
2027 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2028 smsManager.sendDataMessageWithSelfPermissions(number, null,
2029 (short) port, data, sentIntent, null);
2030 }
2031 } finally {
2032 Binder.restoreCallingIdentity(identity);
2033 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002034 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002035 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 * Returns the unread count of voicemails
2037 */
2038 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002039 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002040 }
2041
2042 /**
2043 * Returns the unread count of voicemails for a subId
2044 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002045 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002046 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002047 final Phone phone = getPhone(subId);
2048 if (phone != null) {
2049 return phone.getVoiceMessageCount();
2050 } else {
2051 return 0;
2052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
2054
2055 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002056 * returns true, if the device is in a state where both voice and data
2057 * are supported simultaneously. This can change based on location or network condition.
2058 */
2059 @Override
2060 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2061 final Phone phone = getPhone(subId);
2062 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2063 }
2064
2065 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002066 * Returns the data network type.
2067 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 *
2069 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2070 */
2071 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002072 public int getNetworkType() {
2073 final Phone phone = getPhone(getDefaultSubscription());
2074 if (phone != null) {
2075 return phone.getServiceState().getDataNetworkType();
2076 } else {
2077 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2078 }
Wink Saville36469e72014-06-11 15:17:00 -07002079 }
2080
2081 /**
2082 * Returns the network type for a subId
2083 */
2084 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002085 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2086 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2087 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2088 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002089
Sanket Padawe356d7632015-06-22 14:03:32 -07002090 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002091 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002092 return phone.getServiceState().getDataNetworkType();
2093 } else {
2094 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 }
2097
2098 /**
2099 * Returns the data network type
2100 */
2101 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002102 public int getDataNetworkType(String callingPackage) {
2103 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002104 }
2105
2106 /**
2107 * Returns the data network type for a subId
2108 */
2109 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002110 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2111 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2112 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2113 }
2114
Sanket Padawe356d7632015-06-22 14:03:32 -07002115 final Phone phone = getPhone(subId);
2116 if (phone != null) {
2117 return phone.getServiceState().getDataNetworkType();
2118 } else {
2119 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2120 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 }
2122
2123 /**
Wink Saville36469e72014-06-11 15:17:00 -07002124 * Returns the Voice network type for a subId
2125 */
2126 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002127 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2128 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2129 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2130 }
2131
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 final Phone phone = getPhone(subId);
2133 if (phone != null) {
2134 return phone.getServiceState().getVoiceNetworkType();
2135 } else {
2136 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 }
2139
2140 /**
2141 * @return true if a ICC card is present
2142 */
2143 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002144 // FIXME Make changes to pass defaultSimId of type int
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002145 return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002146 }
2147
2148 /**
2149 * @return true if a ICC card is present for a slotId
2150 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002151 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002152 public boolean hasIccCardUsingSlotId(int slotId) {
fionaxu6e6c68b2016-06-23 13:31:32 -07002153 final Phone phone = PhoneFactory.getPhone(slotId);
2154 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002155 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002156 } else {
2157 return false;
2158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
2161 /**
2162 * Return if the current radio is LTE on CDMA. This
2163 * is a tri-state return value as for a period of time
2164 * the mode may be unknown.
2165 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002166 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002168 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002170 @Override
2171 public int getLteOnCdmaMode(String callingPackage) {
2172 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002173 }
2174
Sanket Padawe356d7632015-06-22 14:03:32 -07002175 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002176 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2177 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2178 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2179 }
2180
Sanket Padawe356d7632015-06-22 14:03:32 -07002181 final Phone phone = getPhone(subId);
2182 if (phone == null) {
2183 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2184 } else {
2185 return phone.getLteOnCdmaMode();
2186 }
Wink Saville36469e72014-06-11 15:17:00 -07002187 }
2188
2189 public void setPhone(Phone phone) {
2190 mPhone = phone;
2191 }
2192
2193 /**
2194 * {@hide}
2195 * Returns Default subId, 0 in the case of single standby.
2196 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002197 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002198 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002199 }
2200
Shishir Agrawala9f32182016-04-12 12:00:16 -07002201 private int getSlotForDefaultSubscription() {
2202 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2203 }
2204
Wink Savilleb564aae2014-10-23 10:18:09 -07002205 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002206 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002208
2209 /**
2210 * @see android.telephony.TelephonyManager.WifiCallingChoices
2211 */
2212 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002213 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2214 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002215 }
2216
2217 /**
2218 * @see android.telephony.TelephonyManager.WifiCallingChoices
2219 */
2220 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002221 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2222 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2223 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002224 }
2225
Sailesh Nepald1e68152013-12-12 19:08:02 -08002226 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002227 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002228 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002229 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002230
Shishir Agrawal566b7612013-10-28 14:41:00 -07002231 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002232 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID) {
2233 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002234
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002235 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002236 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002237 CMD_OPEN_CHANNEL, AID, subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002238 if (DBG) log("iccOpenLogicalChannel: " + response);
2239 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002240 }
2241
2242 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002243 public boolean iccCloseLogicalChannel(int subId, int channel) {
2244 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002245
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002246 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002247 if (channel < 0) {
2248 return false;
2249 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002250 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002251 if (DBG) log("iccCloseLogicalChannel: " + success);
2252 return success;
2253 }
2254
2255 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002256 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002257 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002258 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002259
2260 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002261 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2262 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002263 " data=" + data);
2264 }
2265
2266 if (channel < 0) {
2267 return "";
2268 }
2269
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002270 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002271 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002272 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2273
Shishir Agrawal566b7612013-10-28 14:41:00 -07002274 // Append the returned status code to the end of the response payload.
2275 String s = Integer.toHexString(
2276 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002277 if (response.payload != null) {
2278 s = IccUtils.bytesToHexString(response.payload) + s;
2279 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002280 return s;
2281 }
Jake Hambye994d462014-02-03 13:10:13 -08002282
Evan Charltonc66da362014-05-16 14:06:40 -07002283 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002284 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002285 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002286 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002287
2288 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002289 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2290 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002291 }
2292
2293 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002294 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002295 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2296
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002297 // Append the returned status code to the end of the response payload.
2298 String s = Integer.toHexString(
2299 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002300 if (response.payload != null) {
2301 s = IccUtils.bytesToHexString(response.payload) + s;
2302 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002303 return s;
2304 }
2305
2306 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002307 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002308 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002309 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002310
2311 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002312 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002313 p1 + " " + p2 + " " + p3 + ":" + filePath);
2314 }
2315
2316 IccIoResult response =
2317 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002318 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2319 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002320
2321 if (DBG) {
2322 log("Exchange SIM_IO [R]" + response);
2323 }
2324
2325 byte[] result = null;
2326 int length = 2;
2327 if (response.payload != null) {
2328 length = 2 + response.payload.length;
2329 result = new byte[length];
2330 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2331 } else {
2332 result = new byte[length];
2333 }
2334
2335 result[length - 1] = (byte) response.sw2;
2336 result[length - 2] = (byte) response.sw1;
2337 return result;
2338 }
2339
2340 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002341 public String sendEnvelopeWithStatus(int subId, String content) {
2342 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002343
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002344 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002345 if (response.payload == null) {
2346 return "";
2347 }
2348
2349 // Append the returned status code to the end of the response payload.
2350 String s = Integer.toHexString(
2351 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2352 s = IccUtils.bytesToHexString(response.payload) + s;
2353 return s;
2354 }
2355
Jake Hambye994d462014-02-03 13:10:13 -08002356 /**
2357 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2358 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2359 *
2360 * @param itemID the ID of the item to read
2361 * @return the NV item as a String, or null on error.
2362 */
2363 @Override
2364 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002365 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002366 if (DBG) log("nvReadItem: item " + itemID);
2367 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2368 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2369 return value;
2370 }
2371
2372 /**
2373 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2374 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2375 *
2376 * @param itemID the ID of the item to read
2377 * @param itemValue the value to write, as a String
2378 * @return true on success; false on any failure
2379 */
2380 @Override
2381 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002382 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002383 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2384 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2385 new Pair<Integer, String>(itemID, itemValue));
2386 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2387 return success;
2388 }
2389
2390 /**
2391 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2392 * Used for device configuration by some CDMA operators.
2393 *
2394 * @param preferredRoamingList byte array containing the new PRL
2395 * @return true on success; false on any failure
2396 */
2397 @Override
2398 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002399 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002400 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2401 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2402 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2403 return success;
2404 }
2405
2406 /**
2407 * Perform the specified type of NV config reset.
2408 * Used for device configuration by some CDMA operators.
2409 *
2410 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2411 * @return true on success; false on any failure
2412 */
2413 @Override
2414 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002415 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002416 if (DBG) log("nvResetConfig: type " + resetType);
2417 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2418 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2419 return success;
2420 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002421
2422 /**
Wink Saville36469e72014-06-11 15:17:00 -07002423 * {@hide}
2424 * Returns Default sim, 0 in the case of single standby.
2425 */
2426 public int getDefaultSim() {
2427 //TODO Need to get it from Telephony Devcontroller
2428 return 0;
2429 }
2430
Svet Ganovb320e182015-04-16 12:30:10 -07002431 public String[] getPcscfAddress(String apnType, String callingPackage) {
2432 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2433 return new String[0];
2434 }
2435
2436
ram87fca6f2014-07-18 18:58:44 +05302437 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002438 }
2439
2440 public void setImsRegistrationState(boolean registered) {
2441 enforceModifyPermission();
2442 mPhone.setImsRegistrationState(registered);
2443 }
2444
2445 /**
Stuart Scott54788802015-03-30 13:18:01 -07002446 * Set the network selection mode to automatic.
2447 *
2448 */
2449 @Override
2450 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002451 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002452 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2453 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2454 }
2455
2456 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002457 * Set the network selection mode to manual with the selected carrier.
2458 */
2459 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002460 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2461 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002462 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002463 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002464 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2465 persistSelection);
2466 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002467 }
2468
2469 /**
2470 * Scans for available networks.
2471 */
2472 @Override
2473 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002474 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002475 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2476 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2477 CMD_PERFORM_NETWORK_SCAN, null, subId);
2478 return result;
2479 }
2480
2481 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002482 * Get the calculated preferred network type.
2483 * Used for debugging incorrect network type.
2484 *
2485 * @return the preferred network type, defined in RILConstants.java.
2486 */
2487 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002488 public int getCalculatedPreferredNetworkType(String callingPackage) {
2489 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2490 return RILConstants.PREFERRED_NETWORK_MODE;
2491 }
2492
Amit Mahajan43330e02014-11-18 11:54:45 -08002493 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002494 }
2495
2496 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002497 * Get the preferred network type.
2498 * Used for device configuration by some CDMA operators.
2499 *
2500 * @return the preferred network type, defined in RILConstants.java.
2501 */
2502 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002503 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002504 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002505 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002506 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002507 int networkType = (result != null ? result[0] : -1);
2508 if (DBG) log("getPreferredNetworkType: " + networkType);
2509 return networkType;
2510 }
2511
2512 /**
2513 * Set the preferred network type.
2514 * Used for device configuration by some CDMA operators.
2515 *
2516 * @param networkType the preferred network type, defined in RILConstants.java.
2517 * @return true on success; false on any failure.
2518 */
2519 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002520 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002521 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002522 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2523 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002524 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002525 if (success) {
2526 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002527 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002528 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002529 return success;
2530 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002531
2532 /**
Junda Liu475951f2014-11-07 16:45:03 -08002533 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2534 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2535 * tethering.
2536 *
2537 * @return 0: Not required. 1: required. 2: Not set.
2538 * @hide
2539 */
2540 @Override
2541 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002542 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002543 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2544 Settings.Global.TETHER_DUN_REQUIRED, 2);
2545 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2546 // config_tether_apndata.
2547 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2548 dunRequired = 1;
2549 }
2550 return dunRequired;
2551 }
2552
2553 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002554 * Set mobile data enabled
2555 * Used by the user through settings etc to turn on/off mobile data
2556 *
2557 * @param enable {@code true} turn turn data on, else {@code false}
2558 */
2559 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002560 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002561 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002562 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002563 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002564 Phone phone = PhoneFactory.getPhone(phoneId);
2565 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002566 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002567 phone.setDataEnabled(enable);
2568 } else {
2569 loge("setDataEnabled: no phone for subId=" + subId);
2570 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002571 }
2572
2573 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002574 * Get whether mobile data is enabled.
2575 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002576 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002577 *
2578 * @return {@code true} if data is enabled else {@code false}
2579 */
2580 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002581 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002582 try {
2583 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2584 null);
2585 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002586 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002587 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002588 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002589 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002590 Phone phone = PhoneFactory.getPhone(phoneId);
2591 if (phone != null) {
2592 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002593 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002594 return retVal;
2595 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002596 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002597 return false;
2598 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002599 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002600
2601 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002602 public int getCarrierPrivilegeStatus(int subId) {
2603 final Phone phone = getPhone(subId);
2604 if (phone == null) {
2605 loge("getCarrierPrivilegeStatus: Invalid subId");
2606 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2607 }
2608 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002609 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002610 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002611 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2612 }
2613 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002614 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002615 }
Junda Liu29340342014-07-10 15:23:27 -07002616
2617 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002618 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002619 if (TextUtils.isEmpty(pkgName))
2620 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002621 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002622 if (card == null) {
2623 loge("checkCarrierPrivilegesForPackage: No UICC");
2624 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2625 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002626 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2627 }
2628
2629 @Override
2630 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002631 if (TextUtils.isEmpty(pkgName))
2632 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002633 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2634 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2635 UiccCard card = UiccController.getInstance().getUiccCard(i);
2636 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002637 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002638 continue;
2639 }
2640
2641 result = card.getCarrierPrivilegeStatus(
2642 mPhone.getContext().getPackageManager(), pkgName);
2643 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2644 break;
2645 }
2646 }
2647
2648 return result;
Junda Liu29340342014-07-10 15:23:27 -07002649 }
Derek Tan89e89d42014-07-08 17:00:10 -07002650
2651 @Override
Junda Liue64de782015-04-16 17:19:16 -07002652 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2653 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2654 loge("phoneId " + phoneId + " is not valid.");
2655 return null;
2656 }
2657 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002658 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002659 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002660 return null ;
2661 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002662 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002663 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002664 }
2665
Amith Yamasani6e118872016-02-19 12:53:51 -08002666 @Override
2667 public List<String> getPackagesWithCarrierPrivileges() {
2668 PackageManager pm = mPhone.getContext().getPackageManager();
2669 List<String> privilegedPackages = new ArrayList<>();
2670 List<PackageInfo> packages = null;
2671 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2672 UiccCard card = UiccController.getInstance().getUiccCard(i);
2673 if (card == null) {
2674 // No UICC in that slot.
2675 continue;
2676 }
2677 if (card.hasCarrierPrivilegeRules()) {
2678 if (packages == null) {
2679 // Only check packages in user 0 for now
2680 packages = pm.getInstalledPackagesAsUser(
2681 PackageManager.MATCH_DISABLED_COMPONENTS
2682 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2683 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2684 }
2685 for (int p = packages.size() - 1; p >= 0; p--) {
2686 PackageInfo pkgInfo = packages.get(p);
2687 if (pkgInfo != null && pkgInfo.packageName != null
2688 && card.getCarrierPrivilegeStatus(pkgInfo)
2689 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2690 privilegedPackages.add(pkgInfo.packageName);
2691 }
2692 }
2693 }
2694 }
2695 return privilegedPackages;
2696 }
2697
Wink Savilleb564aae2014-10-23 10:18:09 -07002698 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002699 final Phone phone = getPhone(subId);
2700 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002701 if (card == null) {
2702 loge("getIccId: No UICC");
2703 return null;
2704 }
2705 String iccId = card.getIccId();
2706 if (TextUtils.isEmpty(iccId)) {
2707 loge("getIccId: ICC ID is null or empty.");
2708 return null;
2709 }
2710 return iccId;
2711 }
2712
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002713 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002714 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2715 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002716 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002717
Jeff Sharkey85190e62014-12-05 09:40:12 -08002718 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002719 final Phone phone = getPhone(subId);
2720 if (phone == null) {
2721 return false;
2722 }
2723 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002724
2725 if (DBG_MERGE) {
2726 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2727 + subscriberId + " to " + number);
2728 }
2729
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002730 if (TextUtils.isEmpty(iccId)) {
2731 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002732 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002733
Jeff Sharkey85190e62014-12-05 09:40:12 -08002734 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2735
2736 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002737 if (alphaTag == null) {
2738 editor.remove(alphaTagPrefKey);
2739 } else {
2740 editor.putString(alphaTagPrefKey, alphaTag);
2741 }
2742
Jeff Sharkey85190e62014-12-05 09:40:12 -08002743 // Record both the line number and IMSI for this ICCID, since we need to
2744 // track all merged IMSIs based on line number
2745 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2746 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002747 if (number == null) {
2748 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002749 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002750 } else {
2751 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002752 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002753 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002754
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002755 editor.commit();
2756 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002757 }
2758
2759 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002760 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002761 // This is open to apps with WRITE_SMS.
2762 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002763 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002764 return null;
2765 }
Derek Tan97ebb422014-09-05 16:55:38 -07002766
2767 String iccId = getIccId(subId);
2768 if (iccId != null) {
2769 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002770 if (DBG_MERGE) {
2771 log("getLine1NumberForDisplay returning " +
2772 mTelephonySharedPreferences.getString(numberPrefKey, null));
2773 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002774 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002775 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002776 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002777 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002778 }
2779
2780 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002781 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2782 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2783 return null;
2784 }
Derek Tan97ebb422014-09-05 16:55:38 -07002785
2786 String iccId = getIccId(subId);
2787 if (iccId != null) {
2788 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002789 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002790 }
Derek Tan97ebb422014-09-05 16:55:38 -07002791 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002792 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002793
2794 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002795 public String[] getMergedSubscriberIds(String callingPackage) {
2796 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2797 return null;
2798 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002799 final Context context = mPhone.getContext();
2800 final TelephonyManager tele = TelephonyManager.from(context);
2801 final SubscriptionManager sub = SubscriptionManager.from(context);
2802
2803 // Figure out what subscribers are currently active
2804 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002805 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2806 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 final int[] subIds = sub.getActiveSubscriptionIdList();
2810 for (int subId : subIds) {
2811 activeSubscriberIds.add(tele.getSubscriberId(subId));
2812 }
2813 } finally {
2814 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002815 }
2816
2817 // First pass, find a number override for an active subscriber
2818 String mergeNumber = null;
2819 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2820 for (String key : prefs.keySet()) {
2821 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2822 final String subscriberId = (String) prefs.get(key);
2823 if (activeSubscriberIds.contains(subscriberId)) {
2824 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2825 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2826 mergeNumber = (String) prefs.get(numberKey);
2827 if (DBG_MERGE) {
2828 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2829 + " for active subscriber " + subscriberId);
2830 }
2831 if (!TextUtils.isEmpty(mergeNumber)) {
2832 break;
2833 }
2834 }
2835 }
2836 }
2837
2838 // Shortcut when no active merged subscribers
2839 if (TextUtils.isEmpty(mergeNumber)) {
2840 return null;
2841 }
2842
2843 // Second pass, find all subscribers under that line override
2844 final ArraySet<String> result = new ArraySet<>();
2845 for (String key : prefs.keySet()) {
2846 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2847 final String number = (String) prefs.get(key);
2848 if (mergeNumber.equals(number)) {
2849 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2850 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2851 final String subscriberId = (String) prefs.get(subscriberKey);
2852 if (!TextUtils.isEmpty(subscriberId)) {
2853 result.add(subscriberId);
2854 }
2855 }
2856 }
2857 }
2858
2859 final String[] resultArray = result.toArray(new String[result.size()]);
2860 Arrays.sort(resultArray);
2861 if (DBG_MERGE) {
2862 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2863 }
2864 return resultArray;
2865 }
2866
2867 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002868 public boolean setOperatorBrandOverride(int subId, String brand) {
2869 enforceCarrierPrivilege(subId);
2870 final Phone phone = getPhone(subId);
2871 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002872 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002873
2874 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002875 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002876 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2877 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002878 enforceCarrierPrivilege(subId);
2879 final Phone phone = getPhone(subId);
2880 if (phone == null) {
2881 return false;
2882 }
2883 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002884 cdmaNonRoamingList);
2885 }
2886
2887 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002888 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2889 enforceModifyPermission();
2890
2891 int returnValue = 0;
2892 try {
2893 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2894 if(result.exception == null) {
2895 if (result.result != null) {
2896 byte[] responseData = (byte[])(result.result);
2897 if(responseData.length > oemResp.length) {
2898 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2899 responseData.length + "bytes. Buffer Size is " +
2900 oemResp.length + "bytes.");
2901 }
2902 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2903 returnValue = responseData.length;
2904 }
2905 } else {
2906 CommandException ex = (CommandException) result.exception;
2907 returnValue = ex.getCommandError().ordinal();
2908 if(returnValue > 0) returnValue *= -1;
2909 }
2910 } catch (RuntimeException e) {
2911 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2912 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2913 if(returnValue > 0) returnValue *= -1;
2914 }
2915
2916 return returnValue;
2917 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002918
2919 @Override
2920 public void setRadioCapability(RadioAccessFamily[] rafs) {
2921 try {
2922 ProxyController.getInstance().setRadioCapability(rafs);
2923 } catch (RuntimeException e) {
2924 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2925 }
2926 }
2927
2928 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002929 public int getRadioAccessFamily(int phoneId, String callingPackage) {
2930 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
2931 return RadioAccessFamily.RAF_UNKNOWN;
2932 }
2933
Wink Saville5d475dd2014-10-17 15:00:58 -07002934 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2935 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002936
2937 @Override
2938 public void enableVideoCalling(boolean enable) {
2939 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002940 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07002941 }
2942
2943 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002944 public boolean isVideoCallingEnabled(String callingPackage) {
2945 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
2946 return false;
2947 }
2948
Andrew Lee77527ac2014-10-21 16:57:39 -07002949 // Check the user preference and the system-level IMS setting. Even if the user has
2950 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2951 // In the long run, we may instead need to check if there exists a connection service
2952 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002953 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2954 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002955 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07002956 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002957
Andrew Leea1239f22015-03-02 17:44:07 -08002958 @Override
2959 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002960 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002961 }
2962
2963 @Override
2964 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002965 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002966 }
2967
Andrew Lee9431b832015-03-09 18:46:45 -07002968 @Override
2969 public boolean isTtyModeSupported() {
2970 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
2971 TelephonyManager telephonyManager =
2972 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08002973 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07002974 }
2975
2976 @Override
2977 public boolean isHearingAidCompatibilitySupported() {
2978 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
2979 }
2980
Sanket Padawe7310cc72015-01-14 09:53:20 -08002981 /**
2982 * Returns the unique device ID of phone, for example, the IMEI for
2983 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
2984 *
2985 * <p>Requires Permission:
2986 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
2987 */
2988 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002989 public String getDeviceId(String callingPackage) {
2990 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
2991 return null;
2992 }
2993
Sanket Padawe7310cc72015-01-14 09:53:20 -08002994 final Phone phone = PhoneFactory.getPhone(0);
2995 if (phone != null) {
2996 return phone.getDeviceId();
2997 } else {
2998 return null;
2999 }
3000 }
3001
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003002 /*
3003 * {@hide}
3004 * Returns the IMS Registration Status
3005 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003006 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003007 public boolean isImsRegistered() {
3008 return mPhone.isImsRegistered();
3009 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003010
3011 @Override
3012 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3013 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3014 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003015
Nathan Haroldc55097a2015-03-11 18:14:50 -07003016 /*
3017 * {@hide}
3018 * Returns the IMS Registration Status
3019 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003020 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003021 return mPhone.isWifiCallingEnabled();
3022 }
3023
3024 /*
3025 * {@hide}
3026 * Returns the IMS Registration Status
3027 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003028 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003029 return mPhone.isVolteEnabled();
3030 }
Svet Ganovb320e182015-04-16 12:30:10 -07003031
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003032 /*
3033 * {@hide} Returns the IMS Registration Status
3034 */
3035 public boolean isVideoTelephonyAvailable() {
3036 return mPhone.isVideoEnabled();
3037 }
3038
Svet Ganovb320e182015-04-16 12:30:10 -07003039 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003040 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003041 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003042 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3043
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003044 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003045 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003046 } catch (SecurityException e) {
3047 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3048 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003049 }
Svet Ganovb320e182015-04-16 12:30:10 -07003050
3051 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3052 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3053 return false;
3054 }
3055
3056 return true;
3057 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003058
Makoto Onukifee69342015-06-29 14:44:50 -07003059 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003060 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003061 */
3062 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003063 // Default SMS app can always read it.
3064 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3065 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3066 return true;
3067 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003068
Makoto Onukie4072d12015-08-03 15:12:23 -07003069 try {
3070 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003071 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003072 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003073 // Can be read with READ_SMS too.
3074 try {
3075 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3076 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3077 if (opCode != AppOpsManager.OP_NONE) {
3078 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3079 == AppOpsManager.MODE_ALLOWED;
3080 } else {
3081 return true;
3082 }
3083 } catch (SecurityException readSmsSecurityException) {
3084 }
3085 // Can be read with READ_PHONE_NUMBER too.
3086 try {
3087 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBER,
3088 message);
3089 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBER);
3090 if (opCode != AppOpsManager.OP_NONE) {
3091 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3092 == AppOpsManager.MODE_ALLOWED;
3093 } else {
3094 return true;
3095 }
3096 } catch (SecurityException readPhoneNumberSecurityException) {
3097 }
3098
3099 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3100 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3101 ", " + android.Manifest.permission.READ_SMS + ", or " +
3102 android.Manifest.permission.READ_PHONE_NUMBER);
Makoto Onukifee69342015-06-29 14:44:50 -07003103 }
3104
Stuart Scott8eef64f2015-04-08 15:13:54 -07003105 @Override
3106 public void factoryReset(int subId) {
3107 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003108 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3109 return;
3110 }
3111
Svet Ganovcc087f82015-05-12 20:35:54 -07003112 final long identity = Binder.clearCallingIdentity();
3113 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003114 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3115 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003116 // Enable data
3117 setDataEnabled(subId, true);
3118 // Set network selection mode to automatic
3119 setNetworkSelectionModeAutomatic(subId);
3120 // Set preferred mobile network type to the best available
3121 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3122 // Turn off roaming
3123 SubscriptionManager.from(mApp).setDataRoaming(0, subId);
3124 }
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003127 }
3128 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003129
3130 @Override
3131 public String getLocaleFromDefaultSim() {
3132 // We query all subscriptions instead of just the active ones, because
3133 // this might be called early on in the provisioning flow when the
3134 // subscriptions potentially aren't active yet.
3135 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3136 if (slist == null || slist.isEmpty()) {
3137 return null;
3138 }
3139
3140 // This function may be called very early, say, from the setup wizard, at
3141 // which point we won't have a default subscription set. If that's the case
3142 // we just choose the first, which will be valid in "most cases".
3143 final int defaultSubId = getDefaultSubscription();
3144 SubscriptionInfo info = null;
3145 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3146 info = slist.get(0);
3147 } else {
3148 for (SubscriptionInfo item : slist) {
3149 if (item.getSubscriptionId() == defaultSubId) {
3150 info = item;
3151 break;
3152 }
3153 }
3154
3155 if (info == null) {
3156 return null;
3157 }
3158 }
3159
3160 // Try and fetch the locale from the carrier properties or from the SIM language
3161 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003162 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003163 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003164 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003165 if (defaultPhone != null) {
3166 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3167 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003168 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003169 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3170 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003171 } else {
3172 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003173 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003174 }
3175 }
3176
Narayan Kamath011676f2015-07-29 12:04:08 +01003177 // The SIM language preferences only store a language (e.g. fr = French), not an
3178 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3179 // the SIM and carrier preferences does not include a country we add the country
3180 // determined from the SIM MCC to provide an exact locale.
3181 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003182 if (mccLocale != null) {
3183 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3184 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003185 }
3186
Tony Hill183b2de2015-06-24 14:53:58 +01003187 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003188 return null;
3189 }
3190
3191 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 return mSubscriptionController.getAllSubInfoList(
3195 mPhone.getContext().getOpPackageName());
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
3199 }
3200
3201 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 return mSubscriptionController.getActiveSubscriptionInfoList(
3205 mPhone.getContext().getOpPackageName());
3206 } finally {
3207 Binder.restoreCallingIdentity(identity);
3208 }
3209 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003210
3211 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003212 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3213 * representing the state of the modem.
3214 *
3215 * NOTE: This clears the modem state, so there should only every be one caller.
3216 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003217 */
3218 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003219 public void requestModemActivityInfo(ResultReceiver result) {
3220 enforceModifyPermission();
3221
3222 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3223 Bundle bundle = new Bundle();
3224 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3225 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003226 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003227
3228 /**
3229 * {@hide}
3230 * Returns the service state information on specified subscription.
3231 */
3232 @Override
3233 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3234
3235 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3236 return null;
3237 }
3238
3239 final Phone phone = getPhone(subId);
3240 if (phone == null) {
3241 return null;
3242 }
3243
3244 return phone.getServiceState();
3245 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003246
3247 /**
3248 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3249 *
3250 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3251 * voicemail ringtone.
3252 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3253 * PhoneAccount.
3254 */
3255 @Override
3256 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
3257 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3258 if (phone == null) {
3259 return null;
3260 }
3261
3262 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
3263 }
3264
3265 /**
3266 * Returns whether vibration is set for voicemail notification in Phone settings.
3267 *
3268 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3269 * voicemail vibration setting.
3270 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3271 */
3272 @Override
3273 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
3274 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3275 if (phone == null) {
3276 return false;
3277 }
3278
3279 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone);
3280 }
3281
Youhan Wange64578a2016-05-02 15:32:42 -07003282 /**
3283 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3284 *
3285 * @throws SecurityException if the caller does not have the required permission
3286 */
3287 private void enforceReadPrivilegedPermission() {
3288 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3289 null);
3290 }
3291
3292 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003293 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3294 * permission.
3295 *
3296 * @throws SecurityException if the caller does not have the required permission
3297 */
3298 private void enforceSendSmsPermission() {
3299 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3300 }
3301
3302 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003303 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003304 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003305 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003306 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003307 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
3308 String vvmPackage = RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId)
3309 .getPackageName();
3310 if (!callingPackage.equals(vvmPackage)) {
3311 throw new SecurityException("Caller not current active visual voicemail package[" +
3312 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003313 }
3314 }
3315
3316 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003317 * Return the application ID for the app type.
3318 *
3319 * @param subId the subscription ID that this request applies to.
3320 * @param appType the uicc app type.
3321 * @return Application ID for specificied app type, or null if no uicc.
3322 */
3323 @Override
3324 public String getAidForAppType(int subId, int appType) {
3325 enforceReadPrivilegedPermission();
3326 Phone phone = getPhone(subId);
3327 if (phone == null) {
3328 return null;
3329 }
3330 String aid = null;
3331 try {
3332 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3333 .getApplicationByType(appType).getAid();
3334 } catch (Exception e) {
3335 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3336 }
3337 return aid;
3338 }
3339
Youhan Wang4001d252016-05-11 10:29:41 -07003340 /**
3341 * Return the Electronic Serial Number.
3342 *
3343 * @param subId the subscription ID that this request applies to.
3344 * @return ESN or null if error.
3345 */
3346 @Override
3347 public String getEsn(int subId) {
3348 enforceReadPrivilegedPermission();
3349 Phone phone = getPhone(subId);
3350 if (phone == null) {
3351 return null;
3352 }
3353 String esn = null;
3354 try {
3355 esn = phone.getEsn();
3356 } catch (Exception e) {
3357 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3358 }
3359 return esn;
3360 }
3361
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003362 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003363 * Return the Preferred Roaming List Version.
3364 *
3365 * @param subId the subscription ID that this request applies to.
3366 * @return PRLVersion or null if error.
3367 */
3368 @Override
3369 public String getCdmaPrlVersion(int subId) {
3370 enforceReadPrivilegedPermission();
3371 Phone phone = getPhone(subId);
3372 if (phone == null) {
3373 return null;
3374 }
3375 String cdmaPrlVersion = null;
3376 try {
3377 cdmaPrlVersion = phone.getCdmaPrlVersion();
3378 } catch (Exception e) {
3379 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3380 }
3381 return cdmaPrlVersion;
3382 }
3383
3384 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003385 * Get snapshot of Telephony histograms
3386 * @return List of Telephony histograms
3387 * @hide
3388 */
3389 @Override
3390 public List<TelephonyHistogram> getTelephonyHistograms() {
3391 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3392 return RIL.getTelephonyRILTimingHistograms();
3393 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003394
3395 /**
3396 * {@hide}
3397 * Set the allowed carrier list for slotId
3398 * Require system privileges. In the future we may add this to carrier APIs.
3399 *
3400 * @return The number of carriers set successfully, should match length of carriers
3401 */
3402 @Override
3403 public int setAllowedCarriers(int slotId, List<CarrierIdentifier> carriers) {
3404 enforceModifyPermission();
3405 int subId = SubscriptionManager.getSubId(slotId)[0];
3406 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3407 return retVal[0];
3408 }
3409
3410 /**
3411 * {@hide}
3412 * Get the allowed carrier list for slotId.
3413 * Require system privileges. In the future we may add this to carrier APIs.
3414 *
3415 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3416 * means all carriers are allowed.
3417 */
3418 @Override
3419 public List<CarrierIdentifier> getAllowedCarriers(int slotId) {
3420 enforceReadPrivilegedPermission();
3421 int subId = SubscriptionManager.getSubId(slotId)[0];
3422 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3423 }
3424
fionaxu59545b42016-05-25 15:53:37 -07003425 /**
3426 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3427 * @param subId the subscription ID that this action applies to.
3428 * @param enabled control enable or disable metered apns.
3429 * {@hide}
3430 */
3431 @Override
3432 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3433 enforceModifyPermission();
3434 final Phone phone = getPhone(subId);
3435 if (phone == null) {
3436 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3437 return;
3438 }
3439 try {
3440 phone.carrierActionSetMeteredApnsEnabled(enabled);
3441 } catch (Exception e) {
3442 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3443 }
3444 }
3445
3446 /**
3447 * Action set from carrier signalling broadcast receivers to enable/disable radio
3448 * @param subId the subscription ID that this action applies to.
3449 * @param enabled control enable or disable radio.
3450 * {@hide}
3451 */
3452 @Override
3453 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3454 enforceModifyPermission();
3455 final Phone phone = getPhone(subId);
3456 if (phone == null) {
3457 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3458 return;
3459 }
3460 try {
3461 phone.carrierActionSetRadioEnabled(enabled);
3462 } catch (Exception e) {
3463 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3464 }
3465 }
3466
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003467 /**
3468 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3469 * bug report is being generated.
3470 */
3471 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003472 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003473 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3474 != PackageManager.PERMISSION_GRANTED) {
3475 writer.println("Permission Denial: can't dump Phone from pid="
3476 + Binder.getCallingPid()
3477 + ", uid=" + Binder.getCallingUid()
3478 + "without permission "
3479 + android.Manifest.permission.DUMP);
3480 return;
3481 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003482 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003483 }
Jack Yueb89b242016-06-22 13:27:47 -07003484
3485 /**
3486 * Get aggregated video call data usage from all subscriptions since boot.
3487 * @return total data usage in bytes
3488 * {@hide}
3489 */
3490 @Override
3491 public long getVtDataUsage() {
3492 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3493 null);
3494
3495 // NetworkStatsService keeps tracking the active network interface and identity. It will
3496 // record the delta with the corresponding network identity. What we need to do here is
3497 // returning total video call data usage from all subscriptions since boot.
3498
3499 // TODO: Add sub id support in the future. We'll need it when we support DSDA and
3500 // simultaneous VT calls.
3501 final Phone[] phones = PhoneFactory.getPhones();
3502 long total = 0;
3503 for (Phone phone : phones) {
3504 total += phone.getVtDataUsage();
3505 }
3506 return total;
3507 }
Jack Yu75ab2952016-07-08 14:29:33 -07003508
3509 /**
3510 * Policy control of data connection. Usually used when data limit is passed.
3511 * @param enabled True if enabling the data, otherwise disabling.
3512 * @param subId Subscription index
3513 * {@hide}
3514 */
3515 @Override
3516 public void setPolicyDataEnabled(boolean enabled, int subId) {
3517 enforceModifyPermission();
3518 Phone phone = getPhone(subId);
3519 if (phone != null) {
3520 phone.setPolicyDataEnabled(enabled);
3521 }
3522 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003523
3524 /**
3525 * Get Client request stats
3526 * @return List of Client Request Stats
3527 * @hide
3528 */
3529 @Override
3530 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3531 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3532 return null;
3533 }
3534
3535 Phone phone = getPhone(subId);
3536 if (phone != null) {
3537 return phone.getClientRequestStats();
3538 }
3539
3540 return null;
3541 }
3542
3543 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3544 if (workSource != null) {
3545 return workSource;
3546 }
3547
3548 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3549 workSource = new WorkSource(uid, packageName);
3550 return workSource;
3551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003552}