blob: de60c61a9090b51b6067336b2af1554f52274952 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.ActivityManager;
23import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070025import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.content.Context;
27import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070028import android.content.SharedPreferences;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Process;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070058import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080059import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070060import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070061import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080064import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070065import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080066import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080067import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070068import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070069import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070071import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080075import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080076import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080077
Andrew Lee312e8172014-10-23 17:01:36 -070078import com.android.ims.ImsManager;
Brad Ebinger51f743a2017-01-23 13:50:20 -080079import com.android.ims.internal.IImsServiceController;
80import com.android.ims.internal.IImsServiceFeatureListener;
Shishir Agrawal566b7612013-10-28 14:41:00 -070081import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070082import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070083import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070084import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080087import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010088import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070089import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070090import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080092import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070093import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070094import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070095import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070096import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070097import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080098import com.android.internal.telephony.SubscriptionController;
Shishir Agrawal566b7612013-10-28 14:41:00 -070099import com.android.internal.telephony.uicc.IccIoResult;
100import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800101import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700102import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800103import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700104import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700105import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800106import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700107import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800108import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700109import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700110import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800111
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700112import java.io.FileDescriptor;
113import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800114import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800117import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100118import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120
121/**
122 * Implementation of the ITelephony interface.
123 */
Santos Cordon117fee72014-05-16 17:56:12 -0700124public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125 private static final String LOG_TAG = "PhoneInterfaceManager";
126 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
127 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800128 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129
130 // Message codes used with mMainThreadHandler
131 private static final int CMD_HANDLE_PIN_MMI = 1;
132 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
133 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
134 private static final int CMD_ANSWER_RINGING_CALL = 4;
135 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700136 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
137 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700138 private static final int CMD_OPEN_CHANNEL = 9;
139 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
140 private static final int CMD_CLOSE_CHANNEL = 11;
141 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800142 private static final int CMD_NV_READ_ITEM = 13;
143 private static final int EVENT_NV_READ_ITEM_DONE = 14;
144 private static final int CMD_NV_WRITE_ITEM = 15;
145 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
146 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
147 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
148 private static final int CMD_NV_RESET_CONFIG = 19;
149 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800150 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
151 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
152 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
153 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800154 private static final int CMD_SEND_ENVELOPE = 25;
155 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700156 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
157 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
158 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
159 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
160 private static final int CMD_EXCHANGE_SIM_IO = 31;
161 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800162 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
163 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700164 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
165 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700166 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
167 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700168 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
169 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
170 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
171 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700172 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
173 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
174 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
175 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700176 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800177 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
178 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179
180 /** The singleton instance. */
181 private static PhoneInterfaceManager sInstance;
182
Wink Saville3ab207e2014-11-20 13:07:20 -0800183 private PhoneGlobals mApp;
184 private Phone mPhone;
185 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700186 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800187 private AppOpsManager mAppOps;
188 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800189 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800190 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191
Derek Tan97ebb422014-09-05 16:55:38 -0700192 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
193 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800194 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700195
yinxub1bed742017-04-17 11:45:04 -0700196 private NetworkScanRequestTracker mNetworkScanRequestTracker;
197
Derek Tan89e89d42014-07-08 17:00:10 -0700198 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199 * A request object to use for transmitting data to an ICC.
200 */
201 private static final class IccAPDUArgument {
202 public int channel, cla, command, p1, p2, p3;
203 public String data;
204
205 public IccAPDUArgument(int channel, int cla, int command,
206 int p1, int p2, int p3, String data) {
207 this.channel = channel;
208 this.cla = cla;
209 this.command = command;
210 this.p1 = p1;
211 this.p2 = p2;
212 this.p3 = p3;
213 this.data = data;
214 }
215 }
216
217 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700218 * A request object to use for transmitting data to an ICC.
219 */
220 private static final class ManualNetworkSelectionArgument {
221 public OperatorInfo operatorInfo;
222 public boolean persistSelection;
223
224 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
225 this.operatorInfo = operatorInfo;
226 this.persistSelection = persistSelection;
227 }
228 }
229
230 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
232 * request after sending. The main thread will notify the request when it is complete.
233 */
234 private static final class MainThreadRequest {
235 /** The argument to use for the request */
236 public Object argument;
237 /** The result of the request that is run on the main thread */
238 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800239 // The subscriber id that this request applies to. Defaults to
240 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
241 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700242
243 public MainThreadRequest(Object argument) {
244 this.argument = argument;
245 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800246
247 public MainThreadRequest(Object argument, Integer subId) {
248 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800249 if (subId != null) {
250 this.subId = subId;
251 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 }
254
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800255 private static final class IncomingThirdPartyCallArgs {
256 public final ComponentName component;
257 public final String callId;
258 public final String callerDisplayName;
259
260 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
261 String callerDisplayName) {
262 this.component = component;
263 this.callId = callId;
264 this.callerDisplayName = callerDisplayName;
265 }
266 }
267
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268 /**
269 * A handler that processes messages on the main thread in the phone process. Since many
270 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
271 * inbound binder threads to the main thread in the phone process. The Binder thread
272 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
273 * on, which will be notified when the operation completes and will contain the result of the
274 * request.
275 *
276 * <p>If a MainThreadRequest object is provided in the msg.obj field,
277 * note that request.result must be set to something non-null for the calling thread to
278 * unblock.
279 */
280 private final class MainThreadHandler extends Handler {
281 @Override
282 public void handleMessage(Message msg) {
283 MainThreadRequest request;
284 Message onCompleted;
285 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800286 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700287 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288
289 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700290 case CMD_HANDLE_USSD_REQUEST: {
291 request = (MainThreadRequest) msg.obj;
292 final Phone phone = getPhoneFromRequest(request);
293 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
294 String ussdRequest = ussdObject.first;
295 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700296
297 if (!isUssdApiAllowed(request.subId)) {
298 // Carrier does not support use of this API, return failure.
299 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
300 UssdResponse response = new UssdResponse(ussdRequest, null);
301 Bundle returnData = new Bundle();
302 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
303 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
304
305 request.result = true;
306 synchronized (request) {
307 request.notifyAll();
308 }
309 return;
310 }
311
Tyler Gunn52dcf772017-04-26 11:30:31 -0700312 try {
313 request.result = phone != null ?
314 phone.handleUssdRequest(ussdRequest, wrappedCallback)
315 : false;
316 } catch (CallStateException cse) {
317 request.result = false;
318 }
pkanwar32d516d2016-10-14 19:37:38 -0700319 // Wake up the requesting thread
320 synchronized (request) {
321 request.notifyAll();
322 }
323 break;
324 }
325
Yorke Lee716f67e2015-06-17 15:39:16 -0700326 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700328 final Phone phone = getPhoneFromRequest(request);
329 request.result = phone != null ?
330 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
331 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 // Wake up the requesting thread
333 synchronized (request) {
334 request.notifyAll();
335 }
336 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338
339 case CMD_HANDLE_NEIGHBORING_CELL:
340 request = (MainThreadRequest) msg.obj;
341 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
342 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700343 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 break;
345
346 case EVENT_NEIGHBORING_CELL_DONE:
347 ar = (AsyncResult) msg.obj;
348 request = (MainThreadRequest) ar.userObj;
349 if (ar.exception == null && ar.result != null) {
350 request.result = ar.result;
351 } else {
352 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800353 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 }
355 // Wake up the requesting thread
356 synchronized (request) {
357 request.notifyAll();
358 }
359 break;
360
361 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700362 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800363 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700364 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 break;
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 case CMD_END_CALL:
368 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800369 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700370 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700371 Phone phone = getPhone(end_subId);
372 if (phone == null) {
373 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
374 break;
375 }
376 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
378 // CDMA: If the user presses the Power button we treat it as
379 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700380 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
382 // GSM: End the call as per the Phone state
383 hungUp = PhoneUtils.hangup(mCM);
384 } else {
385 throw new IllegalStateException("Unexpected phone type: " + phoneType);
386 }
387 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
388 request.result = hungUp;
389 // Wake up the requesting thread
390 synchronized (request) {
391 request.notifyAll();
392 }
393 break;
394
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700395 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700396 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700397 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800398 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700399 if (uiccCard == null) {
400 loge("iccTransmitApduLogicalChannel: No UICC");
401 request.result = new IccIoResult(0x6F, 0, (byte[])null);
402 synchronized (request) {
403 request.notifyAll();
404 }
405 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700406 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
407 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700408 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700409 iccArgument.channel, iccArgument.cla, iccArgument.command,
410 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700411 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700412 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700413 break;
414
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 ar = (AsyncResult) msg.obj;
417 request = (MainThreadRequest) ar.userObj;
418 if (ar.exception == null && ar.result != null) {
419 request.result = ar.result;
420 } else {
421 request.result = new IccIoResult(0x6F, 0, (byte[])null);
422 if (ar.result == null) {
423 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800424 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800426 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700427 } else {
428 loge("iccTransmitApduLogicalChannel: Unknown exception");
429 }
430 }
431 synchronized (request) {
432 request.notifyAll();
433 }
434 break;
435
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
437 request = (MainThreadRequest) msg.obj;
438 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800439 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 if (uiccCard == null) {
441 loge("iccTransmitApduBasicChannel: No UICC");
442 request.result = new IccIoResult(0x6F, 0, (byte[])null);
443 synchronized (request) {
444 request.notifyAll();
445 }
446 } else {
447 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
448 request);
449 uiccCard.iccTransmitApduBasicChannel(
450 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
451 iccArgument.p3, iccArgument.data, onCompleted);
452 }
453 break;
454
455 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
456 ar = (AsyncResult) msg.obj;
457 request = (MainThreadRequest) ar.userObj;
458 if (ar.exception == null && ar.result != null) {
459 request.result = ar.result;
460 } else {
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
462 if (ar.result == null) {
463 loge("iccTransmitApduBasicChannel: Empty response");
464 } else if (ar.exception instanceof CommandException) {
465 loge("iccTransmitApduBasicChannel: CommandException: " +
466 ar.exception);
467 } else {
468 loge("iccTransmitApduBasicChannel: Unknown exception");
469 }
470 }
471 synchronized (request) {
472 request.notifyAll();
473 }
474 break;
475
476 case CMD_EXCHANGE_SIM_IO:
477 request = (MainThreadRequest) msg.obj;
478 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800479 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 if (uiccCard == null) {
481 loge("iccExchangeSimIO: No UICC");
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
483 synchronized (request) {
484 request.notifyAll();
485 }
486 } else {
487 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
488 request);
489 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
490 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
491 iccArgument.data, onCompleted);
492 }
493 break;
494
495 case EVENT_EXCHANGE_SIM_IO_DONE:
496 ar = (AsyncResult) msg.obj;
497 request = (MainThreadRequest) ar.userObj;
498 if (ar.exception == null && ar.result != null) {
499 request.result = ar.result;
500 } else {
501 request.result = new IccIoResult(0x6f, 0, (byte[])null);
502 }
503 synchronized (request) {
504 request.notifyAll();
505 }
506 break;
507
Derek Tan4d5e5c12014-02-04 11:54:58 -0800508 case CMD_SEND_ENVELOPE:
509 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800510 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700511 if (uiccCard == null) {
512 loge("sendEnvelopeWithStatus: No UICC");
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 synchronized (request) {
515 request.notifyAll();
516 }
517 } else {
518 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
519 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
520 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800521 break;
522
523 case EVENT_SEND_ENVELOPE_DONE:
524 ar = (AsyncResult) msg.obj;
525 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700526 if (ar.exception == null && ar.result != null) {
527 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800528 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
530 if (ar.result == null) {
531 loge("sendEnvelopeWithStatus: Empty response");
532 } else if (ar.exception instanceof CommandException) {
533 loge("sendEnvelopeWithStatus: CommandException: " +
534 ar.exception);
535 } else {
536 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
537 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 }
539 synchronized (request) {
540 request.notifyAll();
541 }
542 break;
543
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 case CMD_OPEN_CHANNEL:
545 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800546 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800547 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700548 if (uiccCard == null) {
549 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800550 request.result = new IccOpenLogicalChannelResponse(-1,
551 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 synchronized (request) {
553 request.notifyAll();
554 }
555 } else {
556 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800557 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
558 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 break;
561
562 case EVENT_OPEN_CHANNEL_DONE:
563 ar = (AsyncResult) msg.obj;
564 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 int[] result = (int[]) ar.result;
568 int channelId = result[0];
569 byte[] selectResponse = null;
570 if (result.length > 1) {
571 selectResponse = new byte[result.length - 1];
572 for (int i = 1; i < result.length; ++i) {
573 selectResponse[i - 1] = (byte) result[i];
574 }
575 }
576 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700577 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 if (ar.result == null) {
580 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 if (ar.exception != null) {
583 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
584 }
585
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700586 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700587 if (ar.exception instanceof CommandException) {
588 CommandException.Error error =
589 ((CommandException) (ar.exception)).getCommandError();
590 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700591 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700592 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700593 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 }
595 }
596 openChannelResp = new IccOpenLogicalChannelResponse(
597 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700599 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 synchronized (request) {
601 request.notifyAll();
602 }
603 break;
604
605 case CMD_CLOSE_CHANNEL:
606 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800607 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 if (uiccCard == null) {
609 loge("iccCloseLogicalChannel: No UICC");
610 request.result = new IccIoResult(0x6F, 0, (byte[])null);
611 synchronized (request) {
612 request.notifyAll();
613 }
614 } else {
615 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
616 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
617 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 break;
619
620 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800621 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
622 break;
623
624 case CMD_NV_READ_ITEM:
625 request = (MainThreadRequest) msg.obj;
626 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
627 mPhone.nvReadItem((Integer) request.argument, onCompleted);
628 break;
629
630 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800636 request.result = "";
637 if (ar.result == null) {
638 loge("nvReadItem: Empty response");
639 } else if (ar.exception instanceof CommandException) {
640 loge("nvReadItem: CommandException: " +
641 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800643 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
645 }
646 synchronized (request) {
647 request.notifyAll();
648 }
649 break;
650
Jake Hambye994d462014-02-03 13:10:13 -0800651 case CMD_NV_WRITE_ITEM:
652 request = (MainThreadRequest) msg.obj;
653 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
654 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
655 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
656 break;
657
658 case EVENT_NV_WRITE_ITEM_DONE:
659 handleNullReturnEvent(msg, "nvWriteItem");
660 break;
661
662 case CMD_NV_WRITE_CDMA_PRL:
663 request = (MainThreadRequest) msg.obj;
664 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
665 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
666 break;
667
668 case EVENT_NV_WRITE_CDMA_PRL_DONE:
669 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
670 break;
671
672 case CMD_NV_RESET_CONFIG:
673 request = (MainThreadRequest) msg.obj;
674 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
675 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
676 break;
677
678 case EVENT_NV_RESET_CONFIG_DONE:
679 handleNullReturnEvent(msg, "nvResetConfig");
680 break;
681
Jake Hamby7c27be32014-03-03 13:25:59 -0800682 case CMD_GET_PREFERRED_NETWORK_TYPE:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700685 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800686 break;
687
688 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
691 if (ar.exception == null && ar.result != null) {
692 request.result = ar.result; // Integer
693 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800694 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800695 if (ar.result == null) {
696 loge("getPreferredNetworkType: Empty response");
697 } else if (ar.exception instanceof CommandException) {
698 loge("getPreferredNetworkType: CommandException: " +
699 ar.exception);
700 } else {
701 loge("getPreferredNetworkType: Unknown exception");
702 }
703 }
704 synchronized (request) {
705 request.notifyAll();
706 }
707 break;
708
709 case CMD_SET_PREFERRED_NETWORK_TYPE:
710 request = (MainThreadRequest) msg.obj;
711 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
712 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700713 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 break;
715
716 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
717 handleNullReturnEvent(msg, "setPreferredNetworkType");
718 break;
719
Steven Liu4bf01bc2014-07-17 11:05:29 -0500720 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
721 request = (MainThreadRequest)msg.obj;
722 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
723 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
724 break;
725
726 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
727 ar = (AsyncResult)msg.obj;
728 request = (MainThreadRequest)ar.userObj;
729 request.result = ar;
730 synchronized (request) {
731 request.notifyAll();
732 }
733 break;
734
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800735 case CMD_SET_VOICEMAIL_NUMBER:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
738 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800739 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
740 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800741 break;
742
743 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
744 handleNullReturnEvent(msg, "setVoicemailNumber");
745 break;
746
Stuart Scott54788802015-03-30 13:18:01 -0700747 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
750 request);
751 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
752 break;
753
754 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
755 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
756 break;
757
Shishir Agrawal302c8692015-06-19 13:49:39 -0700758 case CMD_PERFORM_NETWORK_SCAN:
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
761 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
762 break;
763
764 case EVENT_PERFORM_NETWORK_SCAN_DONE:
765 ar = (AsyncResult) msg.obj;
766 request = (MainThreadRequest) ar.userObj;
767 CellNetworkScanResult cellScanResult;
768 if (ar.exception == null && ar.result != null) {
769 cellScanResult = new CellNetworkScanResult(
770 CellNetworkScanResult.STATUS_SUCCESS,
771 (List<OperatorInfo>) ar.result);
772 } else {
773 if (ar.result == null) {
774 loge("getCellNetworkScanResults: Empty response");
775 }
776 if (ar.exception != null) {
777 loge("getCellNetworkScanResults: Exception: " + ar.exception);
778 }
779 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
780 if (ar.exception instanceof CommandException) {
781 CommandException.Error error =
782 ((CommandException) (ar.exception)).getCommandError();
783 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
784 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
785 } else if (error == CommandException.Error.GENERIC_FAILURE) {
786 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
787 }
788 }
789 cellScanResult = new CellNetworkScanResult(errorCode, null);
790 }
791 request.result = cellScanResult;
792 synchronized (request) {
793 request.notifyAll();
794 }
795 break;
796
797 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
798 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700799 ManualNetworkSelectionArgument selArg =
800 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700801 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
802 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700803 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
804 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700805 break;
806
807 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
808 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
809 break;
810
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700811 case CMD_GET_MODEM_ACTIVITY_INFO:
812 request = (MainThreadRequest) msg.obj;
813 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700814 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700815 break;
816
817 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
818 ar = (AsyncResult) msg.obj;
819 request = (MainThreadRequest) ar.userObj;
820 if (ar.exception == null && ar.result != null) {
821 request.result = ar.result;
822 } else {
823 if (ar.result == null) {
824 loge("queryModemActivityInfo: Empty response");
825 } else if (ar.exception instanceof CommandException) {
826 loge("queryModemActivityInfo: CommandException: " +
827 ar.exception);
828 } else {
829 loge("queryModemActivityInfo: Unknown exception");
830 }
831 }
Amit Mahajand4766222016-01-28 15:28:28 -0800832 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
833 if (request.result == null) {
834 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
835 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700836 synchronized (request) {
837 request.notifyAll();
838 }
839 break;
840
Meng Wang1a7c35a2016-05-05 20:56:15 -0700841 case CMD_SET_ALLOWED_CARRIERS:
842 request = (MainThreadRequest) msg.obj;
843 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
844 mPhone.setAllowedCarriers(
845 (List<CarrierIdentifier>) request.argument,
846 onCompleted);
847 break;
848
849 case EVENT_SET_ALLOWED_CARRIERS_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result;
854 } else {
855 if (ar.result == null) {
856 loge("setAllowedCarriers: Empty response");
857 } else if (ar.exception instanceof CommandException) {
858 loge("setAllowedCarriers: CommandException: " +
859 ar.exception);
860 } else {
861 loge("setAllowedCarriers: Unknown exception");
862 }
863 }
864 // Result cannot be null. Return -1 on error.
865 if (request.result == null) {
866 request.result = new int[]{-1};
867 }
868 synchronized (request) {
869 request.notifyAll();
870 }
871 break;
872
873 case CMD_GET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
876 mPhone.getAllowedCarriers(onCompleted);
877 break;
878
879 case EVENT_GET_ALLOWED_CARRIERS_DONE:
880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
882 if (ar.exception == null && ar.result != null) {
883 request.result = ar.result;
884 } else {
885 if (ar.result == null) {
886 loge("getAllowedCarriers: Empty response");
887 } else if (ar.exception instanceof CommandException) {
888 loge("getAllowedCarriers: CommandException: " +
889 ar.exception);
890 } else {
891 loge("getAllowedCarriers: Unknown exception");
892 }
893 }
894 // Result cannot be null. Return empty list of CarrierIdentifier.
895 if (request.result == null) {
896 request.result = new ArrayList<CarrierIdentifier>(0);
897 }
898 synchronized (request) {
899 request.notifyAll();
900 }
901 break;
902
Nathan Haroldb3014052017-01-25 15:57:32 -0800903 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
904 ar = (AsyncResult) msg.obj;
905 request = (MainThreadRequest) ar.userObj;
906 if (ar.exception == null && ar.result != null) {
907 request.result = ar.result;
908 } else {
909 request.result = new IllegalArgumentException(
910 "Failed to retrieve Forbidden Plmns");
911 if (ar.result == null) {
912 loge("getForbiddenPlmns: Empty response");
913 } else {
914 loge("getForbiddenPlmns: Unknown exception");
915 }
916 }
917 synchronized (request) {
918 request.notifyAll();
919 }
920 break;
921
922 case CMD_GET_FORBIDDEN_PLMNS:
923 request = (MainThreadRequest) msg.obj;
924 uiccCard = getUiccCardFromRequest(request);
925 if (uiccCard == null) {
926 loge("getForbiddenPlmns() UiccCard is null");
927 request.result = new IllegalArgumentException(
928 "getForbiddenPlmns() UiccCard is null");
929 synchronized (request) {
930 request.notifyAll();
931 }
932 break;
933 }
934 Integer appType = (Integer) request.argument;
935 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
936 if (uiccApp == null) {
937 loge("getForbiddenPlmns() no app with specified type -- "
938 + appType);
939 request.result = new IllegalArgumentException("Failed to get UICC App");
940 synchronized (request) {
941 request.notifyAll();
942 }
943 break;
944 } else {
945 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
946 + " specified type -- " + appType);
947 }
948 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
949 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
950 onCompleted);
951 break;
952
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700953 default:
954 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
955 break;
956 }
957 }
Jake Hambye994d462014-02-03 13:10:13 -0800958
959 private void handleNullReturnEvent(Message msg, String command) {
960 AsyncResult ar = (AsyncResult) msg.obj;
961 MainThreadRequest request = (MainThreadRequest) ar.userObj;
962 if (ar.exception == null) {
963 request.result = true;
964 } else {
965 request.result = false;
966 if (ar.exception instanceof CommandException) {
967 loge(command + ": CommandException: " + ar.exception);
968 } else {
969 loge(command + ": Unknown exception");
970 }
971 }
972 synchronized (request) {
973 request.notifyAll();
974 }
975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700976 }
977
978 /**
979 * Posts the specified command to be executed on the main thread,
980 * waits for the request to complete, and returns the result.
981 * @see #sendRequestAsync
982 */
983 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800984 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700985 }
986
987 /**
988 * Posts the specified command to be executed on the main thread,
989 * waits for the request to complete, and returns the result.
990 * @see #sendRequestAsync
991 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800992 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700993 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
994 throw new RuntimeException("This method will deadlock if called from the main thread.");
995 }
996
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800997 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700998 Message msg = mMainThreadHandler.obtainMessage(command, request);
999 msg.sendToTarget();
1000
1001 // Wait for the request to complete
1002 synchronized (request) {
1003 while (request.result == null) {
1004 try {
1005 request.wait();
1006 } catch (InterruptedException e) {
1007 // Do nothing, go back and wait until the request is complete
1008 }
1009 }
1010 }
1011 return request.result;
1012 }
1013
1014 /**
1015 * Asynchronous ("fire and forget") version of sendRequest():
1016 * Posts the specified command to be executed on the main thread, and
1017 * returns immediately.
1018 * @see #sendRequest
1019 */
1020 private void sendRequestAsync(int command) {
1021 mMainThreadHandler.sendEmptyMessage(command);
1022 }
1023
1024 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001025 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1026 * @see {@link #sendRequest(int,Object)}
1027 */
1028 private void sendRequestAsync(int command, Object argument) {
1029 MainThreadRequest request = new MainThreadRequest(argument);
1030 Message msg = mMainThreadHandler.obtainMessage(command, request);
1031 msg.sendToTarget();
1032 }
1033
1034 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001035 * Initialize the singleton PhoneInterfaceManager instance.
1036 * This is only done once, at startup, from PhoneApp.onCreate().
1037 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001038 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001039 synchronized (PhoneInterfaceManager.class) {
1040 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001041 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001042 } else {
1043 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1044 }
1045 return sInstance;
1046 }
1047 }
1048
1049 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001050 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001051 mApp = app;
1052 mPhone = phone;
1053 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001054 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001055 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1056 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001057 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001058 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001059 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001060 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001061
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001062 publish();
1063 }
1064
1065 private void publish() {
1066 if (DBG) log("publish: " + this);
1067
1068 ServiceManager.addService("phone", this);
1069 }
1070
Stuart Scott584921c2015-01-15 17:10:34 -08001071 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001072 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1073 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001074 }
1075
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001076 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1077 Phone phone = getPhoneFromRequest(request);
1078 return phone == null ? null :
1079 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1080 }
1081
Wink Saville36469e72014-06-11 15:17:00 -07001082 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001083 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001084 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001086 //
1087 // Implementation of the ITelephony interface.
1088 //
1089
1090 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001091 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001092 }
1093
Wink Savilleb564aae2014-10-23 10:18:09 -07001094 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001095 if (DBG) log("dial: " + number);
1096 // No permission check needed here: This is just a wrapper around the
1097 // ACTION_DIAL intent, which is available to any app since it puts up
1098 // the UI before it does anything.
1099
1100 String url = createTelUrl(number);
1101 if (url == null) {
1102 return;
1103 }
1104
1105 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001106 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001107 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1108 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1109 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1110 mApp.startActivity(intent);
1111 }
1112 }
1113
1114 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001115 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001116 }
1117
Wink Savilleb564aae2014-10-23 10:18:09 -07001118 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001119 if (DBG) log("call: " + number);
1120
1121 // This is just a wrapper around the ACTION_CALL intent, but we still
1122 // need to do a permission check since we're calling startActivity()
1123 // from the context of the phone app.
1124 enforceCallPermission();
1125
1126 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1127 != AppOpsManager.MODE_ALLOWED) {
1128 return;
1129 }
1130
1131 String url = createTelUrl(number);
1132 if (url == null) {
1133 return;
1134 }
1135
Wink Saville08874612014-08-31 19:19:58 -07001136 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001137 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001138 if (slist != null) {
1139 for (SubscriptionInfo subInfoRecord : slist) {
1140 if (subInfoRecord.getSubscriptionId() == subId) {
1141 isValid = true;
1142 break;
1143 }
Wink Saville08874612014-08-31 19:19:58 -07001144 }
1145 }
1146 if (isValid == false) {
1147 return;
1148 }
1149
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001150 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001151 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001152 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1153 mApp.startActivity(intent);
1154 }
1155
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001156 /**
1157 * End a call based on call state
1158 * @return true is a call was ended
1159 */
1160 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001161 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001162 }
1163
1164 /**
1165 * End a call based on the call state of the subId
1166 * @return true is a call was ended
1167 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001168 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001170 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 }
1172
1173 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001174 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001175 }
1176
Wink Savilleb564aae2014-10-23 10:18:09 -07001177 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001178 if (DBG) log("answerRingingCall...");
1179 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1180 // but that can probably wait till the big TelephonyManager API overhaul.
1181 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1182 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001183 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184 }
1185
1186 /**
1187 * Make the actual telephony calls to implement answerRingingCall().
1188 * This should only be called from the main thread of the Phone app.
1189 * @see #answerRingingCall
1190 *
1191 * TODO: it would be nice to return true if we answered the call, or
1192 * false if there wasn't actually a ringing incoming call, or some
1193 * other error occurred. (In other words, pass back the return value
1194 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1195 * But that would require calling this method via sendRequest() rather
1196 * than sendRequestAsync(), and right now we don't actually *need* that
1197 * return value, so let's just return void for now.
1198 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001199 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001200 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001201 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001202 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1203 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 if (hasActiveCall && hasHoldingCall) {
1205 // Both lines are in use!
1206 // TODO: provide a flag to let the caller specify what
1207 // policy to use if both lines are in use. (The current
1208 // behavior is hardwired to "answer incoming, end ongoing",
1209 // which is how the CALL button is specced to behave.)
1210 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1211 return;
1212 } else {
1213 // answerCall() will automatically hold the current active
1214 // call, if there is one.
1215 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1216 return;
1217 }
1218 } else {
1219 // No call was ringing.
1220 return;
1221 }
1222 }
1223
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001224 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001225 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001227 public void silenceRinger() {
1228 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 }
1230
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001231 @Override
1232 public boolean isOffhook(String callingPackage) {
1233 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001234 }
1235
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001236 @Override
1237 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1238 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1239 return false;
1240 }
1241
Sanket Padawe356d7632015-06-22 14:03:32 -07001242 final Phone phone = getPhone(subId);
1243 if (phone != null) {
1244 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1245 } else {
1246 return false;
1247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 }
1249
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001250 @Override
1251 public boolean isRinging(String callingPackage) {
1252 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001253 }
1254
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001255 @Override
1256 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1257 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1258 return false;
1259 }
1260
Sanket Padawe356d7632015-06-22 14:03:32 -07001261 final Phone phone = getPhone(subId);
1262 if (phone != null) {
1263 return (phone.getState() == PhoneConstants.State.RINGING);
1264 } else {
1265 return false;
1266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 }
1268
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001269 @Override
1270 public boolean isIdle(String callingPackage) {
1271 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001272 }
1273
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001274 @Override
1275 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1276 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1277 return false;
1278 }
1279
Sanket Padawe356d7632015-06-22 14:03:32 -07001280 final Phone phone = getPhone(subId);
1281 if (phone != null) {
1282 return (phone.getState() == PhoneConstants.State.IDLE);
1283 } else {
1284 return false;
1285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 }
1287
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001289 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001290 }
1291
Wink Savilleb564aae2014-10-23 10:18:09 -07001292 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001293 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001294 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1295 }
1296
1297 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001298 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001299 }
1300
Wink Savilleb564aae2014-10-23 10:18:09 -07001301 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001302 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001303 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1304 }
1305
1306 /** {@hide} */
1307 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001308 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001309 }
1310
Wink Savilleb564aae2014-10-23 10:18:09 -07001311 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001313 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 checkSimPin.start();
1315 return checkSimPin.unlockSim(null, pin);
1316 }
1317
Wink Saville9de0f752013-10-22 19:04:03 -07001318 /** {@hide} */
1319 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001321 }
1322
Wink Savilleb564aae2014-10-23 10:18:09 -07001323 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001325 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 checkSimPuk.start();
1327 return checkSimPuk.unlockSim(puk, pin);
1328 }
1329
1330 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001331 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 * a synchronous one.
1333 */
1334 private static class UnlockSim extends Thread {
1335
1336 private final IccCard mSimCard;
1337
1338 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001339 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1340 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341
1342 // For replies from SimCard interface
1343 private Handler mHandler;
1344
1345 // For async handler to identify request type
1346 private static final int SUPPLY_PIN_COMPLETE = 100;
1347
1348 public UnlockSim(IccCard simCard) {
1349 mSimCard = simCard;
1350 }
1351
1352 @Override
1353 public void run() {
1354 Looper.prepare();
1355 synchronized (UnlockSim.this) {
1356 mHandler = new Handler() {
1357 @Override
1358 public void handleMessage(Message msg) {
1359 AsyncResult ar = (AsyncResult) msg.obj;
1360 switch (msg.what) {
1361 case SUPPLY_PIN_COMPLETE:
1362 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1363 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001364 mRetryCount = msg.arg1;
1365 if (ar.exception != null) {
1366 if (ar.exception instanceof CommandException &&
1367 ((CommandException)(ar.exception)).getCommandError()
1368 == CommandException.Error.PASSWORD_INCORRECT) {
1369 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1370 } else {
1371 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1372 }
1373 } else {
1374 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1375 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 mDone = true;
1377 UnlockSim.this.notifyAll();
1378 }
1379 break;
1380 }
1381 }
1382 };
1383 UnlockSim.this.notifyAll();
1384 }
1385 Looper.loop();
1386 }
1387
1388 /*
1389 * Use PIN or PUK to unlock SIM card
1390 *
1391 * If PUK is null, unlock SIM card with PIN
1392 *
1393 * If PUK is not null, unlock SIM card with PUK and set PIN code
1394 */
Wink Saville9de0f752013-10-22 19:04:03 -07001395 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396
1397 while (mHandler == null) {
1398 try {
1399 wait();
1400 } catch (InterruptedException e) {
1401 Thread.currentThread().interrupt();
1402 }
1403 }
1404 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1405
1406 if (puk == null) {
1407 mSimCard.supplyPin(pin, callback);
1408 } else {
1409 mSimCard.supplyPuk(puk, pin, callback);
1410 }
1411
1412 while (!mDone) {
1413 try {
1414 Log.d(LOG_TAG, "wait for done");
1415 wait();
1416 } catch (InterruptedException e) {
1417 // Restore the interrupted status
1418 Thread.currentThread().interrupt();
1419 }
1420 }
1421 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001422 int[] resultArray = new int[2];
1423 resultArray[0] = mResult;
1424 resultArray[1] = mRetryCount;
1425 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426 }
1427 }
1428
1429 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001430 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001431
1432 }
1433
Wink Savilleb564aae2014-10-23 10:18:09 -07001434 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001435 // No permission check needed here: this call is harmless, and it's
1436 // needed for the ServiceState.requestStateUpdate() call (which is
1437 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001438 final Phone phone = getPhone(subId);
1439 if (phone != null) {
1440 phone.updateServiceLocation();
1441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442 }
1443
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001444 @Override
1445 public boolean isRadioOn(String callingPackage) {
1446 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001447 }
1448
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001449 @Override
1450 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1451 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1452 return false;
1453 }
1454 return isRadioOnForSubscriber(subId);
1455 }
1456
1457 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001458 final Phone phone = getPhone(subId);
1459 if (phone != null) {
1460 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1461 } else {
1462 return false;
1463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 }
1465
1466 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001467 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001468
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469 }
Wink Saville36469e72014-06-11 15:17:00 -07001470
Wink Savilleb564aae2014-10-23 10:18:09 -07001471 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001472 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001473 final Phone phone = getPhone(subId);
1474 if (phone != null) {
1475 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1476 }
Wink Saville36469e72014-06-11 15:17:00 -07001477 }
1478
1479 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001480 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001481 }
1482
Wink Savilleb564aae2014-10-23 10:18:09 -07001483 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001484 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001485 final Phone phone = getPhone(subId);
1486 if (phone == null) {
1487 return false;
1488 }
1489 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001490 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001491 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001492 }
1493 return true;
1494 }
Wink Saville36469e72014-06-11 15:17:00 -07001495
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001496 public boolean needMobileRadioShutdown() {
1497 /*
1498 * If any of the Radios are available, it will need to be
1499 * shutdown. So return true if any Radio is available.
1500 */
1501 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1502 Phone phone = PhoneFactory.getPhone(i);
1503 if (phone != null && phone.isRadioAvailable()) return true;
1504 }
1505 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1506 return false;
1507 }
1508
1509 public void shutdownMobileRadios() {
1510 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1511 logv("Shutting down Phone " + i);
1512 shutdownRadioUsingPhoneId(i);
1513 }
1514 }
1515
1516 private void shutdownRadioUsingPhoneId(int phoneId) {
1517 enforceModifyPermission();
1518 Phone phone = PhoneFactory.getPhone(phoneId);
1519 if (phone != null && phone.isRadioAvailable()) {
1520 phone.shutdownRadio();
1521 }
1522 }
1523
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001525 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001526 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1527 if (defaultPhone != null) {
1528 defaultPhone.setRadioPower(turnOn);
1529 return true;
1530 } else {
1531 loge("There's no default phone.");
1532 return false;
1533 }
Wink Saville36469e72014-06-11 15:17:00 -07001534 }
1535
Wink Savilleb564aae2014-10-23 10:18:09 -07001536 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001537 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001538 final Phone phone = getPhone(subId);
1539 if (phone != null) {
1540 phone.setRadioPower(turnOn);
1541 return true;
1542 } else {
1543 return false;
1544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 }
1546
Wink Saville36469e72014-06-11 15:17:00 -07001547 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001548 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 public boolean enableDataConnectivity() {
1550 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001551 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001552 final Phone phone = getPhone(subId);
1553 if (phone != null) {
1554 phone.setDataEnabled(true);
1555 return true;
1556 } else {
1557 return false;
1558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 }
1560
Wink Saville36469e72014-06-11 15:17:00 -07001561 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001562 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 public boolean disableDataConnectivity() {
1564 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001565 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001566 final Phone phone = getPhone(subId);
1567 if (phone != null) {
1568 phone.setDataEnabled(false);
1569 return true;
1570 } else {
1571 return false;
1572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 }
1574
Sanket Padawe356d7632015-06-22 14:03:32 -07001575 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001576 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001577 final Phone phone = getPhone(subId);
1578 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001579 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 } else {
1581 return false;
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
1585 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001586 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001587 }
1588
pkanwarae03a6b2016-11-06 20:37:09 -08001589 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001590 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001591 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1592 return;
1593 }
1594 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1595 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1596 };
1597
Wink Savilleb564aae2014-10-23 10:18:09 -07001598 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001600 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1601 return false;
1602 }
Wink Saville36469e72014-06-11 15:17:00 -07001603 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 }
1605
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001607 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001608 }
1609
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001610 public int getCallStateForSlot(int slotIndex) {
1611 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001612 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001613 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 }
1615
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001618 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001620 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001621 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001622 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 }
1625
Sanket Padawe356d7632015-06-22 14:03:32 -07001626 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001628 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 if (phone != null) {
1630 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1631 } else {
1632 return TelephonyManager.DATA_ACTIVITY_NONE;
1633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 }
1635
1636 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001637 public Bundle getCellLocation(String callingPackage) {
1638 enforceFineOrCoarseLocationPermission("getCellLocation");
1639
1640 // OP_COARSE_LOCATION controls both fine and coarse location.
1641 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1642 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001643 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001644 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 }
1646
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001647 if (checkIfCallerIsSelfOrForegroundUser() ||
1648 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 if (DBG_LOC) log("getCellLocation: is active user");
1650 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001651 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001652 if (phone == null) {
1653 return null;
1654 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001655
1656 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1657 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 return data;
1659 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001660 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 return null;
1662 }
1663 }
1664
Svetoslav64fad262015-04-14 14:35:21 -07001665 private void enforceFineOrCoarseLocationPermission(String message) {
1666 try {
1667 mApp.enforceCallingOrSelfPermission(
1668 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1669 } catch (SecurityException e) {
1670 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1671 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1672 // is the weaker precondition
1673 mApp.enforceCallingOrSelfPermission(
1674 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1675 }
1676 }
1677
1678
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 @Override
1680 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001681 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001682 }
1683
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001685 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 mApp.enforceCallingOrSelfPermission(
1687 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001688 final Phone phone = getPhone(subId);
1689 if (phone != null) {
1690 phone.enableLocationUpdates();
1691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 }
1693
1694 @Override
1695 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001696 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001697 }
1698
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001700 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 mApp.enforceCallingOrSelfPermission(
1702 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 final Phone phone = getPhone(subId);
1704 if (phone != null) {
1705 phone.disableLocationUpdates();
1706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
1708
1709 @Override
1710 @SuppressWarnings("unchecked")
1711 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001712 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1713
1714 // OP_COARSE_LOCATION controls both fine and coarse location.
1715 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1716 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1717 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 }
1719
1720 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1721 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1722 return null;
1723 }
Svetoslav64fad262015-04-14 14:35:21 -07001724
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001725 if (checkIfCallerIsSelfOrForegroundUser() ||
1726 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1728
1729 ArrayList<NeighboringCellInfo> cells = null;
1730
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001731 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 try {
1733 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001734 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001735 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001737 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
1739 return cells;
1740 } else {
1741 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1742 return null;
1743 }
1744 }
1745
1746
1747 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001748 public List<CellInfo> getAllCellInfo(String callingPackage) {
1749 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1750
1751 // OP_COARSE_LOCATION controls both fine and coarse location.
1752 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1753 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1754 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 }
1756
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001757 if (checkIfCallerIsSelfOrForegroundUser() ||
1758 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001760 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001761 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1762 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001763 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1764 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001765 }
1766 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 } else {
1768 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1769 return null;
1770 }
1771 }
1772
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001775 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001776 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1777 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Shishir Agrawala9f32182016-04-12 12:00:16 -07001780 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001781 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001782 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1783 return null;
1784 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001785 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001786 return phone == null ? null : phone.getImei();
1787 }
1788
1789 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001790 public String getMeidForSlot(int slotIndex, String callingPackage) {
1791 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1792 return null;
1793 }
1794 Phone phone = PhoneFactory.getPhone(slotIndex);
1795 return phone == null ? null : phone.getMeid();
1796 }
1797
1798 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001799 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001800 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1801 return null;
1802 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001803 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001804 return phone == null ? null : phone.getDeviceSvn();
1805 }
1806
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 //
1808 // Internal helper methods.
1809 //
1810
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001811 /**
1812 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1813 */
1814 private boolean checkCallerInteractAcrossUsersFull() {
1815 return mPhone.getContext().checkCallingOrSelfPermission(
1816 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1817 == PackageManager.PERMISSION_GRANTED;
1818 }
1819
Jake Hambye994d462014-02-03 13:10:13 -08001820 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 boolean ok;
1822
1823 boolean self = Binder.getCallingUid() == Process.myUid();
1824 if (!self) {
1825 // Get the caller's user id then clear the calling identity
1826 // which will be restored in the finally clause.
1827 int callingUser = UserHandle.getCallingUserId();
1828 long ident = Binder.clearCallingIdentity();
1829
1830 try {
1831 // With calling identity cleared the current user is the foreground user.
1832 int foregroundUser = ActivityManager.getCurrentUser();
1833 ok = (foregroundUser == callingUser);
1834 if (DBG_LOC) {
1835 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1836 + " callingUser=" + callingUser + " ok=" + ok);
1837 }
1838 } catch (Exception ex) {
1839 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1840 ok = false;
1841 } finally {
1842 Binder.restoreCallingIdentity(ident);
1843 }
1844 } else {
1845 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1846 ok = true;
1847 }
1848 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1849 return ok;
1850 }
1851
1852 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1854 *
1855 * @throws SecurityException if the caller does not have the required permission
1856 */
1857 private void enforceModifyPermission() {
1858 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1859 }
1860
1861 /**
Junda Liua2e36012014-07-09 18:30:01 -07001862 * Make sure either system app or the caller has carrier privilege.
1863 *
1864 * @throws SecurityException if the caller does not have the required permission/privilege
1865 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001866 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001867 int permission = mApp.checkCallingOrSelfPermission(
1868 android.Manifest.permission.MODIFY_PHONE_STATE);
1869 if (permission == PackageManager.PERMISSION_GRANTED) {
1870 return;
1871 }
1872
1873 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001874 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001875 }
1876
1877 /**
1878 * Make sure the caller has carrier privilege.
1879 *
1880 * @throws SecurityException if the caller does not have the required permission
1881 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001882 private void enforceCarrierPrivilege(int subId) {
1883 if (getCarrierPrivilegeStatus(subId) !=
1884 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001885 loge("No Carrier Privilege.");
1886 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001887 }
1888 }
1889
1890 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 * Make sure the caller has the CALL_PHONE permission.
1892 *
1893 * @throws SecurityException if the caller does not have the required permission
1894 */
1895 private void enforceCallPermission() {
1896 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1897 }
1898
Stuart Scott8eef64f2015-04-08 15:13:54 -07001899 private void enforceConnectivityInternalPermission() {
1900 mApp.enforceCallingOrSelfPermission(
1901 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1902 "ConnectivityService");
1903 }
1904
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 private String createTelUrl(String number) {
1906 if (TextUtils.isEmpty(number)) {
1907 return null;
1908 }
1909
Jake Hambye994d462014-02-03 13:10:13 -08001910 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 }
1912
Ihab Awadf9e92732013-12-05 18:02:52 -08001913 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1915 }
1916
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001917 private static void logv(String msg) {
1918 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1919 }
1920
Ihab Awadf9e92732013-12-05 18:02:52 -08001921 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1923 }
1924
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001925 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001927 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001928 }
1929
Sanket Padawe356d7632015-06-22 14:03:32 -07001930 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001931 public int getActivePhoneTypeForSlot(int slotIndex) {
1932 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001933 if (phone == null) {
1934 return PhoneConstants.PHONE_TYPE_NONE;
1935 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001936 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
1940 /**
1941 * Returns the CDMA ERI icon index to display
1942 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001943 @Override
1944 public int getCdmaEriIconIndex(String callingPackage) {
1945 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001946 }
1947
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001949 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1950 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1951 return -1;
1952 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001953 final Phone phone = getPhone(subId);
1954 if (phone != null) {
1955 return phone.getCdmaEriIconIndex();
1956 } else {
1957 return -1;
1958 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 }
1960
1961 /**
1962 * Returns the CDMA ERI icon mode,
1963 * 0 - ON
1964 * 1 - FLASHING
1965 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001966 @Override
1967 public int getCdmaEriIconMode(String callingPackage) {
1968 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001969 }
1970
Sanket Padawe356d7632015-06-22 14:03:32 -07001971 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001972 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1973 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1974 return -1;
1975 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 final Phone phone = getPhone(subId);
1977 if (phone != null) {
1978 return phone.getCdmaEriIconMode();
1979 } else {
1980 return -1;
1981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
1984 /**
1985 * Returns the CDMA ERI text,
1986 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001987 @Override
1988 public String getCdmaEriText(String callingPackage) {
1989 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001990 }
1991
Sanket Padawe356d7632015-06-22 14:03:32 -07001992 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001993 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1994 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1995 return null;
1996 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 final Phone phone = getPhone(subId);
1998 if (phone != null) {
1999 return phone.getCdmaEriText();
2000 } else {
2001 return null;
2002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 }
2004
2005 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002006 * Returns the CDMA MDN.
2007 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002009 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002010 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002011 final Phone phone = getPhone(subId);
2012 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2013 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002014 } else {
2015 return null;
2016 }
2017 }
2018
2019 /**
2020 * Returns the CDMA MIN.
2021 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002022 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002023 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002024 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002025 final Phone phone = getPhone(subId);
2026 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2027 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002028 } else {
2029 return null;
2030 }
2031 }
2032
2033 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 * Returns true if CDMA provisioning needs to run.
2035 */
2036 public boolean needsOtaServiceProvisioning() {
2037 return mPhone.needsOtaServiceProvisioning();
2038 }
2039
2040 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002041 * Sets the voice mail number of a given subId.
2042 */
2043 @Override
2044 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002045 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002046 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2047 new Pair<String, String>(alphaTag, number), new Integer(subId));
2048 return success;
2049 }
2050
Ta-wei Yen87c49842016-05-13 21:19:52 -07002051 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002052 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2053 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2054 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2055 if (!TextUtils.equals(callingPackage, systemDialer)) {
2056 throw new SecurityException("caller must be system dialer");
2057 }
2058 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2059 if (phoneAccountHandle == null){
2060 return null;
2061 }
2062 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2063 }
2064
2065 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002066 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002067 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2068 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2069 return null;
2070 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002071 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2072 }
2073
2074 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002075 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2076 VisualVoicemailSmsFilterSettings settings) {
2077 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002078 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002079 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2080 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002081 }
2082
2083 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002084 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2085 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002086 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002087 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002088 }
2089
2090 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002091 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2092 String callingPackage, int subId) {
2093 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002094 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002095 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002096 }
2097
2098 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002099 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002100 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002101 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002102 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2103 }
2104
2105 @Override
2106 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2107 String number, int port, String text, PendingIntent sentIntent) {
2108 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002109 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002110 enforceSendSmsPermission();
2111 // Make the calls as the phone process.
2112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2115 if (port == 0) {
2116 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2117 sentIntent, null, false);
2118 } else {
2119 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2120 smsManager.sendDataMessageWithSelfPermissions(number, null,
2121 (short) port, data, sentIntent, null);
2122 }
2123 } finally {
2124 Binder.restoreCallingIdentity(identity);
2125 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002126 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002127 /**
fionaxu0152e512016-11-14 13:36:14 -08002128 * Sets the voice activation state of a given subId.
2129 */
2130 @Override
2131 public void setVoiceActivationState(int subId, int activationState) {
2132 enforceModifyPermissionOrCarrierPrivilege(subId);
2133 final Phone phone = getPhone(subId);
2134 if (phone != null) {
2135 phone.setVoiceActivationState(activationState);
2136 } else {
2137 loge("setVoiceActivationState fails with invalid subId: " + subId);
2138 }
2139 }
2140
2141 /**
2142 * Sets the data activation state of a given subId.
2143 */
2144 @Override
2145 public void setDataActivationState(int subId, int activationState) {
2146 enforceModifyPermissionOrCarrierPrivilege(subId);
2147 final Phone phone = getPhone(subId);
2148 if (phone != null) {
2149 phone.setDataActivationState(activationState);
2150 } else {
2151 loge("setVoiceActivationState fails with invalid subId: " + subId);
2152 }
2153 }
2154
2155 /**
2156 * Returns the voice activation state of a given subId.
2157 */
2158 @Override
2159 public int getVoiceActivationState(int subId, String callingPackage) {
2160 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2161 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2162 }
2163 final Phone phone = getPhone(subId);
2164 if (phone != null) {
2165 return phone.getVoiceActivationState();
2166 } else {
2167 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2168 }
2169 }
2170
2171 /**
2172 * Returns the data activation state of a given subId.
2173 */
2174 @Override
2175 public int getDataActivationState(int subId, String callingPackage) {
2176 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2177 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2178 }
2179 final Phone phone = getPhone(subId);
2180 if (phone != null) {
2181 return phone.getDataActivationState();
2182 } else {
2183 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2184 }
2185 }
2186
2187 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 * Returns the unread count of voicemails
2189 */
2190 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002191 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
2194 /**
2195 * Returns the unread count of voicemails for a subId
2196 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002197 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002198 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002199 final Phone phone = getPhone(subId);
2200 if (phone != null) {
2201 return phone.getVoiceMessageCount();
2202 } else {
2203 return 0;
2204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 }
2206
2207 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002208 * returns true, if the device is in a state where both voice and data
2209 * are supported simultaneously. This can change based on location or network condition.
2210 */
2211 @Override
2212 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2213 final Phone phone = getPhone(subId);
2214 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2215 }
2216
2217 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002218 * Send the dialer code if called from the current default dialer or the caller has
2219 * carrier privilege.
2220 * @param inputCode The dialer code to send
2221 */
2222 @Override
2223 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2224 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2225 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2226 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2227 enforceCarrierPrivilege(getDefaultSubscription());
2228 }
2229 mPhone.sendDialerSpecialCode(inputCode);
2230 }
2231
2232 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002233 * Returns the data network type.
2234 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 *
2236 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2237 */
2238 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002239 public int getNetworkType() {
2240 final Phone phone = getPhone(getDefaultSubscription());
2241 if (phone != null) {
2242 return phone.getServiceState().getDataNetworkType();
2243 } else {
2244 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2245 }
Wink Saville36469e72014-06-11 15:17:00 -07002246 }
2247
2248 /**
2249 * Returns the network type for a subId
2250 */
2251 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002252 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2253 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2254 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2255 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002256
Sanket Padawe356d7632015-06-22 14:03:32 -07002257 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002258 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002259 return phone.getServiceState().getDataNetworkType();
2260 } else {
2261 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 }
2264
2265 /**
2266 * Returns the data network type
2267 */
2268 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002269 public int getDataNetworkType(String callingPackage) {
2270 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002271 }
2272
2273 /**
2274 * Returns the data network type for a subId
2275 */
2276 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002277 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2278 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2279 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2280 }
2281
Sanket Padawe356d7632015-06-22 14:03:32 -07002282 final Phone phone = getPhone(subId);
2283 if (phone != null) {
2284 return phone.getServiceState().getDataNetworkType();
2285 } else {
2286 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
2289
2290 /**
Wink Saville36469e72014-06-11 15:17:00 -07002291 * Returns the Voice network type for a subId
2292 */
2293 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002294 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2295 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2296 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2297 }
2298
Sanket Padawe356d7632015-06-22 14:03:32 -07002299 final Phone phone = getPhone(subId);
2300 if (phone != null) {
2301 return phone.getServiceState().getVoiceNetworkType();
2302 } else {
2303 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 }
2306
2307 /**
2308 * @return true if a ICC card is present
2309 */
2310 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002311 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002312 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2313 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002314 }
2315
2316 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002317 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002318 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002320 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2321 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002322 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002323 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002324 } else {
2325 return false;
2326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 }
2328
2329 /**
2330 * Return if the current radio is LTE on CDMA. This
2331 * is a tri-state return value as for a period of time
2332 * the mode may be unknown.
2333 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002334 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002336 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002338 @Override
2339 public int getLteOnCdmaMode(String callingPackage) {
2340 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002341 }
2342
Sanket Padawe356d7632015-06-22 14:03:32 -07002343 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002344 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2345 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2346 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2347 }
2348
Sanket Padawe356d7632015-06-22 14:03:32 -07002349 final Phone phone = getPhone(subId);
2350 if (phone == null) {
2351 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2352 } else {
2353 return phone.getLteOnCdmaMode();
2354 }
Wink Saville36469e72014-06-11 15:17:00 -07002355 }
2356
2357 public void setPhone(Phone phone) {
2358 mPhone = phone;
2359 }
2360
2361 /**
2362 * {@hide}
2363 * Returns Default subId, 0 in the case of single standby.
2364 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002365 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002366 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002367 }
2368
Shishir Agrawala9f32182016-04-12 12:00:16 -07002369 private int getSlotForDefaultSubscription() {
2370 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2371 }
2372
Wink Savilleb564aae2014-10-23 10:18:09 -07002373 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002374 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002376
2377 /**
2378 * @see android.telephony.TelephonyManager.WifiCallingChoices
2379 */
2380 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002381 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2382 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002383 }
2384
2385 /**
2386 * @see android.telephony.TelephonyManager.WifiCallingChoices
2387 */
2388 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002389 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2390 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2391 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002392 }
2393
Sailesh Nepald1e68152013-12-12 19:08:02 -08002394 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002395 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002396 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002397 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002398
Shishir Agrawal566b7612013-10-28 14:41:00 -07002399 @Override
Ajay Nambid7454d32015-12-03 13:50:00 -08002400 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002401 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002402
Ajay Nambid7454d32015-12-03 13:50:00 -08002403 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + AID + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002404 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Ajay Nambid7454d32015-12-03 13:50:00 -08002405 CMD_OPEN_CHANNEL, new Pair<String, Integer>(AID, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002406 if (DBG) log("iccOpenLogicalChannel: " + response);
2407 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002408 }
2409
2410 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002411 public boolean iccCloseLogicalChannel(int subId, int channel) {
2412 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002413
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002414 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002415 if (channel < 0) {
2416 return false;
2417 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002418 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002419 if (DBG) log("iccCloseLogicalChannel: " + success);
2420 return success;
2421 }
2422
2423 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002425 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002426 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002427
2428 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002429 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2430 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002431 " data=" + data);
2432 }
2433
2434 if (channel < 0) {
2435 return "";
2436 }
2437
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002438 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002439 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002440 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2441
Shishir Agrawal566b7612013-10-28 14:41:00 -07002442 // Append the returned status code to the end of the response payload.
2443 String s = Integer.toHexString(
2444 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002445 if (response.payload != null) {
2446 s = IccUtils.bytesToHexString(response.payload) + s;
2447 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002448 return s;
2449 }
Jake Hambye994d462014-02-03 13:10:13 -08002450
Evan Charltonc66da362014-05-16 14:06:40 -07002451 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002452 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002453 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002454 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002455
2456 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002457 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2458 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002459 }
2460
2461 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002462 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002463 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002465 // Append the returned status code to the end of the response payload.
2466 String s = Integer.toHexString(
2467 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002468 if (response.payload != null) {
2469 s = IccUtils.bytesToHexString(response.payload) + s;
2470 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002471 return s;
2472 }
2473
2474 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002475 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002476 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002478
2479 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002480 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002481 p1 + " " + p2 + " " + p3 + ":" + filePath);
2482 }
2483
2484 IccIoResult response =
2485 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002486 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2487 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002488
2489 if (DBG) {
2490 log("Exchange SIM_IO [R]" + response);
2491 }
2492
2493 byte[] result = null;
2494 int length = 2;
2495 if (response.payload != null) {
2496 length = 2 + response.payload.length;
2497 result = new byte[length];
2498 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2499 } else {
2500 result = new byte[length];
2501 }
2502
2503 result[length - 1] = (byte) response.sw2;
2504 result[length - 2] = (byte) response.sw1;
2505 return result;
2506 }
2507
Nathan Haroldb3014052017-01-25 15:57:32 -08002508 /**
2509 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2510 * on a particular subscription
2511 */
2512 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002513 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2514 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002515 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2516 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2517 return null;
2518 }
2519 Object response = sendRequest(
2520 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2521 if (response instanceof String[]) {
2522 return (String[]) response;
2523 }
2524 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2525 return null;
2526 }
2527
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002528 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002529 public String sendEnvelopeWithStatus(int subId, String content) {
2530 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002531
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002532 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002533 if (response.payload == null) {
2534 return "";
2535 }
2536
2537 // Append the returned status code to the end of the response payload.
2538 String s = Integer.toHexString(
2539 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2540 s = IccUtils.bytesToHexString(response.payload) + s;
2541 return s;
2542 }
2543
Jake Hambye994d462014-02-03 13:10:13 -08002544 /**
2545 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2546 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2547 *
2548 * @param itemID the ID of the item to read
2549 * @return the NV item as a String, or null on error.
2550 */
2551 @Override
2552 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002553 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002554 if (DBG) log("nvReadItem: item " + itemID);
2555 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2556 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2557 return value;
2558 }
2559
2560 /**
2561 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2562 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2563 *
2564 * @param itemID the ID of the item to read
2565 * @param itemValue the value to write, as a String
2566 * @return true on success; false on any failure
2567 */
2568 @Override
2569 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002570 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002571 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2572 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2573 new Pair<Integer, String>(itemID, itemValue));
2574 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2575 return success;
2576 }
2577
2578 /**
2579 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2580 * Used for device configuration by some CDMA operators.
2581 *
2582 * @param preferredRoamingList byte array containing the new PRL
2583 * @return true on success; false on any failure
2584 */
2585 @Override
2586 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002587 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002588 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2589 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2590 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2591 return success;
2592 }
2593
2594 /**
2595 * Perform the specified type of NV config reset.
2596 * Used for device configuration by some CDMA operators.
2597 *
2598 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2599 * @return true on success; false on any failure
2600 */
2601 @Override
2602 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002603 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002604 if (DBG) log("nvResetConfig: type " + resetType);
2605 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2606 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2607 return success;
2608 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002609
2610 /**
Wink Saville36469e72014-06-11 15:17:00 -07002611 * {@hide}
2612 * Returns Default sim, 0 in the case of single standby.
2613 */
2614 public int getDefaultSim() {
2615 //TODO Need to get it from Telephony Devcontroller
2616 return 0;
2617 }
2618
Svet Ganovb320e182015-04-16 12:30:10 -07002619 public String[] getPcscfAddress(String apnType, String callingPackage) {
2620 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2621 return new String[0];
2622 }
2623
2624
ram87fca6f2014-07-18 18:58:44 +05302625 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002626 }
2627
Brad Ebinger51f743a2017-01-23 13:50:20 -08002628 /**
2629 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2630 * feature or {@link null} if the service is not available. If an ImsServiceController is
2631 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2632 * feature updates.
2633 */
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002634 public IImsServiceController getImsServiceControllerAndListen(int slotIndex, int feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002635 IImsServiceFeatureListener callback) {
2636 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002637 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotIndex, feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002638 callback);
2639 }
2640
Wink Saville36469e72014-06-11 15:17:00 -07002641 public void setImsRegistrationState(boolean registered) {
2642 enforceModifyPermission();
2643 mPhone.setImsRegistrationState(registered);
2644 }
2645
2646 /**
Stuart Scott54788802015-03-30 13:18:01 -07002647 * Set the network selection mode to automatic.
2648 *
2649 */
2650 @Override
2651 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002652 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002653 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2654 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2655 }
2656
2657 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002658 * Set the network selection mode to manual with the selected carrier.
2659 */
2660 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002661 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2662 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002663 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002664 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002665 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2666 persistSelection);
2667 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002668 }
2669
2670 /**
2671 * Scans for available networks.
2672 */
2673 @Override
2674 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002675 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002676 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2677 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2678 CMD_PERFORM_NETWORK_SCAN, null, subId);
2679 return result;
2680 }
2681
2682 /**
yinxub1bed742017-04-17 11:45:04 -07002683 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002684 *
yinxub1bed742017-04-17 11:45:04 -07002685 * @param subId id of the subscription
2686 * @param request contains the radio access networks with bands/channels to scan
2687 * @param messenger callback messenger for scan results or errors
2688 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002689 * @return the id of the requested scan which can be used to stop the scan.
2690 */
2691 @Override
2692 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2693 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002694 enforceModifyPermissionOrCarrierPrivilege(subId);
2695 return mNetworkScanRequestTracker.startNetworkScan(
2696 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002697 }
2698
2699 /**
2700 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002701 *
2702 * @param subId id of the subscription
2703 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002704 */
2705 @Override
2706 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002707 enforceModifyPermissionOrCarrierPrivilege(subId);
2708 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002709 }
2710
2711 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002712 * Get the calculated preferred network type.
2713 * Used for debugging incorrect network type.
2714 *
2715 * @return the preferred network type, defined in RILConstants.java.
2716 */
2717 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002718 public int getCalculatedPreferredNetworkType(String callingPackage) {
2719 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2720 return RILConstants.PREFERRED_NETWORK_MODE;
2721 }
2722
Amit Mahajan43330e02014-11-18 11:54:45 -08002723 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002724 }
2725
2726 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002727 * Get the preferred network type.
2728 * Used for device configuration by some CDMA operators.
2729 *
2730 * @return the preferred network type, defined in RILConstants.java.
2731 */
2732 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002733 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002734 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002735 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002736 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002737 int networkType = (result != null ? result[0] : -1);
2738 if (DBG) log("getPreferredNetworkType: " + networkType);
2739 return networkType;
2740 }
2741
2742 /**
2743 * Set the preferred network type.
2744 * Used for device configuration by some CDMA operators.
2745 *
2746 * @param networkType the preferred network type, defined in RILConstants.java.
2747 * @return true on success; false on any failure.
2748 */
2749 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002750 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002751 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002752 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2753 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002754 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002755 if (success) {
2756 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002757 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002758 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002759 return success;
2760 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002761
2762 /**
Junda Liu475951f2014-11-07 16:45:03 -08002763 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2764 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2765 * tethering.
2766 *
2767 * @return 0: Not required. 1: required. 2: Not set.
2768 * @hide
2769 */
2770 @Override
2771 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002772 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002773 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2774 Settings.Global.TETHER_DUN_REQUIRED, 2);
2775 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2776 // config_tether_apndata.
2777 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2778 dunRequired = 1;
2779 }
2780 return dunRequired;
2781 }
2782
2783 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002784 * Set mobile data enabled
2785 * Used by the user through settings etc to turn on/off mobile data
2786 *
2787 * @param enable {@code true} turn turn data on, else {@code false}
2788 */
2789 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002790 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002791 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002792 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002793 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002794 Phone phone = PhoneFactory.getPhone(phoneId);
2795 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002796 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002797 phone.setDataEnabled(enable);
2798 } else {
2799 loge("setDataEnabled: no phone for subId=" + subId);
2800 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002801 }
2802
2803 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002804 * Get whether mobile data is enabled.
2805 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002806 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002807 *
2808 * @return {@code true} if data is enabled else {@code false}
2809 */
2810 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002811 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002812 try {
2813 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2814 null);
2815 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002816 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002817 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002818 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002819 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002820 Phone phone = PhoneFactory.getPhone(phoneId);
2821 if (phone != null) {
2822 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002823 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002824 return retVal;
2825 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002826 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002827 return false;
2828 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002829 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002830
2831 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002832 public int getCarrierPrivilegeStatus(int subId) {
2833 final Phone phone = getPhone(subId);
2834 if (phone == null) {
2835 loge("getCarrierPrivilegeStatus: Invalid subId");
2836 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2837 }
2838 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002839 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002840 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002841 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2842 }
2843 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002844 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002845 }
Junda Liu29340342014-07-10 15:23:27 -07002846
2847 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002848 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002849 if (TextUtils.isEmpty(pkgName))
2850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002851 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002852 if (card == null) {
2853 loge("checkCarrierPrivilegesForPackage: No UICC");
2854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2855 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002856 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2857 }
2858
2859 @Override
2860 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002861 if (TextUtils.isEmpty(pkgName))
2862 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002863 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2864 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2865 UiccCard card = UiccController.getInstance().getUiccCard(i);
2866 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002867 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002868 continue;
2869 }
2870
2871 result = card.getCarrierPrivilegeStatus(
2872 mPhone.getContext().getPackageManager(), pkgName);
2873 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2874 break;
2875 }
2876 }
2877
2878 return result;
Junda Liu29340342014-07-10 15:23:27 -07002879 }
Derek Tan89e89d42014-07-08 17:00:10 -07002880
2881 @Override
Junda Liue64de782015-04-16 17:19:16 -07002882 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2883 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2884 loge("phoneId " + phoneId + " is not valid.");
2885 return null;
2886 }
2887 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002888 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002889 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002890 return null ;
2891 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002892 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002893 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002894 }
2895
Amith Yamasani6e118872016-02-19 12:53:51 -08002896 @Override
2897 public List<String> getPackagesWithCarrierPrivileges() {
2898 PackageManager pm = mPhone.getContext().getPackageManager();
2899 List<String> privilegedPackages = new ArrayList<>();
2900 List<PackageInfo> packages = null;
2901 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2902 UiccCard card = UiccController.getInstance().getUiccCard(i);
2903 if (card == null) {
2904 // No UICC in that slot.
2905 continue;
2906 }
2907 if (card.hasCarrierPrivilegeRules()) {
2908 if (packages == null) {
2909 // Only check packages in user 0 for now
2910 packages = pm.getInstalledPackagesAsUser(
2911 PackageManager.MATCH_DISABLED_COMPONENTS
2912 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2913 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2914 }
2915 for (int p = packages.size() - 1; p >= 0; p--) {
2916 PackageInfo pkgInfo = packages.get(p);
2917 if (pkgInfo != null && pkgInfo.packageName != null
2918 && card.getCarrierPrivilegeStatus(pkgInfo)
2919 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2920 privilegedPackages.add(pkgInfo.packageName);
2921 }
2922 }
2923 }
2924 }
2925 return privilegedPackages;
2926 }
2927
Wink Savilleb564aae2014-10-23 10:18:09 -07002928 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 final Phone phone = getPhone(subId);
2930 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002931 if (card == null) {
2932 loge("getIccId: No UICC");
2933 return null;
2934 }
2935 String iccId = card.getIccId();
2936 if (TextUtils.isEmpty(iccId)) {
2937 loge("getIccId: ICC ID is null or empty.");
2938 return null;
2939 }
2940 return iccId;
2941 }
2942
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002943 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002944 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2945 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002946 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002947
Jeff Sharkey85190e62014-12-05 09:40:12 -08002948 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002949 final Phone phone = getPhone(subId);
2950 if (phone == null) {
2951 return false;
2952 }
2953 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002954
2955 if (DBG_MERGE) {
2956 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2957 + subscriberId + " to " + number);
2958 }
2959
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002960 if (TextUtils.isEmpty(iccId)) {
2961 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002962 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002963
Jeff Sharkey85190e62014-12-05 09:40:12 -08002964 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2965
2966 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002967 if (alphaTag == null) {
2968 editor.remove(alphaTagPrefKey);
2969 } else {
2970 editor.putString(alphaTagPrefKey, alphaTag);
2971 }
2972
Jeff Sharkey85190e62014-12-05 09:40:12 -08002973 // Record both the line number and IMSI for this ICCID, since we need to
2974 // track all merged IMSIs based on line number
2975 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2976 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002977 if (number == null) {
2978 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002979 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002980 } else {
2981 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002982 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002983 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002984
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002985 editor.commit();
2986 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002987 }
2988
2989 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002990 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002991 // This is open to apps with WRITE_SMS.
2992 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002993 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002994 return null;
2995 }
Derek Tan97ebb422014-09-05 16:55:38 -07002996
2997 String iccId = getIccId(subId);
2998 if (iccId != null) {
2999 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003000 if (DBG_MERGE) {
3001 log("getLine1NumberForDisplay returning " +
3002 mTelephonySharedPreferences.getString(numberPrefKey, null));
3003 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003004 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003005 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003006 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003007 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003008 }
3009
3010 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003011 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3012 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3013 return null;
3014 }
Derek Tan97ebb422014-09-05 16:55:38 -07003015
3016 String iccId = getIccId(subId);
3017 if (iccId != null) {
3018 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003019 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003020 }
Derek Tan97ebb422014-09-05 16:55:38 -07003021 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003022 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003023
3024 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003025 public String[] getMergedSubscriberIds(String callingPackage) {
3026 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3027 return null;
3028 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003029 final Context context = mPhone.getContext();
3030 final TelephonyManager tele = TelephonyManager.from(context);
3031 final SubscriptionManager sub = SubscriptionManager.from(context);
3032
3033 // Figure out what subscribers are currently active
3034 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003035 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3036 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3037 final long identity = Binder.clearCallingIdentity();
3038 try {
3039 final int[] subIds = sub.getActiveSubscriptionIdList();
3040 for (int subId : subIds) {
3041 activeSubscriberIds.add(tele.getSubscriberId(subId));
3042 }
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003045 }
3046
3047 // First pass, find a number override for an active subscriber
3048 String mergeNumber = null;
3049 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3050 for (String key : prefs.keySet()) {
3051 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3052 final String subscriberId = (String) prefs.get(key);
3053 if (activeSubscriberIds.contains(subscriberId)) {
3054 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3055 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3056 mergeNumber = (String) prefs.get(numberKey);
3057 if (DBG_MERGE) {
3058 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3059 + " for active subscriber " + subscriberId);
3060 }
3061 if (!TextUtils.isEmpty(mergeNumber)) {
3062 break;
3063 }
3064 }
3065 }
3066 }
3067
3068 // Shortcut when no active merged subscribers
3069 if (TextUtils.isEmpty(mergeNumber)) {
3070 return null;
3071 }
3072
3073 // Second pass, find all subscribers under that line override
3074 final ArraySet<String> result = new ArraySet<>();
3075 for (String key : prefs.keySet()) {
3076 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3077 final String number = (String) prefs.get(key);
3078 if (mergeNumber.equals(number)) {
3079 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3080 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3081 final String subscriberId = (String) prefs.get(subscriberKey);
3082 if (!TextUtils.isEmpty(subscriberId)) {
3083 result.add(subscriberId);
3084 }
3085 }
3086 }
3087 }
3088
3089 final String[] resultArray = result.toArray(new String[result.size()]);
3090 Arrays.sort(resultArray);
3091 if (DBG_MERGE) {
3092 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3093 }
3094 return resultArray;
3095 }
3096
3097 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003098 public boolean setOperatorBrandOverride(int subId, String brand) {
3099 enforceCarrierPrivilege(subId);
3100 final Phone phone = getPhone(subId);
3101 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003102 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003103
3104 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003105 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003106 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3107 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003108 enforceCarrierPrivilege(subId);
3109 final Phone phone = getPhone(subId);
3110 if (phone == null) {
3111 return false;
3112 }
3113 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003114 cdmaNonRoamingList);
3115 }
3116
3117 @Override
Amit Mahajanf43fe462017-02-23 12:08:31 -08003118 @Deprecated
Steven Liu4bf01bc2014-07-17 11:05:29 -05003119 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3120 enforceModifyPermission();
3121
3122 int returnValue = 0;
3123 try {
3124 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3125 if(result.exception == null) {
3126 if (result.result != null) {
3127 byte[] responseData = (byte[])(result.result);
3128 if(responseData.length > oemResp.length) {
3129 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3130 responseData.length + "bytes. Buffer Size is " +
3131 oemResp.length + "bytes.");
3132 }
3133 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3134 returnValue = responseData.length;
3135 }
3136 } else {
3137 CommandException ex = (CommandException) result.exception;
3138 returnValue = ex.getCommandError().ordinal();
3139 if(returnValue > 0) returnValue *= -1;
3140 }
3141 } catch (RuntimeException e) {
3142 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3143 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3144 if(returnValue > 0) returnValue *= -1;
3145 }
3146
3147 return returnValue;
3148 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003149
3150 @Override
3151 public void setRadioCapability(RadioAccessFamily[] rafs) {
3152 try {
3153 ProxyController.getInstance().setRadioCapability(rafs);
3154 } catch (RuntimeException e) {
3155 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3156 }
3157 }
3158
3159 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003160 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3161 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3162 return RadioAccessFamily.RAF_UNKNOWN;
3163 }
3164
Wink Saville5d475dd2014-10-17 15:00:58 -07003165 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3166 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003167
3168 @Override
3169 public void enableVideoCalling(boolean enable) {
3170 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003171 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003172 }
3173
3174 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003175 public boolean isVideoCallingEnabled(String callingPackage) {
3176 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3177 return false;
3178 }
3179
Andrew Lee77527ac2014-10-21 16:57:39 -07003180 // Check the user preference and the system-level IMS setting. Even if the user has
3181 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3182 // In the long run, we may instead need to check if there exists a connection service
3183 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003184 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3185 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003186 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003187 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003188
Andrew Leea1239f22015-03-02 17:44:07 -08003189 @Override
3190 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003191 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003192 }
3193
3194 @Override
3195 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003196 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003197 }
3198
Andrew Lee9431b832015-03-09 18:46:45 -07003199 @Override
3200 public boolean isTtyModeSupported() {
3201 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3202 TelephonyManager telephonyManager =
3203 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003204 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003205 }
3206
3207 @Override
3208 public boolean isHearingAidCompatibilitySupported() {
3209 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3210 }
3211
Sanket Padawe7310cc72015-01-14 09:53:20 -08003212 /**
3213 * Returns the unique device ID of phone, for example, the IMEI for
3214 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3215 *
3216 * <p>Requires Permission:
3217 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3218 */
3219 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003220 public String getDeviceId(String callingPackage) {
3221 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3222 return null;
3223 }
3224
Sanket Padawe7310cc72015-01-14 09:53:20 -08003225 final Phone phone = PhoneFactory.getPhone(0);
3226 if (phone != null) {
3227 return phone.getDeviceId();
3228 } else {
3229 return null;
3230 }
3231 }
3232
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003233 /*
3234 * {@hide}
3235 * Returns the IMS Registration Status
3236 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003237 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003238 public boolean isImsRegistered() {
3239 return mPhone.isImsRegistered();
3240 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003241
3242 @Override
3243 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3244 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3245 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003246
Nathan Haroldc55097a2015-03-11 18:14:50 -07003247 /*
3248 * {@hide}
3249 * Returns the IMS Registration Status
3250 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003251 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003252 return mPhone.isWifiCallingEnabled();
3253 }
3254
3255 /*
3256 * {@hide}
3257 * Returns the IMS Registration Status
3258 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003259 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003260 return mPhone.isVolteEnabled();
3261 }
Svet Ganovb320e182015-04-16 12:30:10 -07003262
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003263 /*
3264 * {@hide} Returns the IMS Registration Status
3265 */
3266 public boolean isVideoTelephonyAvailable() {
3267 return mPhone.isVideoEnabled();
3268 }
3269
Svet Ganovb320e182015-04-16 12:30:10 -07003270 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003271 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003272 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003273 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3274
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003275 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003276 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003277 } catch (SecurityException e) {
3278 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3279 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003280 }
Svet Ganovb320e182015-04-16 12:30:10 -07003281
3282 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3283 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3284 return false;
3285 }
3286
3287 return true;
3288 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003289
Makoto Onukifee69342015-06-29 14:44:50 -07003290 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003291 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003292 */
3293 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003294 // Default SMS app can always read it.
3295 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3296 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3297 return true;
3298 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003299
Makoto Onukie4072d12015-08-03 15:12:23 -07003300 try {
3301 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003302 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003303 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003304 // Can be read with READ_SMS too.
3305 try {
3306 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3307 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3308 if (opCode != AppOpsManager.OP_NONE) {
3309 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3310 == AppOpsManager.MODE_ALLOWED;
3311 } else {
3312 return true;
3313 }
3314 } catch (SecurityException readSmsSecurityException) {
3315 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003316 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003317 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003318 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003319 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003320 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003321 if (opCode != AppOpsManager.OP_NONE) {
3322 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3323 == AppOpsManager.MODE_ALLOWED;
3324 } else {
3325 return true;
3326 }
3327 } catch (SecurityException readPhoneNumberSecurityException) {
3328 }
3329
3330 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3331 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3332 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003333 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003334 }
3335
Stuart Scott8eef64f2015-04-08 15:13:54 -07003336 @Override
3337 public void factoryReset(int subId) {
3338 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003339 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3340 return;
3341 }
3342
Svet Ganovcc087f82015-05-12 20:35:54 -07003343 final long identity = Binder.clearCallingIdentity();
3344 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003345 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3346 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003347 // Enable data
3348 setDataEnabled(subId, true);
3349 // Set network selection mode to automatic
3350 setNetworkSelectionModeAutomatic(subId);
3351 // Set preferred mobile network type to the best available
3352 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3353 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003354 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003355 }
3356 } finally {
3357 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003358 }
3359 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003360
3361 @Override
3362 public String getLocaleFromDefaultSim() {
3363 // We query all subscriptions instead of just the active ones, because
3364 // this might be called early on in the provisioning flow when the
3365 // subscriptions potentially aren't active yet.
3366 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3367 if (slist == null || slist.isEmpty()) {
3368 return null;
3369 }
3370
3371 // This function may be called very early, say, from the setup wizard, at
3372 // which point we won't have a default subscription set. If that's the case
3373 // we just choose the first, which will be valid in "most cases".
3374 final int defaultSubId = getDefaultSubscription();
3375 SubscriptionInfo info = null;
3376 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3377 info = slist.get(0);
3378 } else {
3379 for (SubscriptionInfo item : slist) {
3380 if (item.getSubscriptionId() == defaultSubId) {
3381 info = item;
3382 break;
3383 }
3384 }
3385
3386 if (info == null) {
3387 return null;
3388 }
3389 }
3390
3391 // Try and fetch the locale from the carrier properties or from the SIM language
3392 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003393 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003394 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003395 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003396 if (defaultPhone != null) {
3397 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3398 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003399 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003400 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3401 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003402 } else {
3403 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003404 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003405 }
3406 }
3407
Narayan Kamath011676f2015-07-29 12:04:08 +01003408 // The SIM language preferences only store a language (e.g. fr = French), not an
3409 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3410 // the SIM and carrier preferences does not include a country we add the country
3411 // determined from the SIM MCC to provide an exact locale.
3412 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003413 if (mccLocale != null) {
3414 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3415 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003416 }
3417
Tony Hill183b2de2015-06-24 14:53:58 +01003418 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003419 return null;
3420 }
3421
3422 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 return mSubscriptionController.getAllSubInfoList(
3426 mPhone.getContext().getOpPackageName());
3427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
3432 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3433 final long identity = Binder.clearCallingIdentity();
3434 try {
3435 return mSubscriptionController.getActiveSubscriptionInfoList(
3436 mPhone.getContext().getOpPackageName());
3437 } finally {
3438 Binder.restoreCallingIdentity(identity);
3439 }
3440 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003441
3442 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003443 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3444 * representing the state of the modem.
3445 *
3446 * NOTE: This clears the modem state, so there should only every be one caller.
3447 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003448 */
3449 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003450 public void requestModemActivityInfo(ResultReceiver result) {
3451 enforceModifyPermission();
3452
3453 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3454 Bundle bundle = new Bundle();
3455 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3456 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003457 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003458
3459 /**
3460 * {@hide}
3461 * Returns the service state information on specified subscription.
3462 */
3463 @Override
3464 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3465
3466 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3467 return null;
3468 }
3469
3470 final Phone phone = getPhone(subId);
3471 if (phone == null) {
3472 return null;
3473 }
3474
3475 return phone.getServiceState();
3476 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003477
3478 /**
3479 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3480 *
3481 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3482 * voicemail ringtone.
3483 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3484 * PhoneAccount.
3485 */
3486 @Override
3487 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003488 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003489 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003490 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003491 }
3492
fionaxu7ed723d2017-05-30 18:58:54 -07003493 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003494 }
3495
3496 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003497 * Sets the per-account voicemail ringtone.
3498 *
3499 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3500 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3501 *
3502 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3503 * voicemail ringtone.
3504 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3505 * PhoneAccount.
3506 */
3507 @Override
3508 public void setVoicemailRingtoneUri(String callingPackage,
3509 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3510 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3511 if (!TextUtils.equals(callingPackage,
3512 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3513 enforceModifyPermissionOrCarrierPrivilege(
3514 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3515 }
3516 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3517 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003518 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003519 }
fionaxu7ed723d2017-05-30 18:58:54 -07003520 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003521 }
3522
3523 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003524 * Returns whether vibration is set for voicemail notification in Phone settings.
3525 *
3526 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3527 * voicemail vibration setting.
3528 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3529 */
3530 @Override
3531 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003532 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003533 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003534 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003535 }
3536
fionaxu7ed723d2017-05-30 18:58:54 -07003537 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003538 }
3539
Youhan Wange64578a2016-05-02 15:32:42 -07003540 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003541 * Sets the per-account voicemail vibration.
3542 *
3543 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3544 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3545 *
3546 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3547 * voicemail vibration setting.
3548 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3549 * specific PhoneAccount.
3550 */
3551 @Override
3552 public void setVoicemailVibrationEnabled(String callingPackage,
3553 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3554 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3555 if (!TextUtils.equals(callingPackage,
3556 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3557 enforceModifyPermissionOrCarrierPrivilege(
3558 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3559 }
3560
3561 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3562 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003563 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003564 }
fionaxu7ed723d2017-05-30 18:58:54 -07003565 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003566 }
3567
3568 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003569 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3570 *
3571 * @throws SecurityException if the caller does not have the required permission
3572 */
3573 private void enforceReadPrivilegedPermission() {
3574 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3575 null);
3576 }
3577
3578 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003579 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3580 * permission.
3581 *
3582 * @throws SecurityException if the caller does not have the required permission
3583 */
3584 private void enforceSendSmsPermission() {
3585 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3586 }
3587
3588 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003589 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003590 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003591 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003592 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003593 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003594 ComponentName componentName =
3595 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3596 if(componentName == null) {
3597 throw new SecurityException("Caller not current active visual voicemail package[null]");
3598 }
3599 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003600 if (!callingPackage.equals(vvmPackage)) {
3601 throw new SecurityException("Caller not current active visual voicemail package[" +
3602 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003603 }
3604 }
3605
3606 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003607 * Return the application ID for the app type.
3608 *
3609 * @param subId the subscription ID that this request applies to.
3610 * @param appType the uicc app type.
3611 * @return Application ID for specificied app type, or null if no uicc.
3612 */
3613 @Override
3614 public String getAidForAppType(int subId, int appType) {
3615 enforceReadPrivilegedPermission();
3616 Phone phone = getPhone(subId);
3617 if (phone == null) {
3618 return null;
3619 }
3620 String aid = null;
3621 try {
3622 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3623 .getApplicationByType(appType).getAid();
3624 } catch (Exception e) {
3625 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3626 }
3627 return aid;
3628 }
3629
Youhan Wang4001d252016-05-11 10:29:41 -07003630 /**
3631 * Return the Electronic Serial Number.
3632 *
3633 * @param subId the subscription ID that this request applies to.
3634 * @return ESN or null if error.
3635 */
3636 @Override
3637 public String getEsn(int subId) {
3638 enforceReadPrivilegedPermission();
3639 Phone phone = getPhone(subId);
3640 if (phone == null) {
3641 return null;
3642 }
3643 String esn = null;
3644 try {
3645 esn = phone.getEsn();
3646 } catch (Exception e) {
3647 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3648 }
3649 return esn;
3650 }
3651
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003652 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003653 * Return the Preferred Roaming List Version.
3654 *
3655 * @param subId the subscription ID that this request applies to.
3656 * @return PRLVersion or null if error.
3657 */
3658 @Override
3659 public String getCdmaPrlVersion(int subId) {
3660 enforceReadPrivilegedPermission();
3661 Phone phone = getPhone(subId);
3662 if (phone == null) {
3663 return null;
3664 }
3665 String cdmaPrlVersion = null;
3666 try {
3667 cdmaPrlVersion = phone.getCdmaPrlVersion();
3668 } catch (Exception e) {
3669 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3670 }
3671 return cdmaPrlVersion;
3672 }
3673
3674 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003675 * Get snapshot of Telephony histograms
3676 * @return List of Telephony histograms
3677 * @hide
3678 */
3679 @Override
3680 public List<TelephonyHistogram> getTelephonyHistograms() {
3681 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3682 return RIL.getTelephonyRILTimingHistograms();
3683 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003684
3685 /**
3686 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003687 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003688 * Require system privileges. In the future we may add this to carrier APIs.
3689 *
3690 * @return The number of carriers set successfully, should match length of carriers
3691 */
3692 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003693 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003694 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003695
Meng Wang9b7c4e92017-02-17 11:41:27 -08003696 if (carriers == null) {
3697 throw new NullPointerException("carriers cannot be null");
3698 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003699
3700 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003701 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3702 return retVal[0];
3703 }
3704
3705 /**
3706 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003707 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003708 * Require system privileges. In the future we may add this to carrier APIs.
3709 *
3710 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3711 * means all carriers are allowed.
3712 */
3713 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003714 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003715 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003716 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003717 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3718 }
3719
fionaxu59545b42016-05-25 15:53:37 -07003720 /**
3721 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3722 * @param subId the subscription ID that this action applies to.
3723 * @param enabled control enable or disable metered apns.
3724 * {@hide}
3725 */
3726 @Override
3727 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3728 enforceModifyPermission();
3729 final Phone phone = getPhone(subId);
3730 if (phone == null) {
3731 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3732 return;
3733 }
3734 try {
3735 phone.carrierActionSetMeteredApnsEnabled(enabled);
3736 } catch (Exception e) {
3737 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3738 }
3739 }
3740
3741 /**
3742 * Action set from carrier signalling broadcast receivers to enable/disable radio
3743 * @param subId the subscription ID that this action applies to.
3744 * @param enabled control enable or disable radio.
3745 * {@hide}
3746 */
3747 @Override
3748 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3749 enforceModifyPermission();
3750 final Phone phone = getPhone(subId);
3751 if (phone == null) {
3752 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3753 return;
3754 }
3755 try {
3756 phone.carrierActionSetRadioEnabled(enabled);
3757 } catch (Exception e) {
3758 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3759 }
3760 }
3761
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003762 /**
3763 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3764 * bug report is being generated.
3765 */
3766 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003767 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003768 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3769 != PackageManager.PERMISSION_GRANTED) {
3770 writer.println("Permission Denial: can't dump Phone from pid="
3771 + Binder.getCallingPid()
3772 + ", uid=" + Binder.getCallingUid()
3773 + "without permission "
3774 + android.Manifest.permission.DUMP);
3775 return;
3776 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003777 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003778 }
Jack Yueb89b242016-06-22 13:27:47 -07003779
3780 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003781 * Get aggregated video call data usage since boot.
3782 *
3783 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3784 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003785 * {@hide}
3786 */
3787 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003788 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003789 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3790 null);
3791
Jack Yu84291ec2017-05-26 16:07:50 -07003792 // NetworkStatsService keeps tracking the active network interface and identity. It
3793 // records the delta with the corresponding network identity. We just return the total video
3794 // call data usage snapshot since boot.
3795 Phone phone = getPhone(subId);
3796 if (phone != null) {
3797 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003798 }
Jack Yu84291ec2017-05-26 16:07:50 -07003799 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003800 }
Jack Yu75ab2952016-07-08 14:29:33 -07003801
3802 /**
3803 * Policy control of data connection. Usually used when data limit is passed.
3804 * @param enabled True if enabling the data, otherwise disabling.
3805 * @param subId Subscription index
3806 * {@hide}
3807 */
3808 @Override
3809 public void setPolicyDataEnabled(boolean enabled, int subId) {
3810 enforceModifyPermission();
3811 Phone phone = getPhone(subId);
3812 if (phone != null) {
3813 phone.setPolicyDataEnabled(enabled);
3814 }
3815 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003816
3817 /**
3818 * Get Client request stats
3819 * @return List of Client Request Stats
3820 * @hide
3821 */
3822 @Override
3823 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3824 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3825 return null;
3826 }
3827
3828 Phone phone = getPhone(subId);
3829 if (phone != null) {
3830 return phone.getClientRequestStats();
3831 }
3832
3833 return null;
3834 }
3835
3836 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3837 if (workSource != null) {
3838 return workSource;
3839 }
3840
3841 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3842 workSource = new WorkSource(uid, packageName);
3843 return workSource;
3844 }
Jack Yueb4124c2017-02-16 15:32:43 -08003845
3846 /**
Grace Chen70990072017-03-24 17:21:30 -07003847 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003848 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003849 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003850 * @param state State of SIM (power down, power up, pass through)
3851 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3852 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3853 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003854 *
3855 **/
3856 @Override
Grace Chen70990072017-03-24 17:21:30 -07003857 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003858 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003859 Phone phone = PhoneFactory.getPhone(slotIndex);
3860
Jack Yueb4124c2017-02-16 15:32:43 -08003861 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003862 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003863 }
3864 }
Shuo Qiandd210312017-04-12 22:11:33 +00003865
Tyler Gunn65d45c22017-06-05 11:22:26 -07003866 private boolean isUssdApiAllowed(int subId) {
3867 CarrierConfigManager configManager =
3868 (CarrierConfigManager) mPhone.getContext().getSystemService(
3869 Context.CARRIER_CONFIG_SERVICE);
3870 if (configManager == null) {
3871 return false;
3872 }
3873 PersistableBundle pb = configManager.getConfigForSubId(subId);
3874 if (pb == null) {
3875 return false;
3876 }
3877 return pb.getBoolean(
3878 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3879 }
3880
Shuo Qiandd210312017-04-12 22:11:33 +00003881 /**
3882 * Check if phone is in emergency callback mode
3883 * @return true if phone is in emergency callback mode
3884 * @param subId sub id
3885 */
3886 public boolean getEmergencyCallbackMode(int subId) {
3887 final Phone phone = getPhone(subId);
3888 if (phone != null) {
3889 return phone.isInEcm();
3890 } else {
3891 return false;
3892 }
3893 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003894
3895 /**
3896 * Get the current signal strength information for the given subscription.
3897 * Because this information is not updated when the device is in a low power state
3898 * it should not be relied-upon to be current.
3899 * @param subId Subscription index
3900 * @return the most recent cached signal strength info from the modem
3901 */
3902 @Override
3903 public SignalStrength getSignalStrength(int subId) {
3904 Phone p = getPhone(subId);
3905 if (p == null) {
3906 return null;
3907 }
3908
3909 return p.getSignalStrength();
3910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003911}