blob: d03760603c95710e3bb7298acb765b32da14a8e8 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Ta-wei Yendca928f2017-01-10 16:17:08 -080022import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.app.ActivityManager;
24import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
37import android.os.Looper;
38import android.os.Message;
39import android.os.Process;
Adam Lesinski903a54c2016-04-11 14:49:52 -070040import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.ServiceManager;
42import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070043import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070044import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070045import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080046import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070047import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080048import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080049import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070050import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070051import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070053import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070054import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070055import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080056import android.telephony.NeighboringCellInfo;
Wink Saville5d475dd2014-10-17 15:00:58 -070057import android.telephony.RadioAccessFamily;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.telephony.ServiceState;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080059import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080060import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080061import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070062import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070063import android.telephony.TelephonyManager;
64import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080066import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080068import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080069import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080070
Andrew Lee312e8172014-10-23 17:01:36 -070071import com.android.ims.ImsManager;
Shishir Agrawal566b7612013-10-28 14:41:00 -070072import com.android.internal.telephony.CallManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070073import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070074import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080077import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010078import com.android.internal.telephony.MccTable;
Shishir Agrawal302c8692015-06-19 13:49:39 -070079import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import com.android.internal.telephony.Phone;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070082import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070083import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070084import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070085import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080086import com.android.internal.telephony.SubscriptionController;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.uicc.IccIoResult;
88import com.android.internal.telephony.uicc.IccUtils;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -070089import com.android.internal.telephony.uicc.UiccCard;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.uicc.UiccController;
Jake Hambye994d462014-02-03 13:10:13 -080091import com.android.internal.util.HexDump;
Ta-wei Yenb0f695b2016-08-08 17:33:11 -070092import com.android.phone.settings.VisualVoicemailSettingsUtil;
Nancy Chen31f9ba12016-01-06 11:42:12 -080093import com.android.phone.settings.VoicemailNotificationSettingsUtil;
Ta-wei Yen527a9c02017-01-06 15:29:25 -080094import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080095
Ta-wei Yenc236d6b2016-06-21 13:33:12 -070096import java.io.FileDescriptor;
97import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080098import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800101import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100102import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104
105/**
106 * Implementation of the ITelephony interface.
107 */
Santos Cordon117fee72014-05-16 17:56:12 -0700108public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109 private static final String LOG_TAG = "PhoneInterfaceManager";
110 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
111 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800112 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113
114 // Message codes used with mMainThreadHandler
115 private static final int CMD_HANDLE_PIN_MMI = 1;
116 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
117 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
118 private static final int CMD_ANSWER_RINGING_CALL = 4;
119 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700120 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
121 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122 private static final int CMD_OPEN_CHANNEL = 9;
123 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
124 private static final int CMD_CLOSE_CHANNEL = 11;
125 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800126 private static final int CMD_NV_READ_ITEM = 13;
127 private static final int EVENT_NV_READ_ITEM_DONE = 14;
128 private static final int CMD_NV_WRITE_ITEM = 15;
129 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
130 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
131 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
132 private static final int CMD_NV_RESET_CONFIG = 19;
133 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800134 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
135 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
136 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
137 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800138 private static final int CMD_SEND_ENVELOPE = 25;
139 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700140 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
141 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
142 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
143 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
144 private static final int CMD_EXCHANGE_SIM_IO = 31;
145 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800146 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
147 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700148 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
149 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700150 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
151 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700152 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
153 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
154 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
155 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700156 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
157 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
158 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
159 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700160 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161
162 /** The singleton instance. */
163 private static PhoneInterfaceManager sInstance;
164
Wink Saville3ab207e2014-11-20 13:07:20 -0800165 private PhoneGlobals mApp;
166 private Phone mPhone;
167 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700168 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800169 private AppOpsManager mAppOps;
170 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800171 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800172 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173
Derek Tan97ebb422014-09-05 16:55:38 -0700174 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
175 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800176 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700177
178 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179 * A request object to use for transmitting data to an ICC.
180 */
181 private static final class IccAPDUArgument {
182 public int channel, cla, command, p1, p2, p3;
183 public String data;
184
185 public IccAPDUArgument(int channel, int cla, int command,
186 int p1, int p2, int p3, String data) {
187 this.channel = channel;
188 this.cla = cla;
189 this.command = command;
190 this.p1 = p1;
191 this.p2 = p2;
192 this.p3 = p3;
193 this.data = data;
194 }
195 }
196
197 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700198 * A request object to use for transmitting data to an ICC.
199 */
200 private static final class ManualNetworkSelectionArgument {
201 public OperatorInfo operatorInfo;
202 public boolean persistSelection;
203
204 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
205 this.operatorInfo = operatorInfo;
206 this.persistSelection = persistSelection;
207 }
208 }
209
210 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
212 * request after sending. The main thread will notify the request when it is complete.
213 */
214 private static final class MainThreadRequest {
215 /** The argument to use for the request */
216 public Object argument;
217 /** The result of the request that is run on the main thread */
218 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800219 // The subscriber id that this request applies to. Defaults to
220 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
221 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222
223 public MainThreadRequest(Object argument) {
224 this.argument = argument;
225 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800226
227 public MainThreadRequest(Object argument, Integer subId) {
228 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800229 if (subId != null) {
230 this.subId = subId;
231 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 }
234
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800235 private static final class IncomingThirdPartyCallArgs {
236 public final ComponentName component;
237 public final String callId;
238 public final String callerDisplayName;
239
240 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
241 String callerDisplayName) {
242 this.component = component;
243 this.callId = callId;
244 this.callerDisplayName = callerDisplayName;
245 }
246 }
247
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 /**
249 * A handler that processes messages on the main thread in the phone process. Since many
250 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
251 * inbound binder threads to the main thread in the phone process. The Binder thread
252 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
253 * on, which will be notified when the operation completes and will contain the result of the
254 * request.
255 *
256 * <p>If a MainThreadRequest object is provided in the msg.obj field,
257 * note that request.result must be set to something non-null for the calling thread to
258 * unblock.
259 */
260 private final class MainThreadHandler extends Handler {
261 @Override
262 public void handleMessage(Message msg) {
263 MainThreadRequest request;
264 Message onCompleted;
265 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800266 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700267 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
269 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700270 case CMD_HANDLE_USSD_REQUEST: {
271 request = (MainThreadRequest) msg.obj;
272 final Phone phone = getPhoneFromRequest(request);
273 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
274 String ussdRequest = ussdObject.first;
275 ResultReceiver wrappedCallback = ussdObject.second;
276 request.result = phone != null ?
277 phone.handleUssdRequest(ussdRequest, wrappedCallback)
278 :false;
279 // Wake up the requesting thread
280 synchronized (request) {
281 request.notifyAll();
282 }
283 break;
284 }
285
Yorke Lee716f67e2015-06-17 15:39:16 -0700286 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700288 final Phone phone = getPhoneFromRequest(request);
289 request.result = phone != null ?
290 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
291 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 // Wake up the requesting thread
293 synchronized (request) {
294 request.notifyAll();
295 }
296 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298
299 case CMD_HANDLE_NEIGHBORING_CELL:
300 request = (MainThreadRequest) msg.obj;
301 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
302 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700303 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304 break;
305
306 case EVENT_NEIGHBORING_CELL_DONE:
307 ar = (AsyncResult) msg.obj;
308 request = (MainThreadRequest) ar.userObj;
309 if (ar.exception == null && ar.result != null) {
310 request.result = ar.result;
311 } else {
312 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800313 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314 }
315 // Wake up the requesting thread
316 synchronized (request) {
317 request.notifyAll();
318 }
319 break;
320
321 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700322 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800323 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700324 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325 break;
326
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327 case CMD_END_CALL:
328 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800329 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700330 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700331 Phone phone = getPhone(end_subId);
332 if (phone == null) {
333 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
334 break;
335 }
336 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
338 // CDMA: If the user presses the Power button we treat it as
339 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700340 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
342 // GSM: End the call as per the Phone state
343 hungUp = PhoneUtils.hangup(mCM);
344 } else {
345 throw new IllegalStateException("Unexpected phone type: " + phoneType);
346 }
347 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
348 request.result = hungUp;
349 // Wake up the requesting thread
350 synchronized (request) {
351 request.notifyAll();
352 }
353 break;
354
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700355 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700356 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700357 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800358 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700359 if (uiccCard == null) {
360 loge("iccTransmitApduLogicalChannel: No UICC");
361 request.result = new IccIoResult(0x6F, 0, (byte[])null);
362 synchronized (request) {
363 request.notifyAll();
364 }
365 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700366 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
367 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700368 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700369 iccArgument.channel, iccArgument.cla, iccArgument.command,
370 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700371 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700372 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700373 break;
374
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700375 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700376 ar = (AsyncResult) msg.obj;
377 request = (MainThreadRequest) ar.userObj;
378 if (ar.exception == null && ar.result != null) {
379 request.result = ar.result;
380 } else {
381 request.result = new IccIoResult(0x6F, 0, (byte[])null);
382 if (ar.result == null) {
383 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800384 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700385 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800386 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700387 } else {
388 loge("iccTransmitApduLogicalChannel: Unknown exception");
389 }
390 }
391 synchronized (request) {
392 request.notifyAll();
393 }
394 break;
395
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700396 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
397 request = (MainThreadRequest) msg.obj;
398 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800399 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 if (uiccCard == null) {
401 loge("iccTransmitApduBasicChannel: No UICC");
402 request.result = new IccIoResult(0x6F, 0, (byte[])null);
403 synchronized (request) {
404 request.notifyAll();
405 }
406 } else {
407 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
408 request);
409 uiccCard.iccTransmitApduBasicChannel(
410 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
411 iccArgument.p3, iccArgument.data, onCompleted);
412 }
413 break;
414
415 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
416 ar = (AsyncResult) msg.obj;
417 request = (MainThreadRequest) ar.userObj;
418 if (ar.exception == null && ar.result != null) {
419 request.result = ar.result;
420 } else {
421 request.result = new IccIoResult(0x6F, 0, (byte[])null);
422 if (ar.result == null) {
423 loge("iccTransmitApduBasicChannel: Empty response");
424 } else if (ar.exception instanceof CommandException) {
425 loge("iccTransmitApduBasicChannel: CommandException: " +
426 ar.exception);
427 } else {
428 loge("iccTransmitApduBasicChannel: Unknown exception");
429 }
430 }
431 synchronized (request) {
432 request.notifyAll();
433 }
434 break;
435
436 case CMD_EXCHANGE_SIM_IO:
437 request = (MainThreadRequest) msg.obj;
438 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800439 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 if (uiccCard == null) {
441 loge("iccExchangeSimIO: No UICC");
442 request.result = new IccIoResult(0x6F, 0, (byte[])null);
443 synchronized (request) {
444 request.notifyAll();
445 }
446 } else {
447 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
448 request);
449 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
450 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
451 iccArgument.data, onCompleted);
452 }
453 break;
454
455 case EVENT_EXCHANGE_SIM_IO_DONE:
456 ar = (AsyncResult) msg.obj;
457 request = (MainThreadRequest) ar.userObj;
458 if (ar.exception == null && ar.result != null) {
459 request.result = ar.result;
460 } else {
461 request.result = new IccIoResult(0x6f, 0, (byte[])null);
462 }
463 synchronized (request) {
464 request.notifyAll();
465 }
466 break;
467
Derek Tan4d5e5c12014-02-04 11:54:58 -0800468 case CMD_SEND_ENVELOPE:
469 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800470 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700471 if (uiccCard == null) {
472 loge("sendEnvelopeWithStatus: No UICC");
473 request.result = new IccIoResult(0x6F, 0, (byte[])null);
474 synchronized (request) {
475 request.notifyAll();
476 }
477 } else {
478 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
479 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
480 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800481 break;
482
483 case EVENT_SEND_ENVELOPE_DONE:
484 ar = (AsyncResult) msg.obj;
485 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700486 if (ar.exception == null && ar.result != null) {
487 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800488 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
490 if (ar.result == null) {
491 loge("sendEnvelopeWithStatus: Empty response");
492 } else if (ar.exception instanceof CommandException) {
493 loge("sendEnvelopeWithStatus: CommandException: " +
494 ar.exception);
495 } else {
496 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
497 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800498 }
499 synchronized (request) {
500 request.notifyAll();
501 }
502 break;
503
Shishir Agrawal566b7612013-10-28 14:41:00 -0700504 case CMD_OPEN_CHANNEL:
505 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700507 if (uiccCard == null) {
508 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800509 request.result = new IccOpenLogicalChannelResponse(-1,
510 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700511 synchronized (request) {
512 request.notifyAll();
513 }
514 } else {
515 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
516 uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted);
517 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700518 break;
519
520 case EVENT_OPEN_CHANNEL_DONE:
521 ar = (AsyncResult) msg.obj;
522 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 int[] result = (int[]) ar.result;
526 int channelId = result[0];
527 byte[] selectResponse = null;
528 if (result.length > 1) {
529 selectResponse = new byte[result.length - 1];
530 for (int i = 1; i < result.length; ++i) {
531 selectResponse[i - 1] = (byte) result[i];
532 }
533 }
534 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700535 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700536 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 if (ar.result == null) {
538 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 if (ar.exception != null) {
541 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
542 }
543
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700544 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700545 if (ar.exception instanceof CommandException) {
546 CommandException.Error error =
547 ((CommandException) (ar.exception)).getCommandError();
548 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700549 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700550 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700551 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 }
553 }
554 openChannelResp = new IccOpenLogicalChannelResponse(
555 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700557 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 synchronized (request) {
559 request.notifyAll();
560 }
561 break;
562
563 case CMD_CLOSE_CHANNEL:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("iccCloseLogicalChannel: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
569 synchronized (request) {
570 request.notifyAll();
571 }
572 } else {
573 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
574 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
575 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 break;
577
578 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800579 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
580 break;
581
582 case CMD_NV_READ_ITEM:
583 request = (MainThreadRequest) msg.obj;
584 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
585 mPhone.nvReadItem((Integer) request.argument, onCompleted);
586 break;
587
588 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 ar = (AsyncResult) msg.obj;
590 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800591 if (ar.exception == null && ar.result != null) {
592 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800594 request.result = "";
595 if (ar.result == null) {
596 loge("nvReadItem: Empty response");
597 } else if (ar.exception instanceof CommandException) {
598 loge("nvReadItem: CommandException: " +
599 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800601 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 }
603 }
604 synchronized (request) {
605 request.notifyAll();
606 }
607 break;
608
Jake Hambye994d462014-02-03 13:10:13 -0800609 case CMD_NV_WRITE_ITEM:
610 request = (MainThreadRequest) msg.obj;
611 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
612 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
613 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
614 break;
615
616 case EVENT_NV_WRITE_ITEM_DONE:
617 handleNullReturnEvent(msg, "nvWriteItem");
618 break;
619
620 case CMD_NV_WRITE_CDMA_PRL:
621 request = (MainThreadRequest) msg.obj;
622 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
623 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
624 break;
625
626 case EVENT_NV_WRITE_CDMA_PRL_DONE:
627 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
628 break;
629
630 case CMD_NV_RESET_CONFIG:
631 request = (MainThreadRequest) msg.obj;
632 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
633 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
634 break;
635
636 case EVENT_NV_RESET_CONFIG_DONE:
637 handleNullReturnEvent(msg, "nvResetConfig");
638 break;
639
Jake Hamby7c27be32014-03-03 13:25:59 -0800640 case CMD_GET_PREFERRED_NETWORK_TYPE:
641 request = (MainThreadRequest) msg.obj;
642 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700643 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800644 break;
645
646 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
647 ar = (AsyncResult) msg.obj;
648 request = (MainThreadRequest) ar.userObj;
649 if (ar.exception == null && ar.result != null) {
650 request.result = ar.result; // Integer
651 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800652 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800653 if (ar.result == null) {
654 loge("getPreferredNetworkType: Empty response");
655 } else if (ar.exception instanceof CommandException) {
656 loge("getPreferredNetworkType: CommandException: " +
657 ar.exception);
658 } else {
659 loge("getPreferredNetworkType: Unknown exception");
660 }
661 }
662 synchronized (request) {
663 request.notifyAll();
664 }
665 break;
666
667 case CMD_SET_PREFERRED_NETWORK_TYPE:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
670 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700671 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800672 break;
673
674 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
675 handleNullReturnEvent(msg, "setPreferredNetworkType");
676 break;
677
Steven Liu4bf01bc2014-07-17 11:05:29 -0500678 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
679 request = (MainThreadRequest)msg.obj;
680 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
681 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
682 break;
683
684 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
685 ar = (AsyncResult)msg.obj;
686 request = (MainThreadRequest)ar.userObj;
687 request.result = ar;
688 synchronized (request) {
689 request.notifyAll();
690 }
691 break;
692
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800693 case CMD_SET_VOICEMAIL_NUMBER:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
696 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800697 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
698 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800699 break;
700
701 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
702 handleNullReturnEvent(msg, "setVoicemailNumber");
703 break;
704
Stuart Scott54788802015-03-30 13:18:01 -0700705 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
706 request = (MainThreadRequest) msg.obj;
707 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
708 request);
709 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
710 break;
711
712 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
713 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
714 break;
715
Shishir Agrawal302c8692015-06-19 13:49:39 -0700716 case CMD_PERFORM_NETWORK_SCAN:
717 request = (MainThreadRequest) msg.obj;
718 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
719 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
720 break;
721
722 case EVENT_PERFORM_NETWORK_SCAN_DONE:
723 ar = (AsyncResult) msg.obj;
724 request = (MainThreadRequest) ar.userObj;
725 CellNetworkScanResult cellScanResult;
726 if (ar.exception == null && ar.result != null) {
727 cellScanResult = new CellNetworkScanResult(
728 CellNetworkScanResult.STATUS_SUCCESS,
729 (List<OperatorInfo>) ar.result);
730 } else {
731 if (ar.result == null) {
732 loge("getCellNetworkScanResults: Empty response");
733 }
734 if (ar.exception != null) {
735 loge("getCellNetworkScanResults: Exception: " + ar.exception);
736 }
737 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
738 if (ar.exception instanceof CommandException) {
739 CommandException.Error error =
740 ((CommandException) (ar.exception)).getCommandError();
741 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
742 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
743 } else if (error == CommandException.Error.GENERIC_FAILURE) {
744 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
745 }
746 }
747 cellScanResult = new CellNetworkScanResult(errorCode, null);
748 }
749 request.result = cellScanResult;
750 synchronized (request) {
751 request.notifyAll();
752 }
753 break;
754
755 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
756 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700757 ManualNetworkSelectionArgument selArg =
758 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700759 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
760 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700761 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
762 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700763 break;
764
765 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
766 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
767 break;
768
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700769 case CMD_GET_MODEM_ACTIVITY_INFO:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700772 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700773 break;
774
775 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
776 ar = (AsyncResult) msg.obj;
777 request = (MainThreadRequest) ar.userObj;
778 if (ar.exception == null && ar.result != null) {
779 request.result = ar.result;
780 } else {
781 if (ar.result == null) {
782 loge("queryModemActivityInfo: Empty response");
783 } else if (ar.exception instanceof CommandException) {
784 loge("queryModemActivityInfo: CommandException: " +
785 ar.exception);
786 } else {
787 loge("queryModemActivityInfo: Unknown exception");
788 }
789 }
Amit Mahajand4766222016-01-28 15:28:28 -0800790 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
791 if (request.result == null) {
792 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
793 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700794 synchronized (request) {
795 request.notifyAll();
796 }
797 break;
798
Meng Wang1a7c35a2016-05-05 20:56:15 -0700799 case CMD_SET_ALLOWED_CARRIERS:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
802 mPhone.setAllowedCarriers(
803 (List<CarrierIdentifier>) request.argument,
804 onCompleted);
805 break;
806
807 case EVENT_SET_ALLOWED_CARRIERS_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
810 if (ar.exception == null && ar.result != null) {
811 request.result = ar.result;
812 } else {
813 if (ar.result == null) {
814 loge("setAllowedCarriers: Empty response");
815 } else if (ar.exception instanceof CommandException) {
816 loge("setAllowedCarriers: CommandException: " +
817 ar.exception);
818 } else {
819 loge("setAllowedCarriers: Unknown exception");
820 }
821 }
822 // Result cannot be null. Return -1 on error.
823 if (request.result == null) {
824 request.result = new int[]{-1};
825 }
826 synchronized (request) {
827 request.notifyAll();
828 }
829 break;
830
831 case CMD_GET_ALLOWED_CARRIERS:
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
834 mPhone.getAllowedCarriers(onCompleted);
835 break;
836
837 case EVENT_GET_ALLOWED_CARRIERS_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result;
842 } else {
843 if (ar.result == null) {
844 loge("getAllowedCarriers: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("getAllowedCarriers: CommandException: " +
847 ar.exception);
848 } else {
849 loge("getAllowedCarriers: Unknown exception");
850 }
851 }
852 // Result cannot be null. Return empty list of CarrierIdentifier.
853 if (request.result == null) {
854 request.result = new ArrayList<CarrierIdentifier>(0);
855 }
856 synchronized (request) {
857 request.notifyAll();
858 }
859 break;
860
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700861 default:
862 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
863 break;
864 }
865 }
Jake Hambye994d462014-02-03 13:10:13 -0800866
867 private void handleNullReturnEvent(Message msg, String command) {
868 AsyncResult ar = (AsyncResult) msg.obj;
869 MainThreadRequest request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null) {
871 request.result = true;
872 } else {
873 request.result = false;
874 if (ar.exception instanceof CommandException) {
875 loge(command + ": CommandException: " + ar.exception);
876 } else {
877 loge(command + ": Unknown exception");
878 }
879 }
880 synchronized (request) {
881 request.notifyAll();
882 }
883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700884 }
885
886 /**
887 * Posts the specified command to be executed on the main thread,
888 * waits for the request to complete, and returns the result.
889 * @see #sendRequestAsync
890 */
891 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800892 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700893 }
894
895 /**
896 * Posts the specified command to be executed on the main thread,
897 * waits for the request to complete, and returns the result.
898 * @see #sendRequestAsync
899 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800900 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700901 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
902 throw new RuntimeException("This method will deadlock if called from the main thread.");
903 }
904
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800905 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700906 Message msg = mMainThreadHandler.obtainMessage(command, request);
907 msg.sendToTarget();
908
909 // Wait for the request to complete
910 synchronized (request) {
911 while (request.result == null) {
912 try {
913 request.wait();
914 } catch (InterruptedException e) {
915 // Do nothing, go back and wait until the request is complete
916 }
917 }
918 }
919 return request.result;
920 }
921
922 /**
923 * Asynchronous ("fire and forget") version of sendRequest():
924 * Posts the specified command to be executed on the main thread, and
925 * returns immediately.
926 * @see #sendRequest
927 */
928 private void sendRequestAsync(int command) {
929 mMainThreadHandler.sendEmptyMessage(command);
930 }
931
932 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -0700933 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
934 * @see {@link #sendRequest(int,Object)}
935 */
936 private void sendRequestAsync(int command, Object argument) {
937 MainThreadRequest request = new MainThreadRequest(argument);
938 Message msg = mMainThreadHandler.obtainMessage(command, request);
939 msg.sendToTarget();
940 }
941
942 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700943 * Initialize the singleton PhoneInterfaceManager instance.
944 * This is only done once, at startup, from PhoneApp.onCreate().
945 */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700946 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700947 synchronized (PhoneInterfaceManager.class) {
948 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -0700949 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700950 } else {
951 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
952 }
953 return sInstance;
954 }
955 }
956
957 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700958 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700959 mApp = app;
960 mPhone = phone;
961 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700962 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700963 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
964 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -0700965 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -0700966 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800967 mSubscriptionController = SubscriptionController.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -0800968
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700969 publish();
970 }
971
972 private void publish() {
973 if (DBG) log("publish: " + this);
974
975 ServiceManager.addService("phone", this);
976 }
977
Stuart Scott584921c2015-01-15 17:10:34 -0800978 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800979 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
980 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -0800981 }
982
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800983 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
984 Phone phone = getPhoneFromRequest(request);
985 return phone == null ? null :
986 UiccController.getInstance().getUiccCard(phone.getPhoneId());
987 }
988
Wink Saville36469e72014-06-11 15:17:00 -0700989 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -0700990 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800991 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -0700992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700993 //
994 // Implementation of the ITelephony interface.
995 //
996
997 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700998 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -0700999 }
1000
Wink Savilleb564aae2014-10-23 10:18:09 -07001001 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001002 if (DBG) log("dial: " + number);
1003 // No permission check needed here: This is just a wrapper around the
1004 // ACTION_DIAL intent, which is available to any app since it puts up
1005 // the UI before it does anything.
1006
1007 String url = createTelUrl(number);
1008 if (url == null) {
1009 return;
1010 }
1011
1012 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001013 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001014 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1015 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1016 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1017 mApp.startActivity(intent);
1018 }
1019 }
1020
1021 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001022 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001023 }
1024
Wink Savilleb564aae2014-10-23 10:18:09 -07001025 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 if (DBG) log("call: " + number);
1027
1028 // This is just a wrapper around the ACTION_CALL intent, but we still
1029 // need to do a permission check since we're calling startActivity()
1030 // from the context of the phone app.
1031 enforceCallPermission();
1032
1033 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1034 != AppOpsManager.MODE_ALLOWED) {
1035 return;
1036 }
1037
1038 String url = createTelUrl(number);
1039 if (url == null) {
1040 return;
1041 }
1042
Wink Saville08874612014-08-31 19:19:58 -07001043 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001044 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001045 if (slist != null) {
1046 for (SubscriptionInfo subInfoRecord : slist) {
1047 if (subInfoRecord.getSubscriptionId() == subId) {
1048 isValid = true;
1049 break;
1050 }
Wink Saville08874612014-08-31 19:19:58 -07001051 }
1052 }
1053 if (isValid == false) {
1054 return;
1055 }
1056
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001057 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001058 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001059 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1060 mApp.startActivity(intent);
1061 }
1062
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001063 /**
1064 * End a call based on call state
1065 * @return true is a call was ended
1066 */
1067 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001068 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001069 }
1070
1071 /**
1072 * End a call based on the call state of the subId
1073 * @return true is a call was ended
1074 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001075 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001076 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001077 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 }
1079
1080 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001081 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001082 }
1083
Wink Savilleb564aae2014-10-23 10:18:09 -07001084 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 if (DBG) log("answerRingingCall...");
1086 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1087 // but that can probably wait till the big TelephonyManager API overhaul.
1088 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1089 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001090 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 }
1092
1093 /**
1094 * Make the actual telephony calls to implement answerRingingCall().
1095 * This should only be called from the main thread of the Phone app.
1096 * @see #answerRingingCall
1097 *
1098 * TODO: it would be nice to return true if we answered the call, or
1099 * false if there wasn't actually a ringing incoming call, or some
1100 * other error occurred. (In other words, pass back the return value
1101 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1102 * But that would require calling this method via sendRequest() rather
1103 * than sendRequestAsync(), and right now we don't actually *need* that
1104 * return value, so let's just return void for now.
1105 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001106 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001107 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001108 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001109 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1110 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001111 if (hasActiveCall && hasHoldingCall) {
1112 // Both lines are in use!
1113 // TODO: provide a flag to let the caller specify what
1114 // policy to use if both lines are in use. (The current
1115 // behavior is hardwired to "answer incoming, end ongoing",
1116 // which is how the CALL button is specced to behave.)
1117 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1118 return;
1119 } else {
1120 // answerCall() will automatically hold the current active
1121 // call, if there is one.
1122 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1123 return;
1124 }
1125 } else {
1126 // No call was ringing.
1127 return;
1128 }
1129 }
1130
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001131 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001132 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001133 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001134 public void silenceRinger() {
1135 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 }
1137
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001138 @Override
1139 public boolean isOffhook(String callingPackage) {
1140 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001141 }
1142
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001143 @Override
1144 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1145 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1146 return false;
1147 }
1148
Sanket Padawe356d7632015-06-22 14:03:32 -07001149 final Phone phone = getPhone(subId);
1150 if (phone != null) {
1151 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1152 } else {
1153 return false;
1154 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001155 }
1156
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001157 @Override
1158 public boolean isRinging(String callingPackage) {
1159 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001160 }
1161
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001162 @Override
1163 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1164 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1165 return false;
1166 }
1167
Sanket Padawe356d7632015-06-22 14:03:32 -07001168 final Phone phone = getPhone(subId);
1169 if (phone != null) {
1170 return (phone.getState() == PhoneConstants.State.RINGING);
1171 } else {
1172 return false;
1173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 }
1175
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001176 @Override
1177 public boolean isIdle(String callingPackage) {
1178 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001179 }
1180
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001181 @Override
1182 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1183 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1184 return false;
1185 }
1186
Sanket Padawe356d7632015-06-22 14:03:32 -07001187 final Phone phone = getPhone(subId);
1188 if (phone != null) {
1189 return (phone.getState() == PhoneConstants.State.IDLE);
1190 } else {
1191 return false;
1192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001193 }
1194
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001196 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001197 }
1198
Wink Savilleb564aae2014-10-23 10:18:09 -07001199 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001200 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001201 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1202 }
1203
1204 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001205 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001206 }
1207
Wink Savilleb564aae2014-10-23 10:18:09 -07001208 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001209 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001210 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1211 }
1212
1213 /** {@hide} */
1214 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001215 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001216 }
1217
Wink Savilleb564aae2014-10-23 10:18:09 -07001218 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001220 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 checkSimPin.start();
1222 return checkSimPin.unlockSim(null, pin);
1223 }
1224
Wink Saville9de0f752013-10-22 19:04:03 -07001225 /** {@hide} */
1226 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001227 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001228 }
1229
Wink Savilleb564aae2014-10-23 10:18:09 -07001230 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001232 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 checkSimPuk.start();
1234 return checkSimPuk.unlockSim(puk, pin);
1235 }
1236
1237 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001238 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001239 * a synchronous one.
1240 */
1241 private static class UnlockSim extends Thread {
1242
1243 private final IccCard mSimCard;
1244
1245 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001246 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1247 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248
1249 // For replies from SimCard interface
1250 private Handler mHandler;
1251
1252 // For async handler to identify request type
1253 private static final int SUPPLY_PIN_COMPLETE = 100;
1254
1255 public UnlockSim(IccCard simCard) {
1256 mSimCard = simCard;
1257 }
1258
1259 @Override
1260 public void run() {
1261 Looper.prepare();
1262 synchronized (UnlockSim.this) {
1263 mHandler = new Handler() {
1264 @Override
1265 public void handleMessage(Message msg) {
1266 AsyncResult ar = (AsyncResult) msg.obj;
1267 switch (msg.what) {
1268 case SUPPLY_PIN_COMPLETE:
1269 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1270 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001271 mRetryCount = msg.arg1;
1272 if (ar.exception != null) {
1273 if (ar.exception instanceof CommandException &&
1274 ((CommandException)(ar.exception)).getCommandError()
1275 == CommandException.Error.PASSWORD_INCORRECT) {
1276 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1277 } else {
1278 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1279 }
1280 } else {
1281 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 mDone = true;
1284 UnlockSim.this.notifyAll();
1285 }
1286 break;
1287 }
1288 }
1289 };
1290 UnlockSim.this.notifyAll();
1291 }
1292 Looper.loop();
1293 }
1294
1295 /*
1296 * Use PIN or PUK to unlock SIM card
1297 *
1298 * If PUK is null, unlock SIM card with PIN
1299 *
1300 * If PUK is not null, unlock SIM card with PUK and set PIN code
1301 */
Wink Saville9de0f752013-10-22 19:04:03 -07001302 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303
1304 while (mHandler == null) {
1305 try {
1306 wait();
1307 } catch (InterruptedException e) {
1308 Thread.currentThread().interrupt();
1309 }
1310 }
1311 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1312
1313 if (puk == null) {
1314 mSimCard.supplyPin(pin, callback);
1315 } else {
1316 mSimCard.supplyPuk(puk, pin, callback);
1317 }
1318
1319 while (!mDone) {
1320 try {
1321 Log.d(LOG_TAG, "wait for done");
1322 wait();
1323 } catch (InterruptedException e) {
1324 // Restore the interrupted status
1325 Thread.currentThread().interrupt();
1326 }
1327 }
1328 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001329 int[] resultArray = new int[2];
1330 resultArray[0] = mResult;
1331 resultArray[1] = mRetryCount;
1332 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 }
1334 }
1335
1336 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001337 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001338
1339 }
1340
Wink Savilleb564aae2014-10-23 10:18:09 -07001341 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 // No permission check needed here: this call is harmless, and it's
1343 // needed for the ServiceState.requestStateUpdate() call (which is
1344 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001345 final Phone phone = getPhone(subId);
1346 if (phone != null) {
1347 phone.updateServiceLocation();
1348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 }
1350
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001351 @Override
1352 public boolean isRadioOn(String callingPackage) {
1353 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001354 }
1355
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001356 @Override
1357 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1358 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1359 return false;
1360 }
1361 return isRadioOnForSubscriber(subId);
1362 }
1363
1364 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001365 final Phone phone = getPhone(subId);
1366 if (phone != null) {
1367 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1368 } else {
1369 return false;
1370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001371 }
1372
1373 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001375
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 }
Wink Saville36469e72014-06-11 15:17:00 -07001377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001380 final Phone phone = getPhone(subId);
1381 if (phone != null) {
1382 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1383 }
Wink Saville36469e72014-06-11 15:17:00 -07001384 }
1385
1386 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001387 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001388 }
1389
Wink Savilleb564aae2014-10-23 10:18:09 -07001390 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001391 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001392 final Phone phone = getPhone(subId);
1393 if (phone == null) {
1394 return false;
1395 }
1396 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001397 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 }
1400 return true;
1401 }
Wink Saville36469e72014-06-11 15:17:00 -07001402
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001403 public boolean needMobileRadioShutdown() {
1404 /*
1405 * If any of the Radios are available, it will need to be
1406 * shutdown. So return true if any Radio is available.
1407 */
1408 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1409 Phone phone = PhoneFactory.getPhone(i);
1410 if (phone != null && phone.isRadioAvailable()) return true;
1411 }
1412 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1413 return false;
1414 }
1415
1416 public void shutdownMobileRadios() {
1417 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1418 logv("Shutting down Phone " + i);
1419 shutdownRadioUsingPhoneId(i);
1420 }
1421 }
1422
1423 private void shutdownRadioUsingPhoneId(int phoneId) {
1424 enforceModifyPermission();
1425 Phone phone = PhoneFactory.getPhone(phoneId);
1426 if (phone != null && phone.isRadioAvailable()) {
1427 phone.shutdownRadio();
1428 }
1429 }
1430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 public boolean setRadioPower(boolean turnOn) {
Wei Liu9ae2a062016-08-08 11:09:34 -07001432 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1433 if (defaultPhone != null) {
1434 defaultPhone.setRadioPower(turnOn);
1435 return true;
1436 } else {
1437 loge("There's no default phone.");
1438 return false;
1439 }
Wink Saville36469e72014-06-11 15:17:00 -07001440 }
1441
Wink Savilleb564aae2014-10-23 10:18:09 -07001442 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001444 final Phone phone = getPhone(subId);
1445 if (phone != null) {
1446 phone.setRadioPower(turnOn);
1447 return true;
1448 } else {
1449 return false;
1450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 }
1452
Wink Saville36469e72014-06-11 15:17:00 -07001453 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001454 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 public boolean enableDataConnectivity() {
1456 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001457 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001458 final Phone phone = getPhone(subId);
1459 if (phone != null) {
1460 phone.setDataEnabled(true);
1461 return true;
1462 } else {
1463 return false;
1464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 }
1466
Wink Saville36469e72014-06-11 15:17:00 -07001467 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001468 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 public boolean disableDataConnectivity() {
1470 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001471 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001472 final Phone phone = getPhone(subId);
1473 if (phone != null) {
1474 phone.setDataEnabled(false);
1475 return true;
1476 } else {
1477 return false;
1478 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480
Wink Saville36469e72014-06-11 15:17:00 -07001481 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001482 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 public boolean isDataConnectivityPossible() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001484 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001485 final Phone phone = getPhone(subId);
1486 if (phone != null) {
1487 return phone.isDataConnectivityPossible();
1488 } else {
1489 return false;
1490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 }
1492
1493 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001494 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001495 }
1496
pkanwarae03a6b2016-11-06 20:37:09 -08001497 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001498 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001499 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1500 return;
1501 }
1502 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1503 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1504 };
1505
1506
Wink Savilleb564aae2014-10-23 10:18:09 -07001507 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001509 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1510 return false;
1511 }
Wink Saville36469e72014-06-11 15:17:00 -07001512 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513 }
1514
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001516 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001517 }
1518
Shishir Agrawala9f32182016-04-12 12:00:16 -07001519 public int getCallStateForSlot(int slotId) {
1520 Phone phone = PhoneFactory.getPhone(slotId);
1521 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1522 DefaultPhoneNotifier.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523 }
1524
Sanket Padawe356d7632015-06-22 14:03:32 -07001525 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001527 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001528 if (phone != null) {
1529 return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
1530 } else {
1531 return DefaultPhoneNotifier.convertDataState(PhoneConstants.DataState.DISCONNECTED);
1532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 }
1534
Sanket Padawe356d7632015-06-22 14:03:32 -07001535 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001537 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001538 if (phone != null) {
1539 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1540 } else {
1541 return TelephonyManager.DATA_ACTIVITY_NONE;
1542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 }
1544
1545 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001546 public Bundle getCellLocation(String callingPackage) {
1547 enforceFineOrCoarseLocationPermission("getCellLocation");
1548
1549 // OP_COARSE_LOCATION controls both fine and coarse location.
1550 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1551 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001552 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001553 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001556 if (checkIfCallerIsSelfOrForegroundUser() ||
1557 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 if (DBG_LOC) log("getCellLocation: is active user");
1559 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001560 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001561 if (phone == null) {
1562 return null;
1563 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001564
1565 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1566 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 return data;
1568 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001569 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 return null;
1571 }
1572 }
1573
Svetoslav64fad262015-04-14 14:35:21 -07001574 private void enforceFineOrCoarseLocationPermission(String message) {
1575 try {
1576 mApp.enforceCallingOrSelfPermission(
1577 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1578 } catch (SecurityException e) {
1579 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1580 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1581 // is the weaker precondition
1582 mApp.enforceCallingOrSelfPermission(
1583 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1584 }
1585 }
1586
1587
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 @Override
1589 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001590 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001591 }
1592
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001594 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 mApp.enforceCallingOrSelfPermission(
1596 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001597 final Phone phone = getPhone(subId);
1598 if (phone != null) {
1599 phone.enableLocationUpdates();
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
1603 @Override
1604 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001605 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001606 }
1607
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001609 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 mApp.enforceCallingOrSelfPermission(
1611 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 final Phone phone = getPhone(subId);
1613 if (phone != null) {
1614 phone.disableLocationUpdates();
1615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 }
1617
1618 @Override
1619 @SuppressWarnings("unchecked")
1620 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001621 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1622
1623 // OP_COARSE_LOCATION controls both fine and coarse location.
1624 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1625 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1626 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 }
1628
1629 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1630 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1631 return null;
1632 }
Svetoslav64fad262015-04-14 14:35:21 -07001633
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001634 if (checkIfCallerIsSelfOrForegroundUser() ||
1635 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1637
1638 ArrayList<NeighboringCellInfo> cells = null;
1639
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001640 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 try {
1642 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001643 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001644 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001646 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 }
1648 return cells;
1649 } else {
1650 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1651 return null;
1652 }
1653 }
1654
1655
1656 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001657 public List<CellInfo> getAllCellInfo(String callingPackage) {
1658 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1659
1660 // OP_COARSE_LOCATION controls both fine and coarse location.
1661 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1662 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1663 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 }
1665
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001666 if (checkIfCallerIsSelfOrForegroundUser() ||
1667 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001669 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001670 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1671 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001672 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1673 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001674 }
1675 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 } else {
1677 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1678 return null;
1679 }
1680 }
1681
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001682 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 public void setCellInfoListRate(int rateInMillis) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001684 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1685 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687
Shishir Agrawala9f32182016-04-12 12:00:16 -07001688 @Override
1689 public String getImeiForSlot(int slotId, String callingPackage) {
1690 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1691 return null;
1692 }
1693 Phone phone = PhoneFactory.getPhone(slotId);
1694 return phone == null ? null : phone.getImei();
1695 }
1696
1697 @Override
1698 public String getDeviceSoftwareVersionForSlot(int slotId, String callingPackage) {
1699 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1700 return null;
1701 }
1702 Phone phone = PhoneFactory.getPhone(slotId);
1703 return phone == null ? null : phone.getDeviceSvn();
1704 }
1705
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 //
1707 // Internal helper methods.
1708 //
1709
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001710 /**
1711 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1712 */
1713 private boolean checkCallerInteractAcrossUsersFull() {
1714 return mPhone.getContext().checkCallingOrSelfPermission(
1715 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1716 == PackageManager.PERMISSION_GRANTED;
1717 }
1718
Jake Hambye994d462014-02-03 13:10:13 -08001719 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 boolean ok;
1721
1722 boolean self = Binder.getCallingUid() == Process.myUid();
1723 if (!self) {
1724 // Get the caller's user id then clear the calling identity
1725 // which will be restored in the finally clause.
1726 int callingUser = UserHandle.getCallingUserId();
1727 long ident = Binder.clearCallingIdentity();
1728
1729 try {
1730 // With calling identity cleared the current user is the foreground user.
1731 int foregroundUser = ActivityManager.getCurrentUser();
1732 ok = (foregroundUser == callingUser);
1733 if (DBG_LOC) {
1734 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1735 + " callingUser=" + callingUser + " ok=" + ok);
1736 }
1737 } catch (Exception ex) {
1738 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1739 ok = false;
1740 } finally {
1741 Binder.restoreCallingIdentity(ident);
1742 }
1743 } else {
1744 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1745 ok = true;
1746 }
1747 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1748 return ok;
1749 }
1750
1751 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1753 *
1754 * @throws SecurityException if the caller does not have the required permission
1755 */
1756 private void enforceModifyPermission() {
1757 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1758 }
1759
1760 /**
Junda Liua2e36012014-07-09 18:30:01 -07001761 * Make sure either system app or the caller has carrier privilege.
1762 *
1763 * @throws SecurityException if the caller does not have the required permission/privilege
1764 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001765 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001766 int permission = mApp.checkCallingOrSelfPermission(
1767 android.Manifest.permission.MODIFY_PHONE_STATE);
1768 if (permission == PackageManager.PERMISSION_GRANTED) {
1769 return;
1770 }
1771
1772 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001773 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001774 }
1775
1776 /**
1777 * Make sure the caller has carrier privilege.
1778 *
1779 * @throws SecurityException if the caller does not have the required permission
1780 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001781 private void enforceCarrierPrivilege(int subId) {
1782 if (getCarrierPrivilegeStatus(subId) !=
1783 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001784 loge("No Carrier Privilege.");
1785 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001786 }
1787 }
1788
1789 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 * Make sure the caller has the CALL_PHONE permission.
1791 *
1792 * @throws SecurityException if the caller does not have the required permission
1793 */
1794 private void enforceCallPermission() {
1795 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1796 }
1797
Stuart Scott8eef64f2015-04-08 15:13:54 -07001798 private void enforceConnectivityInternalPermission() {
1799 mApp.enforceCallingOrSelfPermission(
1800 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1801 "ConnectivityService");
1802 }
1803
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 private String createTelUrl(String number) {
1805 if (TextUtils.isEmpty(number)) {
1806 return null;
1807 }
1808
Jake Hambye994d462014-02-03 13:10:13 -08001809 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 }
1811
Ihab Awadf9e92732013-12-05 18:02:52 -08001812 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1814 }
1815
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001816 private static void logv(String msg) {
1817 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1818 }
1819
Ihab Awadf9e92732013-12-05 18:02:52 -08001820 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1822 }
1823
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001824 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001826 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001827 }
1828
Sanket Padawe356d7632015-06-22 14:03:32 -07001829 @Override
Shishir Agrawala9f32182016-04-12 12:00:16 -07001830 public int getActivePhoneTypeForSlot(int slotId) {
1831 final Phone phone = PhoneFactory.getPhone(slotId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001832 if (phone == null) {
1833 return PhoneConstants.PHONE_TYPE_NONE;
1834 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001835 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001837 }
1838
1839 /**
1840 * Returns the CDMA ERI icon index to display
1841 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001842 @Override
1843 public int getCdmaEriIconIndex(String callingPackage) {
1844 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001845 }
1846
Sanket Padawe356d7632015-06-22 14:03:32 -07001847 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001848 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1849 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1850 return -1;
1851 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001852 final Phone phone = getPhone(subId);
1853 if (phone != null) {
1854 return phone.getCdmaEriIconIndex();
1855 } else {
1856 return -1;
1857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
1860 /**
1861 * Returns the CDMA ERI icon mode,
1862 * 0 - ON
1863 * 1 - FLASHING
1864 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001865 @Override
1866 public int getCdmaEriIconMode(String callingPackage) {
1867 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001868 }
1869
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001871 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1872 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1873 return -1;
1874 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
1877 return phone.getCdmaEriIconMode();
1878 } else {
1879 return -1;
1880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 }
1882
1883 /**
1884 * Returns the CDMA ERI text,
1885 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001886 @Override
1887 public String getCdmaEriText(String callingPackage) {
1888 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001889 }
1890
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001892 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1893 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1894 return null;
1895 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
1898 return phone.getCdmaEriText();
1899 } else {
1900 return null;
1901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
1904 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001905 * Returns the CDMA MDN.
1906 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001908 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001909 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001910 final Phone phone = getPhone(subId);
1911 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1912 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001913 } else {
1914 return null;
1915 }
1916 }
1917
1918 /**
1919 * Returns the CDMA MIN.
1920 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001921 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001922 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001923 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 final Phone phone = getPhone(subId);
1925 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1926 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001927 } else {
1928 return null;
1929 }
1930 }
1931
1932 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 * Returns true if CDMA provisioning needs to run.
1934 */
1935 public boolean needsOtaServiceProvisioning() {
1936 return mPhone.needsOtaServiceProvisioning();
1937 }
1938
1939 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001940 * Sets the voice mail number of a given subId.
1941 */
1942 @Override
1943 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001944 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001945 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1946 new Pair<String, String>(alphaTag, number), new Integer(subId));
1947 return success;
1948 }
1949
Ta-wei Yen87c49842016-05-13 21:19:52 -07001950 @Override
Ta-wei Yenb0f695b2016-08-08 17:33:11 -07001951 public void setVisualVoicemailEnabled(String callingPackage,
1952 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
1953 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1954 if (!TextUtils.equals(callingPackage,
1955 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
1956 enforceModifyPermissionOrCarrierPrivilege(
1957 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
1958 }
1959 VisualVoicemailSettingsUtil.setEnabled(mPhone.getContext(), phoneAccountHandle, enabled);
1960 }
1961
1962 @Override
1963 public boolean isVisualVoicemailEnabled(String callingPackage,
1964 PhoneAccountHandle phoneAccountHandle) {
1965 if (!canReadPhoneState(callingPackage, "isVisualVoicemailEnabled")) {
1966 return false;
1967 }
1968 return VisualVoicemailSettingsUtil.isEnabled(mPhone.getContext(), phoneAccountHandle);
1969 }
1970
1971 @Override
Ta-wei Yendca928f2017-01-10 16:17:08 -08001972 public String getVisualVoicemailPackageName(String callingPackage,
1973 @Nullable PhoneAccountHandle phoneAccountHandle) {
1974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1975 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
1976 return null;
1977 }
1978 int subId = PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
1979 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
1980 }
1981
1982 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001983 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
1984 VisualVoicemailSmsFilterSettings settings) {
1985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001986 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001987 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
1988 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001989 }
1990
1991 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001992 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
1993 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001994 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07001995 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07001996 }
1997
1998 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07001999 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2000 String callingPackage, int subId) {
2001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002002 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002003 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002004 }
2005
2006 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002007 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002008 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002009 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002010 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2011 }
2012
2013 @Override
2014 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2015 String number, int port, String text, PendingIntent sentIntent) {
2016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002017 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002018 enforceSendSmsPermission();
2019 // Make the calls as the phone process.
2020 final long identity = Binder.clearCallingIdentity();
2021 try {
2022 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2023 if (port == 0) {
2024 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2025 sentIntent, null, false);
2026 } else {
2027 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2028 smsManager.sendDataMessageWithSelfPermissions(number, null,
2029 (short) port, data, sentIntent, null);
2030 }
2031 } finally {
2032 Binder.restoreCallingIdentity(identity);
2033 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002034 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002035 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 * Returns the unread count of voicemails
2037 */
2038 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002039 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002040 }
2041
2042 /**
2043 * Returns the unread count of voicemails for a subId
2044 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002045 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002046 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002047 final Phone phone = getPhone(subId);
2048 if (phone != null) {
2049 return phone.getVoiceMessageCount();
2050 } else {
2051 return 0;
2052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
2054
2055 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002056 * Returns the data network type.
2057 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 *
2059 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2060 */
2061 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002062 public int getNetworkType() {
2063 final Phone phone = getPhone(getDefaultSubscription());
2064 if (phone != null) {
2065 return phone.getServiceState().getDataNetworkType();
2066 } else {
2067 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2068 }
Wink Saville36469e72014-06-11 15:17:00 -07002069 }
2070
2071 /**
2072 * Returns the network type for a subId
2073 */
2074 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002075 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2076 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2077 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2078 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002079
Sanket Padawe356d7632015-06-22 14:03:32 -07002080 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002081 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002082 return phone.getServiceState().getDataNetworkType();
2083 } else {
2084 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 }
2087
2088 /**
2089 * Returns the data network type
2090 */
2091 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002092 public int getDataNetworkType(String callingPackage) {
2093 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002094 }
2095
2096 /**
2097 * Returns the data network type for a subId
2098 */
2099 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002100 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2101 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2102 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2103 }
2104
Sanket Padawe356d7632015-06-22 14:03:32 -07002105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
2107 return phone.getServiceState().getDataNetworkType();
2108 } else {
2109 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 }
2112
2113 /**
Wink Saville36469e72014-06-11 15:17:00 -07002114 * Returns the Voice network type for a subId
2115 */
2116 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002117 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2118 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2119 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2120 }
2121
Sanket Padawe356d7632015-06-22 14:03:32 -07002122 final Phone phone = getPhone(subId);
2123 if (phone != null) {
2124 return phone.getServiceState().getVoiceNetworkType();
2125 } else {
2126 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
2129
2130 /**
2131 * @return true if a ICC card is present
2132 */
2133 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002134 // FIXME Make changes to pass defaultSimId of type int
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002135 return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002136 }
2137
2138 /**
2139 * @return true if a ICC card is present for a slotId
2140 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002141 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002142 public boolean hasIccCardUsingSlotId(int slotId) {
fionaxu6e6c68b2016-06-23 13:31:32 -07002143 final Phone phone = PhoneFactory.getPhone(slotId);
2144 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002145 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002146 } else {
2147 return false;
2148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 }
2150
2151 /**
2152 * Return if the current radio is LTE on CDMA. This
2153 * is a tri-state return value as for a period of time
2154 * the mode may be unknown.
2155 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002156 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002158 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002160 @Override
2161 public int getLteOnCdmaMode(String callingPackage) {
2162 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002163 }
2164
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002166 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2167 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2168 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2169 }
2170
Sanket Padawe356d7632015-06-22 14:03:32 -07002171 final Phone phone = getPhone(subId);
2172 if (phone == null) {
2173 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2174 } else {
2175 return phone.getLteOnCdmaMode();
2176 }
Wink Saville36469e72014-06-11 15:17:00 -07002177 }
2178
2179 public void setPhone(Phone phone) {
2180 mPhone = phone;
2181 }
2182
2183 /**
2184 * {@hide}
2185 * Returns Default subId, 0 in the case of single standby.
2186 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002187 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002188 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002189 }
2190
Shishir Agrawala9f32182016-04-12 12:00:16 -07002191 private int getSlotForDefaultSubscription() {
2192 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2193 }
2194
Wink Savilleb564aae2014-10-23 10:18:09 -07002195 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002196 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002198
2199 /**
2200 * @see android.telephony.TelephonyManager.WifiCallingChoices
2201 */
2202 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002203 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2204 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002205 }
2206
2207 /**
2208 * @see android.telephony.TelephonyManager.WifiCallingChoices
2209 */
2210 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002211 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2212 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2213 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002214 }
2215
Sailesh Nepald1e68152013-12-12 19:08:02 -08002216 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002217 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002218 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002219 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002220
Shishir Agrawal566b7612013-10-28 14:41:00 -07002221 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002222 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID) {
2223 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002224
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002225 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002226 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002227 CMD_OPEN_CHANNEL, AID, subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002228 if (DBG) log("iccOpenLogicalChannel: " + response);
2229 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002230 }
2231
2232 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002233 public boolean iccCloseLogicalChannel(int subId, int channel) {
2234 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002235
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002236 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002237 if (channel < 0) {
2238 return false;
2239 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002240 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002241 if (DBG) log("iccCloseLogicalChannel: " + success);
2242 return success;
2243 }
2244
2245 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002246 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002247 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002248 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002249
2250 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002251 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2252 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002253 " data=" + data);
2254 }
2255
2256 if (channel < 0) {
2257 return "";
2258 }
2259
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002260 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002261 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002262 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2263
Shishir Agrawal566b7612013-10-28 14:41:00 -07002264 // Append the returned status code to the end of the response payload.
2265 String s = Integer.toHexString(
2266 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002267 if (response.payload != null) {
2268 s = IccUtils.bytesToHexString(response.payload) + s;
2269 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002270 return s;
2271 }
Jake Hambye994d462014-02-03 13:10:13 -08002272
Evan Charltonc66da362014-05-16 14:06:40 -07002273 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002274 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002275 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002276 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002277
2278 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002279 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2280 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002281 }
2282
2283 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002284 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002285 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2286
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002287 // Append the returned status code to the end of the response payload.
2288 String s = Integer.toHexString(
2289 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002290 if (response.payload != null) {
2291 s = IccUtils.bytesToHexString(response.payload) + s;
2292 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002293 return s;
2294 }
2295
2296 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002297 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002298 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002299 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002300
2301 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002302 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002303 p1 + " " + p2 + " " + p3 + ":" + filePath);
2304 }
2305
2306 IccIoResult response =
2307 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002308 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2309 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002310
2311 if (DBG) {
2312 log("Exchange SIM_IO [R]" + response);
2313 }
2314
2315 byte[] result = null;
2316 int length = 2;
2317 if (response.payload != null) {
2318 length = 2 + response.payload.length;
2319 result = new byte[length];
2320 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2321 } else {
2322 result = new byte[length];
2323 }
2324
2325 result[length - 1] = (byte) response.sw2;
2326 result[length - 2] = (byte) response.sw1;
2327 return result;
2328 }
2329
2330 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002331 public String sendEnvelopeWithStatus(int subId, String content) {
2332 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002333
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002334 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002335 if (response.payload == null) {
2336 return "";
2337 }
2338
2339 // Append the returned status code to the end of the response payload.
2340 String s = Integer.toHexString(
2341 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2342 s = IccUtils.bytesToHexString(response.payload) + s;
2343 return s;
2344 }
2345
Jake Hambye994d462014-02-03 13:10:13 -08002346 /**
2347 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2348 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2349 *
2350 * @param itemID the ID of the item to read
2351 * @return the NV item as a String, or null on error.
2352 */
2353 @Override
2354 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002355 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002356 if (DBG) log("nvReadItem: item " + itemID);
2357 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2358 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2359 return value;
2360 }
2361
2362 /**
2363 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2364 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2365 *
2366 * @param itemID the ID of the item to read
2367 * @param itemValue the value to write, as a String
2368 * @return true on success; false on any failure
2369 */
2370 @Override
2371 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002372 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002373 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2374 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2375 new Pair<Integer, String>(itemID, itemValue));
2376 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2377 return success;
2378 }
2379
2380 /**
2381 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2382 * Used for device configuration by some CDMA operators.
2383 *
2384 * @param preferredRoamingList byte array containing the new PRL
2385 * @return true on success; false on any failure
2386 */
2387 @Override
2388 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002389 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002390 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2391 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2392 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2393 return success;
2394 }
2395
2396 /**
2397 * Perform the specified type of NV config reset.
2398 * Used for device configuration by some CDMA operators.
2399 *
2400 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2401 * @return true on success; false on any failure
2402 */
2403 @Override
2404 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002405 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002406 if (DBG) log("nvResetConfig: type " + resetType);
2407 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2408 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2409 return success;
2410 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002411
2412 /**
Wink Saville36469e72014-06-11 15:17:00 -07002413 * {@hide}
2414 * Returns Default sim, 0 in the case of single standby.
2415 */
2416 public int getDefaultSim() {
2417 //TODO Need to get it from Telephony Devcontroller
2418 return 0;
2419 }
2420
Svet Ganovb320e182015-04-16 12:30:10 -07002421 public String[] getPcscfAddress(String apnType, String callingPackage) {
2422 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2423 return new String[0];
2424 }
2425
2426
ram87fca6f2014-07-18 18:58:44 +05302427 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002428 }
2429
2430 public void setImsRegistrationState(boolean registered) {
2431 enforceModifyPermission();
2432 mPhone.setImsRegistrationState(registered);
2433 }
2434
2435 /**
Stuart Scott54788802015-03-30 13:18:01 -07002436 * Set the network selection mode to automatic.
2437 *
2438 */
2439 @Override
2440 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002441 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002442 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2443 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2444 }
2445
2446 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002447 * Set the network selection mode to manual with the selected carrier.
2448 */
2449 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002450 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2451 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002452 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002453 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002454 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2455 persistSelection);
2456 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002457 }
2458
2459 /**
2460 * Scans for available networks.
2461 */
2462 @Override
2463 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002464 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002465 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2466 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2467 CMD_PERFORM_NETWORK_SCAN, null, subId);
2468 return result;
2469 }
2470
2471 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002472 * Get the calculated preferred network type.
2473 * Used for debugging incorrect network type.
2474 *
2475 * @return the preferred network type, defined in RILConstants.java.
2476 */
2477 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002478 public int getCalculatedPreferredNetworkType(String callingPackage) {
2479 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2480 return RILConstants.PREFERRED_NETWORK_MODE;
2481 }
2482
Amit Mahajan43330e02014-11-18 11:54:45 -08002483 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002484 }
2485
2486 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002487 * Get the preferred network type.
2488 * Used for device configuration by some CDMA operators.
2489 *
2490 * @return the preferred network type, defined in RILConstants.java.
2491 */
2492 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002493 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002494 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002495 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002496 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002497 int networkType = (result != null ? result[0] : -1);
2498 if (DBG) log("getPreferredNetworkType: " + networkType);
2499 return networkType;
2500 }
2501
2502 /**
2503 * Set the preferred network type.
2504 * Used for device configuration by some CDMA operators.
2505 *
2506 * @param networkType the preferred network type, defined in RILConstants.java.
2507 * @return true on success; false on any failure.
2508 */
2509 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002510 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002511 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002512 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2513 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002514 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002515 if (success) {
2516 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002517 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002518 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002519 return success;
2520 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002521
2522 /**
Junda Liu475951f2014-11-07 16:45:03 -08002523 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2524 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2525 * tethering.
2526 *
2527 * @return 0: Not required. 1: required. 2: Not set.
2528 * @hide
2529 */
2530 @Override
2531 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002532 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002533 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2534 Settings.Global.TETHER_DUN_REQUIRED, 2);
2535 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2536 // config_tether_apndata.
2537 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2538 dunRequired = 1;
2539 }
2540 return dunRequired;
2541 }
2542
2543 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002544 * Set mobile data enabled
2545 * Used by the user through settings etc to turn on/off mobile data
2546 *
2547 * @param enable {@code true} turn turn data on, else {@code false}
2548 */
2549 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002550 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002551 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002552 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002553 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002554 Phone phone = PhoneFactory.getPhone(phoneId);
2555 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002556 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002557 phone.setDataEnabled(enable);
2558 } else {
2559 loge("setDataEnabled: no phone for subId=" + subId);
2560 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002561 }
2562
2563 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002564 * Get whether mobile data is enabled.
2565 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002566 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002567 *
2568 * @return {@code true} if data is enabled else {@code false}
2569 */
2570 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002571 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002572 try {
2573 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2574 null);
2575 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002576 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002577 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002578 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002579 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002580 Phone phone = PhoneFactory.getPhone(phoneId);
2581 if (phone != null) {
2582 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002583 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002584 return retVal;
2585 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002586 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002587 return false;
2588 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002589 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002590
2591 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002592 public int getCarrierPrivilegeStatus(int subId) {
2593 final Phone phone = getPhone(subId);
2594 if (phone == null) {
2595 loge("getCarrierPrivilegeStatus: Invalid subId");
2596 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2597 }
2598 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002599 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002600 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002601 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2602 }
2603 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002604 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002605 }
Junda Liu29340342014-07-10 15:23:27 -07002606
2607 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002608 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002609 if (TextUtils.isEmpty(pkgName))
2610 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002611 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002612 if (card == null) {
2613 loge("checkCarrierPrivilegesForPackage: No UICC");
2614 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2615 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002616 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2617 }
2618
2619 @Override
2620 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002621 if (TextUtils.isEmpty(pkgName))
2622 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002623 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2624 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2625 UiccCard card = UiccController.getInstance().getUiccCard(i);
2626 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002627 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002628 continue;
2629 }
2630
2631 result = card.getCarrierPrivilegeStatus(
2632 mPhone.getContext().getPackageManager(), pkgName);
2633 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2634 break;
2635 }
2636 }
2637
2638 return result;
Junda Liu29340342014-07-10 15:23:27 -07002639 }
Derek Tan89e89d42014-07-08 17:00:10 -07002640
2641 @Override
Junda Liue64de782015-04-16 17:19:16 -07002642 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2643 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2644 loge("phoneId " + phoneId + " is not valid.");
2645 return null;
2646 }
2647 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002648 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002649 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002650 return null ;
2651 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002652 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002653 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002654 }
2655
Amith Yamasani6e118872016-02-19 12:53:51 -08002656 @Override
2657 public List<String> getPackagesWithCarrierPrivileges() {
2658 PackageManager pm = mPhone.getContext().getPackageManager();
2659 List<String> privilegedPackages = new ArrayList<>();
2660 List<PackageInfo> packages = null;
2661 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2662 UiccCard card = UiccController.getInstance().getUiccCard(i);
2663 if (card == null) {
2664 // No UICC in that slot.
2665 continue;
2666 }
2667 if (card.hasCarrierPrivilegeRules()) {
2668 if (packages == null) {
2669 // Only check packages in user 0 for now
2670 packages = pm.getInstalledPackagesAsUser(
2671 PackageManager.MATCH_DISABLED_COMPONENTS
2672 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2673 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2674 }
2675 for (int p = packages.size() - 1; p >= 0; p--) {
2676 PackageInfo pkgInfo = packages.get(p);
2677 if (pkgInfo != null && pkgInfo.packageName != null
2678 && card.getCarrierPrivilegeStatus(pkgInfo)
2679 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2680 privilegedPackages.add(pkgInfo.packageName);
2681 }
2682 }
2683 }
2684 }
2685 return privilegedPackages;
2686 }
2687
Wink Savilleb564aae2014-10-23 10:18:09 -07002688 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 final Phone phone = getPhone(subId);
2690 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002691 if (card == null) {
2692 loge("getIccId: No UICC");
2693 return null;
2694 }
2695 String iccId = card.getIccId();
2696 if (TextUtils.isEmpty(iccId)) {
2697 loge("getIccId: ICC ID is null or empty.");
2698 return null;
2699 }
2700 return iccId;
2701 }
2702
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002703 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002704 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2705 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002706 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002707
Jeff Sharkey85190e62014-12-05 09:40:12 -08002708 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002709 final Phone phone = getPhone(subId);
2710 if (phone == null) {
2711 return false;
2712 }
2713 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002714
2715 if (DBG_MERGE) {
2716 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2717 + subscriberId + " to " + number);
2718 }
2719
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002720 if (TextUtils.isEmpty(iccId)) {
2721 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002722 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002723
Jeff Sharkey85190e62014-12-05 09:40:12 -08002724 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2725
2726 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002727 if (alphaTag == null) {
2728 editor.remove(alphaTagPrefKey);
2729 } else {
2730 editor.putString(alphaTagPrefKey, alphaTag);
2731 }
2732
Jeff Sharkey85190e62014-12-05 09:40:12 -08002733 // Record both the line number and IMSI for this ICCID, since we need to
2734 // track all merged IMSIs based on line number
2735 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2736 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002737 if (number == null) {
2738 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002739 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002740 } else {
2741 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002742 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002743 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002744
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002745 editor.commit();
2746 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002747 }
2748
2749 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002750 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002751 // This is open to apps with WRITE_SMS.
2752 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002753 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002754 return null;
2755 }
Derek Tan97ebb422014-09-05 16:55:38 -07002756
2757 String iccId = getIccId(subId);
2758 if (iccId != null) {
2759 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002760 if (DBG_MERGE) {
2761 log("getLine1NumberForDisplay returning " +
2762 mTelephonySharedPreferences.getString(numberPrefKey, null));
2763 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002764 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002765 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002766 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002767 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002768 }
2769
2770 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002771 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2772 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2773 return null;
2774 }
Derek Tan97ebb422014-09-05 16:55:38 -07002775
2776 String iccId = getIccId(subId);
2777 if (iccId != null) {
2778 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002779 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002780 }
Derek Tan97ebb422014-09-05 16:55:38 -07002781 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002782 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002783
2784 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002785 public String[] getMergedSubscriberIds(String callingPackage) {
2786 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2787 return null;
2788 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002789 final Context context = mPhone.getContext();
2790 final TelephonyManager tele = TelephonyManager.from(context);
2791 final SubscriptionManager sub = SubscriptionManager.from(context);
2792
2793 // Figure out what subscribers are currently active
2794 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002795 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2796 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 final int[] subIds = sub.getActiveSubscriptionIdList();
2800 for (int subId : subIds) {
2801 activeSubscriberIds.add(tele.getSubscriberId(subId));
2802 }
2803 } finally {
2804 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002805 }
2806
2807 // First pass, find a number override for an active subscriber
2808 String mergeNumber = null;
2809 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2810 for (String key : prefs.keySet()) {
2811 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2812 final String subscriberId = (String) prefs.get(key);
2813 if (activeSubscriberIds.contains(subscriberId)) {
2814 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2815 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2816 mergeNumber = (String) prefs.get(numberKey);
2817 if (DBG_MERGE) {
2818 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2819 + " for active subscriber " + subscriberId);
2820 }
2821 if (!TextUtils.isEmpty(mergeNumber)) {
2822 break;
2823 }
2824 }
2825 }
2826 }
2827
2828 // Shortcut when no active merged subscribers
2829 if (TextUtils.isEmpty(mergeNumber)) {
2830 return null;
2831 }
2832
2833 // Second pass, find all subscribers under that line override
2834 final ArraySet<String> result = new ArraySet<>();
2835 for (String key : prefs.keySet()) {
2836 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2837 final String number = (String) prefs.get(key);
2838 if (mergeNumber.equals(number)) {
2839 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2840 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2841 final String subscriberId = (String) prefs.get(subscriberKey);
2842 if (!TextUtils.isEmpty(subscriberId)) {
2843 result.add(subscriberId);
2844 }
2845 }
2846 }
2847 }
2848
2849 final String[] resultArray = result.toArray(new String[result.size()]);
2850 Arrays.sort(resultArray);
2851 if (DBG_MERGE) {
2852 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2853 }
2854 return resultArray;
2855 }
2856
2857 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002858 public boolean setOperatorBrandOverride(int subId, String brand) {
2859 enforceCarrierPrivilege(subId);
2860 final Phone phone = getPhone(subId);
2861 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002862 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002863
2864 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002865 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002866 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2867 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002868 enforceCarrierPrivilege(subId);
2869 final Phone phone = getPhone(subId);
2870 if (phone == null) {
2871 return false;
2872 }
2873 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002874 cdmaNonRoamingList);
2875 }
2876
2877 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002878 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2879 enforceModifyPermission();
2880
2881 int returnValue = 0;
2882 try {
2883 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2884 if(result.exception == null) {
2885 if (result.result != null) {
2886 byte[] responseData = (byte[])(result.result);
2887 if(responseData.length > oemResp.length) {
2888 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2889 responseData.length + "bytes. Buffer Size is " +
2890 oemResp.length + "bytes.");
2891 }
2892 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2893 returnValue = responseData.length;
2894 }
2895 } else {
2896 CommandException ex = (CommandException) result.exception;
2897 returnValue = ex.getCommandError().ordinal();
2898 if(returnValue > 0) returnValue *= -1;
2899 }
2900 } catch (RuntimeException e) {
2901 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2902 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2903 if(returnValue > 0) returnValue *= -1;
2904 }
2905
2906 return returnValue;
2907 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002908
2909 @Override
2910 public void setRadioCapability(RadioAccessFamily[] rafs) {
2911 try {
2912 ProxyController.getInstance().setRadioCapability(rafs);
2913 } catch (RuntimeException e) {
2914 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2915 }
2916 }
2917
2918 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002919 public int getRadioAccessFamily(int phoneId, String callingPackage) {
2920 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
2921 return RadioAccessFamily.RAF_UNKNOWN;
2922 }
2923
Wink Saville5d475dd2014-10-17 15:00:58 -07002924 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2925 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002926
2927 @Override
2928 public void enableVideoCalling(boolean enable) {
2929 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002930 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07002931 }
2932
2933 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002934 public boolean isVideoCallingEnabled(String callingPackage) {
2935 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
2936 return false;
2937 }
2938
Andrew Lee77527ac2014-10-21 16:57:39 -07002939 // Check the user preference and the system-level IMS setting. Even if the user has
2940 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2941 // In the long run, we may instead need to check if there exists a connection service
2942 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002943 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2944 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002945 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07002946 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002947
Andrew Leea1239f22015-03-02 17:44:07 -08002948 @Override
2949 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002950 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002951 }
2952
2953 @Override
2954 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002955 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002956 }
2957
Andrew Lee9431b832015-03-09 18:46:45 -07002958 @Override
2959 public boolean isTtyModeSupported() {
2960 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
2961 TelephonyManager telephonyManager =
2962 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08002963 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07002964 }
2965
2966 @Override
2967 public boolean isHearingAidCompatibilitySupported() {
2968 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
2969 }
2970
Sanket Padawe7310cc72015-01-14 09:53:20 -08002971 /**
2972 * Returns the unique device ID of phone, for example, the IMEI for
2973 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
2974 *
2975 * <p>Requires Permission:
2976 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
2977 */
2978 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002979 public String getDeviceId(String callingPackage) {
2980 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
2981 return null;
2982 }
2983
Sanket Padawe7310cc72015-01-14 09:53:20 -08002984 final Phone phone = PhoneFactory.getPhone(0);
2985 if (phone != null) {
2986 return phone.getDeviceId();
2987 } else {
2988 return null;
2989 }
2990 }
2991
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002992 /*
2993 * {@hide}
2994 * Returns the IMS Registration Status
2995 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08002996 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002997 public boolean isImsRegistered() {
2998 return mPhone.isImsRegistered();
2999 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003000
3001 @Override
3002 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3003 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3004 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003005
Nathan Haroldc55097a2015-03-11 18:14:50 -07003006 /*
3007 * {@hide}
3008 * Returns the IMS Registration Status
3009 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003010 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003011 return mPhone.isWifiCallingEnabled();
3012 }
3013
3014 /*
3015 * {@hide}
3016 * Returns the IMS Registration Status
3017 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003018 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003019 return mPhone.isVolteEnabled();
3020 }
Svet Ganovb320e182015-04-16 12:30:10 -07003021
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003022 /*
3023 * {@hide} Returns the IMS Registration Status
3024 */
3025 public boolean isVideoTelephonyAvailable() {
3026 return mPhone.isVideoEnabled();
3027 }
3028
Svet Ganovb320e182015-04-16 12:30:10 -07003029 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003030 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003031 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003032 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3033
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003034 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003035 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003036 } catch (SecurityException e) {
3037 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3038 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003039 }
Svet Ganovb320e182015-04-16 12:30:10 -07003040
3041 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3042 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3043 return false;
3044 }
3045
3046 return true;
3047 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003048
Makoto Onukifee69342015-06-29 14:44:50 -07003049 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003050 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003051 */
3052 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003053 // Default SMS app can always read it.
3054 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3055 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3056 return true;
3057 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003058
Makoto Onukie4072d12015-08-03 15:12:23 -07003059 try {
3060 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003061 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003062 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003063 // Can be read with READ_SMS too.
3064 try {
3065 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3066 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3067 if (opCode != AppOpsManager.OP_NONE) {
3068 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3069 == AppOpsManager.MODE_ALLOWED;
3070 } else {
3071 return true;
3072 }
3073 } catch (SecurityException readSmsSecurityException) {
3074 }
3075 // Can be read with READ_PHONE_NUMBER too.
3076 try {
3077 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBER,
3078 message);
3079 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBER);
3080 if (opCode != AppOpsManager.OP_NONE) {
3081 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3082 == AppOpsManager.MODE_ALLOWED;
3083 } else {
3084 return true;
3085 }
3086 } catch (SecurityException readPhoneNumberSecurityException) {
3087 }
3088
3089 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3090 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3091 ", " + android.Manifest.permission.READ_SMS + ", or " +
3092 android.Manifest.permission.READ_PHONE_NUMBER);
Makoto Onukifee69342015-06-29 14:44:50 -07003093 }
3094
Stuart Scott8eef64f2015-04-08 15:13:54 -07003095 @Override
3096 public void factoryReset(int subId) {
3097 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003098 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3099 return;
3100 }
3101
Svet Ganovcc087f82015-05-12 20:35:54 -07003102 final long identity = Binder.clearCallingIdentity();
3103 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003104 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3105 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003106 // Enable data
3107 setDataEnabled(subId, true);
3108 // Set network selection mode to automatic
3109 setNetworkSelectionModeAutomatic(subId);
3110 // Set preferred mobile network type to the best available
3111 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3112 // Turn off roaming
3113 SubscriptionManager.from(mApp).setDataRoaming(0, subId);
3114 }
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003117 }
3118 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003119
3120 @Override
3121 public String getLocaleFromDefaultSim() {
3122 // We query all subscriptions instead of just the active ones, because
3123 // this might be called early on in the provisioning flow when the
3124 // subscriptions potentially aren't active yet.
3125 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3126 if (slist == null || slist.isEmpty()) {
3127 return null;
3128 }
3129
3130 // This function may be called very early, say, from the setup wizard, at
3131 // which point we won't have a default subscription set. If that's the case
3132 // we just choose the first, which will be valid in "most cases".
3133 final int defaultSubId = getDefaultSubscription();
3134 SubscriptionInfo info = null;
3135 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3136 info = slist.get(0);
3137 } else {
3138 for (SubscriptionInfo item : slist) {
3139 if (item.getSubscriptionId() == defaultSubId) {
3140 info = item;
3141 break;
3142 }
3143 }
3144
3145 if (info == null) {
3146 return null;
3147 }
3148 }
3149
3150 // Try and fetch the locale from the carrier properties or from the SIM language
3151 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003152 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003153 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003154 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003155 if (defaultPhone != null) {
3156 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3157 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003158 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003159 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3160 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003161 } else {
3162 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003163 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003164 }
3165 }
3166
Narayan Kamath011676f2015-07-29 12:04:08 +01003167 // The SIM language preferences only store a language (e.g. fr = French), not an
3168 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3169 // the SIM and carrier preferences does not include a country we add the country
3170 // determined from the SIM MCC to provide an exact locale.
3171 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003172 if (mccLocale != null) {
3173 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3174 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003175 }
3176
Tony Hill183b2de2015-06-24 14:53:58 +01003177 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003178 return null;
3179 }
3180
3181 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 return mSubscriptionController.getAllSubInfoList(
3185 mPhone.getContext().getOpPackageName());
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
3189 }
3190
3191 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 return mSubscriptionController.getActiveSubscriptionInfoList(
3195 mPhone.getContext().getOpPackageName());
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
3199 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003200
3201 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003202 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3203 * representing the state of the modem.
3204 *
3205 * NOTE: This clears the modem state, so there should only every be one caller.
3206 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003207 */
3208 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003209 public void requestModemActivityInfo(ResultReceiver result) {
3210 enforceModifyPermission();
3211
3212 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3213 Bundle bundle = new Bundle();
3214 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3215 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003216 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003217
3218 /**
3219 * {@hide}
3220 * Returns the service state information on specified subscription.
3221 */
3222 @Override
3223 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3224
3225 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3226 return null;
3227 }
3228
3229 final Phone phone = getPhone(subId);
3230 if (phone == null) {
3231 return null;
3232 }
3233
3234 return phone.getServiceState();
3235 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003236
3237 /**
3238 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3239 *
3240 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3241 * voicemail ringtone.
3242 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3243 * PhoneAccount.
3244 */
3245 @Override
3246 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
3247 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3248 if (phone == null) {
3249 return null;
3250 }
3251
3252 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
3253 }
3254
3255 /**
3256 * Returns whether vibration is set for voicemail notification in Phone settings.
3257 *
3258 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3259 * voicemail vibration setting.
3260 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3261 */
3262 @Override
3263 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
3264 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3265 if (phone == null) {
3266 return false;
3267 }
3268
3269 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone);
3270 }
3271
Youhan Wange64578a2016-05-02 15:32:42 -07003272 /**
3273 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3274 *
3275 * @throws SecurityException if the caller does not have the required permission
3276 */
3277 private void enforceReadPrivilegedPermission() {
3278 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3279 null);
3280 }
3281
3282 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003283 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3284 * permission.
3285 *
3286 * @throws SecurityException if the caller does not have the required permission
3287 */
3288 private void enforceSendSmsPermission() {
3289 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3290 }
3291
3292 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003293 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003294 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003295 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003296 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003297 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
3298 String vvmPackage = RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId)
3299 .getPackageName();
3300 if (!callingPackage.equals(vvmPackage)) {
3301 throw new SecurityException("Caller not current active visual voicemail package[" +
3302 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003303 }
3304 }
3305
3306 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003307 * Return the application ID for the app type.
3308 *
3309 * @param subId the subscription ID that this request applies to.
3310 * @param appType the uicc app type.
3311 * @return Application ID for specificied app type, or null if no uicc.
3312 */
3313 @Override
3314 public String getAidForAppType(int subId, int appType) {
3315 enforceReadPrivilegedPermission();
3316 Phone phone = getPhone(subId);
3317 if (phone == null) {
3318 return null;
3319 }
3320 String aid = null;
3321 try {
3322 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3323 .getApplicationByType(appType).getAid();
3324 } catch (Exception e) {
3325 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3326 }
3327 return aid;
3328 }
3329
Youhan Wang4001d252016-05-11 10:29:41 -07003330 /**
3331 * Return the Electronic Serial Number.
3332 *
3333 * @param subId the subscription ID that this request applies to.
3334 * @return ESN or null if error.
3335 */
3336 @Override
3337 public String getEsn(int subId) {
3338 enforceReadPrivilegedPermission();
3339 Phone phone = getPhone(subId);
3340 if (phone == null) {
3341 return null;
3342 }
3343 String esn = null;
3344 try {
3345 esn = phone.getEsn();
3346 } catch (Exception e) {
3347 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3348 }
3349 return esn;
3350 }
3351
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003352 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003353 * Return the Preferred Roaming List Version.
3354 *
3355 * @param subId the subscription ID that this request applies to.
3356 * @return PRLVersion or null if error.
3357 */
3358 @Override
3359 public String getCdmaPrlVersion(int subId) {
3360 enforceReadPrivilegedPermission();
3361 Phone phone = getPhone(subId);
3362 if (phone == null) {
3363 return null;
3364 }
3365 String cdmaPrlVersion = null;
3366 try {
3367 cdmaPrlVersion = phone.getCdmaPrlVersion();
3368 } catch (Exception e) {
3369 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3370 }
3371 return cdmaPrlVersion;
3372 }
3373
3374 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003375 * Get snapshot of Telephony histograms
3376 * @return List of Telephony histograms
3377 * @hide
3378 */
3379 @Override
3380 public List<TelephonyHistogram> getTelephonyHistograms() {
3381 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3382 return RIL.getTelephonyRILTimingHistograms();
3383 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003384
3385 /**
3386 * {@hide}
3387 * Set the allowed carrier list for slotId
3388 * Require system privileges. In the future we may add this to carrier APIs.
3389 *
3390 * @return The number of carriers set successfully, should match length of carriers
3391 */
3392 @Override
3393 public int setAllowedCarriers(int slotId, List<CarrierIdentifier> carriers) {
3394 enforceModifyPermission();
3395 int subId = SubscriptionManager.getSubId(slotId)[0];
3396 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3397 return retVal[0];
3398 }
3399
3400 /**
3401 * {@hide}
3402 * Get the allowed carrier list for slotId.
3403 * Require system privileges. In the future we may add this to carrier APIs.
3404 *
3405 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3406 * means all carriers are allowed.
3407 */
3408 @Override
3409 public List<CarrierIdentifier> getAllowedCarriers(int slotId) {
3410 enforceReadPrivilegedPermission();
3411 int subId = SubscriptionManager.getSubId(slotId)[0];
3412 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3413 }
3414
fionaxu59545b42016-05-25 15:53:37 -07003415 /**
3416 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3417 * @param subId the subscription ID that this action applies to.
3418 * @param enabled control enable or disable metered apns.
3419 * {@hide}
3420 */
3421 @Override
3422 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3423 enforceModifyPermission();
3424 final Phone phone = getPhone(subId);
3425 if (phone == null) {
3426 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3427 return;
3428 }
3429 try {
3430 phone.carrierActionSetMeteredApnsEnabled(enabled);
3431 } catch (Exception e) {
3432 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3433 }
3434 }
3435
3436 /**
3437 * Action set from carrier signalling broadcast receivers to enable/disable radio
3438 * @param subId the subscription ID that this action applies to.
3439 * @param enabled control enable or disable radio.
3440 * {@hide}
3441 */
3442 @Override
3443 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3444 enforceModifyPermission();
3445 final Phone phone = getPhone(subId);
3446 if (phone == null) {
3447 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3448 return;
3449 }
3450 try {
3451 phone.carrierActionSetRadioEnabled(enabled);
3452 } catch (Exception e) {
3453 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3454 }
3455 }
3456
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003457 /**
3458 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3459 * bug report is being generated.
3460 */
3461 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003462 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003463 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3464 != PackageManager.PERMISSION_GRANTED) {
3465 writer.println("Permission Denial: can't dump Phone from pid="
3466 + Binder.getCallingPid()
3467 + ", uid=" + Binder.getCallingUid()
3468 + "without permission "
3469 + android.Manifest.permission.DUMP);
3470 return;
3471 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003472 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003473 }
Jack Yueb89b242016-06-22 13:27:47 -07003474
3475 /**
3476 * Get aggregated video call data usage from all subscriptions since boot.
3477 * @return total data usage in bytes
3478 * {@hide}
3479 */
3480 @Override
3481 public long getVtDataUsage() {
3482 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3483 null);
3484
3485 // NetworkStatsService keeps tracking the active network interface and identity. It will
3486 // record the delta with the corresponding network identity. What we need to do here is
3487 // returning total video call data usage from all subscriptions since boot.
3488
3489 // TODO: Add sub id support in the future. We'll need it when we support DSDA and
3490 // simultaneous VT calls.
3491 final Phone[] phones = PhoneFactory.getPhones();
3492 long total = 0;
3493 for (Phone phone : phones) {
3494 total += phone.getVtDataUsage();
3495 }
3496 return total;
3497 }
Jack Yu75ab2952016-07-08 14:29:33 -07003498
3499 /**
3500 * Policy control of data connection. Usually used when data limit is passed.
3501 * @param enabled True if enabling the data, otherwise disabling.
3502 * @param subId Subscription index
3503 * {@hide}
3504 */
3505 @Override
3506 public void setPolicyDataEnabled(boolean enabled, int subId) {
3507 enforceModifyPermission();
3508 Phone phone = getPhone(subId);
3509 if (phone != null) {
3510 phone.setPolicyDataEnabled(enabled);
3511 }
3512 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003513
3514 /**
3515 * Get Client request stats
3516 * @return List of Client Request Stats
3517 * @hide
3518 */
3519 @Override
3520 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3521 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3522 return null;
3523 }
3524
3525 Phone phone = getPhone(subId);
3526 if (phone != null) {
3527 return phone.getClientRequestStats();
3528 }
3529
3530 return null;
3531 }
3532
3533 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3534 if (workSource != null) {
3535 return workSource;
3536 }
3537
3538 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3539 workSource = new WorkSource(uid, packageName);
3540 return workSource;
3541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003542}