blob: d9c5f0fc2c26dd2abc263d89f853cf723bb0905f [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
19import android.app.ActivityManager;
20import android.app.AppOpsManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070021import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.content.Context;
23import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070024import android.content.SharedPreferences;
Amith Yamasani6e118872016-02-19 12:53:51 -080025import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070026import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.net.Uri;
28import android.os.AsyncResult;
29import android.os.Binder;
30import android.os.Bundle;
31import android.os.Handler;
32import android.os.Looper;
33import android.os.Message;
34import android.os.Process;
35import android.os.ServiceManager;
36import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070037import android.os.UserManager;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080039import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080040import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080041import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070042import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070043import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.telephony.CellInfo;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070045import android.telephony.IccOpenLogicalChannelResponse;
Jake Hambye994d462014-02-03 13:10:13 -080046import android.telephony.NeighboringCellInfo;
Wink Saville5d475dd2014-10-17 15:00:58 -070047import android.telephony.RadioAccessFamily;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.telephony.ServiceState;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080049import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080050import android.telephony.SubscriptionManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080051import android.telephony.TelephonyManager;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -070052import android.telephony.ModemActivityInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080054import android.util.ArrayMap;
55import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080057import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080058import android.util.Slog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059
Andrew Lee312e8172014-10-23 17:01:36 -070060import com.android.ims.ImsManager;
Shishir Agrawal566b7612013-10-28 14:41:00 -070061import com.android.internal.telephony.CallManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070062import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070063import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080066import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010067import com.android.internal.telephony.MccTable;
Shishir Agrawal302c8692015-06-19 13:49:39 -070068import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import com.android.internal.telephony.Phone;
Wink Saville36469e72014-06-11 15:17:00 -070070import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070071import com.android.internal.telephony.ProxyController;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import com.android.internal.telephony.PhoneConstants;
Svet Ganovb320e182015-04-16 12:30:10 -070073import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080074import com.android.internal.telephony.SubscriptionController;
Shishir Agrawal566b7612013-10-28 14:41:00 -070075import com.android.internal.telephony.uicc.IccIoResult;
76import com.android.internal.telephony.uicc.IccUtils;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -070077import com.android.internal.telephony.uicc.UiccCard;
Shishir Agrawal566b7612013-10-28 14:41:00 -070078import com.android.internal.telephony.uicc.UiccController;
Jake Hambye994d462014-02-03 13:10:13 -080079import com.android.internal.util.HexDump;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import com.android.phone.settings.VoicemailNotificationSettingsUtil;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081
Wink Saville36469e72014-06-11 15:17:00 -070082import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
83
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -080085import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -080086import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +010087import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089
90/**
91 * Implementation of the ITelephony interface.
92 */
Santos Cordon117fee72014-05-16 17:56:12 -070093public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094 private static final String LOG_TAG = "PhoneInterfaceManager";
95 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
96 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098
99 // Message codes used with mMainThreadHandler
100 private static final int CMD_HANDLE_PIN_MMI = 1;
101 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
102 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
103 private static final int CMD_ANSWER_RINGING_CALL = 4;
104 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700105 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
106 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700107 private static final int CMD_OPEN_CHANNEL = 9;
108 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
109 private static final int CMD_CLOSE_CHANNEL = 11;
110 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800111 private static final int CMD_NV_READ_ITEM = 13;
112 private static final int EVENT_NV_READ_ITEM_DONE = 14;
113 private static final int CMD_NV_WRITE_ITEM = 15;
114 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
115 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
116 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
117 private static final int CMD_NV_RESET_CONFIG = 19;
118 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800119 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
120 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
121 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
122 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800123 private static final int CMD_SEND_ENVELOPE = 25;
124 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700125 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
126 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
127 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
128 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
129 private static final int CMD_EXCHANGE_SIM_IO = 31;
130 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800131 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
132 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700133 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
134 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700135 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
136 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
138 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
139 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
140 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141
142 /** The singleton instance. */
143 private static PhoneInterfaceManager sInstance;
144
Wink Saville3ab207e2014-11-20 13:07:20 -0800145 private PhoneGlobals mApp;
146 private Phone mPhone;
147 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700148 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800149 private AppOpsManager mAppOps;
150 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800152 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153
Derek Tan97ebb422014-09-05 16:55:38 -0700154 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
155 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800156 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700157
158 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159 * A request object to use for transmitting data to an ICC.
160 */
161 private static final class IccAPDUArgument {
162 public int channel, cla, command, p1, p2, p3;
163 public String data;
164
165 public IccAPDUArgument(int channel, int cla, int command,
166 int p1, int p2, int p3, String data) {
167 this.channel = channel;
168 this.cla = cla;
169 this.command = command;
170 this.p1 = p1;
171 this.p2 = p2;
172 this.p3 = p3;
173 this.data = data;
174 }
175 }
176
177 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700178 * A request object to use for transmitting data to an ICC.
179 */
180 private static final class ManualNetworkSelectionArgument {
181 public OperatorInfo operatorInfo;
182 public boolean persistSelection;
183
184 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
185 this.operatorInfo = operatorInfo;
186 this.persistSelection = persistSelection;
187 }
188 }
189
190 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
192 * request after sending. The main thread will notify the request when it is complete.
193 */
194 private static final class MainThreadRequest {
195 /** The argument to use for the request */
196 public Object argument;
197 /** The result of the request that is run on the main thread */
198 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800199 // The subscriber id that this request applies to. Defaults to
200 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
201 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202
203 public MainThreadRequest(Object argument) {
204 this.argument = argument;
205 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800206
207 public MainThreadRequest(Object argument, Integer subId) {
208 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800209 if (subId != null) {
210 this.subId = subId;
211 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213 }
214
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800215 private static final class IncomingThirdPartyCallArgs {
216 public final ComponentName component;
217 public final String callId;
218 public final String callerDisplayName;
219
220 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
221 String callerDisplayName) {
222 this.component = component;
223 this.callId = callId;
224 this.callerDisplayName = callerDisplayName;
225 }
226 }
227
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228 /**
229 * A handler that processes messages on the main thread in the phone process. Since many
230 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
231 * inbound binder threads to the main thread in the phone process. The Binder thread
232 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
233 * on, which will be notified when the operation completes and will contain the result of the
234 * request.
235 *
236 * <p>If a MainThreadRequest object is provided in the msg.obj field,
237 * note that request.result must be set to something non-null for the calling thread to
238 * unblock.
239 */
240 private final class MainThreadHandler extends Handler {
241 @Override
242 public void handleMessage(Message msg) {
243 MainThreadRequest request;
244 Message onCompleted;
245 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800246 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700247 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
249 switch (msg.what) {
Yorke Lee716f67e2015-06-17 15:39:16 -0700250 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700252 final Phone phone = getPhoneFromRequest(request);
253 request.result = phone != null ?
254 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
255 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256 // Wake up the requesting thread
257 synchronized (request) {
258 request.notifyAll();
259 }
260 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262
263 case CMD_HANDLE_NEIGHBORING_CELL:
264 request = (MainThreadRequest) msg.obj;
265 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
266 request);
267 mPhone.getNeighboringCids(onCompleted);
268 break;
269
270 case EVENT_NEIGHBORING_CELL_DONE:
271 ar = (AsyncResult) msg.obj;
272 request = (MainThreadRequest) ar.userObj;
273 if (ar.exception == null && ar.result != null) {
274 request.result = ar.result;
275 } else {
276 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800277 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 }
279 // Wake up the requesting thread
280 synchronized (request) {
281 request.notifyAll();
282 }
283 break;
284
285 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700286 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800287 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700288 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700289 break;
290
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 case CMD_END_CALL:
292 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800293 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700294 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700295 Phone phone = getPhone(end_subId);
296 if (phone == null) {
297 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
298 break;
299 }
300 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700301 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
302 // CDMA: If the user presses the Power button we treat it as
303 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700304 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
306 // GSM: End the call as per the Phone state
307 hungUp = PhoneUtils.hangup(mCM);
308 } else {
309 throw new IllegalStateException("Unexpected phone type: " + phoneType);
310 }
311 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
312 request.result = hungUp;
313 // Wake up the requesting thread
314 synchronized (request) {
315 request.notifyAll();
316 }
317 break;
318
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700319 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700320 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700321 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800322 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700323 if (uiccCard == null) {
324 loge("iccTransmitApduLogicalChannel: No UICC");
325 request.result = new IccIoResult(0x6F, 0, (byte[])null);
326 synchronized (request) {
327 request.notifyAll();
328 }
329 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700330 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
331 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700332 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700333 iccArgument.channel, iccArgument.cla, iccArgument.command,
334 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700335 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700337 break;
338
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700339 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700340 ar = (AsyncResult) msg.obj;
341 request = (MainThreadRequest) ar.userObj;
342 if (ar.exception == null && ar.result != null) {
343 request.result = ar.result;
344 } else {
345 request.result = new IccIoResult(0x6F, 0, (byte[])null);
346 if (ar.result == null) {
347 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800348 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700349 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800350 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700351 } else {
352 loge("iccTransmitApduLogicalChannel: Unknown exception");
353 }
354 }
355 synchronized (request) {
356 request.notifyAll();
357 }
358 break;
359
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700360 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
361 request = (MainThreadRequest) msg.obj;
362 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800363 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700364 if (uiccCard == null) {
365 loge("iccTransmitApduBasicChannel: No UICC");
366 request.result = new IccIoResult(0x6F, 0, (byte[])null);
367 synchronized (request) {
368 request.notifyAll();
369 }
370 } else {
371 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
372 request);
373 uiccCard.iccTransmitApduBasicChannel(
374 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
375 iccArgument.p3, iccArgument.data, onCompleted);
376 }
377 break;
378
379 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
380 ar = (AsyncResult) msg.obj;
381 request = (MainThreadRequest) ar.userObj;
382 if (ar.exception == null && ar.result != null) {
383 request.result = ar.result;
384 } else {
385 request.result = new IccIoResult(0x6F, 0, (byte[])null);
386 if (ar.result == null) {
387 loge("iccTransmitApduBasicChannel: Empty response");
388 } else if (ar.exception instanceof CommandException) {
389 loge("iccTransmitApduBasicChannel: CommandException: " +
390 ar.exception);
391 } else {
392 loge("iccTransmitApduBasicChannel: Unknown exception");
393 }
394 }
395 synchronized (request) {
396 request.notifyAll();
397 }
398 break;
399
400 case CMD_EXCHANGE_SIM_IO:
401 request = (MainThreadRequest) msg.obj;
402 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800403 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 if (uiccCard == null) {
405 loge("iccExchangeSimIO: No UICC");
406 request.result = new IccIoResult(0x6F, 0, (byte[])null);
407 synchronized (request) {
408 request.notifyAll();
409 }
410 } else {
411 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
412 request);
413 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
414 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
415 iccArgument.data, onCompleted);
416 }
417 break;
418
419 case EVENT_EXCHANGE_SIM_IO_DONE:
420 ar = (AsyncResult) msg.obj;
421 request = (MainThreadRequest) ar.userObj;
422 if (ar.exception == null && ar.result != null) {
423 request.result = ar.result;
424 } else {
425 request.result = new IccIoResult(0x6f, 0, (byte[])null);
426 }
427 synchronized (request) {
428 request.notifyAll();
429 }
430 break;
431
Derek Tan4d5e5c12014-02-04 11:54:58 -0800432 case CMD_SEND_ENVELOPE:
433 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800434 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700435 if (uiccCard == null) {
436 loge("sendEnvelopeWithStatus: No UICC");
437 request.result = new IccIoResult(0x6F, 0, (byte[])null);
438 synchronized (request) {
439 request.notifyAll();
440 }
441 } else {
442 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
443 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
444 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800445 break;
446
447 case EVENT_SEND_ENVELOPE_DONE:
448 ar = (AsyncResult) msg.obj;
449 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700450 if (ar.exception == null && ar.result != null) {
451 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800452 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700453 request.result = new IccIoResult(0x6F, 0, (byte[])null);
454 if (ar.result == null) {
455 loge("sendEnvelopeWithStatus: Empty response");
456 } else if (ar.exception instanceof CommandException) {
457 loge("sendEnvelopeWithStatus: CommandException: " +
458 ar.exception);
459 } else {
460 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
461 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800462 }
463 synchronized (request) {
464 request.notifyAll();
465 }
466 break;
467
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 case CMD_OPEN_CHANNEL:
469 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800470 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700471 if (uiccCard == null) {
472 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800473 request.result = new IccOpenLogicalChannelResponse(-1,
474 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700475 synchronized (request) {
476 request.notifyAll();
477 }
478 } else {
479 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
480 uiccCard.iccOpenLogicalChannel((String)request.argument, onCompleted);
481 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 break;
483
484 case EVENT_OPEN_CHANNEL_DONE:
485 ar = (AsyncResult) msg.obj;
486 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 int[] result = (int[]) ar.result;
490 int channelId = result[0];
491 byte[] selectResponse = null;
492 if (result.length > 1) {
493 selectResponse = new byte[result.length - 1];
494 for (int i = 1; i < result.length; ++i) {
495 selectResponse[i - 1] = (byte) result[i];
496 }
497 }
498 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700499 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 if (ar.result == null) {
502 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 if (ar.exception != null) {
505 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
506 }
507
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700508 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700509 if (ar.exception instanceof CommandException) {
510 CommandException.Error error =
511 ((CommandException) (ar.exception)).getCommandError();
512 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700513 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700514 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700515 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 }
517 }
518 openChannelResp = new IccOpenLogicalChannelResponse(
519 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700520 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700521 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 synchronized (request) {
523 request.notifyAll();
524 }
525 break;
526
527 case CMD_CLOSE_CHANNEL:
528 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 if (uiccCard == null) {
531 loge("iccCloseLogicalChannel: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
533 synchronized (request) {
534 request.notifyAll();
535 }
536 } else {
537 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
538 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
539 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 break;
541
542 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800543 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
544 break;
545
546 case CMD_NV_READ_ITEM:
547 request = (MainThreadRequest) msg.obj;
548 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
549 mPhone.nvReadItem((Integer) request.argument, onCompleted);
550 break;
551
552 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800558 request.result = "";
559 if (ar.result == null) {
560 loge("nvReadItem: Empty response");
561 } else if (ar.exception instanceof CommandException) {
562 loge("nvReadItem: CommandException: " +
563 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800565 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 }
567 }
568 synchronized (request) {
569 request.notifyAll();
570 }
571 break;
572
Jake Hambye994d462014-02-03 13:10:13 -0800573 case CMD_NV_WRITE_ITEM:
574 request = (MainThreadRequest) msg.obj;
575 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
576 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
577 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
578 break;
579
580 case EVENT_NV_WRITE_ITEM_DONE:
581 handleNullReturnEvent(msg, "nvWriteItem");
582 break;
583
584 case CMD_NV_WRITE_CDMA_PRL:
585 request = (MainThreadRequest) msg.obj;
586 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
587 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
588 break;
589
590 case EVENT_NV_WRITE_CDMA_PRL_DONE:
591 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
592 break;
593
594 case CMD_NV_RESET_CONFIG:
595 request = (MainThreadRequest) msg.obj;
596 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
597 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
598 break;
599
600 case EVENT_NV_RESET_CONFIG_DONE:
601 handleNullReturnEvent(msg, "nvResetConfig");
602 break;
603
Jake Hamby7c27be32014-03-03 13:25:59 -0800604 case CMD_GET_PREFERRED_NETWORK_TYPE:
605 request = (MainThreadRequest) msg.obj;
606 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700607 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800608 break;
609
610 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
611 ar = (AsyncResult) msg.obj;
612 request = (MainThreadRequest) ar.userObj;
613 if (ar.exception == null && ar.result != null) {
614 request.result = ar.result; // Integer
615 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800616 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800617 if (ar.result == null) {
618 loge("getPreferredNetworkType: Empty response");
619 } else if (ar.exception instanceof CommandException) {
620 loge("getPreferredNetworkType: CommandException: " +
621 ar.exception);
622 } else {
623 loge("getPreferredNetworkType: Unknown exception");
624 }
625 }
626 synchronized (request) {
627 request.notifyAll();
628 }
629 break;
630
631 case CMD_SET_PREFERRED_NETWORK_TYPE:
632 request = (MainThreadRequest) msg.obj;
633 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
634 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700635 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800636 break;
637
638 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
639 handleNullReturnEvent(msg, "setPreferredNetworkType");
640 break;
641
Steven Liu4bf01bc2014-07-17 11:05:29 -0500642 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
643 request = (MainThreadRequest)msg.obj;
644 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
645 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
646 break;
647
648 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
649 ar = (AsyncResult)msg.obj;
650 request = (MainThreadRequest)ar.userObj;
651 request.result = ar;
652 synchronized (request) {
653 request.notifyAll();
654 }
655 break;
656
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800657 case CMD_SET_VOICEMAIL_NUMBER:
658 request = (MainThreadRequest) msg.obj;
659 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
660 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800661 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
662 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800663 break;
664
665 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
666 handleNullReturnEvent(msg, "setVoicemailNumber");
667 break;
668
Stuart Scott54788802015-03-30 13:18:01 -0700669 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
672 request);
673 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
674 break;
675
676 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
677 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
678 break;
679
Shishir Agrawal302c8692015-06-19 13:49:39 -0700680 case CMD_PERFORM_NETWORK_SCAN:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
683 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
684 break;
685
686 case EVENT_PERFORM_NETWORK_SCAN_DONE:
687 ar = (AsyncResult) msg.obj;
688 request = (MainThreadRequest) ar.userObj;
689 CellNetworkScanResult cellScanResult;
690 if (ar.exception == null && ar.result != null) {
691 cellScanResult = new CellNetworkScanResult(
692 CellNetworkScanResult.STATUS_SUCCESS,
693 (List<OperatorInfo>) ar.result);
694 } else {
695 if (ar.result == null) {
696 loge("getCellNetworkScanResults: Empty response");
697 }
698 if (ar.exception != null) {
699 loge("getCellNetworkScanResults: Exception: " + ar.exception);
700 }
701 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
702 if (ar.exception instanceof CommandException) {
703 CommandException.Error error =
704 ((CommandException) (ar.exception)).getCommandError();
705 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
706 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
707 } else if (error == CommandException.Error.GENERIC_FAILURE) {
708 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
709 }
710 }
711 cellScanResult = new CellNetworkScanResult(errorCode, null);
712 }
713 request.result = cellScanResult;
714 synchronized (request) {
715 request.notifyAll();
716 }
717 break;
718
719 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
720 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700721 ManualNetworkSelectionArgument selArg =
722 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700723 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
724 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700725 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
726 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700727 break;
728
729 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
730 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
731 break;
732
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700733 case CMD_GET_MODEM_ACTIVITY_INFO:
734 request = (MainThreadRequest) msg.obj;
735 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700736 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700737 break;
738
739 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
740 ar = (AsyncResult) msg.obj;
741 request = (MainThreadRequest) ar.userObj;
742 if (ar.exception == null && ar.result != null) {
743 request.result = ar.result;
744 } else {
745 if (ar.result == null) {
746 loge("queryModemActivityInfo: Empty response");
747 } else if (ar.exception instanceof CommandException) {
748 loge("queryModemActivityInfo: CommandException: " +
749 ar.exception);
750 } else {
751 loge("queryModemActivityInfo: Unknown exception");
752 }
753 }
Amit Mahajand4766222016-01-28 15:28:28 -0800754 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
755 if (request.result == null) {
756 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
757 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700758 synchronized (request) {
759 request.notifyAll();
760 }
761 break;
762
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700763 default:
764 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
765 break;
766 }
767 }
Jake Hambye994d462014-02-03 13:10:13 -0800768
769 private void handleNullReturnEvent(Message msg, String command) {
770 AsyncResult ar = (AsyncResult) msg.obj;
771 MainThreadRequest request = (MainThreadRequest) ar.userObj;
772 if (ar.exception == null) {
773 request.result = true;
774 } else {
775 request.result = false;
776 if (ar.exception instanceof CommandException) {
777 loge(command + ": CommandException: " + ar.exception);
778 } else {
779 loge(command + ": Unknown exception");
780 }
781 }
782 synchronized (request) {
783 request.notifyAll();
784 }
785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700786 }
787
788 /**
789 * Posts the specified command to be executed on the main thread,
790 * waits for the request to complete, and returns the result.
791 * @see #sendRequestAsync
792 */
793 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800794 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700795 }
796
797 /**
798 * Posts the specified command to be executed on the main thread,
799 * waits for the request to complete, and returns the result.
800 * @see #sendRequestAsync
801 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800802 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700803 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
804 throw new RuntimeException("This method will deadlock if called from the main thread.");
805 }
806
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800807 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700808 Message msg = mMainThreadHandler.obtainMessage(command, request);
809 msg.sendToTarget();
810
811 // Wait for the request to complete
812 synchronized (request) {
813 while (request.result == null) {
814 try {
815 request.wait();
816 } catch (InterruptedException e) {
817 // Do nothing, go back and wait until the request is complete
818 }
819 }
820 }
821 return request.result;
822 }
823
824 /**
825 * Asynchronous ("fire and forget") version of sendRequest():
826 * Posts the specified command to be executed on the main thread, and
827 * returns immediately.
828 * @see #sendRequest
829 */
830 private void sendRequestAsync(int command) {
831 mMainThreadHandler.sendEmptyMessage(command);
832 }
833
834 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -0700835 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
836 * @see {@link #sendRequest(int,Object)}
837 */
838 private void sendRequestAsync(int command, Object argument) {
839 MainThreadRequest request = new MainThreadRequest(argument);
840 Message msg = mMainThreadHandler.obtainMessage(command, request);
841 msg.sendToTarget();
842 }
843
844 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700845 * Initialize the singleton PhoneInterfaceManager instance.
846 * This is only done once, at startup, from PhoneApp.onCreate().
847 */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700848 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700849 synchronized (PhoneInterfaceManager.class) {
850 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -0700851 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700852 } else {
853 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
854 }
855 return sInstance;
856 }
857 }
858
859 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -0700860 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700861 mApp = app;
862 mPhone = phone;
863 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700864 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700865 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
866 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -0700867 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -0700868 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800869 mSubscriptionController = SubscriptionController.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -0800870
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700871 publish();
872 }
873
874 private void publish() {
875 if (DBG) log("publish: " + this);
876
877 ServiceManager.addService("phone", this);
878 }
879
Stuart Scott584921c2015-01-15 17:10:34 -0800880 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800881 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
882 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -0800883 }
884
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800885 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
886 Phone phone = getPhoneFromRequest(request);
887 return phone == null ? null :
888 UiccController.getInstance().getUiccCard(phone.getPhoneId());
889 }
890
Wink Saville36469e72014-06-11 15:17:00 -0700891 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -0700892 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800893 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -0700894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700895 //
896 // Implementation of the ITelephony interface.
897 //
898
899 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700900 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -0700901 }
902
Wink Savilleb564aae2014-10-23 10:18:09 -0700903 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700904 if (DBG) log("dial: " + number);
905 // No permission check needed here: This is just a wrapper around the
906 // ACTION_DIAL intent, which is available to any app since it puts up
907 // the UI before it does anything.
908
909 String url = createTelUrl(number);
910 if (url == null) {
911 return;
912 }
913
914 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -0700915 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700916 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
917 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
918 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
919 mApp.startActivity(intent);
920 }
921 }
922
923 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700924 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -0700925 }
926
Wink Savilleb564aae2014-10-23 10:18:09 -0700927 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700928 if (DBG) log("call: " + number);
929
930 // This is just a wrapper around the ACTION_CALL intent, but we still
931 // need to do a permission check since we're calling startActivity()
932 // from the context of the phone app.
933 enforceCallPermission();
934
935 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
936 != AppOpsManager.MODE_ALLOWED) {
937 return;
938 }
939
940 String url = createTelUrl(number);
941 if (url == null) {
942 return;
943 }
944
Wink Saville08874612014-08-31 19:19:58 -0700945 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100946 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -0800947 if (slist != null) {
948 for (SubscriptionInfo subInfoRecord : slist) {
949 if (subInfoRecord.getSubscriptionId() == subId) {
950 isValid = true;
951 break;
952 }
Wink Saville08874612014-08-31 19:19:58 -0700953 }
954 }
955 if (isValid == false) {
956 return;
957 }
958
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700959 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -0700960 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700961 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
962 mApp.startActivity(intent);
963 }
964
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700965 /**
966 * End a call based on call state
967 * @return true is a call was ended
968 */
969 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700970 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700971 }
972
973 /**
974 * End a call based on the call state of the subId
975 * @return true is a call was ended
976 */
Wink Savilleb564aae2014-10-23 10:18:09 -0700977 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700978 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -0800979 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700980 }
981
982 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -0700983 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -0700984 }
985
Wink Savilleb564aae2014-10-23 10:18:09 -0700986 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700987 if (DBG) log("answerRingingCall...");
988 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
989 // but that can probably wait till the big TelephonyManager API overhaul.
990 // For now, protect this call with the MODIFY_PHONE_STATE permission.
991 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -0800992 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700993 }
994
995 /**
996 * Make the actual telephony calls to implement answerRingingCall().
997 * This should only be called from the main thread of the Phone app.
998 * @see #answerRingingCall
999 *
1000 * TODO: it would be nice to return true if we answered the call, or
1001 * false if there wasn't actually a ringing incoming call, or some
1002 * other error occurred. (In other words, pass back the return value
1003 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1004 * But that would require calling this method via sendRequest() rather
1005 * than sendRequestAsync(), and right now we don't actually *need* that
1006 * return value, so let's just return void for now.
1007 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001008 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001009 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001010 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001011 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1012 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001013 if (hasActiveCall && hasHoldingCall) {
1014 // Both lines are in use!
1015 // TODO: provide a flag to let the caller specify what
1016 // policy to use if both lines are in use. (The current
1017 // behavior is hardwired to "answer incoming, end ongoing",
1018 // which is how the CALL button is specced to behave.)
1019 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1020 return;
1021 } else {
1022 // answerCall() will automatically hold the current active
1023 // call, if there is one.
1024 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1025 return;
1026 }
1027 } else {
1028 // No call was ringing.
1029 return;
1030 }
1031 }
1032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001033 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001034 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001035 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001036 public void silenceRinger() {
1037 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001038 }
1039
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001040 @Override
1041 public boolean isOffhook(String callingPackage) {
1042 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001043 }
1044
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001045 @Override
1046 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1047 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1048 return false;
1049 }
1050
Sanket Padawe356d7632015-06-22 14:03:32 -07001051 final Phone phone = getPhone(subId);
1052 if (phone != null) {
1053 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1054 } else {
1055 return false;
1056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001057 }
1058
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001059 @Override
1060 public boolean isRinging(String callingPackage) {
1061 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001062 }
1063
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001064 @Override
1065 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1066 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1067 return false;
1068 }
1069
Sanket Padawe356d7632015-06-22 14:03:32 -07001070 final Phone phone = getPhone(subId);
1071 if (phone != null) {
1072 return (phone.getState() == PhoneConstants.State.RINGING);
1073 } else {
1074 return false;
1075 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001076 }
1077
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001078 @Override
1079 public boolean isIdle(String callingPackage) {
1080 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001081 }
1082
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001083 @Override
1084 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1085 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1086 return false;
1087 }
1088
Sanket Padawe356d7632015-06-22 14:03:32 -07001089 final Phone phone = getPhone(subId);
1090 if (phone != null) {
1091 return (phone.getState() == PhoneConstants.State.IDLE);
1092 } else {
1093 return false;
1094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001095 }
1096
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001097 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001098 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001099 }
1100
Wink Savilleb564aae2014-10-23 10:18:09 -07001101 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001102 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001103 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1104 }
1105
1106 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001107 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001108 }
1109
Wink Savilleb564aae2014-10-23 10:18:09 -07001110 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001111 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001112 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1113 }
1114
1115 /** {@hide} */
1116 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001117 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001118 }
1119
Wink Savilleb564aae2014-10-23 10:18:09 -07001120 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001121 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001122 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 checkSimPin.start();
1124 return checkSimPin.unlockSim(null, pin);
1125 }
1126
Wink Saville9de0f752013-10-22 19:04:03 -07001127 /** {@hide} */
1128 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001129 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001130 }
1131
Wink Savilleb564aae2014-10-23 10:18:09 -07001132 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001133 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001134 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 checkSimPuk.start();
1136 return checkSimPuk.unlockSim(puk, pin);
1137 }
1138
1139 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001140 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 * a synchronous one.
1142 */
1143 private static class UnlockSim extends Thread {
1144
1145 private final IccCard mSimCard;
1146
1147 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001148 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1149 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150
1151 // For replies from SimCard interface
1152 private Handler mHandler;
1153
1154 // For async handler to identify request type
1155 private static final int SUPPLY_PIN_COMPLETE = 100;
1156
1157 public UnlockSim(IccCard simCard) {
1158 mSimCard = simCard;
1159 }
1160
1161 @Override
1162 public void run() {
1163 Looper.prepare();
1164 synchronized (UnlockSim.this) {
1165 mHandler = new Handler() {
1166 @Override
1167 public void handleMessage(Message msg) {
1168 AsyncResult ar = (AsyncResult) msg.obj;
1169 switch (msg.what) {
1170 case SUPPLY_PIN_COMPLETE:
1171 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1172 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001173 mRetryCount = msg.arg1;
1174 if (ar.exception != null) {
1175 if (ar.exception instanceof CommandException &&
1176 ((CommandException)(ar.exception)).getCommandError()
1177 == CommandException.Error.PASSWORD_INCORRECT) {
1178 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1179 } else {
1180 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1181 }
1182 } else {
1183 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001185 mDone = true;
1186 UnlockSim.this.notifyAll();
1187 }
1188 break;
1189 }
1190 }
1191 };
1192 UnlockSim.this.notifyAll();
1193 }
1194 Looper.loop();
1195 }
1196
1197 /*
1198 * Use PIN or PUK to unlock SIM card
1199 *
1200 * If PUK is null, unlock SIM card with PIN
1201 *
1202 * If PUK is not null, unlock SIM card with PUK and set PIN code
1203 */
Wink Saville9de0f752013-10-22 19:04:03 -07001204 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205
1206 while (mHandler == null) {
1207 try {
1208 wait();
1209 } catch (InterruptedException e) {
1210 Thread.currentThread().interrupt();
1211 }
1212 }
1213 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1214
1215 if (puk == null) {
1216 mSimCard.supplyPin(pin, callback);
1217 } else {
1218 mSimCard.supplyPuk(puk, pin, callback);
1219 }
1220
1221 while (!mDone) {
1222 try {
1223 Log.d(LOG_TAG, "wait for done");
1224 wait();
1225 } catch (InterruptedException e) {
1226 // Restore the interrupted status
1227 Thread.currentThread().interrupt();
1228 }
1229 }
1230 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001231 int[] resultArray = new int[2];
1232 resultArray[0] = mResult;
1233 resultArray[1] = mRetryCount;
1234 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 }
1236 }
1237
1238 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001239 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001240
1241 }
1242
Wink Savilleb564aae2014-10-23 10:18:09 -07001243 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 // No permission check needed here: this call is harmless, and it's
1245 // needed for the ServiceState.requestStateUpdate() call (which is
1246 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001247 final Phone phone = getPhone(subId);
1248 if (phone != null) {
1249 phone.updateServiceLocation();
1250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 }
1252
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001253 @Override
1254 public boolean isRadioOn(String callingPackage) {
1255 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001256 }
1257
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001258 @Override
1259 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1260 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1261 return false;
1262 }
1263 return isRadioOnForSubscriber(subId);
1264 }
1265
1266 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001267 final Phone phone = getPhone(subId);
1268 if (phone != null) {
1269 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1270 } else {
1271 return false;
1272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 }
1274
1275 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001276 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001277
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 }
Wink Saville36469e72014-06-11 15:17:00 -07001279
Wink Savilleb564aae2014-10-23 10:18:09 -07001280 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001282 final Phone phone = getPhone(subId);
1283 if (phone != null) {
1284 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1285 }
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
1287
1288 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001289 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001290 }
1291
Wink Savilleb564aae2014-10-23 10:18:09 -07001292 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001293 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001294 final Phone phone = getPhone(subId);
1295 if (phone == null) {
1296 return false;
1297 }
1298 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001299 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001300 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 }
1302 return true;
1303 }
Wink Saville36469e72014-06-11 15:17:00 -07001304
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001305 public boolean needMobileRadioShutdown() {
1306 /*
1307 * If any of the Radios are available, it will need to be
1308 * shutdown. So return true if any Radio is available.
1309 */
1310 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1311 Phone phone = PhoneFactory.getPhone(i);
1312 if (phone != null && phone.isRadioAvailable()) return true;
1313 }
1314 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1315 return false;
1316 }
1317
1318 public void shutdownMobileRadios() {
1319 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1320 logv("Shutting down Phone " + i);
1321 shutdownRadioUsingPhoneId(i);
1322 }
1323 }
1324
1325 private void shutdownRadioUsingPhoneId(int phoneId) {
1326 enforceModifyPermission();
1327 Phone phone = PhoneFactory.getPhone(phoneId);
1328 if (phone != null && phone.isRadioAvailable()) {
1329 phone.shutdownRadio();
1330 }
1331 }
1332
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 public boolean setRadioPower(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001334 return setRadioPowerForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001335 }
1336
Wink Savilleb564aae2014-10-23 10:18:09 -07001337 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001338 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001339 final Phone phone = getPhone(subId);
1340 if (phone != null) {
1341 phone.setRadioPower(turnOn);
1342 return true;
1343 } else {
1344 return false;
1345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001346 }
1347
Wink Saville36469e72014-06-11 15:17:00 -07001348 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001349 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 public boolean enableDataConnectivity() {
1351 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001352 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001353 final Phone phone = getPhone(subId);
1354 if (phone != null) {
1355 phone.setDataEnabled(true);
1356 return true;
1357 } else {
1358 return false;
1359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 }
1361
Wink Saville36469e72014-06-11 15:17:00 -07001362 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001363 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 public boolean disableDataConnectivity() {
1365 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001366 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001367 final Phone phone = getPhone(subId);
1368 if (phone != null) {
1369 phone.setDataEnabled(false);
1370 return true;
1371 } else {
1372 return false;
1373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 }
1375
Wink Saville36469e72014-06-11 15:17:00 -07001376 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001377 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 public boolean isDataConnectivityPossible() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001379 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001380 final Phone phone = getPhone(subId);
1381 if (phone != null) {
1382 return phone.isDataConnectivityPossible();
1383 } else {
1384 return false;
1385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 }
1387
1388 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001389 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001390 }
1391
Wink Savilleb564aae2014-10-23 10:18:09 -07001392 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001394 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1395 return false;
1396 }
Wink Saville36469e72014-06-11 15:17:00 -07001397 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001398 }
1399
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 public int getCallState() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001401 return getCallStateForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001402 }
1403
Wink Savilleb564aae2014-10-23 10:18:09 -07001404 public int getCallStateForSubscriber(int subId) {
Wink Saville36469e72014-06-11 15:17:00 -07001405 return DefaultPhoneNotifier.convertCallState(getPhone(subId).getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 }
1407
Sanket Padawe356d7632015-06-22 14:03:32 -07001408 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001410 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001411 if (phone != null) {
1412 return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
1413 } else {
1414 return DefaultPhoneNotifier.convertDataState(PhoneConstants.DataState.DISCONNECTED);
1415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 }
1417
Sanket Padawe356d7632015-06-22 14:03:32 -07001418 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001420 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001421 if (phone != null) {
1422 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1423 } else {
1424 return TelephonyManager.DATA_ACTIVITY_NONE;
1425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426 }
1427
1428 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001429 public Bundle getCellLocation(String callingPackage) {
1430 enforceFineOrCoarseLocationPermission("getCellLocation");
1431
1432 // OP_COARSE_LOCATION controls both fine and coarse location.
1433 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1434 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001435 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001436 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001437 }
1438
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001439 if (checkIfCallerIsSelfOrForegroundUser() ||
1440 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441 if (DBG_LOC) log("getCellLocation: is active user");
1442 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001443 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001444 if (phone == null) {
1445 return null;
1446 }
Legler Wu2c01cdf2014-12-08 19:00:59 +08001447 phone.getCellLocation().fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 return data;
1449 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001450 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 return null;
1452 }
1453 }
1454
Svetoslav64fad262015-04-14 14:35:21 -07001455 private void enforceFineOrCoarseLocationPermission(String message) {
1456 try {
1457 mApp.enforceCallingOrSelfPermission(
1458 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1459 } catch (SecurityException e) {
1460 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1461 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1462 // is the weaker precondition
1463 mApp.enforceCallingOrSelfPermission(
1464 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1465 }
1466 }
1467
1468
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 @Override
1470 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001471 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001472 }
1473
Sanket Padawe356d7632015-06-22 14:03:32 -07001474 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001475 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476 mApp.enforceCallingOrSelfPermission(
1477 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001478 final Phone phone = getPhone(subId);
1479 if (phone != null) {
1480 phone.enableLocationUpdates();
1481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483
1484 @Override
1485 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
Sanket Padawe356d7632015-06-22 14:03:32 -07001489 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 mApp.enforceCallingOrSelfPermission(
1492 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001493 final Phone phone = getPhone(subId);
1494 if (phone != null) {
1495 phone.disableLocationUpdates();
1496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 }
1498
1499 @Override
1500 @SuppressWarnings("unchecked")
1501 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001502 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1503
1504 // OP_COARSE_LOCATION controls both fine and coarse location.
1505 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1506 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1507 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 }
1509
1510 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1511 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1512 return null;
1513 }
Svetoslav64fad262015-04-14 14:35:21 -07001514
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001515 if (checkIfCallerIsSelfOrForegroundUser() ||
1516 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001517 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1518
1519 ArrayList<NeighboringCellInfo> cells = null;
1520
1521 try {
1522 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sanket Padawe56e75a32016-02-08 12:18:19 -08001523 CMD_HANDLE_NEIGHBORING_CELL, null,
1524 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001526 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 }
1528 return cells;
1529 } else {
1530 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1531 return null;
1532 }
1533 }
1534
1535
1536 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001537 public List<CellInfo> getAllCellInfo(String callingPackage) {
1538 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1539
1540 // OP_COARSE_LOCATION controls both fine and coarse location.
1541 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1542 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1543 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 }
1545
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001546 if (checkIfCallerIsSelfOrForegroundUser() ||
1547 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 if (DBG_LOC) log("getAllCellInfo: is active user");
Legler Wu2c01cdf2014-12-08 19:00:59 +08001549 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1550 for (Phone phone : PhoneFactory.getPhones()) {
Robert Greenwaltd9eb7da2015-08-19 12:18:12 -07001551 final List<CellInfo> info = phone.getAllCellInfo();
1552 if (info != null) cellInfos.addAll(phone.getAllCellInfo());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001553 }
1554 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 } else {
1556 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1557 return null;
1558 }
1559 }
1560
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001561 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 public void setCellInfoListRate(int rateInMillis) {
1563 mPhone.setCellInfoListRate(rateInMillis);
1564 }
1565
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 //
1567 // Internal helper methods.
1568 //
1569
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001570 /**
1571 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1572 */
1573 private boolean checkCallerInteractAcrossUsersFull() {
1574 return mPhone.getContext().checkCallingOrSelfPermission(
1575 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1576 == PackageManager.PERMISSION_GRANTED;
1577 }
1578
Jake Hambye994d462014-02-03 13:10:13 -08001579 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 boolean ok;
1581
1582 boolean self = Binder.getCallingUid() == Process.myUid();
1583 if (!self) {
1584 // Get the caller's user id then clear the calling identity
1585 // which will be restored in the finally clause.
1586 int callingUser = UserHandle.getCallingUserId();
1587 long ident = Binder.clearCallingIdentity();
1588
1589 try {
1590 // With calling identity cleared the current user is the foreground user.
1591 int foregroundUser = ActivityManager.getCurrentUser();
1592 ok = (foregroundUser == callingUser);
1593 if (DBG_LOC) {
1594 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1595 + " callingUser=" + callingUser + " ok=" + ok);
1596 }
1597 } catch (Exception ex) {
1598 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1599 ok = false;
1600 } finally {
1601 Binder.restoreCallingIdentity(ident);
1602 }
1603 } else {
1604 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1605 ok = true;
1606 }
1607 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1608 return ok;
1609 }
1610
1611 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1613 *
1614 * @throws SecurityException if the caller does not have the required permission
1615 */
1616 private void enforceModifyPermission() {
1617 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1618 }
1619
1620 /**
Junda Liua2e36012014-07-09 18:30:01 -07001621 * Make sure either system app or the caller has carrier privilege.
1622 *
1623 * @throws SecurityException if the caller does not have the required permission/privilege
1624 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001625 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001626 int permission = mApp.checkCallingOrSelfPermission(
1627 android.Manifest.permission.MODIFY_PHONE_STATE);
1628 if (permission == PackageManager.PERMISSION_GRANTED) {
1629 return;
1630 }
1631
1632 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001633 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001634 }
1635
1636 /**
1637 * Make sure the caller has carrier privilege.
1638 *
1639 * @throws SecurityException if the caller does not have the required permission
1640 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001641 private void enforceCarrierPrivilege(int subId) {
1642 if (getCarrierPrivilegeStatus(subId) !=
1643 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001644 loge("No Carrier Privilege.");
1645 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001646 }
1647 }
1648
1649 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 * Make sure the caller has the CALL_PHONE permission.
1651 *
1652 * @throws SecurityException if the caller does not have the required permission
1653 */
1654 private void enforceCallPermission() {
1655 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1656 }
1657
Stuart Scott8eef64f2015-04-08 15:13:54 -07001658 private void enforceConnectivityInternalPermission() {
1659 mApp.enforceCallingOrSelfPermission(
1660 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1661 "ConnectivityService");
1662 }
1663
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 private String createTelUrl(String number) {
1665 if (TextUtils.isEmpty(number)) {
1666 return null;
1667 }
1668
Jake Hambye994d462014-02-03 13:10:13 -08001669 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 }
1671
Ihab Awadf9e92732013-12-05 18:02:52 -08001672 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1674 }
1675
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001676 private static void logv(String msg) {
1677 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1678 }
1679
Ihab Awadf9e92732013-12-05 18:02:52 -08001680 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1682 }
1683
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001684 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 public int getActivePhoneType() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001686 return getActivePhoneTypeForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001687 }
1688
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 public int getActivePhoneTypeForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001691 final Phone phone = getPhone(subId);
1692 if (phone == null) {
1693 return PhoneConstants.PHONE_TYPE_NONE;
1694 } else {
1695 return getPhone(subId).getPhoneType();
1696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 }
1698
1699 /**
1700 * Returns the CDMA ERI icon index to display
1701 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001702 @Override
1703 public int getCdmaEriIconIndex(String callingPackage) {
1704 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001705 }
1706
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001708 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1709 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1710 return -1;
1711 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 final Phone phone = getPhone(subId);
1713 if (phone != null) {
1714 return phone.getCdmaEriIconIndex();
1715 } else {
1716 return -1;
1717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 }
1719
1720 /**
1721 * Returns the CDMA ERI icon mode,
1722 * 0 - ON
1723 * 1 - FLASHING
1724 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001725 @Override
1726 public int getCdmaEriIconMode(String callingPackage) {
1727 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001728 }
1729
Sanket Padawe356d7632015-06-22 14:03:32 -07001730 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001731 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1732 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1733 return -1;
1734 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001735 final Phone phone = getPhone(subId);
1736 if (phone != null) {
1737 return phone.getCdmaEriIconMode();
1738 } else {
1739 return -1;
1740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
1742
1743 /**
1744 * Returns the CDMA ERI text,
1745 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001746 @Override
1747 public String getCdmaEriText(String callingPackage) {
1748 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001749 }
1750
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001752 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1753 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1754 return null;
1755 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001756 final Phone phone = getPhone(subId);
1757 if (phone != null) {
1758 return phone.getCdmaEriText();
1759 } else {
1760 return null;
1761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763
1764 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001765 * Returns the CDMA MDN.
1766 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001768 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001769 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001770 final Phone phone = getPhone(subId);
1771 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1772 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001773 } else {
1774 return null;
1775 }
1776 }
1777
1778 /**
1779 * Returns the CDMA MIN.
1780 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001781 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001782 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001783 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001784 final Phone phone = getPhone(subId);
1785 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1786 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001787 } else {
1788 return null;
1789 }
1790 }
1791
1792 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 * Returns true if CDMA provisioning needs to run.
1794 */
1795 public boolean needsOtaServiceProvisioning() {
1796 return mPhone.needsOtaServiceProvisioning();
1797 }
1798
1799 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001800 * Sets the voice mail number of a given subId.
1801 */
1802 @Override
1803 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001804 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001805 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1806 new Pair<String, String>(alphaTag, number), new Integer(subId));
1807 return success;
1808 }
1809
1810 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 * Returns the unread count of voicemails
1812 */
1813 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001814 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001815 }
1816
1817 /**
1818 * Returns the unread count of voicemails for a subId
1819 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001820 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001821 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001822 final Phone phone = getPhone(subId);
1823 if (phone != null) {
1824 return phone.getVoiceMessageCount();
1825 } else {
1826 return 0;
1827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
1830 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07001831 * Returns the data network type.
1832 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 *
1834 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
1835 */
1836 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07001837 public int getNetworkType() {
1838 final Phone phone = getPhone(getDefaultSubscription());
1839 if (phone != null) {
1840 return phone.getServiceState().getDataNetworkType();
1841 } else {
1842 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1843 }
Wink Saville36469e72014-06-11 15:17:00 -07001844 }
1845
1846 /**
1847 * Returns the network type for a subId
1848 */
1849 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001850 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
1851 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
1852 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1853 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07001854
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001856 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 return phone.getServiceState().getDataNetworkType();
1858 } else {
1859 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
1863 /**
1864 * Returns the data network type
1865 */
1866 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001867 public int getDataNetworkType(String callingPackage) {
1868 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001869 }
1870
1871 /**
1872 * Returns the data network type for a subId
1873 */
1874 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001875 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
1876 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
1877 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1878 }
1879
Sanket Padawe356d7632015-06-22 14:03:32 -07001880 final Phone phone = getPhone(subId);
1881 if (phone != null) {
1882 return phone.getServiceState().getDataNetworkType();
1883 } else {
1884 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 }
1887
1888 /**
Wink Saville36469e72014-06-11 15:17:00 -07001889 * Returns the Voice network type for a subId
1890 */
1891 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07001892 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
1893 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
1894 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1895 }
1896
Sanket Padawe356d7632015-06-22 14:03:32 -07001897 final Phone phone = getPhone(subId);
1898 if (phone != null) {
1899 return phone.getServiceState().getVoiceNetworkType();
1900 } else {
1901 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
1902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905 /**
1906 * @return true if a ICC card is present
1907 */
1908 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07001909 // FIXME Make changes to pass defaultSimId of type int
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001910 return hasIccCardUsingSlotId(mSubscriptionController.getSlotId(getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07001911 }
1912
1913 /**
1914 * @return true if a ICC card is present for a slotId
1915 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001916 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001917 public boolean hasIccCardUsingSlotId(int slotId) {
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001918 int subId[] = mSubscriptionController.getSubIdUsingSlotId(slotId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 final Phone phone = getPhone(subId[0]);
1920 if (subId != null && phone != null) {
1921 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08001922 } else {
1923 return false;
1924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
1927 /**
1928 * Return if the current radio is LTE on CDMA. This
1929 * is a tri-state return value as for a period of time
1930 * the mode may be unknown.
1931 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001932 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08001934 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001936 @Override
1937 public int getLteOnCdmaMode(String callingPackage) {
1938 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001939 }
1940
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001942 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
1943 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
1944 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
1945 }
1946
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 final Phone phone = getPhone(subId);
1948 if (phone == null) {
1949 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
1950 } else {
1951 return phone.getLteOnCdmaMode();
1952 }
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
1954
1955 public void setPhone(Phone phone) {
1956 mPhone = phone;
1957 }
1958
1959 /**
1960 * {@hide}
1961 * Returns Default subId, 0 in the case of single standby.
1962 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001963 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001964 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07001965 }
1966
Wink Savilleb564aae2014-10-23 10:18:09 -07001967 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001968 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
Ihab Awadf2177b72013-11-25 13:33:23 -08001970
1971 /**
1972 * @see android.telephony.TelephonyManager.WifiCallingChoices
1973 */
1974 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001975 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
1976 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08001977 }
1978
1979 /**
1980 * @see android.telephony.TelephonyManager.WifiCallingChoices
1981 */
1982 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08001983 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
1984 Settings.System.putInt(mPhone.getContext().getContentResolver(),
1985 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08001986 }
1987
Sailesh Nepald1e68152013-12-12 19:08:02 -08001988 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07001989 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08001990 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08001991 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08001992
Shishir Agrawal566b7612013-10-28 14:41:00 -07001993 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001994 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID) {
1995 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001996
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001997 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + AID);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001998 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001999 CMD_OPEN_CHANNEL, AID, subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002000 if (DBG) log("iccOpenLogicalChannel: " + response);
2001 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002002 }
2003
2004 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002005 public boolean iccCloseLogicalChannel(int subId, int channel) {
2006 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002007
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002008 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002009 if (channel < 0) {
2010 return false;
2011 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002012 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002013 if (DBG) log("iccCloseLogicalChannel: " + success);
2014 return success;
2015 }
2016
2017 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002018 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002019 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002020 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002021
2022 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002023 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2024 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002025 " data=" + data);
2026 }
2027
2028 if (channel < 0) {
2029 return "";
2030 }
2031
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002032 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002033 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002034 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2035
Shishir Agrawal566b7612013-10-28 14:41:00 -07002036 // Append the returned status code to the end of the response payload.
2037 String s = Integer.toHexString(
2038 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002039 if (response.payload != null) {
2040 s = IccUtils.bytesToHexString(response.payload) + s;
2041 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002042 return s;
2043 }
Jake Hambye994d462014-02-03 13:10:13 -08002044
Evan Charltonc66da362014-05-16 14:06:40 -07002045 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002046 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002047 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002048 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002049
2050 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002051 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2052 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002053 }
2054
2055 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002056 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002057 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2058
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002059 // Append the returned status code to the end of the response payload.
2060 String s = Integer.toHexString(
2061 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002062 if (response.payload != null) {
2063 s = IccUtils.bytesToHexString(response.payload) + s;
2064 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002065 return s;
2066 }
2067
2068 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002069 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002070 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002071 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002072
2073 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002074 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002075 p1 + " " + p2 + " " + p3 + ":" + filePath);
2076 }
2077
2078 IccIoResult response =
2079 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002080 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2081 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002082
2083 if (DBG) {
2084 log("Exchange SIM_IO [R]" + response);
2085 }
2086
2087 byte[] result = null;
2088 int length = 2;
2089 if (response.payload != null) {
2090 length = 2 + response.payload.length;
2091 result = new byte[length];
2092 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2093 } else {
2094 result = new byte[length];
2095 }
2096
2097 result[length - 1] = (byte) response.sw2;
2098 result[length - 2] = (byte) response.sw1;
2099 return result;
2100 }
2101
2102 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002103 public String sendEnvelopeWithStatus(int subId, String content) {
2104 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002105
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002106 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002107 if (response.payload == null) {
2108 return "";
2109 }
2110
2111 // Append the returned status code to the end of the response payload.
2112 String s = Integer.toHexString(
2113 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2114 s = IccUtils.bytesToHexString(response.payload) + s;
2115 return s;
2116 }
2117
Jake Hambye994d462014-02-03 13:10:13 -08002118 /**
2119 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2120 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2121 *
2122 * @param itemID the ID of the item to read
2123 * @return the NV item as a String, or null on error.
2124 */
2125 @Override
2126 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002127 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002128 if (DBG) log("nvReadItem: item " + itemID);
2129 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2130 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2131 return value;
2132 }
2133
2134 /**
2135 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2136 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2137 *
2138 * @param itemID the ID of the item to read
2139 * @param itemValue the value to write, as a String
2140 * @return true on success; false on any failure
2141 */
2142 @Override
2143 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002144 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002145 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2146 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2147 new Pair<Integer, String>(itemID, itemValue));
2148 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2149 return success;
2150 }
2151
2152 /**
2153 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2154 * Used for device configuration by some CDMA operators.
2155 *
2156 * @param preferredRoamingList byte array containing the new PRL
2157 * @return true on success; false on any failure
2158 */
2159 @Override
2160 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002161 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002162 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2163 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2164 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2165 return success;
2166 }
2167
2168 /**
2169 * Perform the specified type of NV config reset.
2170 * Used for device configuration by some CDMA operators.
2171 *
2172 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2173 * @return true on success; false on any failure
2174 */
2175 @Override
2176 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002177 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002178 if (DBG) log("nvResetConfig: type " + resetType);
2179 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2180 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2181 return success;
2182 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002183
2184 /**
Wink Saville36469e72014-06-11 15:17:00 -07002185 * {@hide}
2186 * Returns Default sim, 0 in the case of single standby.
2187 */
2188 public int getDefaultSim() {
2189 //TODO Need to get it from Telephony Devcontroller
2190 return 0;
2191 }
2192
Svet Ganovb320e182015-04-16 12:30:10 -07002193 public String[] getPcscfAddress(String apnType, String callingPackage) {
2194 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2195 return new String[0];
2196 }
2197
2198
ram87fca6f2014-07-18 18:58:44 +05302199 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002200 }
2201
2202 public void setImsRegistrationState(boolean registered) {
2203 enforceModifyPermission();
2204 mPhone.setImsRegistrationState(registered);
2205 }
2206
2207 /**
Stuart Scott54788802015-03-30 13:18:01 -07002208 * Set the network selection mode to automatic.
2209 *
2210 */
2211 @Override
2212 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002213 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002214 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2215 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2216 }
2217
2218 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002219 * Set the network selection mode to manual with the selected carrier.
2220 */
2221 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002222 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2223 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002224 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002225 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002226 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2227 persistSelection);
2228 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002229 }
2230
2231 /**
2232 * Scans for available networks.
2233 */
2234 @Override
2235 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002236 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002237 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2238 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2239 CMD_PERFORM_NETWORK_SCAN, null, subId);
2240 return result;
2241 }
2242
2243 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002244 * Get the calculated preferred network type.
2245 * Used for debugging incorrect network type.
2246 *
2247 * @return the preferred network type, defined in RILConstants.java.
2248 */
2249 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002250 public int getCalculatedPreferredNetworkType(String callingPackage) {
2251 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2252 return RILConstants.PREFERRED_NETWORK_MODE;
2253 }
2254
Amit Mahajan43330e02014-11-18 11:54:45 -08002255 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002256 }
2257
2258 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002259 * Get the preferred network type.
2260 * Used for device configuration by some CDMA operators.
2261 *
2262 * @return the preferred network type, defined in RILConstants.java.
2263 */
2264 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002265 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002266 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002267 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002268 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002269 int networkType = (result != null ? result[0] : -1);
2270 if (DBG) log("getPreferredNetworkType: " + networkType);
2271 return networkType;
2272 }
2273
2274 /**
2275 * Set the preferred network type.
2276 * Used for device configuration by some CDMA operators.
2277 *
2278 * @param networkType the preferred network type, defined in RILConstants.java.
2279 * @return true on success; false on any failure.
2280 */
2281 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002282 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002283 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002284 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2285 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002286 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002287 if (success) {
2288 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002289 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002290 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002291 return success;
2292 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002293
2294 /**
Junda Liu475951f2014-11-07 16:45:03 -08002295 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2296 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2297 * tethering.
2298 *
2299 * @return 0: Not required. 1: required. 2: Not set.
2300 * @hide
2301 */
2302 @Override
2303 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002304 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002305 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2306 Settings.Global.TETHER_DUN_REQUIRED, 2);
2307 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2308 // config_tether_apndata.
2309 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2310 dunRequired = 1;
2311 }
2312 return dunRequired;
2313 }
2314
2315 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002316 * Set mobile data enabled
2317 * Used by the user through settings etc to turn on/off mobile data
2318 *
2319 * @param enable {@code true} turn turn data on, else {@code false}
2320 */
2321 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002322 public void setDataEnabled(int subId, boolean enable) {
Robert Greenwalted86e582014-05-21 20:03:20 -07002323 enforceModifyPermission();
Wink Savillee7353bb2014-12-05 14:21:41 -08002324 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002325 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002326 Phone phone = PhoneFactory.getPhone(phoneId);
2327 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002328 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002329 phone.setDataEnabled(enable);
2330 } else {
2331 loge("setDataEnabled: no phone for subId=" + subId);
2332 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002333 }
2334
2335 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002336 * Get whether mobile data is enabled.
2337 *
2338 * Note that this used to be available from ConnectivityService, gated by
2339 * ACCESS_NETWORK_STATE permission, so this will accept either that or
2340 * our MODIFY_PHONE_STATE.
Robert Greenwalted86e582014-05-21 20:03:20 -07002341 *
2342 * @return {@code true} if data is enabled else {@code false}
2343 */
2344 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002345 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002346 try {
2347 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2348 null);
2349 } catch (Exception e) {
2350 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE,
2351 null);
2352 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002353 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002354 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002355 Phone phone = PhoneFactory.getPhone(phoneId);
2356 if (phone != null) {
2357 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002358 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002359 return retVal;
2360 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002361 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002362 return false;
2363 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002364 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002365
2366 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002367 public int getCarrierPrivilegeStatus(int subId) {
2368 final Phone phone = getPhone(subId);
2369 if (phone == null) {
2370 loge("getCarrierPrivilegeStatus: Invalid subId");
2371 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2372 }
2373 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002374 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002375 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002376 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2377 }
2378 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002379 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002380 }
Junda Liu29340342014-07-10 15:23:27 -07002381
2382 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002383 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002384 if (TextUtils.isEmpty(pkgName))
2385 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002386 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002387 if (card == null) {
2388 loge("checkCarrierPrivilegesForPackage: No UICC");
2389 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2390 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002391 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2392 }
2393
2394 @Override
2395 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002396 if (TextUtils.isEmpty(pkgName))
2397 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002398 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2399 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2400 UiccCard card = UiccController.getInstance().getUiccCard(i);
2401 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002402 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002403 continue;
2404 }
2405
2406 result = card.getCarrierPrivilegeStatus(
2407 mPhone.getContext().getPackageManager(), pkgName);
2408 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2409 break;
2410 }
2411 }
2412
2413 return result;
Junda Liu29340342014-07-10 15:23:27 -07002414 }
Derek Tan89e89d42014-07-08 17:00:10 -07002415
2416 @Override
Junda Liue64de782015-04-16 17:19:16 -07002417 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2418 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2419 loge("phoneId " + phoneId + " is not valid.");
2420 return null;
2421 }
2422 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002423 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002424 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002425 return null ;
2426 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002427 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002428 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002429 }
2430
Amith Yamasani6e118872016-02-19 12:53:51 -08002431 @Override
2432 public List<String> getPackagesWithCarrierPrivileges() {
2433 PackageManager pm = mPhone.getContext().getPackageManager();
2434 List<String> privilegedPackages = new ArrayList<>();
2435 List<PackageInfo> packages = null;
2436 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2437 UiccCard card = UiccController.getInstance().getUiccCard(i);
2438 if (card == null) {
2439 // No UICC in that slot.
2440 continue;
2441 }
2442 if (card.hasCarrierPrivilegeRules()) {
2443 if (packages == null) {
2444 // Only check packages in user 0 for now
2445 packages = pm.getInstalledPackagesAsUser(
2446 PackageManager.MATCH_DISABLED_COMPONENTS
2447 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2448 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2449 }
2450 for (int p = packages.size() - 1; p >= 0; p--) {
2451 PackageInfo pkgInfo = packages.get(p);
2452 if (pkgInfo != null && pkgInfo.packageName != null
2453 && card.getCarrierPrivilegeStatus(pkgInfo)
2454 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2455 privilegedPackages.add(pkgInfo.packageName);
2456 }
2457 }
2458 }
2459 }
2460 return privilegedPackages;
2461 }
2462
Wink Savilleb564aae2014-10-23 10:18:09 -07002463 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002464 final Phone phone = getPhone(subId);
2465 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002466 if (card == null) {
2467 loge("getIccId: No UICC");
2468 return null;
2469 }
2470 String iccId = card.getIccId();
2471 if (TextUtils.isEmpty(iccId)) {
2472 loge("getIccId: ICC ID is null or empty.");
2473 return null;
2474 }
2475 return iccId;
2476 }
2477
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002478 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002479 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2480 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002481 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002482
Jeff Sharkey85190e62014-12-05 09:40:12 -08002483 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 final Phone phone = getPhone(subId);
2485 if (phone == null) {
2486 return false;
2487 }
2488 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002489
2490 if (DBG_MERGE) {
2491 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2492 + subscriberId + " to " + number);
2493 }
2494
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002495 if (TextUtils.isEmpty(iccId)) {
2496 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002497 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002498
Jeff Sharkey85190e62014-12-05 09:40:12 -08002499 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2500
2501 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002502 if (alphaTag == null) {
2503 editor.remove(alphaTagPrefKey);
2504 } else {
2505 editor.putString(alphaTagPrefKey, alphaTag);
2506 }
2507
Jeff Sharkey85190e62014-12-05 09:40:12 -08002508 // Record both the line number and IMSI for this ICCID, since we need to
2509 // track all merged IMSIs based on line number
2510 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2511 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002512 if (number == null) {
2513 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002514 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002515 } else {
2516 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002517 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002518 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002519
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002520 editor.commit();
2521 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002522 }
2523
2524 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002525 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002526 // This is open to apps with WRITE_SMS.
2527 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002528 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002529 return null;
2530 }
Derek Tan97ebb422014-09-05 16:55:38 -07002531
2532 String iccId = getIccId(subId);
2533 if (iccId != null) {
2534 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002535 if (DBG_MERGE) {
2536 log("getLine1NumberForDisplay returning " +
2537 mTelephonySharedPreferences.getString(numberPrefKey, null));
2538 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002539 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002540 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002541 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002542 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002543 }
2544
2545 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002546 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2547 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2548 return null;
2549 }
Derek Tan97ebb422014-09-05 16:55:38 -07002550
2551 String iccId = getIccId(subId);
2552 if (iccId != null) {
2553 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002554 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002555 }
Derek Tan97ebb422014-09-05 16:55:38 -07002556 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002557 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002558
2559 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002560 public String[] getMergedSubscriberIds(String callingPackage) {
2561 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2562 return null;
2563 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002564 final Context context = mPhone.getContext();
2565 final TelephonyManager tele = TelephonyManager.from(context);
2566 final SubscriptionManager sub = SubscriptionManager.from(context);
2567
2568 // Figure out what subscribers are currently active
2569 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002570 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2571 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 final int[] subIds = sub.getActiveSubscriptionIdList();
2575 for (int subId : subIds) {
2576 activeSubscriberIds.add(tele.getSubscriberId(subId));
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002580 }
2581
2582 // First pass, find a number override for an active subscriber
2583 String mergeNumber = null;
2584 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
2585 for (String key : prefs.keySet()) {
2586 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
2587 final String subscriberId = (String) prefs.get(key);
2588 if (activeSubscriberIds.contains(subscriberId)) {
2589 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
2590 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2591 mergeNumber = (String) prefs.get(numberKey);
2592 if (DBG_MERGE) {
2593 Slog.d(LOG_TAG, "Found line number " + mergeNumber
2594 + " for active subscriber " + subscriberId);
2595 }
2596 if (!TextUtils.isEmpty(mergeNumber)) {
2597 break;
2598 }
2599 }
2600 }
2601 }
2602
2603 // Shortcut when no active merged subscribers
2604 if (TextUtils.isEmpty(mergeNumber)) {
2605 return null;
2606 }
2607
2608 // Second pass, find all subscribers under that line override
2609 final ArraySet<String> result = new ArraySet<>();
2610 for (String key : prefs.keySet()) {
2611 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
2612 final String number = (String) prefs.get(key);
2613 if (mergeNumber.equals(number)) {
2614 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
2615 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
2616 final String subscriberId = (String) prefs.get(subscriberKey);
2617 if (!TextUtils.isEmpty(subscriberId)) {
2618 result.add(subscriberId);
2619 }
2620 }
2621 }
2622 }
2623
2624 final String[] resultArray = result.toArray(new String[result.size()]);
2625 Arrays.sort(resultArray);
2626 if (DBG_MERGE) {
2627 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
2628 }
2629 return resultArray;
2630 }
2631
2632 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002633 public boolean setOperatorBrandOverride(int subId, String brand) {
2634 enforceCarrierPrivilege(subId);
2635 final Phone phone = getPhone(subId);
2636 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002637 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05002638
2639 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002640 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002641 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
2642 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002643 enforceCarrierPrivilege(subId);
2644 final Phone phone = getPhone(subId);
2645 if (phone == null) {
2646 return false;
2647 }
2648 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08002649 cdmaNonRoamingList);
2650 }
2651
2652 @Override
Steven Liu4bf01bc2014-07-17 11:05:29 -05002653 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
2654 enforceModifyPermission();
2655
2656 int returnValue = 0;
2657 try {
2658 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
2659 if(result.exception == null) {
2660 if (result.result != null) {
2661 byte[] responseData = (byte[])(result.result);
2662 if(responseData.length > oemResp.length) {
2663 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
2664 responseData.length + "bytes. Buffer Size is " +
2665 oemResp.length + "bytes.");
2666 }
2667 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
2668 returnValue = responseData.length;
2669 }
2670 } else {
2671 CommandException ex = (CommandException) result.exception;
2672 returnValue = ex.getCommandError().ordinal();
2673 if(returnValue > 0) returnValue *= -1;
2674 }
2675 } catch (RuntimeException e) {
2676 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
2677 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
2678 if(returnValue > 0) returnValue *= -1;
2679 }
2680
2681 return returnValue;
2682 }
Wink Saville5d475dd2014-10-17 15:00:58 -07002683
2684 @Override
2685 public void setRadioCapability(RadioAccessFamily[] rafs) {
2686 try {
2687 ProxyController.getInstance().setRadioCapability(rafs);
2688 } catch (RuntimeException e) {
2689 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
2690 }
2691 }
2692
2693 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002694 public int getRadioAccessFamily(int phoneId, String callingPackage) {
2695 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
2696 return RadioAccessFamily.RAF_UNKNOWN;
2697 }
2698
Wink Saville5d475dd2014-10-17 15:00:58 -07002699 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
2700 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002701
2702 @Override
2703 public void enableVideoCalling(boolean enable) {
2704 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002705 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07002706 }
2707
2708 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002709 public boolean isVideoCallingEnabled(String callingPackage) {
2710 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
2711 return false;
2712 }
2713
Andrew Lee77527ac2014-10-21 16:57:39 -07002714 // Check the user preference and the system-level IMS setting. Even if the user has
2715 // enabled video calling, if IMS is disabled we aren't able to support video calling.
2716 // In the long run, we may instead need to check if there exists a connection service
2717 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07002718 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
2719 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08002720 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07002721 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002722
Andrew Leea1239f22015-03-02 17:44:07 -08002723 @Override
2724 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002725 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002726 }
2727
2728 @Override
2729 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07002730 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08002731 }
2732
Andrew Lee9431b832015-03-09 18:46:45 -07002733 @Override
2734 public boolean isTtyModeSupported() {
2735 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
2736 TelephonyManager telephonyManager =
2737 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
2738 return !telephonyManager.isMultiSimEnabled() && telecomManager.isTtySupported();
2739 }
2740
2741 @Override
2742 public boolean isHearingAidCompatibilitySupported() {
2743 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
2744 }
2745
Sanket Padawe7310cc72015-01-14 09:53:20 -08002746 /**
2747 * Returns the unique device ID of phone, for example, the IMEI for
2748 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
2749 *
2750 * <p>Requires Permission:
2751 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
2752 */
2753 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002754 public String getDeviceId(String callingPackage) {
2755 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
2756 return null;
2757 }
2758
Sanket Padawe7310cc72015-01-14 09:53:20 -08002759 final Phone phone = PhoneFactory.getPhone(0);
2760 if (phone != null) {
2761 return phone.getDeviceId();
2762 } else {
2763 return null;
2764 }
2765 }
2766
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002767 /*
2768 * {@hide}
2769 * Returns the IMS Registration Status
2770 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08002771 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06002772 public boolean isImsRegistered() {
2773 return mPhone.isImsRegistered();
2774 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08002775
2776 @Override
2777 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
2778 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
2779 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07002780
Nathan Haroldc55097a2015-03-11 18:14:50 -07002781 /*
2782 * {@hide}
2783 * Returns the IMS Registration Status
2784 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07002785 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07002786 return mPhone.isWifiCallingEnabled();
2787 }
2788
2789 /*
2790 * {@hide}
2791 * Returns the IMS Registration Status
2792 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07002793 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07002794 return mPhone.isVolteEnabled();
2795 }
Svet Ganovb320e182015-04-16 12:30:10 -07002796
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07002797 /*
2798 * {@hide} Returns the IMS Registration Status
2799 */
2800 public boolean isVideoTelephonyAvailable() {
2801 return mPhone.isVideoEnabled();
2802 }
2803
Svet Ganovb320e182015-04-16 12:30:10 -07002804 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07002805 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07002806 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07002807 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
2808
Amit Mahajan83ea23b2015-07-30 16:05:11 -07002809 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07002810 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07002811 } catch (SecurityException e) {
2812 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2813 message);
Etan Cohen921655c2015-06-24 13:54:50 -07002814 }
Svet Ganovb320e182015-04-16 12:30:10 -07002815
2816 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
2817 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2818 return false;
2819 }
2820
2821 return true;
2822 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07002823
Makoto Onukifee69342015-06-29 14:44:50 -07002824 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07002825 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07002826 */
2827 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07002828 // Default SMS app can always read it.
2829 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
2830 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
2831 return true;
2832 }
2833 try {
2834 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07002835 } catch (SecurityException readPhoneStateSecurityException) {
2836 try {
2837 // Can be read with READ_SMS too.
2838 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
2839 return mAppOps.noteOp(AppOpsManager.OP_READ_SMS,
2840 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED;
2841 } catch (SecurityException readSmsSecurityException) {
2842 // Throw exception with message including both READ_PHONE_STATE and READ_SMS
2843 // permissions
2844 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
2845 " nor current process has " + android.Manifest.permission.READ_PHONE_STATE +
2846 " or " + android.Manifest.permission.READ_SMS + ".");
2847 }
Makoto Onukie4072d12015-08-03 15:12:23 -07002848 }
Makoto Onukifee69342015-06-29 14:44:50 -07002849 }
2850
Stuart Scott8eef64f2015-04-08 15:13:54 -07002851 @Override
2852 public void factoryReset(int subId) {
2853 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07002854 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
2855 return;
2856 }
2857
Svet Ganovcc087f82015-05-12 20:35:54 -07002858 final long identity = Binder.clearCallingIdentity();
2859 try {
Stuart Scott981d8582015-04-21 14:09:50 -07002860 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
2861 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07002862 // Enable data
2863 setDataEnabled(subId, true);
2864 // Set network selection mode to automatic
2865 setNetworkSelectionModeAutomatic(subId);
2866 // Set preferred mobile network type to the best available
2867 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
2868 // Turn off roaming
2869 SubscriptionManager.from(mApp).setDataRoaming(0, subId);
2870 }
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002873 }
2874 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01002875
2876 @Override
2877 public String getLocaleFromDefaultSim() {
2878 // We query all subscriptions instead of just the active ones, because
2879 // this might be called early on in the provisioning flow when the
2880 // subscriptions potentially aren't active yet.
2881 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
2882 if (slist == null || slist.isEmpty()) {
2883 return null;
2884 }
2885
2886 // This function may be called very early, say, from the setup wizard, at
2887 // which point we won't have a default subscription set. If that's the case
2888 // we just choose the first, which will be valid in "most cases".
2889 final int defaultSubId = getDefaultSubscription();
2890 SubscriptionInfo info = null;
2891 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
2892 info = slist.get(0);
2893 } else {
2894 for (SubscriptionInfo item : slist) {
2895 if (item.getSubscriptionId() == defaultSubId) {
2896 info = item;
2897 break;
2898 }
2899 }
2900
2901 if (info == null) {
2902 return null;
2903 }
2904 }
2905
2906 // Try and fetch the locale from the carrier properties or from the SIM language
2907 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01002908 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01002909 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01002910 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01002911 if (defaultPhone != null) {
2912 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
2913 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01002914 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01002915 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
2916 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01002917 } else {
2918 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01002919 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01002920 }
2921 }
2922
Narayan Kamath011676f2015-07-29 12:04:08 +01002923 // The SIM language preferences only store a language (e.g. fr = French), not an
2924 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
2925 // the SIM and carrier preferences does not include a country we add the country
2926 // determined from the SIM MCC to provide an exact locale.
2927 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01002928 if (mccLocale != null) {
2929 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
2930 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01002931 }
2932
Tony Hill183b2de2015-06-24 14:53:58 +01002933 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01002934 return null;
2935 }
2936
2937 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 return mSubscriptionController.getAllSubInfoList(
2941 mPhone.getContext().getOpPackageName());
2942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
2945 }
2946
2947 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 return mSubscriptionController.getActiveSubscriptionInfoList(
2951 mPhone.getContext().getOpPackageName());
2952 } finally {
2953 Binder.restoreCallingIdentity(identity);
2954 }
2955 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07002956
2957 /**
2958 * {@hide}
2959 * Returns the modem stats
2960 */
2961 @Override
2962 public ModemActivityInfo getModemActivityInfo() {
2963 return (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
2964 }
Jack Yu85bd38a2015-11-09 11:34:32 -08002965
2966 /**
2967 * {@hide}
2968 * Returns the service state information on specified subscription.
2969 */
2970 @Override
2971 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
2972
2973 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
2974 return null;
2975 }
2976
2977 final Phone phone = getPhone(subId);
2978 if (phone == null) {
2979 return null;
2980 }
2981
2982 return phone.getServiceState();
2983 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08002984
2985 /**
2986 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
2987 *
2988 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
2989 * voicemail ringtone.
2990 * @return The URI for the ringtone to play when receiving a voicemail from a specific
2991 * PhoneAccount.
2992 */
2993 @Override
2994 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
2995 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
2996 if (phone == null) {
2997 return null;
2998 }
2999
3000 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone);
3001 }
3002
3003 /**
3004 * Returns whether vibration is set for voicemail notification in Phone settings.
3005 *
3006 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3007 * voicemail vibration setting.
3008 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3009 */
3010 @Override
3011 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
3012 final Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
3013 if (phone == null) {
3014 return false;
3015 }
3016
3017 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone);
3018 }
3019
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020}