blob: 340ec3fa0ac6dcdc958acaa84e321056a07a8276 [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) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001684 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001685 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1686 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 }
1688
Shishir Agrawala9f32182016-04-12 12:00:16 -07001689 @Override
1690 public String getImeiForSlot(int slotId, String callingPackage) {
1691 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1692 return null;
1693 }
1694 Phone phone = PhoneFactory.getPhone(slotId);
1695 return phone == null ? null : phone.getImei();
1696 }
1697
1698 @Override
1699 public String getDeviceSoftwareVersionForSlot(int slotId, String callingPackage) {
1700 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1701 return null;
1702 }
1703 Phone phone = PhoneFactory.getPhone(slotId);
1704 return phone == null ? null : phone.getDeviceSvn();
1705 }
1706
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 //
1708 // Internal helper methods.
1709 //
1710
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001711 /**
1712 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1713 */
1714 private boolean checkCallerInteractAcrossUsersFull() {
1715 return mPhone.getContext().checkCallingOrSelfPermission(
1716 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1717 == PackageManager.PERMISSION_GRANTED;
1718 }
1719
Jake Hambye994d462014-02-03 13:10:13 -08001720 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 boolean ok;
1722
1723 boolean self = Binder.getCallingUid() == Process.myUid();
1724 if (!self) {
1725 // Get the caller's user id then clear the calling identity
1726 // which will be restored in the finally clause.
1727 int callingUser = UserHandle.getCallingUserId();
1728 long ident = Binder.clearCallingIdentity();
1729
1730 try {
1731 // With calling identity cleared the current user is the foreground user.
1732 int foregroundUser = ActivityManager.getCurrentUser();
1733 ok = (foregroundUser == callingUser);
1734 if (DBG_LOC) {
1735 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1736 + " callingUser=" + callingUser + " ok=" + ok);
1737 }
1738 } catch (Exception ex) {
1739 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1740 ok = false;
1741 } finally {
1742 Binder.restoreCallingIdentity(ident);
1743 }
1744 } else {
1745 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1746 ok = true;
1747 }
1748 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1749 return ok;
1750 }
1751
1752 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1754 *
1755 * @throws SecurityException if the caller does not have the required permission
1756 */
1757 private void enforceModifyPermission() {
1758 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1759 }
1760
1761 /**
Junda Liua2e36012014-07-09 18:30:01 -07001762 * Make sure either system app or the caller has carrier privilege.
1763 *
1764 * @throws SecurityException if the caller does not have the required permission/privilege
1765 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001766 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001767 int permission = mApp.checkCallingOrSelfPermission(
1768 android.Manifest.permission.MODIFY_PHONE_STATE);
1769 if (permission == PackageManager.PERMISSION_GRANTED) {
1770 return;
1771 }
1772
1773 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001774 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001775 }
1776
1777 /**
1778 * Make sure the caller has carrier privilege.
1779 *
1780 * @throws SecurityException if the caller does not have the required permission
1781 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001782 private void enforceCarrierPrivilege(int subId) {
1783 if (getCarrierPrivilegeStatus(subId) !=
1784 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001785 loge("No Carrier Privilege.");
1786 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001787 }
1788 }
1789
1790 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 * Make sure the caller has the CALL_PHONE permission.
1792 *
1793 * @throws SecurityException if the caller does not have the required permission
1794 */
1795 private void enforceCallPermission() {
1796 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1797 }
1798
Stuart Scott8eef64f2015-04-08 15:13:54 -07001799 private void enforceConnectivityInternalPermission() {
1800 mApp.enforceCallingOrSelfPermission(
1801 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1802 "ConnectivityService");
1803 }
1804
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 private String createTelUrl(String number) {
1806 if (TextUtils.isEmpty(number)) {
1807 return null;
1808 }
1809
Jake Hambye994d462014-02-03 13:10:13 -08001810 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
1812
Ihab Awadf9e92732013-12-05 18:02:52 -08001813 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1815 }
1816
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001817 private static void logv(String msg) {
1818 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1819 }
1820
Ihab Awadf9e92732013-12-05 18:02:52 -08001821 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1823 }
1824
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001827 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001828 }
1829
Sanket Padawe356d7632015-06-22 14:03:32 -07001830 @Override
Shishir Agrawala9f32182016-04-12 12:00:16 -07001831 public int getActivePhoneTypeForSlot(int slotId) {
1832 final Phone phone = PhoneFactory.getPhone(slotId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001833 if (phone == null) {
1834 return PhoneConstants.PHONE_TYPE_NONE;
1835 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001836 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 }
1839
1840 /**
1841 * Returns the CDMA ERI icon index to display
1842 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001843 @Override
1844 public int getCdmaEriIconIndex(String callingPackage) {
1845 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001846 }
1847
Sanket Padawe356d7632015-06-22 14:03:32 -07001848 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001849 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1850 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1851 return -1;
1852 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001853 final Phone phone = getPhone(subId);
1854 if (phone != null) {
1855 return phone.getCdmaEriIconIndex();
1856 } else {
1857 return -1;
1858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 }
1860
1861 /**
1862 * Returns the CDMA ERI icon mode,
1863 * 0 - ON
1864 * 1 - FLASHING
1865 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001866 @Override
1867 public int getCdmaEriIconMode(String callingPackage) {
1868 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001869 }
1870
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001872 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1873 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1874 return -1;
1875 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 final Phone phone = getPhone(subId);
1877 if (phone != null) {
1878 return phone.getCdmaEriIconMode();
1879 } else {
1880 return -1;
1881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 }
1883
1884 /**
1885 * Returns the CDMA ERI text,
1886 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001887 @Override
1888 public String getCdmaEriText(String callingPackage) {
1889 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001890 }
1891
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001893 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1894 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1895 return null;
1896 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001897 final Phone phone = getPhone(subId);
1898 if (phone != null) {
1899 return phone.getCdmaEriText();
1900 } else {
1901 return null;
1902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001906 * Returns the CDMA MDN.
1907 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001909 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001910 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001911 final Phone phone = getPhone(subId);
1912 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1913 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001914 } else {
1915 return null;
1916 }
1917 }
1918
1919 /**
1920 * Returns the CDMA MIN.
1921 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001922 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001923 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001924 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 final Phone phone = getPhone(subId);
1926 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1927 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001928 } else {
1929 return null;
1930 }
1931 }
1932
1933 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 * Returns true if CDMA provisioning needs to run.
1935 */
1936 public boolean needsOtaServiceProvisioning() {
1937 return mPhone.needsOtaServiceProvisioning();
1938 }
1939
1940 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001941 * Sets the voice mail number of a given subId.
1942 */
1943 @Override
1944 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001945 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001946 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1947 new Pair<String, String>(alphaTag, number), new Integer(subId));
1948 return success;
1949 }
1950
Ta-wei Yen87c49842016-05-13 21:19:52 -07001951 @Override
Ta-wei Yenb0f695b2016-08-08 17:33:11 -07001952 public void setVisualVoicemailEnabled(String callingPackage,
1953 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
1954 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1955 if (!TextUtils.equals(callingPackage,
1956 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
1957 enforceModifyPermissionOrCarrierPrivilege(
1958 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
1959 }
1960 VisualVoicemailSettingsUtil.setEnabled(mPhone.getContext(), phoneAccountHandle, enabled);
1961 }
1962
1963 @Override
1964 public boolean isVisualVoicemailEnabled(String callingPackage,
1965 PhoneAccountHandle phoneAccountHandle) {
1966 if (!canReadPhoneState(callingPackage, "isVisualVoicemailEnabled")) {
1967 return false;
1968 }
1969 return VisualVoicemailSettingsUtil.isEnabled(mPhone.getContext(), phoneAccountHandle);
1970 }
1971
1972 @Override
Ta-wei Yendca928f2017-01-10 16:17:08 -08001973 public String getVisualVoicemailPackageName(String callingPackage,
1974 @Nullable PhoneAccountHandle phoneAccountHandle) {
1975 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1976 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
1977 return null;
1978 }
1979 int subId = PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
1980 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
1981 }
1982
1983 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001984 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
1985 VisualVoicemailSmsFilterSettings settings) {
1986 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001987 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001988 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
1989 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001990 }
1991
1992 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001993 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
1994 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001995 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001996 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001997 }
1998
1999 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002000 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2001 String callingPackage, int subId) {
2002 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002003 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002004 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002005 }
2006
2007 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002008 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002009 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002010 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002011 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2012 }
2013
2014 @Override
2015 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2016 String number, int port, String text, PendingIntent sentIntent) {
2017 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002018 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002019 enforceSendSmsPermission();
2020 // Make the calls as the phone process.
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2024 if (port == 0) {
2025 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2026 sentIntent, null, false);
2027 } else {
2028 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2029 smsManager.sendDataMessageWithSelfPermissions(number, null,
2030 (short) port, data, sentIntent, null);
2031 }
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
2034 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002035 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002036 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 * Returns the unread count of voicemails
2038 */
2039 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002040 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002041 }
2042
2043 /**
2044 * Returns the unread count of voicemails for a subId
2045 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002046 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002047 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002048 final Phone phone = getPhone(subId);
2049 if (phone != null) {
2050 return phone.getVoiceMessageCount();
2051 } else {
2052 return 0;
2053 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 }
2055
2056 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002057 * returns true, if the device is in a state where both voice and data
2058 * are supported simultaneously. This can change based on location or network condition.
2059 */
2060 @Override
2061 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2062 final Phone phone = getPhone(subId);
2063 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2064 }
2065
2066 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002067 * Returns the data network type.
2068 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 *
2070 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2071 */
2072 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002073 public int getNetworkType() {
2074 final Phone phone = getPhone(getDefaultSubscription());
2075 if (phone != null) {
2076 return phone.getServiceState().getDataNetworkType();
2077 } else {
2078 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2079 }
Wink Saville36469e72014-06-11 15:17:00 -07002080 }
2081
2082 /**
2083 * Returns the network type for a subId
2084 */
2085 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002086 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2087 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2088 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2089 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002090
Sanket Padawe356d7632015-06-22 14:03:32 -07002091 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002092 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002093 return phone.getServiceState().getDataNetworkType();
2094 } else {
2095 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 }
2098
2099 /**
2100 * Returns the data network type
2101 */
2102 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002103 public int getDataNetworkType(String callingPackage) {
2104 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002105 }
2106
2107 /**
2108 * Returns the data network type for a subId
2109 */
2110 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002111 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2112 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2113 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2114 }
2115
Sanket Padawe356d7632015-06-22 14:03:32 -07002116 final Phone phone = getPhone(subId);
2117 if (phone != null) {
2118 return phone.getServiceState().getDataNetworkType();
2119 } else {
2120 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2121 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 }
2123
2124 /**
Wink Saville36469e72014-06-11 15:17:00 -07002125 * Returns the Voice network type for a subId
2126 */
2127 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002128 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2129 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2130 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2131 }
2132
Sanket Padawe356d7632015-06-22 14:03:32 -07002133 final Phone phone = getPhone(subId);
2134 if (phone != null) {
2135 return phone.getServiceState().getVoiceNetworkType();
2136 } else {
2137 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 }
2140
2141 /**
2142 * @return true if a ICC card is present
2143 */
2144 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002145 // FIXME Make changes to pass defaultSimId of type int
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002146 return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002147 }
2148
2149 /**
2150 * @return true if a ICC card is present for a slotId
2151 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002152 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002153 public boolean hasIccCardUsingSlotId(int slotId) {
fionaxu6e6c68b2016-06-23 13:31:32 -07002154 final Phone phone = PhoneFactory.getPhone(slotId);
2155 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002156 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002157 } else {
2158 return false;
2159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 }
2161
2162 /**
2163 * Return if the current radio is LTE on CDMA. This
2164 * is a tri-state return value as for a period of time
2165 * the mode may be unknown.
2166 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002167 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002169 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002171 @Override
2172 public int getLteOnCdmaMode(String callingPackage) {
2173 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002174 }
2175
Sanket Padawe356d7632015-06-22 14:03:32 -07002176 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002177 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2178 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2179 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2180 }
2181
Sanket Padawe356d7632015-06-22 14:03:32 -07002182 final Phone phone = getPhone(subId);
2183 if (phone == null) {
2184 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2185 } else {
2186 return phone.getLteOnCdmaMode();
2187 }
Wink Saville36469e72014-06-11 15:17:00 -07002188 }
2189
2190 public void setPhone(Phone phone) {
2191 mPhone = phone;
2192 }
2193
2194 /**
2195 * {@hide}
2196 * Returns Default subId, 0 in the case of single standby.
2197 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002198 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002199 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002200 }
2201
Shishir Agrawala9f32182016-04-12 12:00:16 -07002202 private int getSlotForDefaultSubscription() {
2203 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2204 }
2205
Wink Savilleb564aae2014-10-23 10:18:09 -07002206 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002207 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002209
2210 /**
2211 * @see android.telephony.TelephonyManager.WifiCallingChoices
2212 */
2213 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002214 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2215 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002216 }
2217
2218 /**
2219 * @see android.telephony.TelephonyManager.WifiCallingChoices
2220 */
2221 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002222 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2223 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2224 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002225 }
2226
Sailesh Nepald1e68152013-12-12 19:08:02 -08002227 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002228 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002229 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002230 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002231
Shishir Agrawal566b7612013-10-28 14:41:00 -07002232 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002233 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID) {
2234 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002235
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002236 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002237 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002238 CMD_OPEN_CHANNEL, AID, subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002239 if (DBG) log("iccOpenLogicalChannel: " + response);
2240 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002241 }
2242
2243 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002244 public boolean iccCloseLogicalChannel(int subId, int channel) {
2245 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002246
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002247 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002248 if (channel < 0) {
2249 return false;
2250 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002251 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002252 if (DBG) log("iccCloseLogicalChannel: " + success);
2253 return success;
2254 }
2255
2256 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002257 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002258 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002259 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002260
2261 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002262 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2263 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002264 " data=" + data);
2265 }
2266
2267 if (channel < 0) {
2268 return "";
2269 }
2270
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002271 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002272 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002273 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2274
Shishir Agrawal566b7612013-10-28 14:41:00 -07002275 // Append the returned status code to the end of the response payload.
2276 String s = Integer.toHexString(
2277 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002278 if (response.payload != null) {
2279 s = IccUtils.bytesToHexString(response.payload) + s;
2280 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002281 return s;
2282 }
Jake Hambye994d462014-02-03 13:10:13 -08002283
Evan Charltonc66da362014-05-16 14:06:40 -07002284 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002285 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002286 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002287 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002288
2289 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002290 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2291 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002292 }
2293
2294 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002295 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002296 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2297
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002298 // Append the returned status code to the end of the response payload.
2299 String s = Integer.toHexString(
2300 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002301 if (response.payload != null) {
2302 s = IccUtils.bytesToHexString(response.payload) + s;
2303 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002304 return s;
2305 }
2306
2307 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002308 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002309 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002310 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002311
2312 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002313 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002314 p1 + " " + p2 + " " + p3 + ":" + filePath);
2315 }
2316
2317 IccIoResult response =
2318 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002319 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2320 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002321
2322 if (DBG) {
2323 log("Exchange SIM_IO [R]" + response);
2324 }
2325
2326 byte[] result = null;
2327 int length = 2;
2328 if (response.payload != null) {
2329 length = 2 + response.payload.length;
2330 result = new byte[length];
2331 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2332 } else {
2333 result = new byte[length];
2334 }
2335
2336 result[length - 1] = (byte) response.sw2;
2337 result[length - 2] = (byte) response.sw1;
2338 return result;
2339 }
2340
2341 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002342 public String sendEnvelopeWithStatus(int subId, String content) {
2343 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002344
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002345 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002346 if (response.payload == null) {
2347 return "";
2348 }
2349
2350 // Append the returned status code to the end of the response payload.
2351 String s = Integer.toHexString(
2352 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2353 s = IccUtils.bytesToHexString(response.payload) + s;
2354 return s;
2355 }
2356
Jake Hambye994d462014-02-03 13:10:13 -08002357 /**
2358 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2359 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2360 *
2361 * @param itemID the ID of the item to read
2362 * @return the NV item as a String, or null on error.
2363 */
2364 @Override
2365 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002366 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002367 if (DBG) log("nvReadItem: item " + itemID);
2368 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2369 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2370 return value;
2371 }
2372
2373 /**
2374 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2375 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2376 *
2377 * @param itemID the ID of the item to read
2378 * @param itemValue the value to write, as a String
2379 * @return true on success; false on any failure
2380 */
2381 @Override
2382 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002383 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002384 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2385 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2386 new Pair<Integer, String>(itemID, itemValue));
2387 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2388 return success;
2389 }
2390
2391 /**
2392 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2393 * Used for device configuration by some CDMA operators.
2394 *
2395 * @param preferredRoamingList byte array containing the new PRL
2396 * @return true on success; false on any failure
2397 */
2398 @Override
2399 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002400 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002401 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2402 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2403 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2404 return success;
2405 }
2406
2407 /**
2408 * Perform the specified type of NV config reset.
2409 * Used for device configuration by some CDMA operators.
2410 *
2411 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2412 * @return true on success; false on any failure
2413 */
2414 @Override
2415 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002416 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002417 if (DBG) log("nvResetConfig: type " + resetType);
2418 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2419 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2420 return success;
2421 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002422
2423 /**
Wink Saville36469e72014-06-11 15:17:00 -07002424 * {@hide}
2425 * Returns Default sim, 0 in the case of single standby.
2426 */
2427 public int getDefaultSim() {
2428 //TODO Need to get it from Telephony Devcontroller
2429 return 0;
2430 }
2431
Svet Ganovb320e182015-04-16 12:30:10 -07002432 public String[] getPcscfAddress(String apnType, String callingPackage) {
2433 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2434 return new String[0];
2435 }
2436
2437
ram87fca6f2014-07-18 18:58:44 +05302438 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002439 }
2440
2441 public void setImsRegistrationState(boolean registered) {
2442 enforceModifyPermission();
2443 mPhone.setImsRegistrationState(registered);
2444 }
2445
2446 /**
Stuart Scott54788802015-03-30 13:18:01 -07002447 * Set the network selection mode to automatic.
2448 *
2449 */
2450 @Override
2451 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002452 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002453 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2454 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2455 }
2456
2457 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002458 * Set the network selection mode to manual with the selected carrier.
2459 */
2460 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002461 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2462 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002463 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002464 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002465 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2466 persistSelection);
2467 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002468 }
2469
2470 /**
2471 * Scans for available networks.
2472 */
2473 @Override
2474 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002475 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002476 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2477 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2478 CMD_PERFORM_NETWORK_SCAN, null, subId);
2479 return result;
2480 }
2481
2482 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002483 * Get the calculated preferred network type.
2484 * Used for debugging incorrect network type.
2485 *
2486 * @return the preferred network type, defined in RILConstants.java.
2487 */
2488 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002489 public int getCalculatedPreferredNetworkType(String callingPackage) {
2490 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2491 return RILConstants.PREFERRED_NETWORK_MODE;
2492 }
2493
Amit Mahajan43330e02014-11-18 11:54:45 -08002494 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002495 }
2496
2497 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002498 * Get the preferred network type.
2499 * Used for device configuration by some CDMA operators.
2500 *
2501 * @return the preferred network type, defined in RILConstants.java.
2502 */
2503 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002504 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002505 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002506 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002507 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002508 int networkType = (result != null ? result[0] : -1);
2509 if (DBG) log("getPreferredNetworkType: " + networkType);
2510 return networkType;
2511 }
2512
2513 /**
2514 * Set the preferred network type.
2515 * Used for device configuration by some CDMA operators.
2516 *
2517 * @param networkType the preferred network type, defined in RILConstants.java.
2518 * @return true on success; false on any failure.
2519 */
2520 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002521 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002522 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002523 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2524 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002525 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002526 if (success) {
2527 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002528 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002529 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002530 return success;
2531 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002532
2533 /**
Junda Liu475951f2014-11-07 16:45:03 -08002534 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2535 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2536 * tethering.
2537 *
2538 * @return 0: Not required. 1: required. 2: Not set.
2539 * @hide
2540 */
2541 @Override
2542 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002543 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002544 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2545 Settings.Global.TETHER_DUN_REQUIRED, 2);
2546 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2547 // config_tether_apndata.
2548 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2549 dunRequired = 1;
2550 }
2551 return dunRequired;
2552 }
2553
2554 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002555 * Set mobile data enabled
2556 * Used by the user through settings etc to turn on/off mobile data
2557 *
2558 * @param enable {@code true} turn turn data on, else {@code false}
2559 */
2560 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002561 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002562 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002563 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002564 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002565 Phone phone = PhoneFactory.getPhone(phoneId);
2566 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002567 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002568 phone.setDataEnabled(enable);
2569 } else {
2570 loge("setDataEnabled: no phone for subId=" + subId);
2571 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002572 }
2573
2574 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002575 * Get whether mobile data is enabled.
2576 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002577 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002578 *
2579 * @return {@code true} if data is enabled else {@code false}
2580 */
2581 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002582 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002583 try {
2584 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2585 null);
2586 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002587 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002588 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002589 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002590 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002591 Phone phone = PhoneFactory.getPhone(phoneId);
2592 if (phone != null) {
2593 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002594 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002595 return retVal;
2596 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002597 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002598 return false;
2599 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002600 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002601
2602 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002603 public int getCarrierPrivilegeStatus(int subId) {
2604 final Phone phone = getPhone(subId);
2605 if (phone == null) {
2606 loge("getCarrierPrivilegeStatus: Invalid subId");
2607 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2608 }
2609 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002610 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002611 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002612 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2613 }
2614 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002615 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002616 }
Junda Liu29340342014-07-10 15:23:27 -07002617
2618 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002619 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002620 if (TextUtils.isEmpty(pkgName))
2621 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002622 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002623 if (card == null) {
2624 loge("checkCarrierPrivilegesForPackage: No UICC");
2625 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2626 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002627 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2628 }
2629
2630 @Override
2631 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002632 if (TextUtils.isEmpty(pkgName))
2633 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002634 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2635 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2636 UiccCard card = UiccController.getInstance().getUiccCard(i);
2637 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002638 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002639 continue;
2640 }
2641
2642 result = card.getCarrierPrivilegeStatus(
2643 mPhone.getContext().getPackageManager(), pkgName);
2644 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2645 break;
2646 }
2647 }
2648
2649 return result;
Junda Liu29340342014-07-10 15:23:27 -07002650 }
Derek Tan89e89d42014-07-08 17:00:10 -07002651
2652 @Override
Junda Liue64de782015-04-16 17:19:16 -07002653 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2654 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2655 loge("phoneId " + phoneId + " is not valid.");
2656 return null;
2657 }
2658 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002659 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002660 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002661 return null ;
2662 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002663 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002664 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002665 }
2666
Amith Yamasani6e118872016-02-19 12:53:51 -08002667 @Override
2668 public List<String> getPackagesWithCarrierPrivileges() {
2669 PackageManager pm = mPhone.getContext().getPackageManager();
2670 List<String> privilegedPackages = new ArrayList<>();
2671 List<PackageInfo> packages = null;
2672 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2673 UiccCard card = UiccController.getInstance().getUiccCard(i);
2674 if (card == null) {
2675 // No UICC in that slot.
2676 continue;
2677 }
2678 if (card.hasCarrierPrivilegeRules()) {
2679 if (packages == null) {
2680 // Only check packages in user 0 for now
2681 packages = pm.getInstalledPackagesAsUser(
2682 PackageManager.MATCH_DISABLED_COMPONENTS
2683 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2684 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2685 }
2686 for (int p = packages.size() - 1; p >= 0; p--) {
2687 PackageInfo pkgInfo = packages.get(p);
2688 if (pkgInfo != null && pkgInfo.packageName != null
2689 && card.getCarrierPrivilegeStatus(pkgInfo)
2690 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2691 privilegedPackages.add(pkgInfo.packageName);
2692 }
2693 }
2694 }
2695 }
2696 return privilegedPackages;
2697 }
2698
Wink Savilleb564aae2014-10-23 10:18:09 -07002699 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002700 final Phone phone = getPhone(subId);
2701 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002702 if (card == null) {
2703 loge("getIccId: No UICC");
2704 return null;
2705 }
2706 String iccId = card.getIccId();
2707 if (TextUtils.isEmpty(iccId)) {
2708 loge("getIccId: ICC ID is null or empty.");
2709 return null;
2710 }
2711 return iccId;
2712 }
2713
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002714 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002715 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2716 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002717 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002718
Jeff Sharkey85190e62014-12-05 09:40:12 -08002719 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002720 final Phone phone = getPhone(subId);
2721 if (phone == null) {
2722 return false;
2723 }
2724 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002725
2726 if (DBG_MERGE) {
2727 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2728 + subscriberId + " to " + number);
2729 }
2730
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002731 if (TextUtils.isEmpty(iccId)) {
2732 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002733 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002734
Jeff Sharkey85190e62014-12-05 09:40:12 -08002735 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2736
2737 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002738 if (alphaTag == null) {
2739 editor.remove(alphaTagPrefKey);
2740 } else {
2741 editor.putString(alphaTagPrefKey, alphaTag);
2742 }
2743
Jeff Sharkey85190e62014-12-05 09:40:12 -08002744 // Record both the line number and IMSI for this ICCID, since we need to
2745 // track all merged IMSIs based on line number
2746 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2747 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002748 if (number == null) {
2749 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002750 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002751 } else {
2752 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002753 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002754 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002755
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002756 editor.commit();
2757 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002758 }
2759
2760 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002761 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002762 // This is open to apps with WRITE_SMS.
2763 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002764 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002765 return null;
2766 }
Derek Tan97ebb422014-09-05 16:55:38 -07002767
2768 String iccId = getIccId(subId);
2769 if (iccId != null) {
2770 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002771 if (DBG_MERGE) {
2772 log("getLine1NumberForDisplay returning " +
2773 mTelephonySharedPreferences.getString(numberPrefKey, null));
2774 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002775 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002776 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002777 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002778 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002779 }
2780
2781 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002782 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2783 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2784 return null;
2785 }
Derek Tan97ebb422014-09-05 16:55:38 -07002786
2787 String iccId = getIccId(subId);
2788 if (iccId != null) {
2789 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002790 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002791 }
Derek Tan97ebb422014-09-05 16:55:38 -07002792 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002793 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002794
2795 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002796 public String[] getMergedSubscriberIds(String callingPackage) {
2797 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2798 return null;
2799 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002800 final Context context = mPhone.getContext();
2801 final TelephonyManager tele = TelephonyManager.from(context);
2802 final SubscriptionManager sub = SubscriptionManager.from(context);
2803
2804 // Figure out what subscribers are currently active
2805 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002806 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2807 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 final int[] subIds = sub.getActiveSubscriptionIdList();
2811 for (int subId : subIds) {
2812 activeSubscriberIds.add(tele.getSubscriberId(subId));
2813 }
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002816 }
2817
2818 // First pass, find a number override for an active subscriber
2819 String mergeNumber = null;
2820 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2821 for (String key : prefs.keySet()) {
2822 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2823 final String subscriberId = (String) prefs.get(key);
2824 if (activeSubscriberIds.contains(subscriberId)) {
2825 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2826 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2827 mergeNumber = (String) prefs.get(numberKey);
2828 if (DBG_MERGE) {
2829 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2830 + " for active subscriber " + subscriberId);
2831 }
2832 if (!TextUtils.isEmpty(mergeNumber)) {
2833 break;
2834 }
2835 }
2836 }
2837 }
2838
2839 // Shortcut when no active merged subscribers
2840 if (TextUtils.isEmpty(mergeNumber)) {
2841 return null;
2842 }
2843
2844 // Second pass, find all subscribers under that line override
2845 final ArraySet<String> result = new ArraySet<>();
2846 for (String key : prefs.keySet()) {
2847 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2848 final String number = (String) prefs.get(key);
2849 if (mergeNumber.equals(number)) {
2850 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2851 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2852 final String subscriberId = (String) prefs.get(subscriberKey);
2853 if (!TextUtils.isEmpty(subscriberId)) {
2854 result.add(subscriberId);
2855 }
2856 }
2857 }
2858 }
2859
2860 final String[] resultArray = result.toArray(new String[result.size()]);
2861 Arrays.sort(resultArray);
2862 if (DBG_MERGE) {
2863 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2864 }
2865 return resultArray;
2866 }
2867
2868 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002869 public boolean setOperatorBrandOverride(int subId, String brand) {
2870 enforceCarrierPrivilege(subId);
2871 final Phone phone = getPhone(subId);
2872 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002873 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002874
2875 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002876 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002877 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2878 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002879 enforceCarrierPrivilege(subId);
2880 final Phone phone = getPhone(subId);
2881 if (phone == null) {
2882 return false;
2883 }
2884 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002885 cdmaNonRoamingList);
2886 }
2887
2888 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002889 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2890 enforceModifyPermission();
2891
2892 int returnValue = 0;
2893 try {
2894 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2895 if(result.exception == null) {
2896 if (result.result != null) {
2897 byte[] responseData = (byte[])(result.result);
2898 if(responseData.length > oemResp.length) {
2899 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2900 responseData.length + "bytes. Buffer Size is " +
2901 oemResp.length + "bytes.");
2902 }
2903 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2904 returnValue = responseData.length;
2905 }
2906 } else {
2907 CommandException ex = (CommandException) result.exception;
2908 returnValue = ex.getCommandError().ordinal();
2909 if(returnValue > 0) returnValue *= -1;
2910 }
2911 } catch (RuntimeException e) {
2912 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2913 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2914 if(returnValue > 0) returnValue *= -1;
2915 }
2916
2917 return returnValue;
2918 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002919
2920 @Override
2921 public void setRadioCapability(RadioAccessFamily[] rafs) {
2922 try {
2923 ProxyController.getInstance().setRadioCapability(rafs);
2924 } catch (RuntimeException e) {
2925 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2926 }
2927 }
2928
2929 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002930 public int getRadioAccessFamily(int phoneId, String callingPackage) {
2931 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
2932 return RadioAccessFamily.RAF_UNKNOWN;
2933 }
2934
Wink Saville5d475dd2014-10-17 15:00:58 -07002935 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2936 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002937
2938 @Override
2939 public void enableVideoCalling(boolean enable) {
2940 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002941 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07002942 }
2943
2944 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002945 public boolean isVideoCallingEnabled(String callingPackage) {
2946 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
2947 return false;
2948 }
2949
Andrew Lee77527ac2014-10-21 16:57:39 -07002950 // Check the user preference and the system-level IMS setting. Even if the user has
2951 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2952 // In the long run, we may instead need to check if there exists a connection service
2953 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002954 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2955 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002956 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07002957 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002958
Andrew Leea1239f22015-03-02 17:44:07 -08002959 @Override
2960 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002961 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002962 }
2963
2964 @Override
2965 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002966 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002967 }
2968
Andrew Lee9431b832015-03-09 18:46:45 -07002969 @Override
2970 public boolean isTtyModeSupported() {
2971 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
2972 TelephonyManager telephonyManager =
2973 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08002974 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07002975 }
2976
2977 @Override
2978 public boolean isHearingAidCompatibilitySupported() {
2979 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
2980 }
2981
Sanket Padawe7310cc72015-01-14 09:53:20 -08002982 /**
2983 * Returns the unique device ID of phone, for example, the IMEI for
2984 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
2985 *
2986 * <p>Requires Permission:
2987 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
2988 */
2989 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002990 public String getDeviceId(String callingPackage) {
2991 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
2992 return null;
2993 }
2994
Sanket Padawe7310cc72015-01-14 09:53:20 -08002995 final Phone phone = PhoneFactory.getPhone(0);
2996 if (phone != null) {
2997 return phone.getDeviceId();
2998 } else {
2999 return null;
3000 }
3001 }
3002
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003003 /*
3004 * {@hide}
3005 * Returns the IMS Registration Status
3006 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003007 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003008 public boolean isImsRegistered() {
3009 return mPhone.isImsRegistered();
3010 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003011
3012 @Override
3013 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3014 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3015 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003016
Nathan Haroldc55097a2015-03-11 18:14:50 -07003017 /*
3018 * {@hide}
3019 * Returns the IMS Registration Status
3020 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003021 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003022 return mPhone.isWifiCallingEnabled();
3023 }
3024
3025 /*
3026 * {@hide}
3027 * Returns the IMS Registration Status
3028 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003029 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003030 return mPhone.isVolteEnabled();
3031 }
Svet Ganovb320e182015-04-16 12:30:10 -07003032
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003033 /*
3034 * {@hide} Returns the IMS Registration Status
3035 */
3036 public boolean isVideoTelephonyAvailable() {
3037 return mPhone.isVideoEnabled();
3038 }
3039
Svet Ganovb320e182015-04-16 12:30:10 -07003040 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003041 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003042 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003043 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3044
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003045 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003046 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003047 } catch (SecurityException e) {
3048 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3049 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003050 }
Svet Ganovb320e182015-04-16 12:30:10 -07003051
3052 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3053 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3054 return false;
3055 }
3056
3057 return true;
3058 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003059
Makoto Onukifee69342015-06-29 14:44:50 -07003060 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003061 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003062 */
3063 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003064 // Default SMS app can always read it.
3065 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3066 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3067 return true;
3068 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003069
Makoto Onukie4072d12015-08-03 15:12:23 -07003070 try {
3071 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003072 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003073 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003074 // Can be read with READ_SMS too.
3075 try {
3076 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3077 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3078 if (opCode != AppOpsManager.OP_NONE) {
3079 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3080 == AppOpsManager.MODE_ALLOWED;
3081 } else {
3082 return true;
3083 }
3084 } catch (SecurityException readSmsSecurityException) {
3085 }
3086 // Can be read with READ_PHONE_NUMBER too.
3087 try {
3088 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBER,
3089 message);
3090 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBER);
3091 if (opCode != AppOpsManager.OP_NONE) {
3092 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3093 == AppOpsManager.MODE_ALLOWED;
3094 } else {
3095 return true;
3096 }
3097 } catch (SecurityException readPhoneNumberSecurityException) {
3098 }
3099
3100 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3101 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3102 ", " + android.Manifest.permission.READ_SMS + ", or " +
3103 android.Manifest.permission.READ_PHONE_NUMBER);
Makoto Onukifee69342015-06-29 14:44:50 -07003104 }
3105
Stuart Scott8eef64f2015-04-08 15:13:54 -07003106 @Override
3107 public void factoryReset(int subId) {
3108 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003109 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3110 return;
3111 }
3112
Svet Ganovcc087f82015-05-12 20:35:54 -07003113 final long identity = Binder.clearCallingIdentity();
3114 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003115 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3116 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003117 // Enable data
3118 setDataEnabled(subId, true);
3119 // Set network selection mode to automatic
3120 setNetworkSelectionModeAutomatic(subId);
3121 // Set preferred mobile network type to the best available
3122 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3123 // Turn off roaming
3124 SubscriptionManager.from(mApp).setDataRoaming(0, subId);
3125 }
3126 } finally {
3127 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003128 }
3129 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003130
3131 @Override
3132 public String getLocaleFromDefaultSim() {
3133 // We query all subscriptions instead of just the active ones, because
3134 // this might be called early on in the provisioning flow when the
3135 // subscriptions potentially aren't active yet.
3136 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3137 if (slist == null || slist.isEmpty()) {
3138 return null;
3139 }
3140
3141 // This function may be called very early, say, from the setup wizard, at
3142 // which point we won't have a default subscription set. If that's the case
3143 // we just choose the first, which will be valid in "most cases".
3144 final int defaultSubId = getDefaultSubscription();
3145 SubscriptionInfo info = null;
3146 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3147 info = slist.get(0);
3148 } else {
3149 for (SubscriptionInfo item : slist) {
3150 if (item.getSubscriptionId() == defaultSubId) {
3151 info = item;
3152 break;
3153 }
3154 }
3155
3156 if (info == null) {
3157 return null;
3158 }
3159 }
3160
3161 // Try and fetch the locale from the carrier properties or from the SIM language
3162 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003163 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003164 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003165 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003166 if (defaultPhone != null) {
3167 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3168 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003169 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003170 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3171 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003172 } else {
3173 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003174 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003175 }
3176 }
3177
Narayan Kamath011676f2015-07-29 12:04:08 +01003178 // The SIM language preferences only store a language (e.g. fr = French), not an
3179 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3180 // the SIM and carrier preferences does not include a country we add the country
3181 // determined from the SIM MCC to provide an exact locale.
3182 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003183 if (mccLocale != null) {
3184 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3185 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003186 }
3187
Tony Hill183b2de2015-06-24 14:53:58 +01003188 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003189 return null;
3190 }
3191
3192 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 return mSubscriptionController.getAllSubInfoList(
3196 mPhone.getContext().getOpPackageName());
3197 } finally {
3198 Binder.restoreCallingIdentity(identity);
3199 }
3200 }
3201
3202 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 return mSubscriptionController.getActiveSubscriptionInfoList(
3206 mPhone.getContext().getOpPackageName());
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
3210 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003211
3212 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003213 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3214 * representing the state of the modem.
3215 *
3216 * NOTE: This clears the modem state, so there should only every be one caller.
3217 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003218 */
3219 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003220 public void requestModemActivityInfo(ResultReceiver result) {
3221 enforceModifyPermission();
3222
3223 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3224 Bundle bundle = new Bundle();
3225 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3226 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003227 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003228
3229 /**
3230 * {@hide}
3231 * Returns the service state information on specified subscription.
3232 */
3233 @Override
3234 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3235
3236 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3237 return null;
3238 }
3239
3240 final Phone phone = getPhone(subId);
3241 if (phone == null) {
3242 return null;
3243 }
3244
3245 return phone.getServiceState();
3246 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003247
3248 /**
3249 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3250 *
3251 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3252 * voicemail ringtone.
3253 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3254 * PhoneAccount.
3255 */
3256 @Override
3257 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
3258 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3259 if (phone == null) {
3260 return null;
3261 }
3262
3263 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
3264 }
3265
3266 /**
3267 * Returns whether vibration is set for voicemail notification in Phone settings.
3268 *
3269 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3270 * voicemail vibration setting.
3271 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3272 */
3273 @Override
3274 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
3275 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3276 if (phone == null) {
3277 return false;
3278 }
3279
3280 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone);
3281 }
3282
Youhan Wange64578a2016-05-02 15:32:42 -07003283 /**
3284 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3285 *
3286 * @throws SecurityException if the caller does not have the required permission
3287 */
3288 private void enforceReadPrivilegedPermission() {
3289 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3290 null);
3291 }
3292
3293 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003294 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3295 * permission.
3296 *
3297 * @throws SecurityException if the caller does not have the required permission
3298 */
3299 private void enforceSendSmsPermission() {
3300 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3301 }
3302
3303 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003304 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003305 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003306 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003307 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003308 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
3309 String vvmPackage = RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId)
3310 .getPackageName();
3311 if (!callingPackage.equals(vvmPackage)) {
3312 throw new SecurityException("Caller not current active visual voicemail package[" +
3313 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003314 }
3315 }
3316
3317 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003318 * Return the application ID for the app type.
3319 *
3320 * @param subId the subscription ID that this request applies to.
3321 * @param appType the uicc app type.
3322 * @return Application ID for specificied app type, or null if no uicc.
3323 */
3324 @Override
3325 public String getAidForAppType(int subId, int appType) {
3326 enforceReadPrivilegedPermission();
3327 Phone phone = getPhone(subId);
3328 if (phone == null) {
3329 return null;
3330 }
3331 String aid = null;
3332 try {
3333 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3334 .getApplicationByType(appType).getAid();
3335 } catch (Exception e) {
3336 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3337 }
3338 return aid;
3339 }
3340
Youhan Wang4001d252016-05-11 10:29:41 -07003341 /**
3342 * Return the Electronic Serial Number.
3343 *
3344 * @param subId the subscription ID that this request applies to.
3345 * @return ESN or null if error.
3346 */
3347 @Override
3348 public String getEsn(int subId) {
3349 enforceReadPrivilegedPermission();
3350 Phone phone = getPhone(subId);
3351 if (phone == null) {
3352 return null;
3353 }
3354 String esn = null;
3355 try {
3356 esn = phone.getEsn();
3357 } catch (Exception e) {
3358 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3359 }
3360 return esn;
3361 }
3362
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003363 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003364 * Return the Preferred Roaming List Version.
3365 *
3366 * @param subId the subscription ID that this request applies to.
3367 * @return PRLVersion or null if error.
3368 */
3369 @Override
3370 public String getCdmaPrlVersion(int subId) {
3371 enforceReadPrivilegedPermission();
3372 Phone phone = getPhone(subId);
3373 if (phone == null) {
3374 return null;
3375 }
3376 String cdmaPrlVersion = null;
3377 try {
3378 cdmaPrlVersion = phone.getCdmaPrlVersion();
3379 } catch (Exception e) {
3380 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3381 }
3382 return cdmaPrlVersion;
3383 }
3384
3385 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003386 * Get snapshot of Telephony histograms
3387 * @return List of Telephony histograms
3388 * @hide
3389 */
3390 @Override
3391 public List<TelephonyHistogram> getTelephonyHistograms() {
3392 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3393 return RIL.getTelephonyRILTimingHistograms();
3394 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003395
3396 /**
3397 * {@hide}
3398 * Set the allowed carrier list for slotId
3399 * Require system privileges. In the future we may add this to carrier APIs.
3400 *
3401 * @return The number of carriers set successfully, should match length of carriers
3402 */
3403 @Override
3404 public int setAllowedCarriers(int slotId, List<CarrierIdentifier> carriers) {
3405 enforceModifyPermission();
3406 int subId = SubscriptionManager.getSubId(slotId)[0];
3407 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3408 return retVal[0];
3409 }
3410
3411 /**
3412 * {@hide}
3413 * Get the allowed carrier list for slotId.
3414 * Require system privileges. In the future we may add this to carrier APIs.
3415 *
3416 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3417 * means all carriers are allowed.
3418 */
3419 @Override
3420 public List<CarrierIdentifier> getAllowedCarriers(int slotId) {
3421 enforceReadPrivilegedPermission();
3422 int subId = SubscriptionManager.getSubId(slotId)[0];
3423 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3424 }
3425
fionaxu59545b42016-05-25 15:53:37 -07003426 /**
3427 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3428 * @param subId the subscription ID that this action applies to.
3429 * @param enabled control enable or disable metered apns.
3430 * {@hide}
3431 */
3432 @Override
3433 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3434 enforceModifyPermission();
3435 final Phone phone = getPhone(subId);
3436 if (phone == null) {
3437 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3438 return;
3439 }
3440 try {
3441 phone.carrierActionSetMeteredApnsEnabled(enabled);
3442 } catch (Exception e) {
3443 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3444 }
3445 }
3446
3447 /**
3448 * Action set from carrier signalling broadcast receivers to enable/disable radio
3449 * @param subId the subscription ID that this action applies to.
3450 * @param enabled control enable or disable radio.
3451 * {@hide}
3452 */
3453 @Override
3454 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3455 enforceModifyPermission();
3456 final Phone phone = getPhone(subId);
3457 if (phone == null) {
3458 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3459 return;
3460 }
3461 try {
3462 phone.carrierActionSetRadioEnabled(enabled);
3463 } catch (Exception e) {
3464 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3465 }
3466 }
3467
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003468 /**
3469 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3470 * bug report is being generated.
3471 */
3472 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003473 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003474 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3475 != PackageManager.PERMISSION_GRANTED) {
3476 writer.println("Permission Denial: can't dump Phone from pid="
3477 + Binder.getCallingPid()
3478 + ", uid=" + Binder.getCallingUid()
3479 + "without permission "
3480 + android.Manifest.permission.DUMP);
3481 return;
3482 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003483 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003484 }
Jack Yueb89b242016-06-22 13:27:47 -07003485
3486 /**
3487 * Get aggregated video call data usage from all subscriptions since boot.
3488 * @return total data usage in bytes
3489 * {@hide}
3490 */
3491 @Override
3492 public long getVtDataUsage() {
3493 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3494 null);
3495
3496 // NetworkStatsService keeps tracking the active network interface and identity. It will
3497 // record the delta with the corresponding network identity. What we need to do here is
3498 // returning total video call data usage from all subscriptions since boot.
3499
3500 // TODO: Add sub id support in the future. We'll need it when we support DSDA and
3501 // simultaneous VT calls.
3502 final Phone[] phones = PhoneFactory.getPhones();
3503 long total = 0;
3504 for (Phone phone : phones) {
3505 total += phone.getVtDataUsage();
3506 }
3507 return total;
3508 }
Jack Yu75ab2952016-07-08 14:29:33 -07003509
3510 /**
3511 * Policy control of data connection. Usually used when data limit is passed.
3512 * @param enabled True if enabling the data, otherwise disabling.
3513 * @param subId Subscription index
3514 * {@hide}
3515 */
3516 @Override
3517 public void setPolicyDataEnabled(boolean enabled, int subId) {
3518 enforceModifyPermission();
3519 Phone phone = getPhone(subId);
3520 if (phone != null) {
3521 phone.setPolicyDataEnabled(enabled);
3522 }
3523 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003524
3525 /**
3526 * Get Client request stats
3527 * @return List of Client Request Stats
3528 * @hide
3529 */
3530 @Override
3531 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3532 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3533 return null;
3534 }
3535
3536 Phone phone = getPhone(subId);
3537 if (phone != null) {
3538 return phone.getClientRequestStats();
3539 }
3540
3541 return null;
3542 }
3543
3544 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3545 if (workSource != null) {
3546 return workSource;
3547 }
3548
3549 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3550 workSource = new WorkSource(uid, packageName);
3551 return workSource;
3552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003553}