blob: 81de9d71216af0b82a7b470abdb7064e7b59a6fc [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 Yen1b455992016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.ActivityManager;
23import android.app.AppOpsManager;
Ta-wei Yen1b455992016-12-27 14:52:32 -080024import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070025import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.content.Context;
27import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070028import android.content.SharedPreferences;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.net.Uri;
32import android.os.AsyncResult;
33import android.os.Binder;
34import android.os.Bundle;
35import android.os.Handler;
36import android.os.Looper;
37import android.os.Message;
38import android.os.Process;
Adam Lesinski903a54c2016-04-11 14:49:52 -070039import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.ServiceManager;
41import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070042import android.os.UserManager;
Sooraj Sasindran22882212016-07-18 11:57:25 -070043import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070044import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080045import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070046import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080047import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080048import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070049import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070050import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.telephony.CellInfo;
Sooraj Sasindran22882212016-07-18 11:57:25 -070052import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070053import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070054import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080055import android.telephony.NeighboringCellInfo;
Wink Saville5d475dd2014-10-17 15:00:58 -070056import android.telephony.RadioAccessFamily;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.telephony.ServiceState;
Ta-wei Yen1b455992016-12-27 14:52:32 -080058import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080059import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080060import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070061import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070062import android.telephony.TelephonyManager;
63import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080065import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080067import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.util.Slog;
Ta-wei Yen1b455992016-12-27 14:52:32 -080069
Andrew Lee312e8172014-10-23 17:01:36 -070070import com.android.ims.ImsManager;
Brad Ebinger76681002017-01-23 13:50:20 -080071import com.android.ims.internal.IImsServiceController;
72import com.android.ims.internal.IImsServiceFeatureListener;
Shishir Agrawal566b7612013-10-28 14:41:00 -070073import com.android.internal.telephony.CallManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070074import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070075import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080078import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010079import com.android.internal.telephony.MccTable;
Shishir Agrawal302c8692015-06-19 13:49:39 -070080import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import com.android.internal.telephony.Phone;
Ta-wei Yen87c49842016-05-13 21:19:52 -070082import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070083import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070084import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070086import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080087import com.android.internal.telephony.SubscriptionController;
Shishir Agrawal566b7612013-10-28 14:41:00 -070088import com.android.internal.telephony.uicc.IccIoResult;
89import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -080090import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -070091import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -080092import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -070093import com.android.internal.telephony.uicc.UiccController;
Jake Hambye994d462014-02-03 13:10:13 -080094import com.android.internal.util.HexDump;
Ta-wei Yenb0f695b2016-08-08 17:33:11 -070095import com.android.phone.settings.VisualVoicemailSettingsUtil;
Nancy Chen31f9ba12016-01-06 11:42:12 -080096import com.android.phone.settings.VoicemailNotificationSettingsUtil;
Ta-wei Yen463efd12017-01-06 15:29:25 -080097import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yen1b455992016-12-27 14:52:32 -080098
Ta-wei Yenc236d6b2016-06-21 13:33:12 -070099import java.io.FileDescriptor;
100import java.io.PrintWriter;
Ta-wei Yen1b455992016-12-27 14:52:32 -0800101import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800104import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100105import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800106import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107
108/**
109 * Implementation of the ITelephony interface.
110 */
Santos Cordon117fee72014-05-16 17:56:12 -0700111public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112 private static final String LOG_TAG = "PhoneInterfaceManager";
113 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
114 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116
117 // Message codes used with mMainThreadHandler
118 private static final int CMD_HANDLE_PIN_MMI = 1;
119 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
120 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
121 private static final int CMD_ANSWER_RINGING_CALL = 4;
122 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700123 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
124 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125 private static final int CMD_OPEN_CHANNEL = 9;
126 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
127 private static final int CMD_CLOSE_CHANNEL = 11;
128 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800129 private static final int CMD_NV_READ_ITEM = 13;
130 private static final int EVENT_NV_READ_ITEM_DONE = 14;
131 private static final int CMD_NV_WRITE_ITEM = 15;
132 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
133 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
134 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
135 private static final int CMD_NV_RESET_CONFIG = 19;
136 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800137 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
138 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
139 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
140 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800141 private static final int CMD_SEND_ENVELOPE = 25;
142 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700143 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
144 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
145 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
146 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
147 private static final int CMD_EXCHANGE_SIM_IO = 31;
148 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800149 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
150 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700151 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
152 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700153 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
154 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700155 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
156 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
157 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
158 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700159 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
160 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
161 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
162 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar7e856482016-10-14 19:37:38 -0700163 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
165 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166
167 /** The singleton instance. */
168 private static PhoneInterfaceManager sInstance;
169
Wink Saville3ab207e2014-11-20 13:07:20 -0800170 private PhoneGlobals mApp;
171 private Phone mPhone;
172 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700173 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800174 private AppOpsManager mAppOps;
175 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800176 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800177 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178
Derek Tan97ebb422014-09-05 16:55:38 -0700179 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
180 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700182
183 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184 * A request object to use for transmitting data to an ICC.
185 */
186 private static final class IccAPDUArgument {
187 public int channel, cla, command, p1, p2, p3;
188 public String data;
189
190 public IccAPDUArgument(int channel, int cla, int command,
191 int p1, int p2, int p3, String data) {
192 this.channel = channel;
193 this.cla = cla;
194 this.command = command;
195 this.p1 = p1;
196 this.p2 = p2;
197 this.p3 = p3;
198 this.data = data;
199 }
200 }
201
202 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700203 * A request object to use for transmitting data to an ICC.
204 */
205 private static final class ManualNetworkSelectionArgument {
206 public OperatorInfo operatorInfo;
207 public boolean persistSelection;
208
209 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
210 this.operatorInfo = operatorInfo;
211 this.persistSelection = persistSelection;
212 }
213 }
214
215 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
217 * request after sending. The main thread will notify the request when it is complete.
218 */
219 private static final class MainThreadRequest {
220 /** The argument to use for the request */
221 public Object argument;
222 /** The result of the request that is run on the main thread */
223 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800224 // The subscriber id that this request applies to. Defaults to
225 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
226 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227
228 public MainThreadRequest(Object argument) {
229 this.argument = argument;
230 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800231
232 public MainThreadRequest(Object argument, Integer subId) {
233 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800234 if (subId != null) {
235 this.subId = subId;
236 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238 }
239
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800240 private static final class IncomingThirdPartyCallArgs {
241 public final ComponentName component;
242 public final String callId;
243 public final String callerDisplayName;
244
245 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
246 String callerDisplayName) {
247 this.component = component;
248 this.callId = callId;
249 this.callerDisplayName = callerDisplayName;
250 }
251 }
252
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 /**
254 * A handler that processes messages on the main thread in the phone process. Since many
255 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
256 * inbound binder threads to the main thread in the phone process. The Binder thread
257 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
258 * on, which will be notified when the operation completes and will contain the result of the
259 * request.
260 *
261 * <p>If a MainThreadRequest object is provided in the msg.obj field,
262 * note that request.result must be set to something non-null for the calling thread to
263 * unblock.
264 */
265 private final class MainThreadHandler extends Handler {
266 @Override
267 public void handleMessage(Message msg) {
268 MainThreadRequest request;
269 Message onCompleted;
270 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800271 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700272 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273
274 switch (msg.what) {
pkanwar7e856482016-10-14 19:37:38 -0700275 case CMD_HANDLE_USSD_REQUEST: {
276 request = (MainThreadRequest) msg.obj;
277 final Phone phone = getPhoneFromRequest(request);
278 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
279 String ussdRequest = ussdObject.first;
280 ResultReceiver wrappedCallback = ussdObject.second;
281 request.result = phone != null ?
282 phone.handleUssdRequest(ussdRequest, wrappedCallback)
283 :false;
284 // Wake up the requesting thread
285 synchronized (request) {
286 request.notifyAll();
287 }
288 break;
289 }
290
Yorke Lee716f67e2015-06-17 15:39:16 -0700291 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700293 final Phone phone = getPhoneFromRequest(request);
294 request.result = phone != null ?
295 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
296 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 // Wake up the requesting thread
298 synchronized (request) {
299 request.notifyAll();
300 }
301 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303
304 case CMD_HANDLE_NEIGHBORING_CELL:
305 request = (MainThreadRequest) msg.obj;
306 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
307 request);
Sooraj Sasindran22882212016-07-18 11:57:25 -0700308 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309 break;
310
311 case EVENT_NEIGHBORING_CELL_DONE:
312 ar = (AsyncResult) msg.obj;
313 request = (MainThreadRequest) ar.userObj;
314 if (ar.exception == null && ar.result != null) {
315 request.result = ar.result;
316 } else {
317 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800318 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 }
320 // Wake up the requesting thread
321 synchronized (request) {
322 request.notifyAll();
323 }
324 break;
325
326 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700327 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800328 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700329 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 break;
331
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 case CMD_END_CALL:
333 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800334 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700335 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700336 Phone phone = getPhone(end_subId);
337 if (phone == null) {
338 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
339 break;
340 }
341 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
343 // CDMA: If the user presses the Power button we treat it as
344 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700345 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
347 // GSM: End the call as per the Phone state
348 hungUp = PhoneUtils.hangup(mCM);
349 } else {
350 throw new IllegalStateException("Unexpected phone type: " + phoneType);
351 }
352 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
353 request.result = hungUp;
354 // Wake up the requesting thread
355 synchronized (request) {
356 request.notifyAll();
357 }
358 break;
359
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700360 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700361 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700362 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800363 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700364 if (uiccCard == null) {
365 loge("iccTransmitApduLogicalChannel: No UICC");
366 request.result = new IccIoResult(0x6F, 0, (byte[])null);
367 synchronized (request) {
368 request.notifyAll();
369 }
370 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700371 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
372 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700373 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700374 iccArgument.channel, iccArgument.cla, iccArgument.command,
375 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700376 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700377 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700378 break;
379
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700380 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700381 ar = (AsyncResult) msg.obj;
382 request = (MainThreadRequest) ar.userObj;
383 if (ar.exception == null && ar.result != null) {
384 request.result = ar.result;
385 } else {
386 request.result = new IccIoResult(0x6F, 0, (byte[])null);
387 if (ar.result == null) {
388 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800389 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700390 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800391 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700392 } else {
393 loge("iccTransmitApduLogicalChannel: Unknown exception");
394 }
395 }
396 synchronized (request) {
397 request.notifyAll();
398 }
399 break;
400
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
402 request = (MainThreadRequest) msg.obj;
403 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800404 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700405 if (uiccCard == null) {
406 loge("iccTransmitApduBasicChannel: No UICC");
407 request.result = new IccIoResult(0x6F, 0, (byte[])null);
408 synchronized (request) {
409 request.notifyAll();
410 }
411 } else {
412 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
413 request);
414 uiccCard.iccTransmitApduBasicChannel(
415 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
416 iccArgument.p3, iccArgument.data, onCompleted);
417 }
418 break;
419
420 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
421 ar = (AsyncResult) msg.obj;
422 request = (MainThreadRequest) ar.userObj;
423 if (ar.exception == null && ar.result != null) {
424 request.result = ar.result;
425 } else {
426 request.result = new IccIoResult(0x6F, 0, (byte[])null);
427 if (ar.result == null) {
428 loge("iccTransmitApduBasicChannel: Empty response");
429 } else if (ar.exception instanceof CommandException) {
430 loge("iccTransmitApduBasicChannel: CommandException: " +
431 ar.exception);
432 } else {
433 loge("iccTransmitApduBasicChannel: Unknown exception");
434 }
435 }
436 synchronized (request) {
437 request.notifyAll();
438 }
439 break;
440
441 case CMD_EXCHANGE_SIM_IO:
442 request = (MainThreadRequest) msg.obj;
443 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800444 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 if (uiccCard == null) {
446 loge("iccExchangeSimIO: No UICC");
447 request.result = new IccIoResult(0x6F, 0, (byte[])null);
448 synchronized (request) {
449 request.notifyAll();
450 }
451 } else {
452 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
453 request);
454 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
455 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
456 iccArgument.data, onCompleted);
457 }
458 break;
459
460 case EVENT_EXCHANGE_SIM_IO_DONE:
461 ar = (AsyncResult) msg.obj;
462 request = (MainThreadRequest) ar.userObj;
463 if (ar.exception == null && ar.result != null) {
464 request.result = ar.result;
465 } else {
466 request.result = new IccIoResult(0x6f, 0, (byte[])null);
467 }
468 synchronized (request) {
469 request.notifyAll();
470 }
471 break;
472
Derek Tan4d5e5c12014-02-04 11:54:58 -0800473 case CMD_SEND_ENVELOPE:
474 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800475 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700476 if (uiccCard == null) {
477 loge("sendEnvelopeWithStatus: No UICC");
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
479 synchronized (request) {
480 request.notifyAll();
481 }
482 } else {
483 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
484 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
485 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800486 break;
487
488 case EVENT_SEND_ENVELOPE_DONE:
489 ar = (AsyncResult) msg.obj;
490 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700491 if (ar.exception == null && ar.result != null) {
492 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800493 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700494 request.result = new IccIoResult(0x6F, 0, (byte[])null);
495 if (ar.result == null) {
496 loge("sendEnvelopeWithStatus: Empty response");
497 } else if (ar.exception instanceof CommandException) {
498 loge("sendEnvelopeWithStatus: CommandException: " +
499 ar.exception);
500 } else {
501 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
502 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800503 }
504 synchronized (request) {
505 request.notifyAll();
506 }
507 break;
508
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 case CMD_OPEN_CHANNEL:
510 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800511 uiccCard = getUiccCardFromRequest(request);
Ajay Nambiabd73502015-12-03 13:50:00 -0800512 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700513 if (uiccCard == null) {
514 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800515 request.result = new IccOpenLogicalChannelResponse(-1,
516 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700517 synchronized (request) {
518 request.notifyAll();
519 }
520 } else {
521 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambiabd73502015-12-03 13:50:00 -0800522 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
523 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700524 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700525 break;
526
527 case EVENT_OPEN_CHANNEL_DONE:
528 ar = (AsyncResult) msg.obj;
529 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700531 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 int[] result = (int[]) ar.result;
533 int channelId = result[0];
534 byte[] selectResponse = null;
535 if (result.length > 1) {
536 selectResponse = new byte[result.length - 1];
537 for (int i = 1; i < result.length; ++i) {
538 selectResponse[i - 1] = (byte) result[i];
539 }
540 }
541 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700542 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 if (ar.result == null) {
545 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 if (ar.exception != null) {
548 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
549 }
550
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700551 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700552 if (ar.exception instanceof CommandException) {
553 CommandException.Error error =
554 ((CommandException) (ar.exception)).getCommandError();
555 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700556 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700557 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700558 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 }
560 }
561 openChannelResp = new IccOpenLogicalChannelResponse(
562 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700564 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 synchronized (request) {
566 request.notifyAll();
567 }
568 break;
569
570 case CMD_CLOSE_CHANNEL:
571 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800572 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700573 if (uiccCard == null) {
574 loge("iccCloseLogicalChannel: No UICC");
575 request.result = new IccIoResult(0x6F, 0, (byte[])null);
576 synchronized (request) {
577 request.notifyAll();
578 }
579 } else {
580 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
581 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
582 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 break;
584
585 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800586 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
587 break;
588
589 case CMD_NV_READ_ITEM:
590 request = (MainThreadRequest) msg.obj;
591 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
592 mPhone.nvReadItem((Integer) request.argument, onCompleted);
593 break;
594
595 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800598 if (ar.exception == null && ar.result != null) {
599 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800601 request.result = "";
602 if (ar.result == null) {
603 loge("nvReadItem: Empty response");
604 } else if (ar.exception instanceof CommandException) {
605 loge("nvReadItem: CommandException: " +
606 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800608 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 }
610 }
611 synchronized (request) {
612 request.notifyAll();
613 }
614 break;
615
Jake Hambye994d462014-02-03 13:10:13 -0800616 case CMD_NV_WRITE_ITEM:
617 request = (MainThreadRequest) msg.obj;
618 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
619 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
620 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
621 break;
622
623 case EVENT_NV_WRITE_ITEM_DONE:
624 handleNullReturnEvent(msg, "nvWriteItem");
625 break;
626
627 case CMD_NV_WRITE_CDMA_PRL:
628 request = (MainThreadRequest) msg.obj;
629 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
630 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
631 break;
632
633 case EVENT_NV_WRITE_CDMA_PRL_DONE:
634 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
635 break;
636
637 case CMD_NV_RESET_CONFIG:
638 request = (MainThreadRequest) msg.obj;
639 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
640 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
641 break;
642
643 case EVENT_NV_RESET_CONFIG_DONE:
644 handleNullReturnEvent(msg, "nvResetConfig");
645 break;
646
Jake Hamby7c27be32014-03-03 13:25:59 -0800647 case CMD_GET_PREFERRED_NETWORK_TYPE:
648 request = (MainThreadRequest) msg.obj;
649 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700650 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800651 break;
652
653 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result; // Integer
658 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800659 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800660 if (ar.result == null) {
661 loge("getPreferredNetworkType: Empty response");
662 } else if (ar.exception instanceof CommandException) {
663 loge("getPreferredNetworkType: CommandException: " +
664 ar.exception);
665 } else {
666 loge("getPreferredNetworkType: Unknown exception");
667 }
668 }
669 synchronized (request) {
670 request.notifyAll();
671 }
672 break;
673
674 case CMD_SET_PREFERRED_NETWORK_TYPE:
675 request = (MainThreadRequest) msg.obj;
676 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
677 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700678 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800679 break;
680
681 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
682 handleNullReturnEvent(msg, "setPreferredNetworkType");
683 break;
684
Steven Liu4bf01bc2014-07-17 11:05:29 -0500685 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
686 request = (MainThreadRequest)msg.obj;
687 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
688 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
689 break;
690
691 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
692 ar = (AsyncResult)msg.obj;
693 request = (MainThreadRequest)ar.userObj;
694 request.result = ar;
695 synchronized (request) {
696 request.notifyAll();
697 }
698 break;
699
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800700 case CMD_SET_VOICEMAIL_NUMBER:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
703 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800704 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
705 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800706 break;
707
708 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
709 handleNullReturnEvent(msg, "setVoicemailNumber");
710 break;
711
Stuart Scott54788802015-03-30 13:18:01 -0700712 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
713 request = (MainThreadRequest) msg.obj;
714 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
715 request);
716 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
717 break;
718
719 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
720 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
721 break;
722
Shishir Agrawal302c8692015-06-19 13:49:39 -0700723 case CMD_PERFORM_NETWORK_SCAN:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
726 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
727 break;
728
729 case EVENT_PERFORM_NETWORK_SCAN_DONE:
730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
732 CellNetworkScanResult cellScanResult;
733 if (ar.exception == null && ar.result != null) {
734 cellScanResult = new CellNetworkScanResult(
735 CellNetworkScanResult.STATUS_SUCCESS,
736 (List<OperatorInfo>) ar.result);
737 } else {
738 if (ar.result == null) {
739 loge("getCellNetworkScanResults: Empty response");
740 }
741 if (ar.exception != null) {
742 loge("getCellNetworkScanResults: Exception: " + ar.exception);
743 }
744 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
745 if (ar.exception instanceof CommandException) {
746 CommandException.Error error =
747 ((CommandException) (ar.exception)).getCommandError();
748 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
749 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
750 } else if (error == CommandException.Error.GENERIC_FAILURE) {
751 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
752 }
753 }
754 cellScanResult = new CellNetworkScanResult(errorCode, null);
755 }
756 request.result = cellScanResult;
757 synchronized (request) {
758 request.notifyAll();
759 }
760 break;
761
762 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
763 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700764 ManualNetworkSelectionArgument selArg =
765 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700766 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
767 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700768 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
769 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700770 break;
771
772 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
773 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
774 break;
775
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700776 case CMD_GET_MODEM_ACTIVITY_INFO:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700779 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700780 break;
781
782 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
783 ar = (AsyncResult) msg.obj;
784 request = (MainThreadRequest) ar.userObj;
785 if (ar.exception == null && ar.result != null) {
786 request.result = ar.result;
787 } else {
788 if (ar.result == null) {
789 loge("queryModemActivityInfo: Empty response");
790 } else if (ar.exception instanceof CommandException) {
791 loge("queryModemActivityInfo: CommandException: " +
792 ar.exception);
793 } else {
794 loge("queryModemActivityInfo: Unknown exception");
795 }
796 }
Amit Mahajand4766222016-01-28 15:28:28 -0800797 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
798 if (request.result == null) {
799 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
800 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700801 synchronized (request) {
802 request.notifyAll();
803 }
804 break;
805
Meng Wang1a7c35a2016-05-05 20:56:15 -0700806 case CMD_SET_ALLOWED_CARRIERS:
807 request = (MainThreadRequest) msg.obj;
808 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
809 mPhone.setAllowedCarriers(
810 (List<CarrierIdentifier>) request.argument,
811 onCompleted);
812 break;
813
814 case EVENT_SET_ALLOWED_CARRIERS_DONE:
815 ar = (AsyncResult) msg.obj;
816 request = (MainThreadRequest) ar.userObj;
817 if (ar.exception == null && ar.result != null) {
818 request.result = ar.result;
819 } else {
820 if (ar.result == null) {
821 loge("setAllowedCarriers: Empty response");
822 } else if (ar.exception instanceof CommandException) {
823 loge("setAllowedCarriers: CommandException: " +
824 ar.exception);
825 } else {
826 loge("setAllowedCarriers: Unknown exception");
827 }
828 }
829 // Result cannot be null. Return -1 on error.
830 if (request.result == null) {
831 request.result = new int[]{-1};
832 }
833 synchronized (request) {
834 request.notifyAll();
835 }
836 break;
837
838 case CMD_GET_ALLOWED_CARRIERS:
839 request = (MainThreadRequest) msg.obj;
840 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
841 mPhone.getAllowedCarriers(onCompleted);
842 break;
843
844 case EVENT_GET_ALLOWED_CARRIERS_DONE:
845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
847 if (ar.exception == null && ar.result != null) {
848 request.result = ar.result;
849 } else {
850 if (ar.result == null) {
851 loge("getAllowedCarriers: Empty response");
852 } else if (ar.exception instanceof CommandException) {
853 loge("getAllowedCarriers: CommandException: " +
854 ar.exception);
855 } else {
856 loge("getAllowedCarriers: Unknown exception");
857 }
858 }
859 // Result cannot be null. Return empty list of CarrierIdentifier.
860 if (request.result == null) {
861 request.result = new ArrayList<CarrierIdentifier>(0);
862 }
863 synchronized (request) {
864 request.notifyAll();
865 }
866 break;
867
Nathan Haroldb3014052017-01-25 15:57:32 -0800868 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
874 request.result = new IllegalArgumentException(
875 "Failed to retrieve Forbidden Plmns");
876 if (ar.result == null) {
877 loge("getForbiddenPlmns: Empty response");
878 } else {
879 loge("getForbiddenPlmns: Unknown exception");
880 }
881 }
882 synchronized (request) {
883 request.notifyAll();
884 }
885 break;
886
887 case CMD_GET_FORBIDDEN_PLMNS:
888 request = (MainThreadRequest) msg.obj;
889 uiccCard = getUiccCardFromRequest(request);
890 if (uiccCard == null) {
891 loge("getForbiddenPlmns() UiccCard is null");
892 request.result = new IllegalArgumentException(
893 "getForbiddenPlmns() UiccCard is null");
894 synchronized (request) {
895 request.notifyAll();
896 }
897 break;
898 }
899 Integer appType = (Integer) request.argument;
900 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
901 if (uiccApp == null) {
902 loge("getForbiddenPlmns() no app with specified type -- "
903 + appType);
904 request.result = new IllegalArgumentException("Failed to get UICC App");
905 synchronized (request) {
906 request.notifyAll();
907 }
908 break;
909 } else {
910 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
911 + " specified type -- " + appType);
912 }
913 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
914 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
915 onCompleted);
916 break;
917
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700918 default:
919 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
920 break;
921 }
922 }
Jake Hambye994d462014-02-03 13:10:13 -0800923
924 private void handleNullReturnEvent(Message msg, String command) {
925 AsyncResult ar = (AsyncResult) msg.obj;
926 MainThreadRequest request = (MainThreadRequest) ar.userObj;
927 if (ar.exception == null) {
928 request.result = true;
929 } else {
930 request.result = false;
931 if (ar.exception instanceof CommandException) {
932 loge(command + ": CommandException: " + ar.exception);
933 } else {
934 loge(command + ": Unknown exception");
935 }
936 }
937 synchronized (request) {
938 request.notifyAll();
939 }
940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700941 }
942
943 /**
944 * Posts the specified command to be executed on the main thread,
945 * waits for the request to complete, and returns the result.
946 * @see #sendRequestAsync
947 */
948 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800949 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700950 }
951
952 /**
953 * Posts the specified command to be executed on the main thread,
954 * waits for the request to complete, and returns the result.
955 * @see #sendRequestAsync
956 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800957 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700958 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
959 throw new RuntimeException("This method will deadlock if called from the main thread.");
960 }
961
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800962 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700963 Message msg = mMainThreadHandler.obtainMessage(command, request);
964 msg.sendToTarget();
965
966 // Wait for the request to complete
967 synchronized (request) {
968 while (request.result == null) {
969 try {
970 request.wait();
971 } catch (InterruptedException e) {
972 // Do nothing, go back and wait until the request is complete
973 }
974 }
975 }
976 return request.result;
977 }
978
979 /**
980 * Asynchronous ("fire and forget") version of sendRequest():
981 * Posts the specified command to be executed on the main thread, and
982 * returns immediately.
983 * @see #sendRequest
984 */
985 private void sendRequestAsync(int command) {
986 mMainThreadHandler.sendEmptyMessage(command);
987 }
988
989 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -0700990 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
991 * @see {@link #sendRequest(int,Object)}
992 */
993 private void sendRequestAsync(int command, Object argument) {
994 MainThreadRequest request = new MainThreadRequest(argument);
995 Message msg = mMainThreadHandler.obtainMessage(command, request);
996 msg.sendToTarget();
997 }
998
999 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001000 * Initialize the singleton PhoneInterfaceManager instance.
1001 * This is only done once, at startup, from PhoneApp.onCreate().
1002 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001003 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001004 synchronized (PhoneInterfaceManager.class) {
1005 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001006 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001007 } else {
1008 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1009 }
1010 return sInstance;
1011 }
1012 }
1013
1014 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001015 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001016 mApp = app;
1017 mPhone = phone;
1018 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001019 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001020 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1021 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001022 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001023 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001024 mSubscriptionController = SubscriptionController.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001025
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 publish();
1027 }
1028
1029 private void publish() {
1030 if (DBG) log("publish: " + this);
1031
1032 ServiceManager.addService("phone", this);
1033 }
1034
Stuart Scott584921c2015-01-15 17:10:34 -08001035 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001036 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1037 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001038 }
1039
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001040 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1041 Phone phone = getPhoneFromRequest(request);
1042 return phone == null ? null :
1043 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1044 }
1045
Wink Saville36469e72014-06-11 15:17:00 -07001046 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001047 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001048 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001049 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001050 //
1051 // Implementation of the ITelephony interface.
1052 //
1053
1054 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001055 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001056 }
1057
Wink Savilleb564aae2014-10-23 10:18:09 -07001058 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001059 if (DBG) log("dial: " + number);
1060 // No permission check needed here: This is just a wrapper around the
1061 // ACTION_DIAL intent, which is available to any app since it puts up
1062 // the UI before it does anything.
1063
1064 String url = createTelUrl(number);
1065 if (url == null) {
1066 return;
1067 }
1068
1069 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001070 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001071 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1072 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1073 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1074 mApp.startActivity(intent);
1075 }
1076 }
1077
1078 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001079 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001080 }
1081
Wink Savilleb564aae2014-10-23 10:18:09 -07001082 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 if (DBG) log("call: " + number);
1084
1085 // This is just a wrapper around the ACTION_CALL intent, but we still
1086 // need to do a permission check since we're calling startActivity()
1087 // from the context of the phone app.
1088 enforceCallPermission();
1089
1090 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1091 != AppOpsManager.MODE_ALLOWED) {
1092 return;
1093 }
1094
1095 String url = createTelUrl(number);
1096 if (url == null) {
1097 return;
1098 }
1099
Wink Saville08874612014-08-31 19:19:58 -07001100 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001101 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001102 if (slist != null) {
1103 for (SubscriptionInfo subInfoRecord : slist) {
1104 if (subInfoRecord.getSubscriptionId() == subId) {
1105 isValid = true;
1106 break;
1107 }
Wink Saville08874612014-08-31 19:19:58 -07001108 }
1109 }
1110 if (isValid == false) {
1111 return;
1112 }
1113
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001115 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001116 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1117 mApp.startActivity(intent);
1118 }
1119
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001120 /**
1121 * End a call based on call state
1122 * @return true is a call was ended
1123 */
1124 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001125 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001126 }
1127
1128 /**
1129 * End a call based on the call state of the subId
1130 * @return true is a call was ended
1131 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001132 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001133 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001134 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 }
1136
1137 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001138 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001139 }
1140
Wink Savilleb564aae2014-10-23 10:18:09 -07001141 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 if (DBG) log("answerRingingCall...");
1143 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1144 // but that can probably wait till the big TelephonyManager API overhaul.
1145 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1146 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001147 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 }
1149
1150 /**
1151 * Make the actual telephony calls to implement answerRingingCall().
1152 * This should only be called from the main thread of the Phone app.
1153 * @see #answerRingingCall
1154 *
1155 * TODO: it would be nice to return true if we answered the call, or
1156 * false if there wasn't actually a ringing incoming call, or some
1157 * other error occurred. (In other words, pass back the return value
1158 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1159 * But that would require calling this method via sendRequest() rather
1160 * than sendRequestAsync(), and right now we don't actually *need* that
1161 * return value, so let's just return void for now.
1162 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001163 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001164 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001166 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1167 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 if (hasActiveCall && hasHoldingCall) {
1169 // Both lines are in use!
1170 // TODO: provide a flag to let the caller specify what
1171 // policy to use if both lines are in use. (The current
1172 // behavior is hardwired to "answer incoming, end ongoing",
1173 // which is how the CALL button is specced to behave.)
1174 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1175 return;
1176 } else {
1177 // answerCall() will automatically hold the current active
1178 // call, if there is one.
1179 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1180 return;
1181 }
1182 } else {
1183 // No call was ringing.
1184 return;
1185 }
1186 }
1187
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001189 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001191 public void silenceRinger() {
1192 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001193 }
1194
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001195 @Override
1196 public boolean isOffhook(String callingPackage) {
1197 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001198 }
1199
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001200 @Override
1201 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1202 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1203 return false;
1204 }
1205
Sanket Padawe356d7632015-06-22 14:03:32 -07001206 final Phone phone = getPhone(subId);
1207 if (phone != null) {
1208 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1209 } else {
1210 return false;
1211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001212 }
1213
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001214 @Override
1215 public boolean isRinging(String callingPackage) {
1216 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001217 }
1218
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001219 @Override
1220 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1221 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1222 return false;
1223 }
1224
Sanket Padawe356d7632015-06-22 14:03:32 -07001225 final Phone phone = getPhone(subId);
1226 if (phone != null) {
1227 return (phone.getState() == PhoneConstants.State.RINGING);
1228 } else {
1229 return false;
1230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 }
1232
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001233 @Override
1234 public boolean isIdle(String callingPackage) {
1235 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001236 }
1237
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001238 @Override
1239 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1240 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1241 return false;
1242 }
1243
Sanket Padawe356d7632015-06-22 14:03:32 -07001244 final Phone phone = getPhone(subId);
1245 if (phone != null) {
1246 return (phone.getState() == PhoneConstants.State.IDLE);
1247 } else {
1248 return false;
1249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 }
1251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001253 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001254 }
1255
Wink Savilleb564aae2014-10-23 10:18:09 -07001256 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001257 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001258 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1259 }
1260
1261 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001262 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001263 }
1264
Wink Savilleb564aae2014-10-23 10:18:09 -07001265 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001266 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001267 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1268 }
1269
1270 /** {@hide} */
1271 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001272 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001273 }
1274
Wink Savilleb564aae2014-10-23 10:18:09 -07001275 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001277 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 checkSimPin.start();
1279 return checkSimPin.unlockSim(null, pin);
1280 }
1281
Wink Saville9de0f752013-10-22 19:04:03 -07001282 /** {@hide} */
1283 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001284 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001285 }
1286
Wink Savilleb564aae2014-10-23 10:18:09 -07001287 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001289 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 checkSimPuk.start();
1291 return checkSimPuk.unlockSim(puk, pin);
1292 }
1293
1294 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001295 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001296 * a synchronous one.
1297 */
1298 private static class UnlockSim extends Thread {
1299
1300 private final IccCard mSimCard;
1301
1302 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001303 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1304 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305
1306 // For replies from SimCard interface
1307 private Handler mHandler;
1308
1309 // For async handler to identify request type
1310 private static final int SUPPLY_PIN_COMPLETE = 100;
1311
1312 public UnlockSim(IccCard simCard) {
1313 mSimCard = simCard;
1314 }
1315
1316 @Override
1317 public void run() {
1318 Looper.prepare();
1319 synchronized (UnlockSim.this) {
1320 mHandler = new Handler() {
1321 @Override
1322 public void handleMessage(Message msg) {
1323 AsyncResult ar = (AsyncResult) msg.obj;
1324 switch (msg.what) {
1325 case SUPPLY_PIN_COMPLETE:
1326 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1327 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001328 mRetryCount = msg.arg1;
1329 if (ar.exception != null) {
1330 if (ar.exception instanceof CommandException &&
1331 ((CommandException)(ar.exception)).getCommandError()
1332 == CommandException.Error.PASSWORD_INCORRECT) {
1333 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1334 } else {
1335 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1336 }
1337 } else {
1338 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001340 mDone = true;
1341 UnlockSim.this.notifyAll();
1342 }
1343 break;
1344 }
1345 }
1346 };
1347 UnlockSim.this.notifyAll();
1348 }
1349 Looper.loop();
1350 }
1351
1352 /*
1353 * Use PIN or PUK to unlock SIM card
1354 *
1355 * If PUK is null, unlock SIM card with PIN
1356 *
1357 * If PUK is not null, unlock SIM card with PUK and set PIN code
1358 */
Wink Saville9de0f752013-10-22 19:04:03 -07001359 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360
1361 while (mHandler == null) {
1362 try {
1363 wait();
1364 } catch (InterruptedException e) {
1365 Thread.currentThread().interrupt();
1366 }
1367 }
1368 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1369
1370 if (puk == null) {
1371 mSimCard.supplyPin(pin, callback);
1372 } else {
1373 mSimCard.supplyPuk(puk, pin, callback);
1374 }
1375
1376 while (!mDone) {
1377 try {
1378 Log.d(LOG_TAG, "wait for done");
1379 wait();
1380 } catch (InterruptedException e) {
1381 // Restore the interrupted status
1382 Thread.currentThread().interrupt();
1383 }
1384 }
1385 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001386 int[] resultArray = new int[2];
1387 resultArray[0] = mResult;
1388 resultArray[1] = mRetryCount;
1389 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 }
1391 }
1392
1393 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001394 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001395
1396 }
1397
Wink Savilleb564aae2014-10-23 10:18:09 -07001398 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 // No permission check needed here: this call is harmless, and it's
1400 // needed for the ServiceState.requestStateUpdate() call (which is
1401 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001402 final Phone phone = getPhone(subId);
1403 if (phone != null) {
1404 phone.updateServiceLocation();
1405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 }
1407
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001408 @Override
1409 public boolean isRadioOn(String callingPackage) {
1410 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001411 }
1412
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001413 @Override
1414 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1415 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1416 return false;
1417 }
1418 return isRadioOnForSubscriber(subId);
1419 }
1420
1421 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001422 final Phone phone = getPhone(subId);
1423 if (phone != null) {
1424 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1425 } else {
1426 return false;
1427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 }
1429
1430 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001431 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001432
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433 }
Wink Saville36469e72014-06-11 15:17:00 -07001434
Wink Savilleb564aae2014-10-23 10:18:09 -07001435 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001436 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001437 final Phone phone = getPhone(subId);
1438 if (phone != null) {
1439 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1440 }
Wink Saville36469e72014-06-11 15:17:00 -07001441 }
1442
1443 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001444 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001445 }
1446
Wink Savilleb564aae2014-10-23 10:18:09 -07001447 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001448 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001449 final Phone phone = getPhone(subId);
1450 if (phone == null) {
1451 return false;
1452 }
1453 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001454 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 }
1457 return true;
1458 }
Wink Saville36469e72014-06-11 15:17:00 -07001459
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001460 public boolean needMobileRadioShutdown() {
1461 /*
1462 * If any of the Radios are available, it will need to be
1463 * shutdown. So return true if any Radio is available.
1464 */
1465 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1466 Phone phone = PhoneFactory.getPhone(i);
1467 if (phone != null && phone.isRadioAvailable()) return true;
1468 }
1469 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1470 return false;
1471 }
1472
1473 public void shutdownMobileRadios() {
1474 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1475 logv("Shutting down Phone " + i);
1476 shutdownRadioUsingPhoneId(i);
1477 }
1478 }
1479
1480 private void shutdownRadioUsingPhoneId(int phoneId) {
1481 enforceModifyPermission();
1482 Phone phone = PhoneFactory.getPhone(phoneId);
1483 if (phone != null && phone.isRadioAvailable()) {
1484 phone.shutdownRadio();
1485 }
1486 }
1487
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 public boolean setRadioPower(boolean turnOn) {
Wei Liu9ae2a062016-08-08 11:09:34 -07001489 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1490 if (defaultPhone != null) {
1491 defaultPhone.setRadioPower(turnOn);
1492 return true;
1493 } else {
1494 loge("There's no default phone.");
1495 return false;
1496 }
Wink Saville36469e72014-06-11 15:17:00 -07001497 }
1498
Wink Savilleb564aae2014-10-23 10:18:09 -07001499 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001501 final Phone phone = getPhone(subId);
1502 if (phone != null) {
1503 phone.setRadioPower(turnOn);
1504 return true;
1505 } else {
1506 return false;
1507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 }
1509
Wink Saville36469e72014-06-11 15:17:00 -07001510 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001511 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 public boolean enableDataConnectivity() {
1513 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001514 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001515 final Phone phone = getPhone(subId);
1516 if (phone != null) {
1517 phone.setDataEnabled(true);
1518 return true;
1519 } else {
1520 return false;
1521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 }
1523
Wink Saville36469e72014-06-11 15:17:00 -07001524 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001525 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 public boolean disableDataConnectivity() {
1527 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001528 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001529 final Phone phone = getPhone(subId);
1530 if (phone != null) {
1531 phone.setDataEnabled(false);
1532 return true;
1533 } else {
1534 return false;
1535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537
Wink Saville36469e72014-06-11 15:17:00 -07001538 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001539 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001540 public boolean isDataConnectivityPossible() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001541 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001542 final Phone phone = getPhone(subId);
1543 if (phone != null) {
1544 return phone.isDataConnectivityPossible();
1545 } else {
1546 return false;
1547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 }
1549
1550 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001551 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001552 }
1553
pkanwarf8520782016-11-06 20:37:09 -08001554 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar7e856482016-10-14 19:37:38 -07001555 enforceCallPermission();
pkanwar7e856482016-10-14 19:37:38 -07001556 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1557 return;
1558 }
1559 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1560 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1561 };
1562
Wink Savilleb564aae2014-10-23 10:18:09 -07001563 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001565 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1566 return false;
1567 }
Wink Saville36469e72014-06-11 15:17:00 -07001568 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
1570
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001572 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001573 }
1574
Sanket Padawe5780e442017-03-20 15:04:47 -07001575 public int getCallStateForSlot(int slotIndex) {
1576 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001577 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1578 DefaultPhoneNotifier.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 }
1580
Sanket Padawe356d7632015-06-22 14:03:32 -07001581 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001583 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001584 if (phone != null) {
1585 return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
1586 } else {
1587 return DefaultPhoneNotifier.convertDataState(PhoneConstants.DataState.DISCONNECTED);
1588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 }
1590
Sanket Padawe356d7632015-06-22 14:03:32 -07001591 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001593 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 if (phone != null) {
1595 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1596 } else {
1597 return TelephonyManager.DATA_ACTIVITY_NONE;
1598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
1600
1601 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001602 public Bundle getCellLocation(String callingPackage) {
1603 enforceFineOrCoarseLocationPermission("getCellLocation");
1604
1605 // OP_COARSE_LOCATION controls both fine and coarse location.
1606 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1607 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001608 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001609 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 }
1611
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001612 if (checkIfCallerIsSelfOrForegroundUser() ||
1613 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 if (DBG_LOC) log("getCellLocation: is active user");
1615 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001616 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 if (phone == null) {
1618 return null;
1619 }
Sooraj Sasindran22882212016-07-18 11:57:25 -07001620
1621 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1622 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 return data;
1624 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001625 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001626 return null;
1627 }
1628 }
1629
Svetoslav64fad262015-04-14 14:35:21 -07001630 private void enforceFineOrCoarseLocationPermission(String message) {
1631 try {
1632 mApp.enforceCallingOrSelfPermission(
1633 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1634 } catch (SecurityException e) {
1635 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1636 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1637 // is the weaker precondition
1638 mApp.enforceCallingOrSelfPermission(
1639 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1640 }
1641 }
1642
1643
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 @Override
1645 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001646 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001647 }
1648
Sanket Padawe356d7632015-06-22 14:03:32 -07001649 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001650 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 mApp.enforceCallingOrSelfPermission(
1652 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 final Phone phone = getPhone(subId);
1654 if (phone != null) {
1655 phone.enableLocationUpdates();
1656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 }
1658
1659 @Override
1660 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001661 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001662 }
1663
Sanket Padawe356d7632015-06-22 14:03:32 -07001664 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001665 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 mApp.enforceCallingOrSelfPermission(
1667 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 final Phone phone = getPhone(subId);
1669 if (phone != null) {
1670 phone.disableLocationUpdates();
1671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 }
1673
1674 @Override
1675 @SuppressWarnings("unchecked")
1676 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001677 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1678
1679 // OP_COARSE_LOCATION controls both fine and coarse location.
1680 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1681 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1682 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 }
1684
1685 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1686 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1687 return null;
1688 }
Svetoslav64fad262015-04-14 14:35:21 -07001689
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001690 if (checkIfCallerIsSelfOrForegroundUser() ||
1691 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1693
1694 ArrayList<NeighboringCellInfo> cells = null;
1695
Sooraj Sasindran22882212016-07-18 11:57:25 -07001696 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 try {
1698 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran22882212016-07-18 11:57:25 -07001699 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001700 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001702 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704 return cells;
1705 } else {
1706 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1707 return null;
1708 }
1709 }
1710
1711
1712 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001713 public List<CellInfo> getAllCellInfo(String callingPackage) {
1714 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1715
1716 // OP_COARSE_LOCATION controls both fine and coarse location.
1717 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1718 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1719 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 }
1721
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001722 if (checkIfCallerIsSelfOrForegroundUser() ||
1723 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran22882212016-07-18 11:57:25 -07001725 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001726 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1727 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran22882212016-07-18 11:57:25 -07001728 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1729 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001730 }
1731 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 } else {
1733 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1734 return null;
1735 }
1736 }
1737
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001738 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 public void setCellInfoListRate(int rateInMillis) {
Jack Yu3128d9e2017-01-16 10:15:34 -08001740 enforceModifyPermission();
Sooraj Sasindran22882212016-07-18 11:57:25 -07001741 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1742 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
1744
Shishir Agrawala9f32182016-04-12 12:00:16 -07001745 @Override
Sanket Padawe5780e442017-03-20 15:04:47 -07001746 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001747 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1748 return null;
1749 }
Sanket Padawe5780e442017-03-20 15:04:47 -07001750 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001751 return phone == null ? null : phone.getImei();
1752 }
1753
1754 @Override
Jack Yuf7e8f152017-03-15 17:14:14 -07001755 public String getMeidForSlot(int slotIndex, String callingPackage) {
1756 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1757 return null;
1758 }
1759 Phone phone = PhoneFactory.getPhone(slotIndex);
1760 return phone == null ? null : phone.getMeid();
1761 }
1762
1763 @Override
Sanket Padawe5780e442017-03-20 15:04:47 -07001764 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001765 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1766 return null;
1767 }
Sanket Padawe5780e442017-03-20 15:04:47 -07001768 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001769 return phone == null ? null : phone.getDeviceSvn();
1770 }
1771
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 //
1773 // Internal helper methods.
1774 //
1775
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001776 /**
1777 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1778 */
1779 private boolean checkCallerInteractAcrossUsersFull() {
1780 return mPhone.getContext().checkCallingOrSelfPermission(
1781 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1782 == PackageManager.PERMISSION_GRANTED;
1783 }
1784
Jake Hambye994d462014-02-03 13:10:13 -08001785 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 boolean ok;
1787
1788 boolean self = Binder.getCallingUid() == Process.myUid();
1789 if (!self) {
1790 // Get the caller's user id then clear the calling identity
1791 // which will be restored in the finally clause.
1792 int callingUser = UserHandle.getCallingUserId();
1793 long ident = Binder.clearCallingIdentity();
1794
1795 try {
1796 // With calling identity cleared the current user is the foreground user.
1797 int foregroundUser = ActivityManager.getCurrentUser();
1798 ok = (foregroundUser == callingUser);
1799 if (DBG_LOC) {
1800 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1801 + " callingUser=" + callingUser + " ok=" + ok);
1802 }
1803 } catch (Exception ex) {
1804 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1805 ok = false;
1806 } finally {
1807 Binder.restoreCallingIdentity(ident);
1808 }
1809 } else {
1810 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1811 ok = true;
1812 }
1813 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1814 return ok;
1815 }
1816
1817 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1819 *
1820 * @throws SecurityException if the caller does not have the required permission
1821 */
1822 private void enforceModifyPermission() {
1823 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1824 }
1825
1826 /**
Junda Liua2e36012014-07-09 18:30:01 -07001827 * Make sure either system app or the caller has carrier privilege.
1828 *
1829 * @throws SecurityException if the caller does not have the required permission/privilege
1830 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001831 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001832 int permission = mApp.checkCallingOrSelfPermission(
1833 android.Manifest.permission.MODIFY_PHONE_STATE);
1834 if (permission == PackageManager.PERMISSION_GRANTED) {
1835 return;
1836 }
1837
1838 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001839 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001840 }
1841
1842 /**
1843 * Make sure the caller has carrier privilege.
1844 *
1845 * @throws SecurityException if the caller does not have the required permission
1846 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001847 private void enforceCarrierPrivilege(int subId) {
1848 if (getCarrierPrivilegeStatus(subId) !=
1849 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001850 loge("No Carrier Privilege.");
1851 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001852 }
1853 }
1854
1855 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 * Make sure the caller has the CALL_PHONE permission.
1857 *
1858 * @throws SecurityException if the caller does not have the required permission
1859 */
1860 private void enforceCallPermission() {
1861 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1862 }
1863
Stuart Scott8eef64f2015-04-08 15:13:54 -07001864 private void enforceConnectivityInternalPermission() {
1865 mApp.enforceCallingOrSelfPermission(
1866 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1867 "ConnectivityService");
1868 }
1869
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 private String createTelUrl(String number) {
1871 if (TextUtils.isEmpty(number)) {
1872 return null;
1873 }
1874
Jake Hambye994d462014-02-03 13:10:13 -08001875 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 }
1877
Ihab Awadf9e92732013-12-05 18:02:52 -08001878 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1880 }
1881
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001882 private static void logv(String msg) {
1883 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1884 }
1885
Ihab Awadf9e92732013-12-05 18:02:52 -08001886 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1888 }
1889
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001890 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001892 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Sanket Padawe5780e442017-03-20 15:04:47 -07001896 public int getActivePhoneTypeForSlot(int slotIndex) {
1897 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 if (phone == null) {
1899 return PhoneConstants.PHONE_TYPE_NONE;
1900 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001901 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905 /**
1906 * Returns the CDMA ERI icon index to display
1907 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001908 @Override
1909 public int getCdmaEriIconIndex(String callingPackage) {
1910 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001911 }
1912
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001914 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1915 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1916 return -1;
1917 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001918 final Phone phone = getPhone(subId);
1919 if (phone != null) {
1920 return phone.getCdmaEriIconIndex();
1921 } else {
1922 return -1;
1923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 }
1925
1926 /**
1927 * Returns the CDMA ERI icon mode,
1928 * 0 - ON
1929 * 1 - FLASHING
1930 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001931 @Override
1932 public int getCdmaEriIconMode(String callingPackage) {
1933 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001934 }
1935
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001937 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1938 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1939 return -1;
1940 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 final Phone phone = getPhone(subId);
1942 if (phone != null) {
1943 return phone.getCdmaEriIconMode();
1944 } else {
1945 return -1;
1946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948
1949 /**
1950 * Returns the CDMA ERI text,
1951 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001952 @Override
1953 public String getCdmaEriText(String callingPackage) {
1954 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001955 }
1956
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001958 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1959 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1960 return null;
1961 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001962 final Phone phone = getPhone(subId);
1963 if (phone != null) {
1964 return phone.getCdmaEriText();
1965 } else {
1966 return null;
1967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
1970 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001971 * Returns the CDMA MDN.
1972 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001974 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001975 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 final Phone phone = getPhone(subId);
1977 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1978 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001979 } else {
1980 return null;
1981 }
1982 }
1983
1984 /**
1985 * Returns the CDMA MIN.
1986 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001988 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001989 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 final Phone phone = getPhone(subId);
1991 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1992 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001993 } else {
1994 return null;
1995 }
1996 }
1997
1998 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 * Returns true if CDMA provisioning needs to run.
2000 */
2001 public boolean needsOtaServiceProvisioning() {
2002 return mPhone.needsOtaServiceProvisioning();
2003 }
2004
2005 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002006 * Sets the voice mail number of a given subId.
2007 */
2008 @Override
2009 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002010 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002011 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2012 new Pair<String, String>(alphaTag, number), new Integer(subId));
2013 return success;
2014 }
2015
Ta-wei Yen87c49842016-05-13 21:19:52 -07002016 @Override
Ta-wei Yenb0f695b2016-08-08 17:33:11 -07002017 public void setVisualVoicemailEnabled(String callingPackage,
2018 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
2019 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2020 if (!TextUtils.equals(callingPackage,
2021 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
2022 enforceModifyPermissionOrCarrierPrivilege(
2023 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
2024 }
2025 VisualVoicemailSettingsUtil.setEnabled(mPhone.getContext(), phoneAccountHandle, enabled);
2026 }
2027
2028 @Override
2029 public boolean isVisualVoicemailEnabled(String callingPackage,
2030 PhoneAccountHandle phoneAccountHandle) {
2031 if (!canReadPhoneState(callingPackage, "isVisualVoicemailEnabled")) {
2032 return false;
2033 }
2034 return VisualVoicemailSettingsUtil.isEnabled(mPhone.getContext(), phoneAccountHandle);
2035 }
2036
2037 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002038 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2039 VisualVoicemailSmsFilterSettings settings) {
2040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002041 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002042 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2043 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002044 }
2045
2046 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002047 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2048 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002049 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002050 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002051 }
2052
2053 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002054 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2055 String callingPackage, int subId) {
2056 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002057 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002058 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002059 }
2060
2061 @Override
Ta-wei Yen1b455992016-12-27 14:52:32 -08002062 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002063 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002064 return VisualVoicemailSmsFilterConfig
Ta-wei Yen1b455992016-12-27 14:52:32 -08002065 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2066 }
2067
2068 @Override
2069 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2070 String number, int port, String text, PendingIntent sentIntent) {
2071 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen463efd12017-01-06 15:29:25 -08002072 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen1b455992016-12-27 14:52:32 -08002073 enforceSendSmsPermission();
2074 // Make the calls as the phone process.
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2078 if (port == 0) {
2079 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2080 sentIntent, null, false);
2081 } else {
2082 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2083 smsManager.sendDataMessageWithSelfPermissions(number, null,
2084 (short) port, data, sentIntent, null);
2085 }
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
2088 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002089 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002090 /**
fionaxuef039d42016-11-14 13:36:14 -08002091 * Sets the voice activation state of a given subId.
2092 */
2093 @Override
2094 public void setVoiceActivationState(int subId, int activationState) {
2095 enforceModifyPermissionOrCarrierPrivilege(subId);
2096 final Phone phone = getPhone(subId);
2097 if (phone != null) {
2098 phone.setVoiceActivationState(activationState);
2099 } else {
2100 loge("setVoiceActivationState fails with invalid subId: " + subId);
2101 }
2102 }
2103
2104 /**
2105 * Sets the data activation state of a given subId.
2106 */
2107 @Override
2108 public void setDataActivationState(int subId, int activationState) {
2109 enforceModifyPermissionOrCarrierPrivilege(subId);
2110 final Phone phone = getPhone(subId);
2111 if (phone != null) {
2112 phone.setDataActivationState(activationState);
2113 } else {
2114 loge("setVoiceActivationState fails with invalid subId: " + subId);
2115 }
2116 }
2117
2118 /**
2119 * Returns the voice activation state of a given subId.
2120 */
2121 @Override
2122 public int getVoiceActivationState(int subId, String callingPackage) {
2123 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2124 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2125 }
2126 final Phone phone = getPhone(subId);
2127 if (phone != null) {
2128 return phone.getVoiceActivationState();
2129 } else {
2130 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2131 }
2132 }
2133
2134 /**
2135 * Returns the data activation state of a given subId.
2136 */
2137 @Override
2138 public int getDataActivationState(int subId, String callingPackage) {
2139 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2140 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2141 }
2142 final Phone phone = getPhone(subId);
2143 if (phone != null) {
2144 return phone.getDataActivationState();
2145 } else {
2146 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2147 }
2148 }
2149
2150 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 * Returns the unread count of voicemails
2152 */
2153 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002154 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002155 }
2156
2157 /**
2158 * Returns the unread count of voicemails for a subId
2159 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002161 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002162 final Phone phone = getPhone(subId);
2163 if (phone != null) {
2164 return phone.getVoiceMessageCount();
2165 } else {
2166 return 0;
2167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
2170 /**
pkanwar8efe6572017-01-19 13:43:16 -08002171 * returns true, if the device is in a state where both voice and data
2172 * are supported simultaneously. This can change based on location or network condition.
2173 */
2174 @Override
2175 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2176 final Phone phone = getPhone(subId);
2177 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2178 }
2179
2180 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002181 * Returns the data network type.
2182 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 *
2184 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2185 */
2186 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002187 public int getNetworkType() {
2188 final Phone phone = getPhone(getDefaultSubscription());
2189 if (phone != null) {
2190 return phone.getServiceState().getDataNetworkType();
2191 } else {
2192 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2193 }
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
2196 /**
2197 * Returns the network type for a subId
2198 */
2199 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002200 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2201 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2202 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2203 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002204
Sanket Padawe356d7632015-06-22 14:03:32 -07002205 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002206 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002207 return phone.getServiceState().getDataNetworkType();
2208 } else {
2209 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 }
2212
2213 /**
2214 * Returns the data network type
2215 */
2216 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002217 public int getDataNetworkType(String callingPackage) {
2218 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
2220
2221 /**
2222 * Returns the data network type for a subId
2223 */
2224 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002225 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2226 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2227 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2228 }
2229
Sanket Padawe356d7632015-06-22 14:03:32 -07002230 final Phone phone = getPhone(subId);
2231 if (phone != null) {
2232 return phone.getServiceState().getDataNetworkType();
2233 } else {
2234 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 }
2237
2238 /**
Wink Saville36469e72014-06-11 15:17:00 -07002239 * Returns the Voice network type for a subId
2240 */
2241 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002242 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2243 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2244 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2245 }
2246
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 final Phone phone = getPhone(subId);
2248 if (phone != null) {
2249 return phone.getServiceState().getVoiceNetworkType();
2250 } else {
2251 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
2255 /**
2256 * @return true if a ICC card is present
2257 */
2258 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002259 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe5780e442017-03-20 15:04:47 -07002260 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2261 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002262 }
2263
2264 /**
Sanket Padawe5780e442017-03-20 15:04:47 -07002265 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002266 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 @Override
Sanket Padawe5780e442017-03-20 15:04:47 -07002268 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2269 int subId[] = mSubscriptionController.getSubIdUsingSlotIndex(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 final Phone phone = getPhone(subId[0]);
2271 if (subId != null && phone != null) {
2272 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002273 } else {
2274 return false;
2275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 }
2277
2278 /**
2279 * Return if the current radio is LTE on CDMA. This
2280 * is a tri-state return value as for a period of time
2281 * the mode may be unknown.
2282 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002283 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002285 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002287 @Override
2288 public int getLteOnCdmaMode(String callingPackage) {
2289 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002290 }
2291
Sanket Padawe356d7632015-06-22 14:03:32 -07002292 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002293 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2294 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2295 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2296 }
2297
Sanket Padawe356d7632015-06-22 14:03:32 -07002298 final Phone phone = getPhone(subId);
2299 if (phone == null) {
2300 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2301 } else {
2302 return phone.getLteOnCdmaMode();
2303 }
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
2306 public void setPhone(Phone phone) {
2307 mPhone = phone;
2308 }
2309
2310 /**
2311 * {@hide}
2312 * Returns Default subId, 0 in the case of single standby.
2313 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002314 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002315 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002316 }
2317
Shishir Agrawala9f32182016-04-12 12:00:16 -07002318 private int getSlotForDefaultSubscription() {
2319 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2320 }
2321
Wink Savilleb564aae2014-10-23 10:18:09 -07002322 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002323 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002325
2326 /**
2327 * @see android.telephony.TelephonyManager.WifiCallingChoices
2328 */
2329 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002330 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2331 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002332 }
2333
2334 /**
2335 * @see android.telephony.TelephonyManager.WifiCallingChoices
2336 */
2337 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002338 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2339 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2340 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002341 }
2342
Sailesh Nepald1e68152013-12-12 19:08:02 -08002343 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002344 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002345 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002346 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002347
Shishir Agrawal566b7612013-10-28 14:41:00 -07002348 @Override
Ajay Nambiabd73502015-12-03 13:50:00 -08002349 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002350 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002351
Ajay Nambiabd73502015-12-03 13:50:00 -08002352 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + AID + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002353 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Ajay Nambiabd73502015-12-03 13:50:00 -08002354 CMD_OPEN_CHANNEL, new Pair<String, Integer>(AID, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002355 if (DBG) log("iccOpenLogicalChannel: " + response);
2356 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002357 }
2358
2359 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002360 public boolean iccCloseLogicalChannel(int subId, int channel) {
2361 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002362
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002363 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002364 if (channel < 0) {
2365 return false;
2366 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002367 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002368 if (DBG) log("iccCloseLogicalChannel: " + success);
2369 return success;
2370 }
2371
2372 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002373 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002374 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002375 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002376
2377 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002378 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2379 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002380 " data=" + data);
2381 }
2382
2383 if (channel < 0) {
2384 return "";
2385 }
2386
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002387 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002388 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2390
Shishir Agrawal566b7612013-10-28 14:41:00 -07002391 // Append the returned status code to the end of the response payload.
2392 String s = Integer.toHexString(
2393 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002394 if (response.payload != null) {
2395 s = IccUtils.bytesToHexString(response.payload) + s;
2396 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002397 return s;
2398 }
Jake Hambye994d462014-02-03 13:10:13 -08002399
Evan Charltonc66da362014-05-16 14:06:40 -07002400 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002401 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002402 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002403 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002404
2405 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002406 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2407 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002408 }
2409
2410 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002411 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002412 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2413
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002414 // Append the returned status code to the end of the response payload.
2415 String s = Integer.toHexString(
2416 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002417 if (response.payload != null) {
2418 s = IccUtils.bytesToHexString(response.payload) + s;
2419 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002420 return s;
2421 }
2422
2423 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002425 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002426 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002427
2428 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002429 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002430 p1 + " " + p2 + " " + p3 + ":" + filePath);
2431 }
2432
2433 IccIoResult response =
2434 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002435 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2436 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002437
2438 if (DBG) {
2439 log("Exchange SIM_IO [R]" + response);
2440 }
2441
2442 byte[] result = null;
2443 int length = 2;
2444 if (response.payload != null) {
2445 length = 2 + response.payload.length;
2446 result = new byte[length];
2447 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2448 } else {
2449 result = new byte[length];
2450 }
2451
2452 result[length - 1] = (byte) response.sw2;
2453 result[length - 2] = (byte) response.sw1;
2454 return result;
2455 }
2456
Nathan Haroldb3014052017-01-25 15:57:32 -08002457 /**
2458 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2459 * on a particular subscription
2460 */
2461 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002462 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2463 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002464 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2465 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2466 return null;
2467 }
2468 Object response = sendRequest(
2469 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2470 if (response instanceof String[]) {
2471 return (String[]) response;
2472 }
2473 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2474 return null;
2475 }
2476
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002477 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002478 public String sendEnvelopeWithStatus(int subId, String content) {
2479 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002480
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002481 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002482 if (response.payload == null) {
2483 return "";
2484 }
2485
2486 // Append the returned status code to the end of the response payload.
2487 String s = Integer.toHexString(
2488 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2489 s = IccUtils.bytesToHexString(response.payload) + s;
2490 return s;
2491 }
2492
Jake Hambye994d462014-02-03 13:10:13 -08002493 /**
2494 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2495 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2496 *
2497 * @param itemID the ID of the item to read
2498 * @return the NV item as a String, or null on error.
2499 */
2500 @Override
2501 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002502 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002503 if (DBG) log("nvReadItem: item " + itemID);
2504 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2505 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2506 return value;
2507 }
2508
2509 /**
2510 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2511 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2512 *
2513 * @param itemID the ID of the item to read
2514 * @param itemValue the value to write, as a String
2515 * @return true on success; false on any failure
2516 */
2517 @Override
2518 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002520 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2521 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2522 new Pair<Integer, String>(itemID, itemValue));
2523 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2524 return success;
2525 }
2526
2527 /**
2528 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2529 * Used for device configuration by some CDMA operators.
2530 *
2531 * @param preferredRoamingList byte array containing the new PRL
2532 * @return true on success; false on any failure
2533 */
2534 @Override
2535 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002536 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002537 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2538 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2539 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2540 return success;
2541 }
2542
2543 /**
2544 * Perform the specified type of NV config reset.
2545 * Used for device configuration by some CDMA operators.
2546 *
2547 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2548 * @return true on success; false on any failure
2549 */
2550 @Override
2551 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002552 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002553 if (DBG) log("nvResetConfig: type " + resetType);
2554 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2555 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2556 return success;
2557 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002558
2559 /**
Wink Saville36469e72014-06-11 15:17:00 -07002560 * {@hide}
2561 * Returns Default sim, 0 in the case of single standby.
2562 */
2563 public int getDefaultSim() {
2564 //TODO Need to get it from Telephony Devcontroller
2565 return 0;
2566 }
2567
Svet Ganovb320e182015-04-16 12:30:10 -07002568 public String[] getPcscfAddress(String apnType, String callingPackage) {
2569 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2570 return new String[0];
2571 }
2572
2573
ram87fca6f2014-07-18 18:58:44 +05302574 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002575 }
2576
Brad Ebinger76681002017-01-23 13:50:20 -08002577 /**
2578 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2579 * feature or {@link null} if the service is not available. If an ImsServiceController is
2580 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2581 * feature updates.
2582 */
Sanket Padawe5780e442017-03-20 15:04:47 -07002583 public IImsServiceController getImsServiceControllerAndListen(int slotIndex, int feature,
Brad Ebinger76681002017-01-23 13:50:20 -08002584 IImsServiceFeatureListener callback) {
2585 enforceModifyPermission();
Sanket Padawe5780e442017-03-20 15:04:47 -07002586 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotIndex, feature,
Brad Ebinger76681002017-01-23 13:50:20 -08002587 callback);
2588 }
2589
Wink Saville36469e72014-06-11 15:17:00 -07002590 public void setImsRegistrationState(boolean registered) {
2591 enforceModifyPermission();
2592 mPhone.setImsRegistrationState(registered);
2593 }
2594
2595 /**
Stuart Scott54788802015-03-30 13:18:01 -07002596 * Set the network selection mode to automatic.
2597 *
2598 */
2599 @Override
2600 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002601 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002602 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2603 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2604 }
2605
2606 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002607 * Set the network selection mode to manual with the selected carrier.
2608 */
2609 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002610 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2611 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002612 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002613 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002614 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2615 persistSelection);
2616 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002617 }
2618
2619 /**
2620 * Scans for available networks.
2621 */
2622 @Override
2623 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002624 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002625 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2626 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2627 CMD_PERFORM_NETWORK_SCAN, null, subId);
2628 return result;
2629 }
2630
2631 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002632 * Get the calculated preferred network type.
2633 * Used for debugging incorrect network type.
2634 *
2635 * @return the preferred network type, defined in RILConstants.java.
2636 */
2637 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002638 public int getCalculatedPreferredNetworkType(String callingPackage) {
2639 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2640 return RILConstants.PREFERRED_NETWORK_MODE;
2641 }
2642
Amit Mahajan43330e02014-11-18 11:54:45 -08002643 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002644 }
2645
2646 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002647 * Get the preferred network type.
2648 * Used for device configuration by some CDMA operators.
2649 *
2650 * @return the preferred network type, defined in RILConstants.java.
2651 */
2652 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002653 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002654 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002655 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002656 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002657 int networkType = (result != null ? result[0] : -1);
2658 if (DBG) log("getPreferredNetworkType: " + networkType);
2659 return networkType;
2660 }
2661
2662 /**
2663 * Set the preferred network type.
2664 * Used for device configuration by some CDMA operators.
2665 *
2666 * @param networkType the preferred network type, defined in RILConstants.java.
2667 * @return true on success; false on any failure.
2668 */
2669 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002670 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002671 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002672 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2673 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002674 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002675 if (success) {
2676 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002677 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002678 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002679 return success;
2680 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002681
2682 /**
Junda Liu475951f2014-11-07 16:45:03 -08002683 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2684 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2685 * tethering.
2686 *
2687 * @return 0: Not required. 1: required. 2: Not set.
2688 * @hide
2689 */
2690 @Override
2691 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002692 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002693 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2694 Settings.Global.TETHER_DUN_REQUIRED, 2);
2695 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2696 // config_tether_apndata.
2697 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2698 dunRequired = 1;
2699 }
2700 return dunRequired;
2701 }
2702
2703 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002704 * Set mobile data enabled
2705 * Used by the user through settings etc to turn on/off mobile data
2706 *
2707 * @param enable {@code true} turn turn data on, else {@code false}
2708 */
2709 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002710 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsonf7eecf02016-11-18 17:05:56 -08002711 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002712 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002713 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002714 Phone phone = PhoneFactory.getPhone(phoneId);
2715 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002716 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002717 phone.setDataEnabled(enable);
2718 } else {
2719 loge("setDataEnabled: no phone for subId=" + subId);
2720 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002721 }
2722
2723 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002724 * Get whether mobile data is enabled.
2725 *
Jeff Davidsonf7eecf02016-11-18 17:05:56 -08002726 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002727 *
2728 * @return {@code true} if data is enabled else {@code false}
2729 */
2730 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002731 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002732 try {
2733 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2734 null);
2735 } catch (Exception e) {
Jeff Davidsonf7eecf02016-11-18 17:05:56 -08002736 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002737 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002738 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002739 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002740 Phone phone = PhoneFactory.getPhone(phoneId);
2741 if (phone != null) {
2742 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002743 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002744 return retVal;
2745 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002746 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002747 return false;
2748 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002749 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002750
2751 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002752 public int getCarrierPrivilegeStatus(int subId) {
2753 final Phone phone = getPhone(subId);
2754 if (phone == null) {
2755 loge("getCarrierPrivilegeStatus: Invalid subId");
2756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2757 }
2758 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002759 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002760 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2762 }
2763 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002764 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002765 }
Junda Liu29340342014-07-10 15:23:27 -07002766
2767 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002768 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002769 if (TextUtils.isEmpty(pkgName))
2770 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002771 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002772 if (card == null) {
2773 loge("checkCarrierPrivilegesForPackage: No UICC");
2774 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2775 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002776 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2777 }
2778
2779 @Override
2780 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002781 if (TextUtils.isEmpty(pkgName))
2782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002783 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2784 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2785 UiccCard card = UiccController.getInstance().getUiccCard(i);
2786 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002787 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002788 continue;
2789 }
2790
2791 result = card.getCarrierPrivilegeStatus(
2792 mPhone.getContext().getPackageManager(), pkgName);
2793 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2794 break;
2795 }
2796 }
2797
2798 return result;
Junda Liu29340342014-07-10 15:23:27 -07002799 }
Derek Tan89e89d42014-07-08 17:00:10 -07002800
2801 @Override
Junda Liue64de782015-04-16 17:19:16 -07002802 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2803 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2804 loge("phoneId " + phoneId + " is not valid.");
2805 return null;
2806 }
2807 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002808 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002809 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002810 return null ;
2811 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002812 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002813 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002814 }
2815
Amith Yamasani6e118872016-02-19 12:53:51 -08002816 @Override
2817 public List<String> getPackagesWithCarrierPrivileges() {
2818 PackageManager pm = mPhone.getContext().getPackageManager();
2819 List<String> privilegedPackages = new ArrayList<>();
2820 List<PackageInfo> packages = null;
2821 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2822 UiccCard card = UiccController.getInstance().getUiccCard(i);
2823 if (card == null) {
2824 // No UICC in that slot.
2825 continue;
2826 }
2827 if (card.hasCarrierPrivilegeRules()) {
2828 if (packages == null) {
2829 // Only check packages in user 0 for now
2830 packages = pm.getInstalledPackagesAsUser(
2831 PackageManager.MATCH_DISABLED_COMPONENTS
2832 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2833 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2834 }
2835 for (int p = packages.size() - 1; p >= 0; p--) {
2836 PackageInfo pkgInfo = packages.get(p);
2837 if (pkgInfo != null && pkgInfo.packageName != null
2838 && card.getCarrierPrivilegeStatus(pkgInfo)
2839 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2840 privilegedPackages.add(pkgInfo.packageName);
2841 }
2842 }
2843 }
2844 }
2845 return privilegedPackages;
2846 }
2847
Wink Savilleb564aae2014-10-23 10:18:09 -07002848 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 final Phone phone = getPhone(subId);
2850 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002851 if (card == null) {
2852 loge("getIccId: No UICC");
2853 return null;
2854 }
2855 String iccId = card.getIccId();
2856 if (TextUtils.isEmpty(iccId)) {
2857 loge("getIccId: ICC ID is null or empty.");
2858 return null;
2859 }
2860 return iccId;
2861 }
2862
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002863 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002864 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2865 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002866 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002867
Jeff Sharkey85190e62014-12-05 09:40:12 -08002868 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002869 final Phone phone = getPhone(subId);
2870 if (phone == null) {
2871 return false;
2872 }
2873 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002874
2875 if (DBG_MERGE) {
2876 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2877 + subscriberId + " to " + number);
2878 }
2879
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002880 if (TextUtils.isEmpty(iccId)) {
2881 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002882 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002883
Jeff Sharkey85190e62014-12-05 09:40:12 -08002884 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2885
2886 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002887 if (alphaTag == null) {
2888 editor.remove(alphaTagPrefKey);
2889 } else {
2890 editor.putString(alphaTagPrefKey, alphaTag);
2891 }
2892
Jeff Sharkey85190e62014-12-05 09:40:12 -08002893 // Record both the line number and IMSI for this ICCID, since we need to
2894 // track all merged IMSIs based on line number
2895 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2896 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002897 if (number == null) {
2898 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002899 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002900 } else {
2901 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002902 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002903 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002904
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002905 editor.commit();
2906 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002907 }
2908
2909 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002910 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002911 // This is open to apps with WRITE_SMS.
2912 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002913 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002914 return null;
2915 }
Derek Tan97ebb422014-09-05 16:55:38 -07002916
2917 String iccId = getIccId(subId);
2918 if (iccId != null) {
2919 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002920 if (DBG_MERGE) {
2921 log("getLine1NumberForDisplay returning " +
2922 mTelephonySharedPreferences.getString(numberPrefKey, null));
2923 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002924 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002925 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002926 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002927 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002928 }
2929
2930 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002931 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2932 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2933 return null;
2934 }
Derek Tan97ebb422014-09-05 16:55:38 -07002935
2936 String iccId = getIccId(subId);
2937 if (iccId != null) {
2938 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002939 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002940 }
Derek Tan97ebb422014-09-05 16:55:38 -07002941 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002942 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002943
2944 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002945 public String[] getMergedSubscriberIds(String callingPackage) {
2946 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2947 return null;
2948 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002949 final Context context = mPhone.getContext();
2950 final TelephonyManager tele = TelephonyManager.from(context);
2951 final SubscriptionManager sub = SubscriptionManager.from(context);
2952
2953 // Figure out what subscribers are currently active
2954 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002955 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2956 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 final int[] subIds = sub.getActiveSubscriptionIdList();
2960 for (int subId : subIds) {
2961 activeSubscriberIds.add(tele.getSubscriberId(subId));
2962 }
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002965 }
2966
2967 // First pass, find a number override for an active subscriber
2968 String mergeNumber = null;
2969 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2970 for (String key : prefs.keySet()) {
2971 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2972 final String subscriberId = (String) prefs.get(key);
2973 if (activeSubscriberIds.contains(subscriberId)) {
2974 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2975 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2976 mergeNumber = (String) prefs.get(numberKey);
2977 if (DBG_MERGE) {
2978 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2979 + " for active subscriber " + subscriberId);
2980 }
2981 if (!TextUtils.isEmpty(mergeNumber)) {
2982 break;
2983 }
2984 }
2985 }
2986 }
2987
2988 // Shortcut when no active merged subscribers
2989 if (TextUtils.isEmpty(mergeNumber)) {
2990 return null;
2991 }
2992
2993 // Second pass, find all subscribers under that line override
2994 final ArraySet<String> result = new ArraySet<>();
2995 for (String key : prefs.keySet()) {
2996 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2997 final String number = (String) prefs.get(key);
2998 if (mergeNumber.equals(number)) {
2999 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3000 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3001 final String subscriberId = (String) prefs.get(subscriberKey);
3002 if (!TextUtils.isEmpty(subscriberId)) {
3003 result.add(subscriberId);
3004 }
3005 }
3006 }
3007 }
3008
3009 final String[] resultArray = result.toArray(new String[result.size()]);
3010 Arrays.sort(resultArray);
3011 if (DBG_MERGE) {
3012 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3013 }
3014 return resultArray;
3015 }
3016
3017 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003018 public boolean setOperatorBrandOverride(int subId, String brand) {
3019 enforceCarrierPrivilege(subId);
3020 final Phone phone = getPhone(subId);
3021 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003022 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003023
3024 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003025 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003026 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3027 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003028 enforceCarrierPrivilege(subId);
3029 final Phone phone = getPhone(subId);
3030 if (phone == null) {
3031 return false;
3032 }
3033 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003034 cdmaNonRoamingList);
3035 }
3036
3037 @Override
Amit Mahajanf43fe462017-02-23 12:08:31 -08003038 @Deprecated
Steven Liu4bf01bc2014-07-17 11:05:29 -05003039 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3040 enforceModifyPermission();
3041
3042 int returnValue = 0;
3043 try {
3044 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3045 if(result.exception == null) {
3046 if (result.result != null) {
3047 byte[] responseData = (byte[])(result.result);
3048 if(responseData.length > oemResp.length) {
3049 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3050 responseData.length + "bytes. Buffer Size is " +
3051 oemResp.length + "bytes.");
3052 }
3053 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3054 returnValue = responseData.length;
3055 }
3056 } else {
3057 CommandException ex = (CommandException) result.exception;
3058 returnValue = ex.getCommandError().ordinal();
3059 if(returnValue > 0) returnValue *= -1;
3060 }
3061 } catch (RuntimeException e) {
3062 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3063 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3064 if(returnValue > 0) returnValue *= -1;
3065 }
3066
3067 return returnValue;
3068 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003069
3070 @Override
3071 public void setRadioCapability(RadioAccessFamily[] rafs) {
3072 try {
3073 ProxyController.getInstance().setRadioCapability(rafs);
3074 } catch (RuntimeException e) {
3075 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3076 }
3077 }
3078
3079 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003080 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3081 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3082 return RadioAccessFamily.RAF_UNKNOWN;
3083 }
3084
Wink Saville5d475dd2014-10-17 15:00:58 -07003085 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3086 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003087
3088 @Override
3089 public void enableVideoCalling(boolean enable) {
3090 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003091 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003092 }
3093
3094 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003095 public boolean isVideoCallingEnabled(String callingPackage) {
3096 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3097 return false;
3098 }
3099
Andrew Lee77527ac2014-10-21 16:57:39 -07003100 // Check the user preference and the system-level IMS setting. Even if the user has
3101 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3102 // In the long run, we may instead need to check if there exists a connection service
3103 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003104 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3105 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003106 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003107 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003108
Andrew Leea1239f22015-03-02 17:44:07 -08003109 @Override
3110 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003111 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003112 }
3113
3114 @Override
3115 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003116 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003117 }
3118
Andrew Lee9431b832015-03-09 18:46:45 -07003119 @Override
3120 public boolean isTtyModeSupported() {
3121 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3122 TelephonyManager telephonyManager =
3123 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003124 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003125 }
3126
3127 @Override
3128 public boolean isHearingAidCompatibilitySupported() {
3129 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3130 }
3131
Sanket Padawe7310cc72015-01-14 09:53:20 -08003132 /**
3133 * Returns the unique device ID of phone, for example, the IMEI for
3134 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3135 *
3136 * <p>Requires Permission:
3137 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3138 */
3139 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003140 public String getDeviceId(String callingPackage) {
3141 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3142 return null;
3143 }
3144
Sanket Padawe7310cc72015-01-14 09:53:20 -08003145 final Phone phone = PhoneFactory.getPhone(0);
3146 if (phone != null) {
3147 return phone.getDeviceId();
3148 } else {
3149 return null;
3150 }
3151 }
3152
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003153 /*
3154 * {@hide}
3155 * Returns the IMS Registration Status
3156 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003157 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003158 public boolean isImsRegistered() {
3159 return mPhone.isImsRegistered();
3160 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003161
3162 @Override
3163 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3164 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3165 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003166
Nathan Haroldc55097a2015-03-11 18:14:50 -07003167 /*
3168 * {@hide}
3169 * Returns the IMS Registration Status
3170 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003171 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003172 return mPhone.isWifiCallingEnabled();
3173 }
3174
3175 /*
3176 * {@hide}
3177 * Returns the IMS Registration Status
3178 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003179 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003180 return mPhone.isVolteEnabled();
3181 }
Svet Ganovb320e182015-04-16 12:30:10 -07003182
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003183 /*
3184 * {@hide} Returns the IMS Registration Status
3185 */
3186 public boolean isVideoTelephonyAvailable() {
3187 return mPhone.isVideoEnabled();
3188 }
3189
Svet Ganovb320e182015-04-16 12:30:10 -07003190 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003191 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003192 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003193 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3194
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003195 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003196 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003197 } catch (SecurityException e) {
3198 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3199 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003200 }
Svet Ganovb320e182015-04-16 12:30:10 -07003201
3202 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3203 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3204 return false;
3205 }
3206
3207 return true;
3208 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003209
Makoto Onukifee69342015-06-29 14:44:50 -07003210 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003211 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003212 */
3213 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003214 // Default SMS app can always read it.
3215 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3216 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3217 return true;
3218 }
3219 try {
3220 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003221 } catch (SecurityException readPhoneStateSecurityException) {
3222 try {
3223 // Can be read with READ_SMS too.
3224 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3225 return mAppOps.noteOp(AppOpsManager.OP_READ_SMS,
3226 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED;
3227 } catch (SecurityException readSmsSecurityException) {
3228 // Throw exception with message including both READ_PHONE_STATE and READ_SMS
3229 // permissions
3230 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3231 " nor current process has " + android.Manifest.permission.READ_PHONE_STATE +
3232 " or " + android.Manifest.permission.READ_SMS + ".");
3233 }
Makoto Onukie4072d12015-08-03 15:12:23 -07003234 }
Makoto Onukifee69342015-06-29 14:44:50 -07003235 }
3236
Stuart Scott8eef64f2015-04-08 15:13:54 -07003237 @Override
3238 public void factoryReset(int subId) {
3239 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003240 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3241 return;
3242 }
3243
Svet Ganovcc087f82015-05-12 20:35:54 -07003244 final long identity = Binder.clearCallingIdentity();
3245 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003246 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3247 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003248 // Enable data
3249 setDataEnabled(subId, true);
3250 // Set network selection mode to automatic
3251 setNetworkSelectionModeAutomatic(subId);
3252 // Set preferred mobile network type to the best available
3253 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3254 // Turn off roaming
3255 SubscriptionManager.from(mApp).setDataRoaming(0, subId);
3256 }
3257 } finally {
3258 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003259 }
3260 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003261
3262 @Override
3263 public String getLocaleFromDefaultSim() {
3264 // We query all subscriptions instead of just the active ones, because
3265 // this might be called early on in the provisioning flow when the
3266 // subscriptions potentially aren't active yet.
3267 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3268 if (slist == null || slist.isEmpty()) {
3269 return null;
3270 }
3271
3272 // This function may be called very early, say, from the setup wizard, at
3273 // which point we won't have a default subscription set. If that's the case
3274 // we just choose the first, which will be valid in "most cases".
3275 final int defaultSubId = getDefaultSubscription();
3276 SubscriptionInfo info = null;
3277 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3278 info = slist.get(0);
3279 } else {
3280 for (SubscriptionInfo item : slist) {
3281 if (item.getSubscriptionId() == defaultSubId) {
3282 info = item;
3283 break;
3284 }
3285 }
3286
3287 if (info == null) {
3288 return null;
3289 }
3290 }
3291
3292 // Try and fetch the locale from the carrier properties or from the SIM language
3293 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003294 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003295 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003296 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003297 if (defaultPhone != null) {
3298 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3299 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003300 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003301 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3302 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003303 } else {
3304 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003305 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003306 }
3307 }
3308
Narayan Kamath011676f2015-07-29 12:04:08 +01003309 // The SIM language preferences only store a language (e.g. fr = French), not an
3310 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3311 // the SIM and carrier preferences does not include a country we add the country
3312 // determined from the SIM MCC to provide an exact locale.
3313 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003314 if (mccLocale != null) {
3315 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3316 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003317 }
3318
Tony Hill183b2de2015-06-24 14:53:58 +01003319 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003320 return null;
3321 }
3322
3323 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 return mSubscriptionController.getAllSubInfoList(
3327 mPhone.getContext().getOpPackageName());
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
3330 }
3331 }
3332
3333 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 return mSubscriptionController.getActiveSubscriptionInfoList(
3337 mPhone.getContext().getOpPackageName());
3338 } finally {
3339 Binder.restoreCallingIdentity(identity);
3340 }
3341 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003342
3343 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003344 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3345 * representing the state of the modem.
3346 *
3347 * NOTE: This clears the modem state, so there should only every be one caller.
3348 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003349 */
3350 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003351 public void requestModemActivityInfo(ResultReceiver result) {
3352 enforceModifyPermission();
3353
3354 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3355 Bundle bundle = new Bundle();
3356 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3357 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003358 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003359
3360 /**
3361 * {@hide}
3362 * Returns the service state information on specified subscription.
3363 */
3364 @Override
3365 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3366
3367 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3368 return null;
3369 }
3370
3371 final Phone phone = getPhone(subId);
3372 if (phone == null) {
3373 return null;
3374 }
3375
3376 return phone.getServiceState();
3377 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003378
3379 /**
3380 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3381 *
3382 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3383 * voicemail ringtone.
3384 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3385 * PhoneAccount.
3386 */
3387 @Override
3388 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
3389 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3390 if (phone == null) {
3391 return null;
3392 }
3393
3394 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
3395 }
3396
3397 /**
3398 * Returns whether vibration is set for voicemail notification in Phone settings.
3399 *
3400 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3401 * voicemail vibration setting.
3402 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3403 */
3404 @Override
3405 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
3406 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3407 if (phone == null) {
3408 return false;
3409 }
3410
3411 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone);
3412 }
3413
Youhan Wange64578a2016-05-02 15:32:42 -07003414 /**
3415 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3416 *
3417 * @throws SecurityException if the caller does not have the required permission
3418 */
3419 private void enforceReadPrivilegedPermission() {
3420 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3421 null);
3422 }
3423
3424 /**
Ta-wei Yen1b455992016-12-27 14:52:32 -08003425 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3426 * permission.
3427 *
3428 * @throws SecurityException if the caller does not have the required permission
3429 */
3430 private void enforceSendSmsPermission() {
3431 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3432 }
3433
3434 /**
Ta-wei Yen463efd12017-01-06 15:29:25 -08003435 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen1b455992016-12-27 14:52:32 -08003436 *
Ta-wei Yen463efd12017-01-06 15:29:25 -08003437 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen1b455992016-12-27 14:52:32 -08003438 */
Ta-wei Yen463efd12017-01-06 15:29:25 -08003439 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
3440 String vvmPackage = RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId)
3441 .getPackageName();
3442 if (!callingPackage.equals(vvmPackage)) {
3443 throw new SecurityException("Caller not current active visual voicemail package[" +
3444 vvmPackage + "]");
Ta-wei Yen1b455992016-12-27 14:52:32 -08003445 }
3446 }
3447
3448 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003449 * Return the application ID for the app type.
3450 *
3451 * @param subId the subscription ID that this request applies to.
3452 * @param appType the uicc app type.
3453 * @return Application ID for specificied app type, or null if no uicc.
3454 */
3455 @Override
3456 public String getAidForAppType(int subId, int appType) {
3457 enforceReadPrivilegedPermission();
3458 Phone phone = getPhone(subId);
3459 if (phone == null) {
3460 return null;
3461 }
3462 String aid = null;
3463 try {
3464 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3465 .getApplicationByType(appType).getAid();
3466 } catch (Exception e) {
3467 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3468 }
3469 return aid;
3470 }
3471
Youhan Wang4001d252016-05-11 10:29:41 -07003472 /**
3473 * Return the Electronic Serial Number.
3474 *
3475 * @param subId the subscription ID that this request applies to.
3476 * @return ESN or null if error.
3477 */
3478 @Override
3479 public String getEsn(int subId) {
3480 enforceReadPrivilegedPermission();
3481 Phone phone = getPhone(subId);
3482 if (phone == null) {
3483 return null;
3484 }
3485 String esn = null;
3486 try {
3487 esn = phone.getEsn();
3488 } catch (Exception e) {
3489 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3490 }
3491 return esn;
3492 }
3493
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003494 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003495 * Return the Preferred Roaming List Version.
3496 *
3497 * @param subId the subscription ID that this request applies to.
3498 * @return PRLVersion or null if error.
3499 */
3500 @Override
3501 public String getCdmaPrlVersion(int subId) {
3502 enforceReadPrivilegedPermission();
3503 Phone phone = getPhone(subId);
3504 if (phone == null) {
3505 return null;
3506 }
3507 String cdmaPrlVersion = null;
3508 try {
3509 cdmaPrlVersion = phone.getCdmaPrlVersion();
3510 } catch (Exception e) {
3511 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3512 }
3513 return cdmaPrlVersion;
3514 }
3515
3516 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003517 * Get snapshot of Telephony histograms
3518 * @return List of Telephony histograms
3519 * @hide
3520 */
3521 @Override
3522 public List<TelephonyHistogram> getTelephonyHistograms() {
3523 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3524 return RIL.getTelephonyRILTimingHistograms();
3525 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003526
3527 /**
3528 * {@hide}
Sanket Padawe5780e442017-03-20 15:04:47 -07003529 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003530 * Require system privileges. In the future we may add this to carrier APIs.
3531 *
3532 * @return The number of carriers set successfully, should match length of carriers
3533 */
3534 @Override
Sanket Padawe5780e442017-03-20 15:04:47 -07003535 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003536 enforceModifyPermission();
Sanket Padawe5780e442017-03-20 15:04:47 -07003537 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003538 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3539 return retVal[0];
3540 }
3541
3542 /**
3543 * {@hide}
Sanket Padawe5780e442017-03-20 15:04:47 -07003544 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003545 * Require system privileges. In the future we may add this to carrier APIs.
3546 *
3547 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3548 * means all carriers are allowed.
3549 */
3550 @Override
Sanket Padawe5780e442017-03-20 15:04:47 -07003551 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003552 enforceReadPrivilegedPermission();
Sanket Padawe5780e442017-03-20 15:04:47 -07003553 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003554 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3555 }
3556
fionaxu59545b42016-05-25 15:53:37 -07003557 /**
3558 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3559 * @param subId the subscription ID that this action applies to.
3560 * @param enabled control enable or disable metered apns.
3561 * {@hide}
3562 */
3563 @Override
3564 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3565 enforceModifyPermission();
3566 final Phone phone = getPhone(subId);
3567 if (phone == null) {
3568 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3569 return;
3570 }
3571 try {
3572 phone.carrierActionSetMeteredApnsEnabled(enabled);
3573 } catch (Exception e) {
3574 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3575 }
3576 }
3577
3578 /**
3579 * Action set from carrier signalling broadcast receivers to enable/disable radio
3580 * @param subId the subscription ID that this action applies to.
3581 * @param enabled control enable or disable radio.
3582 * {@hide}
3583 */
3584 @Override
3585 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3586 enforceModifyPermission();
3587 final Phone phone = getPhone(subId);
3588 if (phone == null) {
3589 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3590 return;
3591 }
3592 try {
3593 phone.carrierActionSetRadioEnabled(enabled);
3594 } catch (Exception e) {
3595 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3596 }
3597 }
3598
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003599 /**
3600 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3601 * bug report is being generated.
3602 */
3603 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003604 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003605 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3606 != PackageManager.PERMISSION_GRANTED) {
3607 writer.println("Permission Denial: can't dump Phone from pid="
3608 + Binder.getCallingPid()
3609 + ", uid=" + Binder.getCallingUid()
3610 + "without permission "
3611 + android.Manifest.permission.DUMP);
3612 return;
3613 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003614 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003615 }
Jack Yueb89b242016-06-22 13:27:47 -07003616
3617 /**
3618 * Get aggregated video call data usage from all subscriptions since boot.
3619 * @return total data usage in bytes
3620 * {@hide}
3621 */
3622 @Override
3623 public long getVtDataUsage() {
3624 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3625 null);
3626
3627 // NetworkStatsService keeps tracking the active network interface and identity. It will
3628 // record the delta with the corresponding network identity. What we need to do here is
3629 // returning total video call data usage from all subscriptions since boot.
3630
3631 // TODO: Add sub id support in the future. We'll need it when we support DSDA and
3632 // simultaneous VT calls.
3633 final Phone[] phones = PhoneFactory.getPhones();
3634 long total = 0;
3635 for (Phone phone : phones) {
3636 total += phone.getVtDataUsage();
3637 }
3638 return total;
3639 }
Jack Yu75ab2952016-07-08 14:29:33 -07003640
3641 /**
3642 * Policy control of data connection. Usually used when data limit is passed.
3643 * @param enabled True if enabling the data, otherwise disabling.
3644 * @param subId Subscription index
3645 * {@hide}
3646 */
3647 @Override
3648 public void setPolicyDataEnabled(boolean enabled, int subId) {
3649 enforceModifyPermission();
3650 Phone phone = getPhone(subId);
3651 if (phone != null) {
3652 phone.setPolicyDataEnabled(enabled);
3653 }
3654 }
Sooraj Sasindran22882212016-07-18 11:57:25 -07003655
3656 /**
3657 * Get Client request stats
3658 * @return List of Client Request Stats
3659 * @hide
3660 */
3661 @Override
3662 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3663 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3664 return null;
3665 }
3666
3667 Phone phone = getPhone(subId);
3668 if (phone != null) {
3669 return phone.getClientRequestStats();
3670 }
3671
3672 return null;
3673 }
3674
3675 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3676 if (workSource != null) {
3677 return workSource;
3678 }
3679
3680 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3681 workSource = new WorkSource(uid, packageName);
3682 return workSource;
3683 }
Jack Yu346de222017-02-16 15:32:43 -08003684
3685 /**
3686 * Set SIM card power state. Request is equivalent to inserting or removing the card.
3687 *
Sanket Padawe5780e442017-03-20 15:04:47 -07003688 * @param slotIndex SIM slot id.
Jack Yu346de222017-02-16 15:32:43 -08003689 * @param powerUp True if powering up the SIM, otherwise powering down
3690 *
3691 **/
3692 @Override
Sanket Padawe5780e442017-03-20 15:04:47 -07003693 public void setSimPowerStateForSlot(int slotIndex, boolean powerUp) {
Jack Yu346de222017-02-16 15:32:43 -08003694 enforceModifyPermission();
Sanket Padawe5780e442017-03-20 15:04:47 -07003695 int subId[] = mSubscriptionController.getSubIdUsingSlotIndex(slotIndex);
Jack Yu346de222017-02-16 15:32:43 -08003696 if (subId == null || subId.length == 0) {
3697 return;
3698 }
3699
3700 final Phone phone = getPhone(subId[0]);
3701 if (phone != null) {
3702 phone.setSimPowerState(powerUp);
3703 }
3704 }
shuoqfef36a32017-01-10 13:02:18 -08003705
3706 /**
3707 * Check if phone is in emergency callback mode
3708 * @return true if phone is in emergency callback mode
3709 * @param subId sub id
3710 */
3711 public boolean getEmergencyCallbackMode(int subId) {
3712 final Phone phone = getPhone(subId);
3713 if (phone != null) {
3714 return phone.isInEcm();
3715 } else {
3716 return false;
3717 }
3718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003719}