blob: d3dd93c6e496236437f90923abc645cd00f8f066 [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;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Process;
Tyler Gunn65d45c22017-06-05 11:22:26 -070043import android.os.PersistableBundle;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
46import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070047import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070048import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070049import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080050import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070051import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080052import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080053import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070054import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070055import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070058import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070059import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080060import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070061import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070062import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080065import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070066import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080067import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070069import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070071import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080076import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080077import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080078
Andrew Lee312e8172014-10-23 17:01:36 -070079import com.android.ims.ImsManager;
Brad Ebinger51f743a2017-01-23 13:50:20 -080080import com.android.ims.internal.IImsServiceController;
81import com.android.ims.internal.IImsServiceFeatureListener;
Shishir Agrawal566b7612013-10-28 14:41:00 -070082import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070083import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070084import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070085import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080088import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010089import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070090import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070091import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080093import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070094import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070095import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070096import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070097import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070098import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080099import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700100import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700101import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700102import com.android.internal.telephony.uicc.IccIoResult;
103import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800104import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700105import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800106import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700107import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700108import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800109import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700110import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800111import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700112import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700113import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800114
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700115import java.io.FileDescriptor;
116import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800117import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800120import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100121import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800122import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123
124/**
125 * Implementation of the ITelephony interface.
126 */
Santos Cordon117fee72014-05-16 17:56:12 -0700127public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128 private static final String LOG_TAG = "PhoneInterfaceManager";
129 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
130 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800131 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132
133 // Message codes used with mMainThreadHandler
134 private static final int CMD_HANDLE_PIN_MMI = 1;
135 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
136 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
137 private static final int CMD_ANSWER_RINGING_CALL = 4;
138 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700139 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
140 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141 private static final int CMD_OPEN_CHANNEL = 9;
142 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
143 private static final int CMD_CLOSE_CHANNEL = 11;
144 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800145 private static final int CMD_NV_READ_ITEM = 13;
146 private static final int EVENT_NV_READ_ITEM_DONE = 14;
147 private static final int CMD_NV_WRITE_ITEM = 15;
148 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
149 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
150 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
151 private static final int CMD_NV_RESET_CONFIG = 19;
152 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800153 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
154 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
155 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
156 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800157 private static final int CMD_SEND_ENVELOPE = 25;
158 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700159 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
160 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
161 private static final int CMD_EXCHANGE_SIM_IO = 31;
162 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800163 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
164 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700165 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
166 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700167 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
168 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700169 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
170 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
171 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
172 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700173 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
174 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
175 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
176 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700177 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800178 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
179 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180
181 /** The singleton instance. */
182 private static PhoneInterfaceManager sInstance;
183
Wink Saville3ab207e2014-11-20 13:07:20 -0800184 private PhoneGlobals mApp;
185 private Phone mPhone;
186 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700187 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800188 private AppOpsManager mAppOps;
189 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800190 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800191 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192
Derek Tan97ebb422014-09-05 16:55:38 -0700193 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
194 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700196
Derek Tan740e1672017-06-27 14:56:27 -0700197 // The AID of ISD-R.
198 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
199
yinxub1bed742017-04-17 11:45:04 -0700200 private NetworkScanRequestTracker mNetworkScanRequestTracker;
201
Derek Tan89e89d42014-07-08 17:00:10 -0700202 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203 * A request object to use for transmitting data to an ICC.
204 */
205 private static final class IccAPDUArgument {
206 public int channel, cla, command, p1, p2, p3;
207 public String data;
208
209 public IccAPDUArgument(int channel, int cla, int command,
210 int p1, int p2, int p3, String data) {
211 this.channel = channel;
212 this.cla = cla;
213 this.command = command;
214 this.p1 = p1;
215 this.p2 = p2;
216 this.p3 = p3;
217 this.data = data;
218 }
219 }
220
221 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700222 * A request object to use for transmitting data to an ICC.
223 */
224 private static final class ManualNetworkSelectionArgument {
225 public OperatorInfo operatorInfo;
226 public boolean persistSelection;
227
228 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
229 this.operatorInfo = operatorInfo;
230 this.persistSelection = persistSelection;
231 }
232 }
233
234 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
236 * request after sending. The main thread will notify the request when it is complete.
237 */
238 private static final class MainThreadRequest {
239 /** The argument to use for the request */
240 public Object argument;
241 /** The result of the request that is run on the main thread */
242 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800243 // The subscriber id that this request applies to. Defaults to
244 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
245 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246
247 public MainThreadRequest(Object argument) {
248 this.argument = argument;
249 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800250
251 public MainThreadRequest(Object argument, Integer subId) {
252 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800253 if (subId != null) {
254 this.subId = subId;
255 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257 }
258
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800259 private static final class IncomingThirdPartyCallArgs {
260 public final ComponentName component;
261 public final String callId;
262 public final String callerDisplayName;
263
264 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
265 String callerDisplayName) {
266 this.component = component;
267 this.callId = callId;
268 this.callerDisplayName = callerDisplayName;
269 }
270 }
271
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 /**
273 * A handler that processes messages on the main thread in the phone process. Since many
274 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
275 * inbound binder threads to the main thread in the phone process. The Binder thread
276 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
277 * on, which will be notified when the operation completes and will contain the result of the
278 * request.
279 *
280 * <p>If a MainThreadRequest object is provided in the msg.obj field,
281 * note that request.result must be set to something non-null for the calling thread to
282 * unblock.
283 */
284 private final class MainThreadHandler extends Handler {
285 @Override
286 public void handleMessage(Message msg) {
287 MainThreadRequest request;
288 Message onCompleted;
289 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800290 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700291 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
293 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700294 case CMD_HANDLE_USSD_REQUEST: {
295 request = (MainThreadRequest) msg.obj;
296 final Phone phone = getPhoneFromRequest(request);
297 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
298 String ussdRequest = ussdObject.first;
299 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700300
301 if (!isUssdApiAllowed(request.subId)) {
302 // Carrier does not support use of this API, return failure.
303 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
304 UssdResponse response = new UssdResponse(ussdRequest, null);
305 Bundle returnData = new Bundle();
306 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
307 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
308
309 request.result = true;
310 synchronized (request) {
311 request.notifyAll();
312 }
313 return;
314 }
315
Tyler Gunn52dcf772017-04-26 11:30:31 -0700316 try {
317 request.result = phone != null ?
318 phone.handleUssdRequest(ussdRequest, wrappedCallback)
319 : false;
320 } catch (CallStateException cse) {
321 request.result = false;
322 }
pkanwar32d516d2016-10-14 19:37:38 -0700323 // Wake up the requesting thread
324 synchronized (request) {
325 request.notifyAll();
326 }
327 break;
328 }
329
Yorke Lee716f67e2015-06-17 15:39:16 -0700330 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700332 final Phone phone = getPhoneFromRequest(request);
333 request.result = phone != null ?
334 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
335 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 // Wake up the requesting thread
337 synchronized (request) {
338 request.notifyAll();
339 }
340 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
343 case CMD_HANDLE_NEIGHBORING_CELL:
344 request = (MainThreadRequest) msg.obj;
345 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
346 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700347 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 break;
349
350 case EVENT_NEIGHBORING_CELL_DONE:
351 ar = (AsyncResult) msg.obj;
352 request = (MainThreadRequest) ar.userObj;
353 if (ar.exception == null && ar.result != null) {
354 request.result = ar.result;
355 } else {
356 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800357 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 }
359 // Wake up the requesting thread
360 synchronized (request) {
361 request.notifyAll();
362 }
363 break;
364
365 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700366 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800367 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700368 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 break;
370
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 case CMD_END_CALL:
372 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800373 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700374 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700375 Phone phone = getPhone(end_subId);
376 if (phone == null) {
377 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
378 break;
379 }
380 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
382 // CDMA: If the user presses the Power button we treat it as
383 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700384 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
386 // GSM: End the call as per the Phone state
387 hungUp = PhoneUtils.hangup(mCM);
388 } else {
389 throw new IllegalStateException("Unexpected phone type: " + phoneType);
390 }
391 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
392 request.result = hungUp;
393 // Wake up the requesting thread
394 synchronized (request) {
395 request.notifyAll();
396 }
397 break;
398
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700399 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700400 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800402 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700403 if (uiccCard == null) {
404 loge("iccTransmitApduLogicalChannel: No UICC");
405 request.result = new IccIoResult(0x6F, 0, (byte[])null);
406 synchronized (request) {
407 request.notifyAll();
408 }
409 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700410 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
411 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700412 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 iccArgument.channel, iccArgument.cla, iccArgument.command,
414 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700415 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700416 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 break;
418
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700420 ar = (AsyncResult) msg.obj;
421 request = (MainThreadRequest) ar.userObj;
422 if (ar.exception == null && ar.result != null) {
423 request.result = ar.result;
424 } else {
425 request.result = new IccIoResult(0x6F, 0, (byte[])null);
426 if (ar.result == null) {
427 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800428 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800430 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 } else {
432 loge("iccTransmitApduLogicalChannel: Unknown exception");
433 }
434 }
435 synchronized (request) {
436 request.notifyAll();
437 }
438 break;
439
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
441 request = (MainThreadRequest) msg.obj;
442 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800443 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 if (uiccCard == null) {
445 loge("iccTransmitApduBasicChannel: No UICC");
446 request.result = new IccIoResult(0x6F, 0, (byte[])null);
447 synchronized (request) {
448 request.notifyAll();
449 }
450 } else {
451 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
452 request);
453 uiccCard.iccTransmitApduBasicChannel(
454 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
455 iccArgument.p3, iccArgument.data, onCompleted);
456 }
457 break;
458
459 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
460 ar = (AsyncResult) msg.obj;
461 request = (MainThreadRequest) ar.userObj;
462 if (ar.exception == null && ar.result != null) {
463 request.result = ar.result;
464 } else {
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
466 if (ar.result == null) {
467 loge("iccTransmitApduBasicChannel: Empty response");
468 } else if (ar.exception instanceof CommandException) {
469 loge("iccTransmitApduBasicChannel: CommandException: " +
470 ar.exception);
471 } else {
472 loge("iccTransmitApduBasicChannel: Unknown exception");
473 }
474 }
475 synchronized (request) {
476 request.notifyAll();
477 }
478 break;
479
480 case CMD_EXCHANGE_SIM_IO:
481 request = (MainThreadRequest) msg.obj;
482 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800483 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 if (uiccCard == null) {
485 loge("iccExchangeSimIO: No UICC");
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
487 synchronized (request) {
488 request.notifyAll();
489 }
490 } else {
491 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
492 request);
493 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
494 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
495 iccArgument.data, onCompleted);
496 }
497 break;
498
499 case EVENT_EXCHANGE_SIM_IO_DONE:
500 ar = (AsyncResult) msg.obj;
501 request = (MainThreadRequest) ar.userObj;
502 if (ar.exception == null && ar.result != null) {
503 request.result = ar.result;
504 } else {
505 request.result = new IccIoResult(0x6f, 0, (byte[])null);
506 }
507 synchronized (request) {
508 request.notifyAll();
509 }
510 break;
511
Derek Tan4d5e5c12014-02-04 11:54:58 -0800512 case CMD_SEND_ENVELOPE:
513 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800514 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700515 if (uiccCard == null) {
516 loge("sendEnvelopeWithStatus: No UICC");
517 request.result = new IccIoResult(0x6F, 0, (byte[])null);
518 synchronized (request) {
519 request.notifyAll();
520 }
521 } else {
522 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
523 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
524 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800525 break;
526
527 case EVENT_SEND_ENVELOPE_DONE:
528 ar = (AsyncResult) msg.obj;
529 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700530 if (ar.exception == null && ar.result != null) {
531 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800532 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700533 request.result = new IccIoResult(0x6F, 0, (byte[])null);
534 if (ar.result == null) {
535 loge("sendEnvelopeWithStatus: Empty response");
536 } else if (ar.exception instanceof CommandException) {
537 loge("sendEnvelopeWithStatus: CommandException: " +
538 ar.exception);
539 } else {
540 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
541 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800542 }
543 synchronized (request) {
544 request.notifyAll();
545 }
546 break;
547
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 case CMD_OPEN_CHANNEL:
549 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800550 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800551 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 if (uiccCard == null) {
553 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800554 request.result = new IccOpenLogicalChannelResponse(-1,
555 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 synchronized (request) {
557 request.notifyAll();
558 }
559 } else {
560 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800561 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
562 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 break;
565
566 case EVENT_OPEN_CHANNEL_DONE:
567 ar = (AsyncResult) msg.obj;
568 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 int[] result = (int[]) ar.result;
572 int channelId = result[0];
573 byte[] selectResponse = null;
574 if (result.length > 1) {
575 selectResponse = new byte[result.length - 1];
576 for (int i = 1; i < result.length; ++i) {
577 selectResponse[i - 1] = (byte) result[i];
578 }
579 }
580 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700581 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 if (ar.result == null) {
584 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 if (ar.exception != null) {
587 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
588 }
589
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700590 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700591 if (ar.exception instanceof CommandException) {
592 CommandException.Error error =
593 ((CommandException) (ar.exception)).getCommandError();
594 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700596 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700597 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 }
599 }
600 openChannelResp = new IccOpenLogicalChannelResponse(
601 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700603 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 synchronized (request) {
605 request.notifyAll();
606 }
607 break;
608
609 case CMD_CLOSE_CHANNEL:
610 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800611 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 if (uiccCard == null) {
613 loge("iccCloseLogicalChannel: No UICC");
614 request.result = new IccIoResult(0x6F, 0, (byte[])null);
615 synchronized (request) {
616 request.notifyAll();
617 }
618 } else {
619 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
620 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
621 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
624 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800625 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
626 break;
627
628 case CMD_NV_READ_ITEM:
629 request = (MainThreadRequest) msg.obj;
630 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
631 mPhone.nvReadItem((Integer) request.argument, onCompleted);
632 break;
633
634 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 ar = (AsyncResult) msg.obj;
636 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800637 if (ar.exception == null && ar.result != null) {
638 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800640 request.result = "";
641 if (ar.result == null) {
642 loge("nvReadItem: Empty response");
643 } else if (ar.exception instanceof CommandException) {
644 loge("nvReadItem: CommandException: " +
645 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800647 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 }
649 }
650 synchronized (request) {
651 request.notifyAll();
652 }
653 break;
654
Jake Hambye994d462014-02-03 13:10:13 -0800655 case CMD_NV_WRITE_ITEM:
656 request = (MainThreadRequest) msg.obj;
657 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
658 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
659 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
660 break;
661
662 case EVENT_NV_WRITE_ITEM_DONE:
663 handleNullReturnEvent(msg, "nvWriteItem");
664 break;
665
666 case CMD_NV_WRITE_CDMA_PRL:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
669 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
670 break;
671
672 case EVENT_NV_WRITE_CDMA_PRL_DONE:
673 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
674 break;
675
676 case CMD_NV_RESET_CONFIG:
677 request = (MainThreadRequest) msg.obj;
678 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
679 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
680 break;
681
682 case EVENT_NV_RESET_CONFIG_DONE:
683 handleNullReturnEvent(msg, "nvResetConfig");
684 break;
685
Jake Hamby7c27be32014-03-03 13:25:59 -0800686 case CMD_GET_PREFERRED_NETWORK_TYPE:
687 request = (MainThreadRequest) msg.obj;
688 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700689 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800690 break;
691
692 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
693 ar = (AsyncResult) msg.obj;
694 request = (MainThreadRequest) ar.userObj;
695 if (ar.exception == null && ar.result != null) {
696 request.result = ar.result; // Integer
697 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800698 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800699 if (ar.result == null) {
700 loge("getPreferredNetworkType: Empty response");
701 } else if (ar.exception instanceof CommandException) {
702 loge("getPreferredNetworkType: CommandException: " +
703 ar.exception);
704 } else {
705 loge("getPreferredNetworkType: Unknown exception");
706 }
707 }
708 synchronized (request) {
709 request.notifyAll();
710 }
711 break;
712
713 case CMD_SET_PREFERRED_NETWORK_TYPE:
714 request = (MainThreadRequest) msg.obj;
715 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
716 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700717 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 break;
719
720 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
721 handleNullReturnEvent(msg, "setPreferredNetworkType");
722 break;
723
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800724 case CMD_SET_VOICEMAIL_NUMBER:
725 request = (MainThreadRequest) msg.obj;
726 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
727 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800728 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
729 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800730 break;
731
732 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
733 handleNullReturnEvent(msg, "setVoicemailNumber");
734 break;
735
Stuart Scott54788802015-03-30 13:18:01 -0700736 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
739 request);
740 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
741 break;
742
743 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
744 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
745 break;
746
Shishir Agrawal302c8692015-06-19 13:49:39 -0700747 case CMD_PERFORM_NETWORK_SCAN:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
750 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
751 break;
752
753 case EVENT_PERFORM_NETWORK_SCAN_DONE:
754 ar = (AsyncResult) msg.obj;
755 request = (MainThreadRequest) ar.userObj;
756 CellNetworkScanResult cellScanResult;
757 if (ar.exception == null && ar.result != null) {
758 cellScanResult = new CellNetworkScanResult(
759 CellNetworkScanResult.STATUS_SUCCESS,
760 (List<OperatorInfo>) ar.result);
761 } else {
762 if (ar.result == null) {
763 loge("getCellNetworkScanResults: Empty response");
764 }
765 if (ar.exception != null) {
766 loge("getCellNetworkScanResults: Exception: " + ar.exception);
767 }
768 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
769 if (ar.exception instanceof CommandException) {
770 CommandException.Error error =
771 ((CommandException) (ar.exception)).getCommandError();
772 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
773 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
774 } else if (error == CommandException.Error.GENERIC_FAILURE) {
775 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
776 }
777 }
778 cellScanResult = new CellNetworkScanResult(errorCode, null);
779 }
780 request.result = cellScanResult;
781 synchronized (request) {
782 request.notifyAll();
783 }
784 break;
785
786 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
787 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700788 ManualNetworkSelectionArgument selArg =
789 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
791 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700792 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
793 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700794 break;
795
796 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
797 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
798 break;
799
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700800 case CMD_GET_MODEM_ACTIVITY_INFO:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700803 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700804 break;
805
806 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null && ar.result != null) {
810 request.result = ar.result;
811 } else {
812 if (ar.result == null) {
813 loge("queryModemActivityInfo: Empty response");
814 } else if (ar.exception instanceof CommandException) {
815 loge("queryModemActivityInfo: CommandException: " +
816 ar.exception);
817 } else {
818 loge("queryModemActivityInfo: Unknown exception");
819 }
820 }
Amit Mahajand4766222016-01-28 15:28:28 -0800821 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
822 if (request.result == null) {
823 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
824 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700825 synchronized (request) {
826 request.notifyAll();
827 }
828 break;
829
Meng Wang1a7c35a2016-05-05 20:56:15 -0700830 case CMD_SET_ALLOWED_CARRIERS:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
833 mPhone.setAllowedCarriers(
834 (List<CarrierIdentifier>) request.argument,
835 onCompleted);
836 break;
837
838 case EVENT_SET_ALLOWED_CARRIERS_DONE:
839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 if (ar.exception == null && ar.result != null) {
842 request.result = ar.result;
843 } else {
844 if (ar.result == null) {
845 loge("setAllowedCarriers: Empty response");
846 } else if (ar.exception instanceof CommandException) {
847 loge("setAllowedCarriers: CommandException: " +
848 ar.exception);
849 } else {
850 loge("setAllowedCarriers: Unknown exception");
851 }
852 }
853 // Result cannot be null. Return -1 on error.
854 if (request.result == null) {
855 request.result = new int[]{-1};
856 }
857 synchronized (request) {
858 request.notifyAll();
859 }
860 break;
861
862 case CMD_GET_ALLOWED_CARRIERS:
863 request = (MainThreadRequest) msg.obj;
864 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
865 mPhone.getAllowedCarriers(onCompleted);
866 break;
867
868 case EVENT_GET_ALLOWED_CARRIERS_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
874 if (ar.result == null) {
875 loge("getAllowedCarriers: Empty response");
876 } else if (ar.exception instanceof CommandException) {
877 loge("getAllowedCarriers: CommandException: " +
878 ar.exception);
879 } else {
880 loge("getAllowedCarriers: Unknown exception");
881 }
882 }
883 // Result cannot be null. Return empty list of CarrierIdentifier.
884 if (request.result == null) {
885 request.result = new ArrayList<CarrierIdentifier>(0);
886 }
887 synchronized (request) {
888 request.notifyAll();
889 }
890 break;
891
Nathan Haroldb3014052017-01-25 15:57:32 -0800892 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result;
897 } else {
898 request.result = new IllegalArgumentException(
899 "Failed to retrieve Forbidden Plmns");
900 if (ar.result == null) {
901 loge("getForbiddenPlmns: Empty response");
902 } else {
903 loge("getForbiddenPlmns: Unknown exception");
904 }
905 }
906 synchronized (request) {
907 request.notifyAll();
908 }
909 break;
910
911 case CMD_GET_FORBIDDEN_PLMNS:
912 request = (MainThreadRequest) msg.obj;
913 uiccCard = getUiccCardFromRequest(request);
914 if (uiccCard == null) {
915 loge("getForbiddenPlmns() UiccCard is null");
916 request.result = new IllegalArgumentException(
917 "getForbiddenPlmns() UiccCard is null");
918 synchronized (request) {
919 request.notifyAll();
920 }
921 break;
922 }
923 Integer appType = (Integer) request.argument;
924 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
925 if (uiccApp == null) {
926 loge("getForbiddenPlmns() no app with specified type -- "
927 + appType);
928 request.result = new IllegalArgumentException("Failed to get UICC App");
929 synchronized (request) {
930 request.notifyAll();
931 }
932 break;
933 } else {
934 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
935 + " specified type -- " + appType);
936 }
937 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
938 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
939 onCompleted);
940 break;
941
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700942 default:
943 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
944 break;
945 }
946 }
Jake Hambye994d462014-02-03 13:10:13 -0800947
948 private void handleNullReturnEvent(Message msg, String command) {
949 AsyncResult ar = (AsyncResult) msg.obj;
950 MainThreadRequest request = (MainThreadRequest) ar.userObj;
951 if (ar.exception == null) {
952 request.result = true;
953 } else {
954 request.result = false;
955 if (ar.exception instanceof CommandException) {
956 loge(command + ": CommandException: " + ar.exception);
957 } else {
958 loge(command + ": Unknown exception");
959 }
960 }
961 synchronized (request) {
962 request.notifyAll();
963 }
964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700965 }
966
967 /**
968 * Posts the specified command to be executed on the main thread,
969 * waits for the request to complete, and returns the result.
970 * @see #sendRequestAsync
971 */
972 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800973 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700974 }
975
976 /**
977 * Posts the specified command to be executed on the main thread,
978 * waits for the request to complete, and returns the result.
979 * @see #sendRequestAsync
980 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800981 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700982 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
983 throw new RuntimeException("This method will deadlock if called from the main thread.");
984 }
985
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800986 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700987 Message msg = mMainThreadHandler.obtainMessage(command, request);
988 msg.sendToTarget();
989
990 // Wait for the request to complete
991 synchronized (request) {
992 while (request.result == null) {
993 try {
994 request.wait();
995 } catch (InterruptedException e) {
996 // Do nothing, go back and wait until the request is complete
997 }
998 }
999 }
1000 return request.result;
1001 }
1002
1003 /**
1004 * Asynchronous ("fire and forget") version of sendRequest():
1005 * Posts the specified command to be executed on the main thread, and
1006 * returns immediately.
1007 * @see #sendRequest
1008 */
1009 private void sendRequestAsync(int command) {
1010 mMainThreadHandler.sendEmptyMessage(command);
1011 }
1012
1013 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001014 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1015 * @see {@link #sendRequest(int,Object)}
1016 */
1017 private void sendRequestAsync(int command, Object argument) {
1018 MainThreadRequest request = new MainThreadRequest(argument);
1019 Message msg = mMainThreadHandler.obtainMessage(command, request);
1020 msg.sendToTarget();
1021 }
1022
1023 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001024 * Initialize the singleton PhoneInterfaceManager instance.
1025 * This is only done once, at startup, from PhoneApp.onCreate().
1026 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001027 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001028 synchronized (PhoneInterfaceManager.class) {
1029 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001030 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001031 } else {
1032 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1033 }
1034 return sInstance;
1035 }
1036 }
1037
1038 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001039 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001040 mApp = app;
1041 mPhone = phone;
1042 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001043 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001044 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1045 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001046 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001047 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001048 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001049 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001050
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001051 publish();
1052 }
1053
1054 private void publish() {
1055 if (DBG) log("publish: " + this);
1056
1057 ServiceManager.addService("phone", this);
1058 }
1059
Stuart Scott584921c2015-01-15 17:10:34 -08001060 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001061 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1062 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001063 }
1064
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001065 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1066 Phone phone = getPhoneFromRequest(request);
1067 return phone == null ? null :
1068 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1069 }
1070
Wink Saville36469e72014-06-11 15:17:00 -07001071 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001072 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001073 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001075 //
1076 // Implementation of the ITelephony interface.
1077 //
1078
1079 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001080 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001081 }
1082
Wink Savilleb564aae2014-10-23 10:18:09 -07001083 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001084 if (DBG) log("dial: " + number);
1085 // No permission check needed here: This is just a wrapper around the
1086 // ACTION_DIAL intent, which is available to any app since it puts up
1087 // the UI before it does anything.
1088
1089 String url = createTelUrl(number);
1090 if (url == null) {
1091 return;
1092 }
1093
1094 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001095 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001096 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1097 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1098 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1099 mApp.startActivity(intent);
1100 }
1101 }
1102
1103 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001104 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001105 }
1106
Wink Savilleb564aae2014-10-23 10:18:09 -07001107 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001108 if (DBG) log("call: " + number);
1109
1110 // This is just a wrapper around the ACTION_CALL intent, but we still
1111 // need to do a permission check since we're calling startActivity()
1112 // from the context of the phone app.
1113 enforceCallPermission();
1114
1115 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1116 != AppOpsManager.MODE_ALLOWED) {
1117 return;
1118 }
1119
1120 String url = createTelUrl(number);
1121 if (url == null) {
1122 return;
1123 }
1124
Wink Saville08874612014-08-31 19:19:58 -07001125 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001126 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001127 if (slist != null) {
1128 for (SubscriptionInfo subInfoRecord : slist) {
1129 if (subInfoRecord.getSubscriptionId() == subId) {
1130 isValid = true;
1131 break;
1132 }
Wink Saville08874612014-08-31 19:19:58 -07001133 }
1134 }
1135 if (isValid == false) {
1136 return;
1137 }
1138
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001140 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1142 mApp.startActivity(intent);
1143 }
1144
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001145 /**
1146 * End a call based on call state
1147 * @return true is a call was ended
1148 */
1149 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001150 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001151 }
1152
1153 /**
1154 * End a call based on the call state of the subId
1155 * @return true is a call was ended
1156 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001157 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001158 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001159 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 }
1161
1162 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001163 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001164 }
1165
Wink Savilleb564aae2014-10-23 10:18:09 -07001166 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001167 if (DBG) log("answerRingingCall...");
1168 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1169 // but that can probably wait till the big TelephonyManager API overhaul.
1170 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1171 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001172 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173 }
1174
1175 /**
1176 * Make the actual telephony calls to implement answerRingingCall().
1177 * This should only be called from the main thread of the Phone app.
1178 * @see #answerRingingCall
1179 *
1180 * TODO: it would be nice to return true if we answered the call, or
1181 * false if there wasn't actually a ringing incoming call, or some
1182 * other error occurred. (In other words, pass back the return value
1183 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1184 * But that would require calling this method via sendRequest() rather
1185 * than sendRequestAsync(), and right now we don't actually *need* that
1186 * return value, so let's just return void for now.
1187 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001188 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001189 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001191 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1192 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001193 if (hasActiveCall && hasHoldingCall) {
1194 // Both lines are in use!
1195 // TODO: provide a flag to let the caller specify what
1196 // policy to use if both lines are in use. (The current
1197 // behavior is hardwired to "answer incoming, end ongoing",
1198 // which is how the CALL button is specced to behave.)
1199 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1200 return;
1201 } else {
1202 // answerCall() will automatically hold the current active
1203 // call, if there is one.
1204 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1205 return;
1206 }
1207 } else {
1208 // No call was ringing.
1209 return;
1210 }
1211 }
1212
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001213 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001214 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001215 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001216 public void silenceRinger() {
1217 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 }
1219
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001220 @Override
1221 public boolean isOffhook(String callingPackage) {
1222 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001223 }
1224
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001225 @Override
1226 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1227 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1228 return false;
1229 }
1230
Sanket Padawe356d7632015-06-22 14:03:32 -07001231 final Phone phone = getPhone(subId);
1232 if (phone != null) {
1233 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1234 } else {
1235 return false;
1236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237 }
1238
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001239 @Override
1240 public boolean isRinging(String callingPackage) {
1241 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001242 }
1243
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001244 @Override
1245 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1246 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1247 return false;
1248 }
1249
Sanket Padawe356d7632015-06-22 14:03:32 -07001250 final Phone phone = getPhone(subId);
1251 if (phone != null) {
1252 return (phone.getState() == PhoneConstants.State.RINGING);
1253 } else {
1254 return false;
1255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001256 }
1257
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001258 @Override
1259 public boolean isIdle(String callingPackage) {
1260 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001261 }
1262
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001263 @Override
1264 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1265 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1266 return false;
1267 }
1268
Sanket Padawe356d7632015-06-22 14:03:32 -07001269 final Phone phone = getPhone(subId);
1270 if (phone != null) {
1271 return (phone.getState() == PhoneConstants.State.IDLE);
1272 } else {
1273 return false;
1274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001275 }
1276
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001278 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001279 }
1280
Wink Savilleb564aae2014-10-23 10:18:09 -07001281 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001282 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001283 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1284 }
1285
1286 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001287 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001288 }
1289
Wink Savilleb564aae2014-10-23 10:18:09 -07001290 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001291 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001292 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1293 }
1294
1295 /** {@hide} */
1296 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001297 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001298 }
1299
Wink Savilleb564aae2014-10-23 10:18:09 -07001300 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001301 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001302 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 checkSimPin.start();
1304 return checkSimPin.unlockSim(null, pin);
1305 }
1306
Wink Saville9de0f752013-10-22 19:04:03 -07001307 /** {@hide} */
1308 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001309 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001310 }
1311
Wink Savilleb564aae2014-10-23 10:18:09 -07001312 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001314 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 checkSimPuk.start();
1316 return checkSimPuk.unlockSim(puk, pin);
1317 }
1318
1319 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001320 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321 * a synchronous one.
1322 */
1323 private static class UnlockSim extends Thread {
1324
1325 private final IccCard mSimCard;
1326
1327 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001328 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1329 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330
1331 // For replies from SimCard interface
1332 private Handler mHandler;
1333
1334 // For async handler to identify request type
1335 private static final int SUPPLY_PIN_COMPLETE = 100;
1336
1337 public UnlockSim(IccCard simCard) {
1338 mSimCard = simCard;
1339 }
1340
1341 @Override
1342 public void run() {
1343 Looper.prepare();
1344 synchronized (UnlockSim.this) {
1345 mHandler = new Handler() {
1346 @Override
1347 public void handleMessage(Message msg) {
1348 AsyncResult ar = (AsyncResult) msg.obj;
1349 switch (msg.what) {
1350 case SUPPLY_PIN_COMPLETE:
1351 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1352 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001353 mRetryCount = msg.arg1;
1354 if (ar.exception != null) {
1355 if (ar.exception instanceof CommandException &&
1356 ((CommandException)(ar.exception)).getCommandError()
1357 == CommandException.Error.PASSWORD_INCORRECT) {
1358 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1359 } else {
1360 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1361 }
1362 } else {
1363 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 mDone = true;
1366 UnlockSim.this.notifyAll();
1367 }
1368 break;
1369 }
1370 }
1371 };
1372 UnlockSim.this.notifyAll();
1373 }
1374 Looper.loop();
1375 }
1376
1377 /*
1378 * Use PIN or PUK to unlock SIM card
1379 *
1380 * If PUK is null, unlock SIM card with PIN
1381 *
1382 * If PUK is not null, unlock SIM card with PUK and set PIN code
1383 */
Wink Saville9de0f752013-10-22 19:04:03 -07001384 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385
1386 while (mHandler == null) {
1387 try {
1388 wait();
1389 } catch (InterruptedException e) {
1390 Thread.currentThread().interrupt();
1391 }
1392 }
1393 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1394
1395 if (puk == null) {
1396 mSimCard.supplyPin(pin, callback);
1397 } else {
1398 mSimCard.supplyPuk(puk, pin, callback);
1399 }
1400
1401 while (!mDone) {
1402 try {
1403 Log.d(LOG_TAG, "wait for done");
1404 wait();
1405 } catch (InterruptedException e) {
1406 // Restore the interrupted status
1407 Thread.currentThread().interrupt();
1408 }
1409 }
1410 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001411 int[] resultArray = new int[2];
1412 resultArray[0] = mResult;
1413 resultArray[1] = mRetryCount;
1414 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 }
1416 }
1417
1418 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001419 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001420
1421 }
1422
Wink Savilleb564aae2014-10-23 10:18:09 -07001423 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424 // No permission check needed here: this call is harmless, and it's
1425 // needed for the ServiceState.requestStateUpdate() call (which is
1426 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001427 final Phone phone = getPhone(subId);
1428 if (phone != null) {
1429 phone.updateServiceLocation();
1430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 }
1432
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001433 @Override
1434 public boolean isRadioOn(String callingPackage) {
1435 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001436 }
1437
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001438 @Override
1439 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1440 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1441 return false;
1442 }
1443 return isRadioOnForSubscriber(subId);
1444 }
1445
1446 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001447 final Phone phone = getPhone(subId);
1448 if (phone != null) {
1449 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1450 } else {
1451 return false;
1452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 }
1454
1455 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001457
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 }
Wink Saville36469e72014-06-11 15:17:00 -07001459
Wink Savilleb564aae2014-10-23 10:18:09 -07001460 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001462 final Phone phone = getPhone(subId);
1463 if (phone != null) {
1464 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1465 }
Wink Saville36469e72014-06-11 15:17:00 -07001466 }
1467
1468 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001469 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001470 }
1471
Wink Savilleb564aae2014-10-23 10:18:09 -07001472 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001473 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001474 final Phone phone = getPhone(subId);
1475 if (phone == null) {
1476 return false;
1477 }
1478 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001479 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001480 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482 return true;
1483 }
Wink Saville36469e72014-06-11 15:17:00 -07001484
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001485 public boolean needMobileRadioShutdown() {
1486 /*
1487 * If any of the Radios are available, it will need to be
1488 * shutdown. So return true if any Radio is available.
1489 */
1490 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1491 Phone phone = PhoneFactory.getPhone(i);
1492 if (phone != null && phone.isRadioAvailable()) return true;
1493 }
1494 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1495 return false;
1496 }
1497
1498 public void shutdownMobileRadios() {
1499 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1500 logv("Shutting down Phone " + i);
1501 shutdownRadioUsingPhoneId(i);
1502 }
1503 }
1504
1505 private void shutdownRadioUsingPhoneId(int phoneId) {
1506 enforceModifyPermission();
1507 Phone phone = PhoneFactory.getPhone(phoneId);
1508 if (phone != null && phone.isRadioAvailable()) {
1509 phone.shutdownRadio();
1510 }
1511 }
1512
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001514 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001515 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1516 if (defaultPhone != null) {
1517 defaultPhone.setRadioPower(turnOn);
1518 return true;
1519 } else {
1520 loge("There's no default phone.");
1521 return false;
1522 }
Wink Saville36469e72014-06-11 15:17:00 -07001523 }
1524
Wink Savilleb564aae2014-10-23 10:18:09 -07001525 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001527 final Phone phone = getPhone(subId);
1528 if (phone != null) {
1529 phone.setRadioPower(turnOn);
1530 return true;
1531 } else {
1532 return false;
1533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 }
1535
Wink Saville36469e72014-06-11 15:17:00 -07001536 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001537 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001538 public boolean enableDataConnectivity() {
1539 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001540 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001541 final Phone phone = getPhone(subId);
1542 if (phone != null) {
1543 phone.setDataEnabled(true);
1544 return true;
1545 } else {
1546 return false;
1547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 }
1549
Wink Saville36469e72014-06-11 15:17:00 -07001550 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001551 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 public boolean disableDataConnectivity() {
1553 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001554 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001555 final Phone phone = getPhone(subId);
1556 if (phone != null) {
1557 phone.setDataEnabled(false);
1558 return true;
1559 } else {
1560 return false;
1561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 }
1563
Sanket Padawe356d7632015-06-22 14:03:32 -07001564 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001565 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001566 final Phone phone = getPhone(subId);
1567 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001568 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001569 } else {
1570 return false;
1571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 }
1573
1574 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001575 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001576 }
1577
pkanwarae03a6b2016-11-06 20:37:09 -08001578 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001579 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001580 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1581 return;
1582 }
1583 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1584 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1585 };
1586
Wink Savilleb564aae2014-10-23 10:18:09 -07001587 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001589 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1590 return false;
1591 }
Wink Saville36469e72014-06-11 15:17:00 -07001592 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 }
1594
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001596 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001597 }
1598
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001599 public int getCallStateForSlot(int slotIndex) {
1600 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001601 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001602 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 }
1604
Sanket Padawe356d7632015-06-22 14:03:32 -07001605 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001607 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001609 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001611 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 }
1614
Sanket Padawe356d7632015-06-22 14:03:32 -07001615 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001617 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 if (phone != null) {
1619 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1620 } else {
1621 return TelephonyManager.DATA_ACTIVITY_NONE;
1622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 }
1624
1625 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001626 public Bundle getCellLocation(String callingPackage) {
1627 enforceFineOrCoarseLocationPermission("getCellLocation");
1628
1629 // OP_COARSE_LOCATION controls both fine and coarse location.
1630 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1631 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001632 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001633 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 }
1635
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001636 if (checkIfCallerIsSelfOrForegroundUser() ||
1637 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 if (DBG_LOC) log("getCellLocation: is active user");
1639 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001640 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001641 if (phone == null) {
1642 return null;
1643 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001644
1645 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1646 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 return data;
1648 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001649 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 return null;
1651 }
1652 }
1653
Svetoslav64fad262015-04-14 14:35:21 -07001654 private void enforceFineOrCoarseLocationPermission(String message) {
1655 try {
1656 mApp.enforceCallingOrSelfPermission(
1657 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1658 } catch (SecurityException e) {
1659 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1660 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1661 // is the weaker precondition
1662 mApp.enforceCallingOrSelfPermission(
1663 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1664 }
1665 }
1666
1667
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001669 public String getNetworkCountryIsoForPhone(int phoneId) {
1670 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1671 // registered cell info, so return a NULL country instead.
1672 final long identity = Binder.clearCallingIdentity();
1673 try {
1674 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1675 if (TelephonyManager.NETWORK_TYPE_IWLAN
1676 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1677 return "";
1678 }
1679 } finally {
1680 Binder.restoreCallingIdentity(identity);
1681 }
1682 return TelephonyManager.getTelephonyProperty(
1683 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1684 }
1685
1686 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001688 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001689 }
1690
Sanket Padawe356d7632015-06-22 14:03:32 -07001691 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001692 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 mApp.enforceCallingOrSelfPermission(
1694 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
1697 phone.enableLocationUpdates();
1698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
1701 @Override
1702 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001703 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001704 }
1705
Sanket Padawe356d7632015-06-22 14:03:32 -07001706 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001707 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 mApp.enforceCallingOrSelfPermission(
1709 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001710 final Phone phone = getPhone(subId);
1711 if (phone != null) {
1712 phone.disableLocationUpdates();
1713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 }
1715
1716 @Override
1717 @SuppressWarnings("unchecked")
1718 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001719 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1720
1721 // OP_COARSE_LOCATION controls both fine and coarse location.
1722 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1723 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1724 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
1727 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1728 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1729 return null;
1730 }
Svetoslav64fad262015-04-14 14:35:21 -07001731
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001732 if (checkIfCallerIsSelfOrForegroundUser() ||
1733 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1735
1736 ArrayList<NeighboringCellInfo> cells = null;
1737
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001738 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 try {
1740 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001741 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001742 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001744 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746 return cells;
1747 } else {
1748 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1749 return null;
1750 }
1751 }
1752
1753
1754 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001755 public List<CellInfo> getAllCellInfo(String callingPackage) {
1756 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1757
1758 // OP_COARSE_LOCATION controls both fine and coarse location.
1759 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1760 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1761 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001764 if (checkIfCallerIsSelfOrForegroundUser() ||
1765 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001767 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001768 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1769 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001770 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1771 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001772 }
1773 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 } else {
1775 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1776 return null;
1777 }
1778 }
1779
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001780 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001782 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001783 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1784 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Shishir Agrawala9f32182016-04-12 12:00:16 -07001787 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001788 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001789 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1790 return null;
1791 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001792 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001793 return phone == null ? null : phone.getImei();
1794 }
1795
1796 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001797 public String getMeidForSlot(int slotIndex, String callingPackage) {
1798 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1799 return null;
1800 }
1801 Phone phone = PhoneFactory.getPhone(slotIndex);
1802 return phone == null ? null : phone.getMeid();
1803 }
1804
1805 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001806 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001807 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1808 return null;
1809 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001810 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001811 return phone == null ? null : phone.getDeviceSvn();
1812 }
1813
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 //
1815 // Internal helper methods.
1816 //
1817
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001818 /**
1819 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1820 */
1821 private boolean checkCallerInteractAcrossUsersFull() {
1822 return mPhone.getContext().checkCallingOrSelfPermission(
1823 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1824 == PackageManager.PERMISSION_GRANTED;
1825 }
1826
Jake Hambye994d462014-02-03 13:10:13 -08001827 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 boolean ok;
1829
1830 boolean self = Binder.getCallingUid() == Process.myUid();
1831 if (!self) {
1832 // Get the caller's user id then clear the calling identity
1833 // which will be restored in the finally clause.
1834 int callingUser = UserHandle.getCallingUserId();
1835 long ident = Binder.clearCallingIdentity();
1836
1837 try {
1838 // With calling identity cleared the current user is the foreground user.
1839 int foregroundUser = ActivityManager.getCurrentUser();
1840 ok = (foregroundUser == callingUser);
1841 if (DBG_LOC) {
1842 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1843 + " callingUser=" + callingUser + " ok=" + ok);
1844 }
1845 } catch (Exception ex) {
1846 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1847 ok = false;
1848 } finally {
1849 Binder.restoreCallingIdentity(ident);
1850 }
1851 } else {
1852 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1853 ok = true;
1854 }
1855 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1856 return ok;
1857 }
1858
1859 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1861 *
1862 * @throws SecurityException if the caller does not have the required permission
1863 */
1864 private void enforceModifyPermission() {
1865 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1866 }
1867
1868 /**
Junda Liua2e36012014-07-09 18:30:01 -07001869 * Make sure either system app or the caller has carrier privilege.
1870 *
1871 * @throws SecurityException if the caller does not have the required permission/privilege
1872 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001873 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001874 int permission = mApp.checkCallingOrSelfPermission(
1875 android.Manifest.permission.MODIFY_PHONE_STATE);
1876 if (permission == PackageManager.PERMISSION_GRANTED) {
1877 return;
1878 }
1879
1880 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001881 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001882 }
1883
1884 /**
1885 * Make sure the caller has carrier privilege.
1886 *
1887 * @throws SecurityException if the caller does not have the required permission
1888 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001889 private void enforceCarrierPrivilege(int subId) {
1890 if (getCarrierPrivilegeStatus(subId) !=
1891 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001892 loge("No Carrier Privilege.");
1893 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001894 }
1895 }
1896
1897 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 * Make sure the caller has the CALL_PHONE permission.
1899 *
1900 * @throws SecurityException if the caller does not have the required permission
1901 */
1902 private void enforceCallPermission() {
1903 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1904 }
1905
Stuart Scott8eef64f2015-04-08 15:13:54 -07001906 private void enforceConnectivityInternalPermission() {
1907 mApp.enforceCallingOrSelfPermission(
1908 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1909 "ConnectivityService");
1910 }
1911
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 private String createTelUrl(String number) {
1913 if (TextUtils.isEmpty(number)) {
1914 return null;
1915 }
1916
Jake Hambye994d462014-02-03 13:10:13 -08001917 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 }
1919
Ihab Awadf9e92732013-12-05 18:02:52 -08001920 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1922 }
1923
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001924 private static void logv(String msg) {
1925 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1926 }
1927
Ihab Awadf9e92732013-12-05 18:02:52 -08001928 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1930 }
1931
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001932 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001934 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001935 }
1936
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001938 public int getActivePhoneTypeForSlot(int slotIndex) {
1939 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001940 if (phone == null) {
1941 return PhoneConstants.PHONE_TYPE_NONE;
1942 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001943 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
1946
1947 /**
1948 * Returns the CDMA ERI icon index to display
1949 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 @Override
1951 public int getCdmaEriIconIndex(String callingPackage) {
1952 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001956 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1957 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1958 return -1;
1959 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001960 final Phone phone = getPhone(subId);
1961 if (phone != null) {
1962 return phone.getCdmaEriIconIndex();
1963 } else {
1964 return -1;
1965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
1968 /**
1969 * Returns the CDMA ERI icon mode,
1970 * 0 - ON
1971 * 1 - FLASHING
1972 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001973 @Override
1974 public int getCdmaEriIconMode(String callingPackage) {
1975 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001976 }
1977
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001979 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1980 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1981 return -1;
1982 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001983 final Phone phone = getPhone(subId);
1984 if (phone != null) {
1985 return phone.getCdmaEriIconMode();
1986 } else {
1987 return -1;
1988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
1991 /**
1992 * Returns the CDMA ERI text,
1993 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001994 @Override
1995 public String getCdmaEriText(String callingPackage) {
1996 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001997 }
1998
Sanket Padawe356d7632015-06-22 14:03:32 -07001999 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002000 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
2001 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
2002 return null;
2003 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002004 final Phone phone = getPhone(subId);
2005 if (phone != null) {
2006 return phone.getCdmaEriText();
2007 } else {
2008 return null;
2009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010 }
2011
2012 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002013 * Returns the CDMA MDN.
2014 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002015 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002016 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002017 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002018 final Phone phone = getPhone(subId);
2019 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2020 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002021 } else {
2022 return null;
2023 }
2024 }
2025
2026 /**
2027 * Returns the CDMA MIN.
2028 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002029 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002030 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002031 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002032 final Phone phone = getPhone(subId);
2033 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2034 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002035 } else {
2036 return null;
2037 }
2038 }
2039
2040 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 * Returns true if CDMA provisioning needs to run.
2042 */
2043 public boolean needsOtaServiceProvisioning() {
2044 return mPhone.needsOtaServiceProvisioning();
2045 }
2046
2047 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002048 * Sets the voice mail number of a given subId.
2049 */
2050 @Override
2051 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002052 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002053 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2054 new Pair<String, String>(alphaTag, number), new Integer(subId));
2055 return success;
2056 }
2057
Ta-wei Yen87c49842016-05-13 21:19:52 -07002058 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002059 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2060 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2061 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2062 if (!TextUtils.equals(callingPackage, systemDialer)) {
2063 throw new SecurityException("caller must be system dialer");
2064 }
2065 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2066 if (phoneAccountHandle == null){
2067 return null;
2068 }
2069 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2070 }
2071
2072 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002073 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002074 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2075 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2076 return null;
2077 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002078 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2079 }
2080
2081 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002082 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2083 VisualVoicemailSmsFilterSettings settings) {
2084 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002085 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002086 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2087 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002088 }
2089
2090 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002091 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2092 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002093 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002094 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002095 }
2096
2097 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002098 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2099 String callingPackage, int subId) {
2100 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002101 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002102 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002103 }
2104
2105 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002106 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002107 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002108 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002109 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2110 }
2111
2112 @Override
2113 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2114 String number, int port, String text, PendingIntent sentIntent) {
2115 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002116 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002117 enforceSendSmsPermission();
2118 // Make the calls as the phone process.
2119 final long identity = Binder.clearCallingIdentity();
2120 try {
2121 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2122 if (port == 0) {
2123 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2124 sentIntent, null, false);
2125 } else {
2126 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2127 smsManager.sendDataMessageWithSelfPermissions(number, null,
2128 (short) port, data, sentIntent, null);
2129 }
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
2132 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002133 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002134 /**
fionaxu0152e512016-11-14 13:36:14 -08002135 * Sets the voice activation state of a given subId.
2136 */
2137 @Override
2138 public void setVoiceActivationState(int subId, int activationState) {
2139 enforceModifyPermissionOrCarrierPrivilege(subId);
2140 final Phone phone = getPhone(subId);
2141 if (phone != null) {
2142 phone.setVoiceActivationState(activationState);
2143 } else {
2144 loge("setVoiceActivationState fails with invalid subId: " + subId);
2145 }
2146 }
2147
2148 /**
2149 * Sets the data activation state of a given subId.
2150 */
2151 @Override
2152 public void setDataActivationState(int subId, int activationState) {
2153 enforceModifyPermissionOrCarrierPrivilege(subId);
2154 final Phone phone = getPhone(subId);
2155 if (phone != null) {
2156 phone.setDataActivationState(activationState);
2157 } else {
2158 loge("setVoiceActivationState fails with invalid subId: " + subId);
2159 }
2160 }
2161
2162 /**
2163 * Returns the voice activation state of a given subId.
2164 */
2165 @Override
2166 public int getVoiceActivationState(int subId, String callingPackage) {
2167 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2168 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2169 }
2170 final Phone phone = getPhone(subId);
2171 if (phone != null) {
2172 return phone.getVoiceActivationState();
2173 } else {
2174 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2175 }
2176 }
2177
2178 /**
2179 * Returns the data activation state of a given subId.
2180 */
2181 @Override
2182 public int getDataActivationState(int subId, String callingPackage) {
2183 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2184 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2185 }
2186 final Phone phone = getPhone(subId);
2187 if (phone != null) {
2188 return phone.getDataActivationState();
2189 } else {
2190 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2191 }
2192 }
2193
2194 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 * Returns the unread count of voicemails
2196 */
2197 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002198 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002199 }
2200
2201 /**
2202 * Returns the unread count of voicemails for a subId
2203 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002204 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002205 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002206 final Phone phone = getPhone(subId);
2207 if (phone != null) {
2208 return phone.getVoiceMessageCount();
2209 } else {
2210 return 0;
2211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 }
2213
2214 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002215 * returns true, if the device is in a state where both voice and data
2216 * are supported simultaneously. This can change based on location or network condition.
2217 */
2218 @Override
2219 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2220 final Phone phone = getPhone(subId);
2221 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2222 }
2223
2224 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002225 * Send the dialer code if called from the current default dialer or the caller has
2226 * carrier privilege.
2227 * @param inputCode The dialer code to send
2228 */
2229 @Override
2230 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2231 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2232 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2233 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2234 enforceCarrierPrivilege(getDefaultSubscription());
2235 }
2236 mPhone.sendDialerSpecialCode(inputCode);
2237 }
2238
2239 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002240 * Returns the data network type.
2241 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 *
2243 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2244 */
2245 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002246 public int getNetworkType() {
2247 final Phone phone = getPhone(getDefaultSubscription());
2248 if (phone != null) {
2249 return phone.getServiceState().getDataNetworkType();
2250 } else {
2251 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2252 }
Wink Saville36469e72014-06-11 15:17:00 -07002253 }
2254
2255 /**
2256 * Returns the network type for a subId
2257 */
2258 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2260 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2261 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2262 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002263
Sanket Padawe356d7632015-06-22 14:03:32 -07002264 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002265 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002266 return phone.getServiceState().getDataNetworkType();
2267 } else {
2268 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 }
2271
2272 /**
2273 * Returns the data network type
2274 */
2275 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002276 public int getDataNetworkType(String callingPackage) {
2277 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002278 }
2279
2280 /**
2281 * Returns the data network type for a subId
2282 */
2283 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002284 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2285 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2286 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2287 }
2288
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 final Phone phone = getPhone(subId);
2290 if (phone != null) {
2291 return phone.getServiceState().getDataNetworkType();
2292 } else {
2293 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
2297 /**
Wink Saville36469e72014-06-11 15:17:00 -07002298 * Returns the Voice network type for a subId
2299 */
2300 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002301 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2302 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2303 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2304 }
2305
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 final Phone phone = getPhone(subId);
2307 if (phone != null) {
2308 return phone.getServiceState().getVoiceNetworkType();
2309 } else {
2310 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
2314 /**
2315 * @return true if a ICC card is present
2316 */
2317 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002318 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002319 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2320 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002321 }
2322
2323 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002324 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002325 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002326 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002327 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2328 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002329 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002330 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002331 } else {
2332 return false;
2333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
2335
2336 /**
2337 * Return if the current radio is LTE on CDMA. This
2338 * is a tri-state return value as for a period of time
2339 * the mode may be unknown.
2340 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002341 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002343 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002345 @Override
2346 public int getLteOnCdmaMode(String callingPackage) {
2347 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002348 }
2349
Sanket Padawe356d7632015-06-22 14:03:32 -07002350 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002351 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2352 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2353 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2354 }
2355
Sanket Padawe356d7632015-06-22 14:03:32 -07002356 final Phone phone = getPhone(subId);
2357 if (phone == null) {
2358 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2359 } else {
2360 return phone.getLteOnCdmaMode();
2361 }
Wink Saville36469e72014-06-11 15:17:00 -07002362 }
2363
2364 public void setPhone(Phone phone) {
2365 mPhone = phone;
2366 }
2367
2368 /**
2369 * {@hide}
2370 * Returns Default subId, 0 in the case of single standby.
2371 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002372 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002373 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002374 }
2375
Shishir Agrawala9f32182016-04-12 12:00:16 -07002376 private int getSlotForDefaultSubscription() {
2377 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2378 }
2379
Wink Savilleb564aae2014-10-23 10:18:09 -07002380 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002381 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002383
2384 /**
2385 * @see android.telephony.TelephonyManager.WifiCallingChoices
2386 */
2387 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002388 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2389 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002390 }
2391
2392 /**
2393 * @see android.telephony.TelephonyManager.WifiCallingChoices
2394 */
2395 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002396 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2397 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2398 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002399 }
2400
Sailesh Nepald1e68152013-12-12 19:08:02 -08002401 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002402 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002403 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002404 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002405
Shishir Agrawal566b7612013-10-28 14:41:00 -07002406 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002407 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2408 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002409 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002410
Derek Tan740e1672017-06-27 14:56:27 -07002411 if (TextUtils.equals(ISDR_AID, aid)) {
2412 // Only allows LPA to open logical channel to ISD-R.
2413 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2414 ComponentInfo bestComponent =
2415 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2416 if (bestComponent == null
2417 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2418 loge("The calling package is not allowed to access ISD-R.");
2419 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2420 }
2421 }
2422
2423 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002424 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002425 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002426 if (DBG) log("iccOpenLogicalChannel: " + response);
2427 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002428 }
2429
2430 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002431 public boolean iccCloseLogicalChannel(int subId, int channel) {
2432 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002433
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002434 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002435 if (channel < 0) {
2436 return false;
2437 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002438 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002439 if (DBG) log("iccCloseLogicalChannel: " + success);
2440 return success;
2441 }
2442
2443 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002444 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002445 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002446 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002447
2448 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002449 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2450 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002451 " data=" + data);
2452 }
2453
2454 if (channel < 0) {
2455 return "";
2456 }
2457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002458 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002459 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002460 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2461
Shishir Agrawal566b7612013-10-28 14:41:00 -07002462 // Append the returned status code to the end of the response payload.
2463 String s = Integer.toHexString(
2464 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002465 if (response.payload != null) {
2466 s = IccUtils.bytesToHexString(response.payload) + s;
2467 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002468 return s;
2469 }
Jake Hambye994d462014-02-03 13:10:13 -08002470
Evan Charltonc66da362014-05-16 14:06:40 -07002471 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002472 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002473 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002474 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002475
2476 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2478 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002479 }
2480
2481 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002482 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002483 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2484
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002485 // Append the returned status code to the end of the response payload.
2486 String s = Integer.toHexString(
2487 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002488 if (response.payload != null) {
2489 s = IccUtils.bytesToHexString(response.payload) + s;
2490 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002491 return s;
2492 }
2493
2494 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002495 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002496 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002497 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002498
2499 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002500 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002501 p1 + " " + p2 + " " + p3 + ":" + filePath);
2502 }
2503
2504 IccIoResult response =
2505 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002506 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2507 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002508
2509 if (DBG) {
2510 log("Exchange SIM_IO [R]" + response);
2511 }
2512
2513 byte[] result = null;
2514 int length = 2;
2515 if (response.payload != null) {
2516 length = 2 + response.payload.length;
2517 result = new byte[length];
2518 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2519 } else {
2520 result = new byte[length];
2521 }
2522
2523 result[length - 1] = (byte) response.sw2;
2524 result[length - 2] = (byte) response.sw1;
2525 return result;
2526 }
2527
Nathan Haroldb3014052017-01-25 15:57:32 -08002528 /**
2529 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2530 * on a particular subscription
2531 */
2532 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002533 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2534 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002535 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2536 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2537 return null;
2538 }
2539 Object response = sendRequest(
2540 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2541 if (response instanceof String[]) {
2542 return (String[]) response;
2543 }
2544 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2545 return null;
2546 }
2547
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002548 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002549 public String sendEnvelopeWithStatus(int subId, String content) {
2550 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002551
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002552 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002553 if (response.payload == null) {
2554 return "";
2555 }
2556
2557 // Append the returned status code to the end of the response payload.
2558 String s = Integer.toHexString(
2559 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2560 s = IccUtils.bytesToHexString(response.payload) + s;
2561 return s;
2562 }
2563
Jake Hambye994d462014-02-03 13:10:13 -08002564 /**
2565 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2566 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2567 *
2568 * @param itemID the ID of the item to read
2569 * @return the NV item as a String, or null on error.
2570 */
2571 @Override
2572 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002573 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002574 if (DBG) log("nvReadItem: item " + itemID);
2575 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2576 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2577 return value;
2578 }
2579
2580 /**
2581 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2582 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2583 *
2584 * @param itemID the ID of the item to read
2585 * @param itemValue the value to write, as a String
2586 * @return true on success; false on any failure
2587 */
2588 @Override
2589 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002590 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002591 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2592 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2593 new Pair<Integer, String>(itemID, itemValue));
2594 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2595 return success;
2596 }
2597
2598 /**
2599 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2600 * Used for device configuration by some CDMA operators.
2601 *
2602 * @param preferredRoamingList byte array containing the new PRL
2603 * @return true on success; false on any failure
2604 */
2605 @Override
2606 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002607 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002608 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2609 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2610 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2611 return success;
2612 }
2613
2614 /**
2615 * Perform the specified type of NV config reset.
2616 * Used for device configuration by some CDMA operators.
2617 *
2618 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2619 * @return true on success; false on any failure
2620 */
2621 @Override
2622 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002623 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002624 if (DBG) log("nvResetConfig: type " + resetType);
2625 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2626 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2627 return success;
2628 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002629
2630 /**
Wink Saville36469e72014-06-11 15:17:00 -07002631 * {@hide}
2632 * Returns Default sim, 0 in the case of single standby.
2633 */
2634 public int getDefaultSim() {
2635 //TODO Need to get it from Telephony Devcontroller
2636 return 0;
2637 }
2638
Svet Ganovb320e182015-04-16 12:30:10 -07002639 public String[] getPcscfAddress(String apnType, String callingPackage) {
2640 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2641 return new String[0];
2642 }
2643
2644
ram87fca6f2014-07-18 18:58:44 +05302645 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002646 }
2647
Brad Ebinger51f743a2017-01-23 13:50:20 -08002648 /**
2649 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2650 * feature or {@link null} if the service is not available. If an ImsServiceController is
2651 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2652 * feature updates.
2653 */
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002654 public IImsServiceController getImsServiceControllerAndListen(int slotIndex, int feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002655 IImsServiceFeatureListener callback) {
2656 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002657 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotIndex, feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002658 callback);
2659 }
2660
Wink Saville36469e72014-06-11 15:17:00 -07002661 public void setImsRegistrationState(boolean registered) {
2662 enforceModifyPermission();
2663 mPhone.setImsRegistrationState(registered);
2664 }
2665
2666 /**
Stuart Scott54788802015-03-30 13:18:01 -07002667 * Set the network selection mode to automatic.
2668 *
2669 */
2670 @Override
2671 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002672 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002673 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2674 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2675 }
2676
2677 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002678 * Set the network selection mode to manual with the selected carrier.
2679 */
2680 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002681 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2682 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002683 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002684 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002685 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2686 persistSelection);
2687 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002688 }
2689
2690 /**
2691 * Scans for available networks.
2692 */
2693 @Override
2694 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002695 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002696 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2697 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2698 CMD_PERFORM_NETWORK_SCAN, null, subId);
2699 return result;
2700 }
2701
2702 /**
yinxub1bed742017-04-17 11:45:04 -07002703 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002704 *
yinxub1bed742017-04-17 11:45:04 -07002705 * @param subId id of the subscription
2706 * @param request contains the radio access networks with bands/channels to scan
2707 * @param messenger callback messenger for scan results or errors
2708 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002709 * @return the id of the requested scan which can be used to stop the scan.
2710 */
2711 @Override
2712 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2713 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002714 enforceModifyPermissionOrCarrierPrivilege(subId);
2715 return mNetworkScanRequestTracker.startNetworkScan(
2716 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002717 }
2718
2719 /**
2720 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002721 *
2722 * @param subId id of the subscription
2723 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002724 */
2725 @Override
2726 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002727 enforceModifyPermissionOrCarrierPrivilege(subId);
2728 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002729 }
2730
2731 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002732 * Get the calculated preferred network type.
2733 * Used for debugging incorrect network type.
2734 *
2735 * @return the preferred network type, defined in RILConstants.java.
2736 */
2737 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002738 public int getCalculatedPreferredNetworkType(String callingPackage) {
2739 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2740 return RILConstants.PREFERRED_NETWORK_MODE;
2741 }
2742
Amit Mahajan43330e02014-11-18 11:54:45 -08002743 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002744 }
2745
2746 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002747 * Get the preferred network type.
2748 * Used for device configuration by some CDMA operators.
2749 *
2750 * @return the preferred network type, defined in RILConstants.java.
2751 */
2752 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002753 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002754 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002755 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002756 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002757 int networkType = (result != null ? result[0] : -1);
2758 if (DBG) log("getPreferredNetworkType: " + networkType);
2759 return networkType;
2760 }
2761
2762 /**
2763 * Set the preferred network type.
2764 * Used for device configuration by some CDMA operators.
2765 *
2766 * @param networkType the preferred network type, defined in RILConstants.java.
2767 * @return true on success; false on any failure.
2768 */
2769 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002770 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002771 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002772 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2773 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002774 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002775 if (success) {
2776 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002777 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002778 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002779 return success;
2780 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002781
2782 /**
Junda Liu475951f2014-11-07 16:45:03 -08002783 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2784 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2785 * tethering.
2786 *
2787 * @return 0: Not required. 1: required. 2: Not set.
2788 * @hide
2789 */
2790 @Override
2791 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002792 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002793 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2794 Settings.Global.TETHER_DUN_REQUIRED, 2);
2795 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2796 // config_tether_apndata.
2797 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2798 dunRequired = 1;
2799 }
2800 return dunRequired;
2801 }
2802
2803 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002804 * Set mobile data enabled
2805 * Used by the user through settings etc to turn on/off mobile data
2806 *
2807 * @param enable {@code true} turn turn data on, else {@code false}
2808 */
2809 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002810 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002811 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002812 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002813 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002814 Phone phone = PhoneFactory.getPhone(phoneId);
2815 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002816 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002817 phone.setDataEnabled(enable);
2818 } else {
2819 loge("setDataEnabled: no phone for subId=" + subId);
2820 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002821 }
2822
2823 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002824 * Get whether mobile data is enabled.
2825 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002826 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002827 *
2828 * @return {@code true} if data is enabled else {@code false}
2829 */
2830 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002831 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002832 try {
2833 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2834 null);
2835 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002836 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002837 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002838 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002839 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002840 Phone phone = PhoneFactory.getPhone(phoneId);
2841 if (phone != null) {
2842 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002843 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002844 return retVal;
2845 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002846 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002847 return false;
2848 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002849 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002850
2851 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002852 public int getCarrierPrivilegeStatus(int subId) {
2853 final Phone phone = getPhone(subId);
2854 if (phone == null) {
2855 loge("getCarrierPrivilegeStatus: Invalid subId");
2856 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2857 }
2858 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002859 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002860 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002861 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2862 }
2863 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002864 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002865 }
Junda Liu29340342014-07-10 15:23:27 -07002866
2867 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002868 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002869 if (TextUtils.isEmpty(pkgName))
2870 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002871 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002872 if (card == null) {
2873 loge("checkCarrierPrivilegesForPackage: No UICC");
2874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2875 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002876 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2877 }
2878
2879 @Override
2880 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002881 if (TextUtils.isEmpty(pkgName))
2882 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002883 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2884 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2885 UiccCard card = UiccController.getInstance().getUiccCard(i);
2886 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002887 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002888 continue;
2889 }
2890
2891 result = card.getCarrierPrivilegeStatus(
2892 mPhone.getContext().getPackageManager(), pkgName);
2893 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2894 break;
2895 }
2896 }
2897
2898 return result;
Junda Liu29340342014-07-10 15:23:27 -07002899 }
Derek Tan89e89d42014-07-08 17:00:10 -07002900
2901 @Override
Junda Liue64de782015-04-16 17:19:16 -07002902 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2903 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2904 loge("phoneId " + phoneId + " is not valid.");
2905 return null;
2906 }
2907 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002908 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002909 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002910 return null ;
2911 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002912 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002913 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002914 }
2915
Amith Yamasani6e118872016-02-19 12:53:51 -08002916 @Override
2917 public List<String> getPackagesWithCarrierPrivileges() {
2918 PackageManager pm = mPhone.getContext().getPackageManager();
2919 List<String> privilegedPackages = new ArrayList<>();
2920 List<PackageInfo> packages = null;
2921 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2922 UiccCard card = UiccController.getInstance().getUiccCard(i);
2923 if (card == null) {
2924 // No UICC in that slot.
2925 continue;
2926 }
2927 if (card.hasCarrierPrivilegeRules()) {
2928 if (packages == null) {
2929 // Only check packages in user 0 for now
2930 packages = pm.getInstalledPackagesAsUser(
2931 PackageManager.MATCH_DISABLED_COMPONENTS
2932 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2933 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2934 }
2935 for (int p = packages.size() - 1; p >= 0; p--) {
2936 PackageInfo pkgInfo = packages.get(p);
2937 if (pkgInfo != null && pkgInfo.packageName != null
2938 && card.getCarrierPrivilegeStatus(pkgInfo)
2939 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2940 privilegedPackages.add(pkgInfo.packageName);
2941 }
2942 }
2943 }
2944 }
2945 return privilegedPackages;
2946 }
2947
Wink Savilleb564aae2014-10-23 10:18:09 -07002948 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002949 final Phone phone = getPhone(subId);
2950 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002951 if (card == null) {
2952 loge("getIccId: No UICC");
2953 return null;
2954 }
2955 String iccId = card.getIccId();
2956 if (TextUtils.isEmpty(iccId)) {
2957 loge("getIccId: ICC ID is null or empty.");
2958 return null;
2959 }
2960 return iccId;
2961 }
2962
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002963 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002964 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2965 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002966 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002967
Jeff Sharkey85190e62014-12-05 09:40:12 -08002968 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002969 final Phone phone = getPhone(subId);
2970 if (phone == null) {
2971 return false;
2972 }
2973 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002974
2975 if (DBG_MERGE) {
2976 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2977 + subscriberId + " to " + number);
2978 }
2979
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002980 if (TextUtils.isEmpty(iccId)) {
2981 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002982 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002983
Jeff Sharkey85190e62014-12-05 09:40:12 -08002984 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2985
2986 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002987 if (alphaTag == null) {
2988 editor.remove(alphaTagPrefKey);
2989 } else {
2990 editor.putString(alphaTagPrefKey, alphaTag);
2991 }
2992
Jeff Sharkey85190e62014-12-05 09:40:12 -08002993 // Record both the line number and IMSI for this ICCID, since we need to
2994 // track all merged IMSIs based on line number
2995 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2996 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002997 if (number == null) {
2998 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002999 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003000 } else {
3001 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003002 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003003 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003004
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003005 editor.commit();
3006 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003007 }
3008
3009 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003010 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003011 // This is open to apps with WRITE_SMS.
3012 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003013 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003014 return null;
3015 }
Derek Tan97ebb422014-09-05 16:55:38 -07003016
3017 String iccId = getIccId(subId);
3018 if (iccId != null) {
3019 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003020 if (DBG_MERGE) {
3021 log("getLine1NumberForDisplay returning " +
3022 mTelephonySharedPreferences.getString(numberPrefKey, null));
3023 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003024 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003025 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003026 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003027 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003028 }
3029
3030 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003031 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3032 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3033 return null;
3034 }
Derek Tan97ebb422014-09-05 16:55:38 -07003035
3036 String iccId = getIccId(subId);
3037 if (iccId != null) {
3038 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003039 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003040 }
Derek Tan97ebb422014-09-05 16:55:38 -07003041 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003042 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003043
3044 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003045 public String[] getMergedSubscriberIds(String callingPackage) {
3046 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3047 return null;
3048 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003049 final Context context = mPhone.getContext();
3050 final TelephonyManager tele = TelephonyManager.from(context);
3051 final SubscriptionManager sub = SubscriptionManager.from(context);
3052
3053 // Figure out what subscribers are currently active
3054 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003055 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3056 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 final int[] subIds = sub.getActiveSubscriptionIdList();
3060 for (int subId : subIds) {
3061 activeSubscriberIds.add(tele.getSubscriberId(subId));
3062 }
3063 } finally {
3064 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003065 }
3066
3067 // First pass, find a number override for an active subscriber
3068 String mergeNumber = null;
3069 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3070 for (String key : prefs.keySet()) {
3071 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3072 final String subscriberId = (String) prefs.get(key);
3073 if (activeSubscriberIds.contains(subscriberId)) {
3074 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3075 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3076 mergeNumber = (String) prefs.get(numberKey);
3077 if (DBG_MERGE) {
3078 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3079 + " for active subscriber " + subscriberId);
3080 }
3081 if (!TextUtils.isEmpty(mergeNumber)) {
3082 break;
3083 }
3084 }
3085 }
3086 }
3087
3088 // Shortcut when no active merged subscribers
3089 if (TextUtils.isEmpty(mergeNumber)) {
3090 return null;
3091 }
3092
3093 // Second pass, find all subscribers under that line override
3094 final ArraySet<String> result = new ArraySet<>();
3095 for (String key : prefs.keySet()) {
3096 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3097 final String number = (String) prefs.get(key);
3098 if (mergeNumber.equals(number)) {
3099 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3100 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3101 final String subscriberId = (String) prefs.get(subscriberKey);
3102 if (!TextUtils.isEmpty(subscriberId)) {
3103 result.add(subscriberId);
3104 }
3105 }
3106 }
3107 }
3108
3109 final String[] resultArray = result.toArray(new String[result.size()]);
3110 Arrays.sort(resultArray);
3111 if (DBG_MERGE) {
3112 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3113 }
3114 return resultArray;
3115 }
3116
3117 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003118 public boolean setOperatorBrandOverride(int subId, String brand) {
3119 enforceCarrierPrivilege(subId);
3120 final Phone phone = getPhone(subId);
3121 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003122 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003123
3124 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003125 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003126 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3127 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003128 enforceCarrierPrivilege(subId);
3129 final Phone phone = getPhone(subId);
3130 if (phone == null) {
3131 return false;
3132 }
3133 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003134 cdmaNonRoamingList);
3135 }
3136
3137 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003138 public void setRadioCapability(RadioAccessFamily[] rafs) {
3139 try {
3140 ProxyController.getInstance().setRadioCapability(rafs);
3141 } catch (RuntimeException e) {
3142 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3143 }
3144 }
3145
3146 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003147 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3148 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3149 return RadioAccessFamily.RAF_UNKNOWN;
3150 }
3151
Wink Saville5d475dd2014-10-17 15:00:58 -07003152 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3153 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003154
3155 @Override
3156 public void enableVideoCalling(boolean enable) {
3157 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003158 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003159 }
3160
3161 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003162 public boolean isVideoCallingEnabled(String callingPackage) {
3163 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3164 return false;
3165 }
3166
Andrew Lee77527ac2014-10-21 16:57:39 -07003167 // Check the user preference and the system-level IMS setting. Even if the user has
3168 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3169 // In the long run, we may instead need to check if there exists a connection service
3170 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003171 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3172 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003173 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003174 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003175
Andrew Leea1239f22015-03-02 17:44:07 -08003176 @Override
3177 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003178 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003179 }
3180
3181 @Override
3182 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003183 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003184 }
3185
Andrew Lee9431b832015-03-09 18:46:45 -07003186 @Override
3187 public boolean isTtyModeSupported() {
3188 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3189 TelephonyManager telephonyManager =
3190 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003191 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003192 }
3193
3194 @Override
3195 public boolean isHearingAidCompatibilitySupported() {
3196 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3197 }
3198
Sanket Padawe7310cc72015-01-14 09:53:20 -08003199 /**
3200 * Returns the unique device ID of phone, for example, the IMEI for
3201 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3202 *
3203 * <p>Requires Permission:
3204 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3205 */
3206 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003207 public String getDeviceId(String callingPackage) {
3208 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3209 return null;
3210 }
3211
Sanket Padawe7310cc72015-01-14 09:53:20 -08003212 final Phone phone = PhoneFactory.getPhone(0);
3213 if (phone != null) {
3214 return phone.getDeviceId();
3215 } else {
3216 return null;
3217 }
3218 }
3219
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003220 /*
3221 * {@hide}
3222 * Returns the IMS Registration Status
3223 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003224 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003225 public boolean isImsRegistered() {
3226 return mPhone.isImsRegistered();
3227 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003228
Ping Sun014fe8e2016-03-02 19:16:45 +08003229 /**
3230 * {@hide}
3231 * Returns the IMS Registration Status on a particular subid
3232 *
3233 * @param subId
3234 */
3235 public boolean isImsRegisteredForSubscriber(int subId) {
3236 Phone phone = getPhone(subId);
3237 if (phone != null) {
3238 return phone.isImsRegistered();
3239 } else {
3240 return false;
3241 }
3242 }
3243
Santos Cordon7a1885b2015-02-03 11:15:19 -08003244 @Override
3245 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3246 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3247 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003248
Nathan Haroldc55097a2015-03-11 18:14:50 -07003249 /*
3250 * {@hide}
3251 * Returns the IMS Registration Status
3252 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003253 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003254 return mPhone.isWifiCallingEnabled();
3255 }
3256
3257 /*
3258 * {@hide}
3259 * Returns the IMS Registration Status
3260 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003261 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003262 return mPhone.isVolteEnabled();
3263 }
Svet Ganovb320e182015-04-16 12:30:10 -07003264
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003265 /*
3266 * {@hide} Returns the IMS Registration Status
3267 */
3268 public boolean isVideoTelephonyAvailable() {
3269 return mPhone.isVideoEnabled();
3270 }
3271
Svet Ganovb320e182015-04-16 12:30:10 -07003272 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003273 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003274 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003275 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3276
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003277 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003278 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003279 } catch (SecurityException e) {
3280 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3281 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003282 }
Svet Ganovb320e182015-04-16 12:30:10 -07003283
3284 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3285 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3286 return false;
3287 }
3288
3289 return true;
3290 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003291
Makoto Onukifee69342015-06-29 14:44:50 -07003292 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003293 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003294 */
3295 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003296 // Default SMS app can always read it.
3297 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3298 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3299 return true;
3300 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003301
Makoto Onukie4072d12015-08-03 15:12:23 -07003302 try {
3303 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003304 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003305 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003306 // Can be read with READ_SMS too.
3307 try {
3308 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3309 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3310 if (opCode != AppOpsManager.OP_NONE) {
3311 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3312 == AppOpsManager.MODE_ALLOWED;
3313 } else {
3314 return true;
3315 }
3316 } catch (SecurityException readSmsSecurityException) {
3317 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003318 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003319 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003320 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003321 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003322 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003323 if (opCode != AppOpsManager.OP_NONE) {
3324 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3325 == AppOpsManager.MODE_ALLOWED;
3326 } else {
3327 return true;
3328 }
3329 } catch (SecurityException readPhoneNumberSecurityException) {
3330 }
3331
3332 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3333 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3334 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003335 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003336 }
3337
Stuart Scott8eef64f2015-04-08 15:13:54 -07003338 @Override
3339 public void factoryReset(int subId) {
3340 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003341 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3342 return;
3343 }
3344
Svet Ganovcc087f82015-05-12 20:35:54 -07003345 final long identity = Binder.clearCallingIdentity();
3346 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003347 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3348 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003349 // Enable data
3350 setDataEnabled(subId, true);
3351 // Set network selection mode to automatic
3352 setNetworkSelectionModeAutomatic(subId);
3353 // Set preferred mobile network type to the best available
3354 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3355 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003356 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003357 }
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003360 }
3361 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003362
3363 @Override
3364 public String getLocaleFromDefaultSim() {
3365 // We query all subscriptions instead of just the active ones, because
3366 // this might be called early on in the provisioning flow when the
3367 // subscriptions potentially aren't active yet.
3368 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3369 if (slist == null || slist.isEmpty()) {
3370 return null;
3371 }
3372
3373 // This function may be called very early, say, from the setup wizard, at
3374 // which point we won't have a default subscription set. If that's the case
3375 // we just choose the first, which will be valid in "most cases".
3376 final int defaultSubId = getDefaultSubscription();
3377 SubscriptionInfo info = null;
3378 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3379 info = slist.get(0);
3380 } else {
3381 for (SubscriptionInfo item : slist) {
3382 if (item.getSubscriptionId() == defaultSubId) {
3383 info = item;
3384 break;
3385 }
3386 }
3387
3388 if (info == null) {
3389 return null;
3390 }
3391 }
3392
3393 // Try and fetch the locale from the carrier properties or from the SIM language
3394 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003395 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003396 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003397 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003398 if (defaultPhone != null) {
3399 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3400 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003401 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003402 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3403 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003404 } else {
3405 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003406 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003407 }
3408 }
3409
Narayan Kamath011676f2015-07-29 12:04:08 +01003410 // The SIM language preferences only store a language (e.g. fr = French), not an
3411 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3412 // the SIM and carrier preferences does not include a country we add the country
3413 // determined from the SIM MCC to provide an exact locale.
3414 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003415 if (mccLocale != null) {
3416 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3417 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003418 }
3419
Tony Hill183b2de2015-06-24 14:53:58 +01003420 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003421 return null;
3422 }
3423
3424 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 return mSubscriptionController.getAllSubInfoList(
3428 mPhone.getContext().getOpPackageName());
3429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
3432 }
3433
3434 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 return mSubscriptionController.getActiveSubscriptionInfoList(
3438 mPhone.getContext().getOpPackageName());
3439 } finally {
3440 Binder.restoreCallingIdentity(identity);
3441 }
3442 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003443
3444 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003445 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3446 * representing the state of the modem.
3447 *
3448 * NOTE: This clears the modem state, so there should only every be one caller.
3449 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003450 */
3451 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003452 public void requestModemActivityInfo(ResultReceiver result) {
3453 enforceModifyPermission();
3454
3455 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3456 Bundle bundle = new Bundle();
3457 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3458 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003459 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003460
3461 /**
3462 * {@hide}
3463 * Returns the service state information on specified subscription.
3464 */
3465 @Override
3466 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3467
3468 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3469 return null;
3470 }
3471
3472 final Phone phone = getPhone(subId);
3473 if (phone == null) {
3474 return null;
3475 }
3476
3477 return phone.getServiceState();
3478 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003479
3480 /**
3481 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3482 *
3483 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3484 * voicemail ringtone.
3485 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3486 * PhoneAccount.
3487 */
3488 @Override
3489 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003490 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003491 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003492 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003493 }
3494
fionaxu7ed723d2017-05-30 18:58:54 -07003495 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003496 }
3497
3498 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003499 * Sets the per-account voicemail ringtone.
3500 *
3501 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3502 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3503 *
3504 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3505 * voicemail ringtone.
3506 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3507 * PhoneAccount.
3508 */
3509 @Override
3510 public void setVoicemailRingtoneUri(String callingPackage,
3511 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3512 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3513 if (!TextUtils.equals(callingPackage,
3514 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3515 enforceModifyPermissionOrCarrierPrivilege(
3516 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3517 }
3518 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3519 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003520 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003521 }
fionaxu7ed723d2017-05-30 18:58:54 -07003522 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003523 }
3524
3525 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003526 * Returns whether vibration is set for voicemail notification in Phone settings.
3527 *
3528 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3529 * voicemail vibration setting.
3530 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3531 */
3532 @Override
3533 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003534 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003535 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003536 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003537 }
3538
fionaxu7ed723d2017-05-30 18:58:54 -07003539 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003540 }
3541
Youhan Wange64578a2016-05-02 15:32:42 -07003542 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003543 * Sets the per-account voicemail vibration.
3544 *
3545 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3546 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3547 *
3548 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3549 * voicemail vibration setting.
3550 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3551 * specific PhoneAccount.
3552 */
3553 @Override
3554 public void setVoicemailVibrationEnabled(String callingPackage,
3555 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3556 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3557 if (!TextUtils.equals(callingPackage,
3558 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3559 enforceModifyPermissionOrCarrierPrivilege(
3560 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3561 }
3562
3563 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3564 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003565 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003566 }
fionaxu7ed723d2017-05-30 18:58:54 -07003567 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003568 }
3569
3570 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003571 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3572 *
3573 * @throws SecurityException if the caller does not have the required permission
3574 */
3575 private void enforceReadPrivilegedPermission() {
3576 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3577 null);
3578 }
3579
3580 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003581 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3582 * permission.
3583 *
3584 * @throws SecurityException if the caller does not have the required permission
3585 */
3586 private void enforceSendSmsPermission() {
3587 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3588 }
3589
3590 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003591 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003592 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003593 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003594 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003595 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003596 ComponentName componentName =
3597 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3598 if(componentName == null) {
3599 throw new SecurityException("Caller not current active visual voicemail package[null]");
3600 }
3601 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003602 if (!callingPackage.equals(vvmPackage)) {
3603 throw new SecurityException("Caller not current active visual voicemail package[" +
3604 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003605 }
3606 }
3607
3608 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003609 * Return the application ID for the app type.
3610 *
3611 * @param subId the subscription ID that this request applies to.
3612 * @param appType the uicc app type.
3613 * @return Application ID for specificied app type, or null if no uicc.
3614 */
3615 @Override
3616 public String getAidForAppType(int subId, int appType) {
3617 enforceReadPrivilegedPermission();
3618 Phone phone = getPhone(subId);
3619 if (phone == null) {
3620 return null;
3621 }
3622 String aid = null;
3623 try {
3624 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3625 .getApplicationByType(appType).getAid();
3626 } catch (Exception e) {
3627 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3628 }
3629 return aid;
3630 }
3631
Youhan Wang4001d252016-05-11 10:29:41 -07003632 /**
3633 * Return the Electronic Serial Number.
3634 *
3635 * @param subId the subscription ID that this request applies to.
3636 * @return ESN or null if error.
3637 */
3638 @Override
3639 public String getEsn(int subId) {
3640 enforceReadPrivilegedPermission();
3641 Phone phone = getPhone(subId);
3642 if (phone == null) {
3643 return null;
3644 }
3645 String esn = null;
3646 try {
3647 esn = phone.getEsn();
3648 } catch (Exception e) {
3649 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3650 }
3651 return esn;
3652 }
3653
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003654 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003655 * Return the Preferred Roaming List Version.
3656 *
3657 * @param subId the subscription ID that this request applies to.
3658 * @return PRLVersion or null if error.
3659 */
3660 @Override
3661 public String getCdmaPrlVersion(int subId) {
3662 enforceReadPrivilegedPermission();
3663 Phone phone = getPhone(subId);
3664 if (phone == null) {
3665 return null;
3666 }
3667 String cdmaPrlVersion = null;
3668 try {
3669 cdmaPrlVersion = phone.getCdmaPrlVersion();
3670 } catch (Exception e) {
3671 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3672 }
3673 return cdmaPrlVersion;
3674 }
3675
3676 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003677 * Get snapshot of Telephony histograms
3678 * @return List of Telephony histograms
3679 * @hide
3680 */
3681 @Override
3682 public List<TelephonyHistogram> getTelephonyHistograms() {
3683 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3684 return RIL.getTelephonyRILTimingHistograms();
3685 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003686
3687 /**
3688 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003689 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003690 * Require system privileges. In the future we may add this to carrier APIs.
3691 *
3692 * @return The number of carriers set successfully, should match length of carriers
3693 */
3694 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003695 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003696 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003697
Meng Wang9b7c4e92017-02-17 11:41:27 -08003698 if (carriers == null) {
3699 throw new NullPointerException("carriers cannot be null");
3700 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003701
3702 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003703 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3704 return retVal[0];
3705 }
3706
3707 /**
3708 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003709 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003710 * Require system privileges. In the future we may add this to carrier APIs.
3711 *
3712 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3713 * means all carriers are allowed.
3714 */
3715 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003716 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003717 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003718 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003719 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3720 }
3721
fionaxu59545b42016-05-25 15:53:37 -07003722 /**
3723 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3724 * @param subId the subscription ID that this action applies to.
3725 * @param enabled control enable or disable metered apns.
3726 * {@hide}
3727 */
3728 @Override
3729 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3730 enforceModifyPermission();
3731 final Phone phone = getPhone(subId);
3732 if (phone == null) {
3733 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3734 return;
3735 }
3736 try {
3737 phone.carrierActionSetMeteredApnsEnabled(enabled);
3738 } catch (Exception e) {
3739 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3740 }
3741 }
3742
3743 /**
3744 * Action set from carrier signalling broadcast receivers to enable/disable radio
3745 * @param subId the subscription ID that this action applies to.
3746 * @param enabled control enable or disable radio.
3747 * {@hide}
3748 */
3749 @Override
3750 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3751 enforceModifyPermission();
3752 final Phone phone = getPhone(subId);
3753 if (phone == null) {
3754 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3755 return;
3756 }
3757 try {
3758 phone.carrierActionSetRadioEnabled(enabled);
3759 } catch (Exception e) {
3760 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3761 }
3762 }
3763
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003764 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003765 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3766 * network status based on which carrier apps could apply actions accordingly,
3767 * enable/disable default url handler for example.
3768 *
3769 * @param subId the subscription ID that this action applies to.
3770 * @param report control start/stop reporting the default network status.
3771 * {@hide}
3772 */
3773 @Override
3774 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3775 enforceModifyPermission();
3776 final Phone phone = getPhone(subId);
3777 if (phone == null) {
3778 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3779 return;
3780 }
3781 try {
3782 phone.carrierActionReportDefaultNetworkStatus(report);
3783 } catch (Exception e) {
3784 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3785 }
3786 }
3787
3788 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003789 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3790 * bug report is being generated.
3791 */
3792 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003793 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003794 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3795 != PackageManager.PERMISSION_GRANTED) {
3796 writer.println("Permission Denial: can't dump Phone from pid="
3797 + Binder.getCallingPid()
3798 + ", uid=" + Binder.getCallingUid()
3799 + "without permission "
3800 + android.Manifest.permission.DUMP);
3801 return;
3802 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003803 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003804 }
Jack Yueb89b242016-06-22 13:27:47 -07003805
3806 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003807 * Get aggregated video call data usage since boot.
3808 *
3809 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3810 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003811 * {@hide}
3812 */
3813 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003814 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003815 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3816 null);
3817
Jack Yu84291ec2017-05-26 16:07:50 -07003818 // NetworkStatsService keeps tracking the active network interface and identity. It
3819 // records the delta with the corresponding network identity. We just return the total video
3820 // call data usage snapshot since boot.
3821 Phone phone = getPhone(subId);
3822 if (phone != null) {
3823 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003824 }
Jack Yu84291ec2017-05-26 16:07:50 -07003825 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003826 }
Jack Yu75ab2952016-07-08 14:29:33 -07003827
3828 /**
3829 * Policy control of data connection. Usually used when data limit is passed.
3830 * @param enabled True if enabling the data, otherwise disabling.
3831 * @param subId Subscription index
3832 * {@hide}
3833 */
3834 @Override
3835 public void setPolicyDataEnabled(boolean enabled, int subId) {
3836 enforceModifyPermission();
3837 Phone phone = getPhone(subId);
3838 if (phone != null) {
3839 phone.setPolicyDataEnabled(enabled);
3840 }
3841 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003842
3843 /**
3844 * Get Client request stats
3845 * @return List of Client Request Stats
3846 * @hide
3847 */
3848 @Override
3849 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3850 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3851 return null;
3852 }
3853
3854 Phone phone = getPhone(subId);
3855 if (phone != null) {
3856 return phone.getClientRequestStats();
3857 }
3858
3859 return null;
3860 }
3861
3862 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3863 if (workSource != null) {
3864 return workSource;
3865 }
3866
3867 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3868 workSource = new WorkSource(uid, packageName);
3869 return workSource;
3870 }
Jack Yueb4124c2017-02-16 15:32:43 -08003871
3872 /**
Grace Chen70990072017-03-24 17:21:30 -07003873 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003874 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003875 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003876 * @param state State of SIM (power down, power up, pass through)
3877 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3878 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3879 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003880 *
3881 **/
3882 @Override
Grace Chen70990072017-03-24 17:21:30 -07003883 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003884 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003885 Phone phone = PhoneFactory.getPhone(slotIndex);
3886
Jack Yueb4124c2017-02-16 15:32:43 -08003887 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003888 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003889 }
3890 }
Shuo Qiandd210312017-04-12 22:11:33 +00003891
Tyler Gunn65d45c22017-06-05 11:22:26 -07003892 private boolean isUssdApiAllowed(int subId) {
3893 CarrierConfigManager configManager =
3894 (CarrierConfigManager) mPhone.getContext().getSystemService(
3895 Context.CARRIER_CONFIG_SERVICE);
3896 if (configManager == null) {
3897 return false;
3898 }
3899 PersistableBundle pb = configManager.getConfigForSubId(subId);
3900 if (pb == null) {
3901 return false;
3902 }
3903 return pb.getBoolean(
3904 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3905 }
3906
Shuo Qiandd210312017-04-12 22:11:33 +00003907 /**
3908 * Check if phone is in emergency callback mode
3909 * @return true if phone is in emergency callback mode
3910 * @param subId sub id
3911 */
3912 public boolean getEmergencyCallbackMode(int subId) {
3913 final Phone phone = getPhone(subId);
3914 if (phone != null) {
3915 return phone.isInEcm();
3916 } else {
3917 return false;
3918 }
3919 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003920
3921 /**
3922 * Get the current signal strength information for the given subscription.
3923 * Because this information is not updated when the device is in a low power state
3924 * it should not be relied-upon to be current.
3925 * @param subId Subscription index
3926 * @return the most recent cached signal strength info from the modem
3927 */
3928 @Override
3929 public SignalStrength getSignalStrength(int subId) {
3930 Phone p = getPhone(subId);
3931 if (p == null) {
3932 return null;
3933 }
3934
3935 return p.getSignalStrength();
3936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003937}