blob: af57f325d2ebe85dfa6d96c62be80e162669385b [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.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger7e934f52017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070058import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080059import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070060import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070061import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080064import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070065import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080066import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080067import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070068import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070069import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070071import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080075import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080076import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080077
Andrew Lee312e8172014-10-23 17:01:36 -070078import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080079import com.android.ims.internal.IImsMMTelFeature;
80import com.android.ims.internal.IImsRcsFeature;
Brad Ebinger7e934f52017-12-14 14:26:15 -080081import com.android.ims.internal.IImsRegistration;
Brad Ebinger34bef922017-11-09 10:27:08 -080082import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070083import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070084import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070085import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070086import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080089import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010090import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070091import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070092import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080094import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070095import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070096import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070098import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070099import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800100import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700101import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700102import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700103import com.android.internal.telephony.uicc.IccIoResult;
104import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800105import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700106import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800107import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700108import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700109import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800110import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700111import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800112import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700113import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700114import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800115
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700116import java.io.FileDescriptor;
117import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800118import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800121import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100122import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800123import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124
125/**
126 * Implementation of the ITelephony interface.
127 */
Santos Cordon117fee72014-05-16 17:56:12 -0700128public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129 private static final String LOG_TAG = "PhoneInterfaceManager";
130 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
131 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133
134 // Message codes used with mMainThreadHandler
135 private static final int CMD_HANDLE_PIN_MMI = 1;
136 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
137 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
138 private static final int CMD_ANSWER_RINGING_CALL = 4;
139 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700140 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
141 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142 private static final int CMD_OPEN_CHANNEL = 9;
143 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
144 private static final int CMD_CLOSE_CHANNEL = 11;
145 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800146 private static final int CMD_NV_READ_ITEM = 13;
147 private static final int EVENT_NV_READ_ITEM_DONE = 14;
148 private static final int CMD_NV_WRITE_ITEM = 15;
149 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
150 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
151 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
152 private static final int CMD_NV_RESET_CONFIG = 19;
153 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800154 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
155 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
156 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
157 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800158 private static final int CMD_SEND_ENVELOPE = 25;
159 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700160 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
161 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
162 private static final int CMD_EXCHANGE_SIM_IO = 31;
163 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800164 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
165 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700166 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
167 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700168 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
169 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
171 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
172 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
173 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700174 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
175 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
176 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
177 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700178 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
180 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182 /** The singleton instance. */
183 private static PhoneInterfaceManager sInstance;
184
Wink Saville3ab207e2014-11-20 13:07:20 -0800185 private PhoneGlobals mApp;
186 private Phone mPhone;
187 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700188 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800189 private AppOpsManager mAppOps;
190 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800191 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800192 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
Derek Tan97ebb422014-09-05 16:55:38 -0700194 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
195 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800196 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700197
Derek Tan740e1672017-06-27 14:56:27 -0700198 // The AID of ISD-R.
199 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
200
yinxub1bed742017-04-17 11:45:04 -0700201 private NetworkScanRequestTracker mNetworkScanRequestTracker;
202
Derek Tan89e89d42014-07-08 17:00:10 -0700203 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204 * A request object to use for transmitting data to an ICC.
205 */
206 private static final class IccAPDUArgument {
207 public int channel, cla, command, p1, p2, p3;
208 public String data;
209
210 public IccAPDUArgument(int channel, int cla, int command,
211 int p1, int p2, int p3, String data) {
212 this.channel = channel;
213 this.cla = cla;
214 this.command = command;
215 this.p1 = p1;
216 this.p2 = p2;
217 this.p3 = p3;
218 this.data = data;
219 }
220 }
221
222 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700223 * A request object to use for transmitting data to an ICC.
224 */
225 private static final class ManualNetworkSelectionArgument {
226 public OperatorInfo operatorInfo;
227 public boolean persistSelection;
228
229 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
230 this.operatorInfo = operatorInfo;
231 this.persistSelection = persistSelection;
232 }
233 }
234
235 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
237 * request after sending. The main thread will notify the request when it is complete.
238 */
239 private static final class MainThreadRequest {
240 /** The argument to use for the request */
241 public Object argument;
242 /** The result of the request that is run on the main thread */
243 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800244 // The subscriber id that this request applies to. Defaults to
245 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
246 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
248 public MainThreadRequest(Object argument) {
249 this.argument = argument;
250 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800251
252 public MainThreadRequest(Object argument, Integer subId) {
253 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800254 if (subId != null) {
255 this.subId = subId;
256 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 }
259
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800260 private static final class IncomingThirdPartyCallArgs {
261 public final ComponentName component;
262 public final String callId;
263 public final String callerDisplayName;
264
265 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
266 String callerDisplayName) {
267 this.component = component;
268 this.callId = callId;
269 this.callerDisplayName = callerDisplayName;
270 }
271 }
272
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 /**
274 * A handler that processes messages on the main thread in the phone process. Since many
275 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
276 * inbound binder threads to the main thread in the phone process. The Binder thread
277 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
278 * on, which will be notified when the operation completes and will contain the result of the
279 * request.
280 *
281 * <p>If a MainThreadRequest object is provided in the msg.obj field,
282 * note that request.result must be set to something non-null for the calling thread to
283 * unblock.
284 */
285 private final class MainThreadHandler extends Handler {
286 @Override
287 public void handleMessage(Message msg) {
288 MainThreadRequest request;
289 Message onCompleted;
290 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800291 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700292 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293
294 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700295 case CMD_HANDLE_USSD_REQUEST: {
296 request = (MainThreadRequest) msg.obj;
297 final Phone phone = getPhoneFromRequest(request);
298 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
299 String ussdRequest = ussdObject.first;
300 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700301
302 if (!isUssdApiAllowed(request.subId)) {
303 // Carrier does not support use of this API, return failure.
304 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
305 UssdResponse response = new UssdResponse(ussdRequest, null);
306 Bundle returnData = new Bundle();
307 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
308 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
309
310 request.result = true;
311 synchronized (request) {
312 request.notifyAll();
313 }
314 return;
315 }
316
Tyler Gunn52dcf772017-04-26 11:30:31 -0700317 try {
318 request.result = phone != null ?
319 phone.handleUssdRequest(ussdRequest, wrappedCallback)
320 : false;
321 } catch (CallStateException cse) {
322 request.result = false;
323 }
pkanwar32d516d2016-10-14 19:37:38 -0700324 // Wake up the requesting thread
325 synchronized (request) {
326 request.notifyAll();
327 }
328 break;
329 }
330
Yorke Lee716f67e2015-06-17 15:39:16 -0700331 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700333 final Phone phone = getPhoneFromRequest(request);
334 request.result = phone != null ?
335 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
336 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 // Wake up the requesting thread
338 synchronized (request) {
339 request.notifyAll();
340 }
341 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
344 case CMD_HANDLE_NEIGHBORING_CELL:
345 request = (MainThreadRequest) msg.obj;
346 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
347 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700348 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 break;
350
351 case EVENT_NEIGHBORING_CELL_DONE:
352 ar = (AsyncResult) msg.obj;
353 request = (MainThreadRequest) ar.userObj;
354 if (ar.exception == null && ar.result != null) {
355 request.result = ar.result;
356 } else {
357 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800358 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 }
360 // Wake up the requesting thread
361 synchronized (request) {
362 request.notifyAll();
363 }
364 break;
365
366 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700367 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800368 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700369 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 break;
371
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 case CMD_END_CALL:
373 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800374 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700375 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700376 Phone phone = getPhone(end_subId);
377 if (phone == null) {
378 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
379 break;
380 }
381 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
383 // CDMA: If the user presses the Power button we treat it as
384 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700385 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
387 // GSM: End the call as per the Phone state
388 hungUp = PhoneUtils.hangup(mCM);
389 } else {
390 throw new IllegalStateException("Unexpected phone type: " + phoneType);
391 }
392 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
393 request.result = hungUp;
394 // Wake up the requesting thread
395 synchronized (request) {
396 request.notifyAll();
397 }
398 break;
399
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700401 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700402 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800403 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700404 if (uiccCard == null) {
405 loge("iccTransmitApduLogicalChannel: No UICC");
406 request.result = new IccIoResult(0x6F, 0, (byte[])null);
407 synchronized (request) {
408 request.notifyAll();
409 }
410 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
412 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700413 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 iccArgument.channel, iccArgument.cla, iccArgument.command,
415 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 break;
419
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 ar = (AsyncResult) msg.obj;
422 request = (MainThreadRequest) ar.userObj;
423 if (ar.exception == null && ar.result != null) {
424 request.result = ar.result;
425 } else {
426 request.result = new IccIoResult(0x6F, 0, (byte[])null);
427 if (ar.result == null) {
428 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800429 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800431 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 } else {
433 loge("iccTransmitApduLogicalChannel: Unknown exception");
434 }
435 }
436 synchronized (request) {
437 request.notifyAll();
438 }
439 break;
440
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
442 request = (MainThreadRequest) msg.obj;
443 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800444 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 if (uiccCard == null) {
446 loge("iccTransmitApduBasicChannel: No UICC");
447 request.result = new IccIoResult(0x6F, 0, (byte[])null);
448 synchronized (request) {
449 request.notifyAll();
450 }
451 } else {
452 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
453 request);
454 uiccCard.iccTransmitApduBasicChannel(
455 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
456 iccArgument.p3, iccArgument.data, onCompleted);
457 }
458 break;
459
460 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
461 ar = (AsyncResult) msg.obj;
462 request = (MainThreadRequest) ar.userObj;
463 if (ar.exception == null && ar.result != null) {
464 request.result = ar.result;
465 } else {
466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
467 if (ar.result == null) {
468 loge("iccTransmitApduBasicChannel: Empty response");
469 } else if (ar.exception instanceof CommandException) {
470 loge("iccTransmitApduBasicChannel: CommandException: " +
471 ar.exception);
472 } else {
473 loge("iccTransmitApduBasicChannel: Unknown exception");
474 }
475 }
476 synchronized (request) {
477 request.notifyAll();
478 }
479 break;
480
481 case CMD_EXCHANGE_SIM_IO:
482 request = (MainThreadRequest) msg.obj;
483 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800484 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 if (uiccCard == null) {
486 loge("iccExchangeSimIO: No UICC");
487 request.result = new IccIoResult(0x6F, 0, (byte[])null);
488 synchronized (request) {
489 request.notifyAll();
490 }
491 } else {
492 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
493 request);
494 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
495 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
496 iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_EXCHANGE_SIM_IO_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6f, 0, (byte[])null);
507 }
508 synchronized (request) {
509 request.notifyAll();
510 }
511 break;
512
Derek Tan4d5e5c12014-02-04 11:54:58 -0800513 case CMD_SEND_ENVELOPE:
514 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800515 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700516 if (uiccCard == null) {
517 loge("sendEnvelopeWithStatus: No UICC");
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 synchronized (request) {
520 request.notifyAll();
521 }
522 } else {
523 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
524 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
525 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 break;
527
528 case EVENT_SEND_ENVELOPE_DONE:
529 ar = (AsyncResult) msg.obj;
530 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700531 if (ar.exception == null && ar.result != null) {
532 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
535 if (ar.result == null) {
536 loge("sendEnvelopeWithStatus: Empty response");
537 } else if (ar.exception instanceof CommandException) {
538 loge("sendEnvelopeWithStatus: CommandException: " +
539 ar.exception);
540 } else {
541 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
542 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 }
544 synchronized (request) {
545 request.notifyAll();
546 }
547 break;
548
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 case CMD_OPEN_CHANNEL:
550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800552 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800555 request.result = new IccOpenLogicalChannelResponse(-1,
556 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 synchronized (request) {
558 request.notifyAll();
559 }
560 } else {
561 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800562 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
563 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
567 case EVENT_OPEN_CHANNEL_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 int[] result = (int[]) ar.result;
573 int channelId = result[0];
574 byte[] selectResponse = null;
575 if (result.length > 1) {
576 selectResponse = new byte[result.length - 1];
577 for (int i = 1; i < result.length; ++i) {
578 selectResponse[i - 1] = (byte) result[i];
579 }
580 }
581 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 if (ar.result == null) {
585 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 if (ar.exception != null) {
588 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
589 }
590
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700591 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700592 if (ar.exception instanceof CommandException) {
593 CommandException.Error error =
594 ((CommandException) (ar.exception)).getCommandError();
595 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700597 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700598 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 }
600 }
601 openChannelResp = new IccOpenLogicalChannelResponse(
602 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700604 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 synchronized (request) {
606 request.notifyAll();
607 }
608 break;
609
610 case CMD_CLOSE_CHANNEL:
611 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800612 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700613 if (uiccCard == null) {
614 loge("iccCloseLogicalChannel: No UICC");
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
616 synchronized (request) {
617 request.notifyAll();
618 }
619 } else {
620 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
621 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
622 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
625 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800626 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
627 break;
628
629 case CMD_NV_READ_ITEM:
630 request = (MainThreadRequest) msg.obj;
631 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
632 mPhone.nvReadItem((Integer) request.argument, onCompleted);
633 break;
634
635 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800638 if (ar.exception == null && ar.result != null) {
639 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800641 request.result = "";
642 if (ar.result == null) {
643 loge("nvReadItem: Empty response");
644 } else if (ar.exception instanceof CommandException) {
645 loge("nvReadItem: CommandException: " +
646 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800648 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 }
650 }
651 synchronized (request) {
652 request.notifyAll();
653 }
654 break;
655
Jake Hambye994d462014-02-03 13:10:13 -0800656 case CMD_NV_WRITE_ITEM:
657 request = (MainThreadRequest) msg.obj;
658 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
659 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
660 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
661 break;
662
663 case EVENT_NV_WRITE_ITEM_DONE:
664 handleNullReturnEvent(msg, "nvWriteItem");
665 break;
666
667 case CMD_NV_WRITE_CDMA_PRL:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
670 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
671 break;
672
673 case EVENT_NV_WRITE_CDMA_PRL_DONE:
674 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
675 break;
676
677 case CMD_NV_RESET_CONFIG:
678 request = (MainThreadRequest) msg.obj;
679 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
680 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
681 break;
682
683 case EVENT_NV_RESET_CONFIG_DONE:
684 handleNullReturnEvent(msg, "nvResetConfig");
685 break;
686
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 case CMD_GET_PREFERRED_NETWORK_TYPE:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700690 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800691 break;
692
693 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
694 ar = (AsyncResult) msg.obj;
695 request = (MainThreadRequest) ar.userObj;
696 if (ar.exception == null && ar.result != null) {
697 request.result = ar.result; // Integer
698 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800699 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 if (ar.result == null) {
701 loge("getPreferredNetworkType: Empty response");
702 } else if (ar.exception instanceof CommandException) {
703 loge("getPreferredNetworkType: CommandException: " +
704 ar.exception);
705 } else {
706 loge("getPreferredNetworkType: Unknown exception");
707 }
708 }
709 synchronized (request) {
710 request.notifyAll();
711 }
712 break;
713
714 case CMD_SET_PREFERRED_NETWORK_TYPE:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
717 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700718 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800719 break;
720
721 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
722 handleNullReturnEvent(msg, "setPreferredNetworkType");
723 break;
724
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800725 case CMD_SET_VOICEMAIL_NUMBER:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
728 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800729 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
730 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800731 break;
732
733 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
734 handleNullReturnEvent(msg, "setVoicemailNumber");
735 break;
736
Stuart Scott54788802015-03-30 13:18:01 -0700737 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
740 request);
741 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
742 break;
743
744 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
745 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
746 break;
747
Shishir Agrawal302c8692015-06-19 13:49:39 -0700748 case CMD_PERFORM_NETWORK_SCAN:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
751 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
752 break;
753
754 case EVENT_PERFORM_NETWORK_SCAN_DONE:
755 ar = (AsyncResult) msg.obj;
756 request = (MainThreadRequest) ar.userObj;
757 CellNetworkScanResult cellScanResult;
758 if (ar.exception == null && ar.result != null) {
759 cellScanResult = new CellNetworkScanResult(
760 CellNetworkScanResult.STATUS_SUCCESS,
761 (List<OperatorInfo>) ar.result);
762 } else {
763 if (ar.result == null) {
764 loge("getCellNetworkScanResults: Empty response");
765 }
766 if (ar.exception != null) {
767 loge("getCellNetworkScanResults: Exception: " + ar.exception);
768 }
769 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
770 if (ar.exception instanceof CommandException) {
771 CommandException.Error error =
772 ((CommandException) (ar.exception)).getCommandError();
773 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
774 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
775 } else if (error == CommandException.Error.GENERIC_FAILURE) {
776 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
777 }
778 }
779 cellScanResult = new CellNetworkScanResult(errorCode, null);
780 }
781 request.result = cellScanResult;
782 synchronized (request) {
783 request.notifyAll();
784 }
785 break;
786
787 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
788 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700789 ManualNetworkSelectionArgument selArg =
790 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
792 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700793 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
794 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 break;
796
797 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
798 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
799 break;
800
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700801 case CMD_GET_MODEM_ACTIVITY_INFO:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700804 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700805 break;
806
807 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
810 if (ar.exception == null && ar.result != null) {
811 request.result = ar.result;
812 } else {
813 if (ar.result == null) {
814 loge("queryModemActivityInfo: Empty response");
815 } else if (ar.exception instanceof CommandException) {
816 loge("queryModemActivityInfo: CommandException: " +
817 ar.exception);
818 } else {
819 loge("queryModemActivityInfo: Unknown exception");
820 }
821 }
Amit Mahajand4766222016-01-28 15:28:28 -0800822 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
823 if (request.result == null) {
824 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
825 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700826 synchronized (request) {
827 request.notifyAll();
828 }
829 break;
830
Meng Wang1a7c35a2016-05-05 20:56:15 -0700831 case CMD_SET_ALLOWED_CARRIERS:
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
834 mPhone.setAllowedCarriers(
835 (List<CarrierIdentifier>) request.argument,
836 onCompleted);
837 break;
838
839 case EVENT_SET_ALLOWED_CARRIERS_DONE:
840 ar = (AsyncResult) msg.obj;
841 request = (MainThreadRequest) ar.userObj;
842 if (ar.exception == null && ar.result != null) {
843 request.result = ar.result;
844 } else {
845 if (ar.result == null) {
846 loge("setAllowedCarriers: Empty response");
847 } else if (ar.exception instanceof CommandException) {
848 loge("setAllowedCarriers: CommandException: " +
849 ar.exception);
850 } else {
851 loge("setAllowedCarriers: Unknown exception");
852 }
853 }
854 // Result cannot be null. Return -1 on error.
855 if (request.result == null) {
856 request.result = new int[]{-1};
857 }
858 synchronized (request) {
859 request.notifyAll();
860 }
861 break;
862
863 case CMD_GET_ALLOWED_CARRIERS:
864 request = (MainThreadRequest) msg.obj;
865 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
866 mPhone.getAllowedCarriers(onCompleted);
867 break;
868
869 case EVENT_GET_ALLOWED_CARRIERS_DONE:
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null && ar.result != null) {
873 request.result = ar.result;
874 } else {
875 if (ar.result == null) {
876 loge("getAllowedCarriers: Empty response");
877 } else if (ar.exception instanceof CommandException) {
878 loge("getAllowedCarriers: CommandException: " +
879 ar.exception);
880 } else {
881 loge("getAllowedCarriers: Unknown exception");
882 }
883 }
884 // Result cannot be null. Return empty list of CarrierIdentifier.
885 if (request.result == null) {
886 request.result = new ArrayList<CarrierIdentifier>(0);
887 }
888 synchronized (request) {
889 request.notifyAll();
890 }
891 break;
892
Nathan Haroldb3014052017-01-25 15:57:32 -0800893 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
899 request.result = new IllegalArgumentException(
900 "Failed to retrieve Forbidden Plmns");
901 if (ar.result == null) {
902 loge("getForbiddenPlmns: Empty response");
903 } else {
904 loge("getForbiddenPlmns: Unknown exception");
905 }
906 }
907 synchronized (request) {
908 request.notifyAll();
909 }
910 break;
911
912 case CMD_GET_FORBIDDEN_PLMNS:
913 request = (MainThreadRequest) msg.obj;
914 uiccCard = getUiccCardFromRequest(request);
915 if (uiccCard == null) {
916 loge("getForbiddenPlmns() UiccCard is null");
917 request.result = new IllegalArgumentException(
918 "getForbiddenPlmns() UiccCard is null");
919 synchronized (request) {
920 request.notifyAll();
921 }
922 break;
923 }
924 Integer appType = (Integer) request.argument;
925 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
926 if (uiccApp == null) {
927 loge("getForbiddenPlmns() no app with specified type -- "
928 + appType);
929 request.result = new IllegalArgumentException("Failed to get UICC App");
930 synchronized (request) {
931 request.notifyAll();
932 }
933 break;
934 } else {
935 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
936 + " specified type -- " + appType);
937 }
938 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
939 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
940 onCompleted);
941 break;
942
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700943 default:
944 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
945 break;
946 }
947 }
Jake Hambye994d462014-02-03 13:10:13 -0800948
949 private void handleNullReturnEvent(Message msg, String command) {
950 AsyncResult ar = (AsyncResult) msg.obj;
951 MainThreadRequest request = (MainThreadRequest) ar.userObj;
952 if (ar.exception == null) {
953 request.result = true;
954 } else {
955 request.result = false;
956 if (ar.exception instanceof CommandException) {
957 loge(command + ": CommandException: " + ar.exception);
958 } else {
959 loge(command + ": Unknown exception");
960 }
961 }
962 synchronized (request) {
963 request.notifyAll();
964 }
965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700966 }
967
968 /**
969 * Posts the specified command to be executed on the main thread,
970 * waits for the request to complete, and returns the result.
971 * @see #sendRequestAsync
972 */
973 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800974 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700975 }
976
977 /**
978 * Posts the specified command to be executed on the main thread,
979 * waits for the request to complete, and returns the result.
980 * @see #sendRequestAsync
981 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800982 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700983 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
984 throw new RuntimeException("This method will deadlock if called from the main thread.");
985 }
986
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800987 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700988 Message msg = mMainThreadHandler.obtainMessage(command, request);
989 msg.sendToTarget();
990
991 // Wait for the request to complete
992 synchronized (request) {
993 while (request.result == null) {
994 try {
995 request.wait();
996 } catch (InterruptedException e) {
997 // Do nothing, go back and wait until the request is complete
998 }
999 }
1000 }
1001 return request.result;
1002 }
1003
1004 /**
1005 * Asynchronous ("fire and forget") version of sendRequest():
1006 * Posts the specified command to be executed on the main thread, and
1007 * returns immediately.
1008 * @see #sendRequest
1009 */
1010 private void sendRequestAsync(int command) {
1011 mMainThreadHandler.sendEmptyMessage(command);
1012 }
1013
1014 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001015 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1016 * @see {@link #sendRequest(int,Object)}
1017 */
1018 private void sendRequestAsync(int command, Object argument) {
1019 MainThreadRequest request = new MainThreadRequest(argument);
1020 Message msg = mMainThreadHandler.obtainMessage(command, request);
1021 msg.sendToTarget();
1022 }
1023
1024 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001025 * Initialize the singleton PhoneInterfaceManager instance.
1026 * This is only done once, at startup, from PhoneApp.onCreate().
1027 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001028 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001029 synchronized (PhoneInterfaceManager.class) {
1030 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001031 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001032 } else {
1033 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1034 }
1035 return sInstance;
1036 }
1037 }
1038
1039 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001040 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001041 mApp = app;
1042 mPhone = phone;
1043 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001044 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1046 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001047 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001048 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001049 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001050 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001051
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001052 publish();
1053 }
1054
1055 private void publish() {
1056 if (DBG) log("publish: " + this);
1057
1058 ServiceManager.addService("phone", this);
1059 }
1060
Stuart Scott584921c2015-01-15 17:10:34 -08001061 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001062 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1063 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001064 }
1065
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001066 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1067 Phone phone = getPhoneFromRequest(request);
1068 return phone == null ? null :
1069 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1070 }
1071
Wink Saville36469e72014-06-11 15:17:00 -07001072 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001073 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001074 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001075 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001076 //
1077 // Implementation of the ITelephony interface.
1078 //
1079
1080 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001081 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001082 }
1083
Wink Savilleb564aae2014-10-23 10:18:09 -07001084 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 if (DBG) log("dial: " + number);
1086 // No permission check needed here: This is just a wrapper around the
1087 // ACTION_DIAL intent, which is available to any app since it puts up
1088 // the UI before it does anything.
1089
1090 String url = createTelUrl(number);
1091 if (url == null) {
1092 return;
1093 }
1094
1095 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001096 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001097 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1098 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1099 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1100 mApp.startActivity(intent);
1101 }
1102 }
1103
1104 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001105 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001106 }
1107
Wink Savilleb564aae2014-10-23 10:18:09 -07001108 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001109 if (DBG) log("call: " + number);
1110
1111 // This is just a wrapper around the ACTION_CALL intent, but we still
1112 // need to do a permission check since we're calling startActivity()
1113 // from the context of the phone app.
1114 enforceCallPermission();
1115
1116 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1117 != AppOpsManager.MODE_ALLOWED) {
1118 return;
1119 }
1120
1121 String url = createTelUrl(number);
1122 if (url == null) {
1123 return;
1124 }
1125
Wink Saville08874612014-08-31 19:19:58 -07001126 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001127 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001128 if (slist != null) {
1129 for (SubscriptionInfo subInfoRecord : slist) {
1130 if (subInfoRecord.getSubscriptionId() == subId) {
1131 isValid = true;
1132 break;
1133 }
Wink Saville08874612014-08-31 19:19:58 -07001134 }
1135 }
1136 if (isValid == false) {
1137 return;
1138 }
1139
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001141 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1143 mApp.startActivity(intent);
1144 }
1145
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001146 /**
1147 * End a call based on call state
1148 * @return true is a call was ended
1149 */
1150 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001151 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001152 }
1153
1154 /**
1155 * End a call based on the call state of the subId
1156 * @return true is a call was ended
1157 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001158 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001159 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001160 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001161 }
1162
1163 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001164 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001165 }
1166
Wink Savilleb564aae2014-10-23 10:18:09 -07001167 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 if (DBG) log("answerRingingCall...");
1169 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1170 // but that can probably wait till the big TelephonyManager API overhaul.
1171 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1172 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001173 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 }
1175
1176 /**
1177 * Make the actual telephony calls to implement answerRingingCall().
1178 * This should only be called from the main thread of the Phone app.
1179 * @see #answerRingingCall
1180 *
1181 * TODO: it would be nice to return true if we answered the call, or
1182 * false if there wasn't actually a ringing incoming call, or some
1183 * other error occurred. (In other words, pass back the return value
1184 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1185 * But that would require calling this method via sendRequest() rather
1186 * than sendRequestAsync(), and right now we don't actually *need* that
1187 * return value, so let's just return void for now.
1188 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001189 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001190 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001192 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1193 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 if (hasActiveCall && hasHoldingCall) {
1195 // Both lines are in use!
1196 // TODO: provide a flag to let the caller specify what
1197 // policy to use if both lines are in use. (The current
1198 // behavior is hardwired to "answer incoming, end ongoing",
1199 // which is how the CALL button is specced to behave.)
1200 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1201 return;
1202 } else {
1203 // answerCall() will automatically hold the current active
1204 // call, if there is one.
1205 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1206 return;
1207 }
1208 } else {
1209 // No call was ringing.
1210 return;
1211 }
1212 }
1213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001215 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001217 public void silenceRinger() {
1218 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 }
1220
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001221 @Override
1222 public boolean isOffhook(String callingPackage) {
1223 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001224 }
1225
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001226 @Override
1227 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1228 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1229 return false;
1230 }
1231
Sanket Padawe356d7632015-06-22 14:03:32 -07001232 final Phone phone = getPhone(subId);
1233 if (phone != null) {
1234 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1235 } else {
1236 return false;
1237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001238 }
1239
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001240 @Override
1241 public boolean isRinging(String callingPackage) {
1242 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001243 }
1244
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001245 @Override
1246 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1247 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1248 return false;
1249 }
1250
Sanket Padawe356d7632015-06-22 14:03:32 -07001251 final Phone phone = getPhone(subId);
1252 if (phone != null) {
1253 return (phone.getState() == PhoneConstants.State.RINGING);
1254 } else {
1255 return false;
1256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 }
1258
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001259 @Override
1260 public boolean isIdle(String callingPackage) {
1261 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001262 }
1263
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001264 @Override
1265 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1266 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1267 return false;
1268 }
1269
Sanket Padawe356d7632015-06-22 14:03:32 -07001270 final Phone phone = getPhone(subId);
1271 if (phone != null) {
1272 return (phone.getState() == PhoneConstants.State.IDLE);
1273 } else {
1274 return false;
1275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 }
1277
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001279 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001280 }
1281
Wink Savilleb564aae2014-10-23 10:18:09 -07001282 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001283 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001284 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1285 }
1286
1287 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001288 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001289 }
1290
Wink Savilleb564aae2014-10-23 10:18:09 -07001291 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001292 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001293 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1294 }
1295
1296 /** {@hide} */
1297 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001298 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001299 }
1300
Wink Savilleb564aae2014-10-23 10:18:09 -07001301 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001303 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 checkSimPin.start();
1305 return checkSimPin.unlockSim(null, pin);
1306 }
1307
Wink Saville9de0f752013-10-22 19:04:03 -07001308 /** {@hide} */
1309 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001310 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001311 }
1312
Wink Savilleb564aae2014-10-23 10:18:09 -07001313 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001315 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 checkSimPuk.start();
1317 return checkSimPuk.unlockSim(puk, pin);
1318 }
1319
1320 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001321 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 * a synchronous one.
1323 */
1324 private static class UnlockSim extends Thread {
1325
1326 private final IccCard mSimCard;
1327
1328 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001329 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1330 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331
1332 // For replies from SimCard interface
1333 private Handler mHandler;
1334
1335 // For async handler to identify request type
1336 private static final int SUPPLY_PIN_COMPLETE = 100;
1337
1338 public UnlockSim(IccCard simCard) {
1339 mSimCard = simCard;
1340 }
1341
1342 @Override
1343 public void run() {
1344 Looper.prepare();
1345 synchronized (UnlockSim.this) {
1346 mHandler = new Handler() {
1347 @Override
1348 public void handleMessage(Message msg) {
1349 AsyncResult ar = (AsyncResult) msg.obj;
1350 switch (msg.what) {
1351 case SUPPLY_PIN_COMPLETE:
1352 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1353 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001354 mRetryCount = msg.arg1;
1355 if (ar.exception != null) {
1356 if (ar.exception instanceof CommandException &&
1357 ((CommandException)(ar.exception)).getCommandError()
1358 == CommandException.Error.PASSWORD_INCORRECT) {
1359 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1360 } else {
1361 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1362 }
1363 } else {
1364 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366 mDone = true;
1367 UnlockSim.this.notifyAll();
1368 }
1369 break;
1370 }
1371 }
1372 };
1373 UnlockSim.this.notifyAll();
1374 }
1375 Looper.loop();
1376 }
1377
1378 /*
1379 * Use PIN or PUK to unlock SIM card
1380 *
1381 * If PUK is null, unlock SIM card with PIN
1382 *
1383 * If PUK is not null, unlock SIM card with PUK and set PIN code
1384 */
Wink Saville9de0f752013-10-22 19:04:03 -07001385 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386
1387 while (mHandler == null) {
1388 try {
1389 wait();
1390 } catch (InterruptedException e) {
1391 Thread.currentThread().interrupt();
1392 }
1393 }
1394 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1395
1396 if (puk == null) {
1397 mSimCard.supplyPin(pin, callback);
1398 } else {
1399 mSimCard.supplyPuk(puk, pin, callback);
1400 }
1401
1402 while (!mDone) {
1403 try {
1404 Log.d(LOG_TAG, "wait for done");
1405 wait();
1406 } catch (InterruptedException e) {
1407 // Restore the interrupted status
1408 Thread.currentThread().interrupt();
1409 }
1410 }
1411 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001412 int[] resultArray = new int[2];
1413 resultArray[0] = mResult;
1414 resultArray[1] = mRetryCount;
1415 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 }
1417 }
1418
1419 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001420 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001421
1422 }
1423
Wink Savilleb564aae2014-10-23 10:18:09 -07001424 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425 // No permission check needed here: this call is harmless, and it's
1426 // needed for the ServiceState.requestStateUpdate() call (which is
1427 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001428 final Phone phone = getPhone(subId);
1429 if (phone != null) {
1430 phone.updateServiceLocation();
1431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432 }
1433
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001434 @Override
1435 public boolean isRadioOn(String callingPackage) {
1436 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001437 }
1438
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001439 @Override
1440 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1441 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1442 return false;
1443 }
1444 return isRadioOnForSubscriber(subId);
1445 }
1446
1447 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001448 final Phone phone = getPhone(subId);
1449 if (phone != null) {
1450 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1451 } else {
1452 return false;
1453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 }
1455
1456 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001457 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001458
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 }
Wink Saville36469e72014-06-11 15:17:00 -07001460
Wink Savilleb564aae2014-10-23 10:18:09 -07001461 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001463 final Phone phone = getPhone(subId);
1464 if (phone != null) {
1465 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1466 }
Wink Saville36469e72014-06-11 15:17:00 -07001467 }
1468
1469 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001470 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001471 }
1472
Wink Savilleb564aae2014-10-23 10:18:09 -07001473 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001474 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001475 final Phone phone = getPhone(subId);
1476 if (phone == null) {
1477 return false;
1478 }
1479 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001480 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001481 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483 return true;
1484 }
Wink Saville36469e72014-06-11 15:17:00 -07001485
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001486 public boolean needMobileRadioShutdown() {
1487 /*
1488 * If any of the Radios are available, it will need to be
1489 * shutdown. So return true if any Radio is available.
1490 */
1491 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1492 Phone phone = PhoneFactory.getPhone(i);
1493 if (phone != null && phone.isRadioAvailable()) return true;
1494 }
1495 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1496 return false;
1497 }
1498
1499 public void shutdownMobileRadios() {
1500 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1501 logv("Shutting down Phone " + i);
1502 shutdownRadioUsingPhoneId(i);
1503 }
1504 }
1505
1506 private void shutdownRadioUsingPhoneId(int phoneId) {
1507 enforceModifyPermission();
1508 Phone phone = PhoneFactory.getPhone(phoneId);
1509 if (phone != null && phone.isRadioAvailable()) {
1510 phone.shutdownRadio();
1511 }
1512 }
1513
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001515 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001516 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1517 if (defaultPhone != null) {
1518 defaultPhone.setRadioPower(turnOn);
1519 return true;
1520 } else {
1521 loge("There's no default phone.");
1522 return false;
1523 }
Wink Saville36469e72014-06-11 15:17:00 -07001524 }
1525
Wink Savilleb564aae2014-10-23 10:18:09 -07001526 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001528 final Phone phone = getPhone(subId);
1529 if (phone != null) {
1530 phone.setRadioPower(turnOn);
1531 return true;
1532 } else {
1533 return false;
1534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 }
1536
Wink Saville36469e72014-06-11 15:17:00 -07001537 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001538 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001539 public boolean enableDataConnectivity() {
1540 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001541 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001542 final Phone phone = getPhone(subId);
1543 if (phone != null) {
1544 phone.setDataEnabled(true);
1545 return true;
1546 } else {
1547 return false;
1548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 }
1550
Wink Saville36469e72014-06-11 15:17:00 -07001551 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001552 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 public boolean disableDataConnectivity() {
1554 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001555 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001556 final Phone phone = getPhone(subId);
1557 if (phone != null) {
1558 phone.setDataEnabled(false);
1559 return true;
1560 } else {
1561 return false;
1562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
1564
Sanket Padawe356d7632015-06-22 14:03:32 -07001565 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001566 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001567 final Phone phone = getPhone(subId);
1568 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001569 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001570 } else {
1571 return false;
1572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 }
1574
1575 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001576 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001577 }
1578
pkanwarae03a6b2016-11-06 20:37:09 -08001579 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001580 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001581 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1582 return;
1583 }
1584 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1585 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1586 };
1587
Wink Savilleb564aae2014-10-23 10:18:09 -07001588 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1591 return false;
1592 }
Wink Saville36469e72014-06-11 15:17:00 -07001593 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 }
1595
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001597 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001598 }
1599
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001600 public int getCallStateForSlot(int slotIndex) {
1601 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001602 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001603 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 }
1605
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001608 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001610 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001612 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 }
1615
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001618 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 if (phone != null) {
1620 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1621 } else {
1622 return TelephonyManager.DATA_ACTIVITY_NONE;
1623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 }
1625
1626 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001627 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001628 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001629 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001630 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 }
1632
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001633 if (DBG_LOC) log("getCellLocation: is active user");
1634 Bundle data = new Bundle();
1635 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1636 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 return null;
1638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001640 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1641 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1642 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001643 }
1644
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001646 public String getNetworkCountryIsoForPhone(int phoneId) {
1647 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1648 // registered cell info, so return a NULL country instead.
1649 final long identity = Binder.clearCallingIdentity();
1650 try {
1651 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1652 if (TelephonyManager.NETWORK_TYPE_IWLAN
1653 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1654 return "";
1655 }
1656 } finally {
1657 Binder.restoreCallingIdentity(identity);
1658 }
1659 return TelephonyManager.getTelephonyProperty(
1660 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1661 }
1662
1663 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001665 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001666 }
1667
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001669 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 mApp.enforceCallingOrSelfPermission(
1671 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 final Phone phone = getPhone(subId);
1673 if (phone != null) {
1674 phone.enableLocationUpdates();
1675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 }
1677
1678 @Override
1679 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001680 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001681 }
1682
Sanket Padawe356d7632015-06-22 14:03:32 -07001683 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001684 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 mApp.enforceCallingOrSelfPermission(
1686 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001687 final Phone phone = getPhone(subId);
1688 if (phone != null) {
1689 phone.disableLocationUpdates();
1690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 }
1692
1693 @Override
1694 @SuppressWarnings("unchecked")
1695 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001696 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001697 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001698 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
1701 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1702 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1703 return null;
1704 }
Svetoslav64fad262015-04-14 14:35:21 -07001705
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001706 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001708 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001710 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1711 try {
1712 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1713 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1714 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1715 } catch (RuntimeException e) {
1716 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001718 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 }
1720
1721
1722 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001723 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001724 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001725 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001726 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 }
1728
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001729 if (DBG_LOC) log("getAllCellInfo: is active user");
1730 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1731 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1732 for (Phone phone : PhoneFactory.getPhones()) {
1733 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1734 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001736 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 }
1738
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001739 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001741 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001742 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1743 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745
Shishir Agrawala9f32182016-04-12 12:00:16 -07001746 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001747 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001748 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1749 return null;
1750 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001751 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001752 return phone == null ? null : phone.getImei();
1753 }
1754
1755 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001756 public String getMeidForSlot(int slotIndex, String callingPackage) {
1757 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1758 return null;
1759 }
1760 Phone phone = PhoneFactory.getPhone(slotIndex);
1761 return phone == null ? null : phone.getMeid();
1762 }
1763
1764 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001765 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001766 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1767 return null;
1768 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001769 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001770 return phone == null ? null : phone.getDeviceSvn();
1771 }
1772
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 //
1774 // Internal helper methods.
1775 //
1776
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001777 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1779 *
1780 * @throws SecurityException if the caller does not have the required permission
1781 */
1782 private void enforceModifyPermission() {
1783 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1784 }
1785
1786 /**
Junda Liua2e36012014-07-09 18:30:01 -07001787 * Make sure either system app or the caller has carrier privilege.
1788 *
1789 * @throws SecurityException if the caller does not have the required permission/privilege
1790 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001791 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001792 int permission = mApp.checkCallingOrSelfPermission(
1793 android.Manifest.permission.MODIFY_PHONE_STATE);
1794 if (permission == PackageManager.PERMISSION_GRANTED) {
1795 return;
1796 }
1797
1798 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001799 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001800 }
1801
1802 /**
1803 * Make sure the caller has carrier privilege.
1804 *
1805 * @throws SecurityException if the caller does not have the required permission
1806 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001807 private void enforceCarrierPrivilege(int subId) {
1808 if (getCarrierPrivilegeStatus(subId) !=
1809 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001810 loge("No Carrier Privilege.");
1811 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001812 }
1813 }
1814
1815 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 * Make sure the caller has the CALL_PHONE permission.
1817 *
1818 * @throws SecurityException if the caller does not have the required permission
1819 */
1820 private void enforceCallPermission() {
1821 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1822 }
1823
Stuart Scott8eef64f2015-04-08 15:13:54 -07001824 private void enforceConnectivityInternalPermission() {
1825 mApp.enforceCallingOrSelfPermission(
1826 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1827 "ConnectivityService");
1828 }
1829
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 private String createTelUrl(String number) {
1831 if (TextUtils.isEmpty(number)) {
1832 return null;
1833 }
1834
Jake Hambye994d462014-02-03 13:10:13 -08001835 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 }
1837
Ihab Awadf9e92732013-12-05 18:02:52 -08001838 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001839 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1840 }
1841
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001842 private static void logv(String msg) {
1843 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1844 }
1845
Ihab Awadf9e92732013-12-05 18:02:52 -08001846 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1848 }
1849
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001850 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001852 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001853 }
1854
Sanket Padawe356d7632015-06-22 14:03:32 -07001855 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001856 public int getActivePhoneTypeForSlot(int slotIndex) {
1857 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001858 if (phone == null) {
1859 return PhoneConstants.PHONE_TYPE_NONE;
1860 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001861 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 }
1864
1865 /**
1866 * Returns the CDMA ERI icon index to display
1867 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001868 @Override
1869 public int getCdmaEriIconIndex(String callingPackage) {
1870 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001871 }
1872
Sanket Padawe356d7632015-06-22 14:03:32 -07001873 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001874 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1875 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1876 return -1;
1877 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001878 final Phone phone = getPhone(subId);
1879 if (phone != null) {
1880 return phone.getCdmaEriIconIndex();
1881 } else {
1882 return -1;
1883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
1886 /**
1887 * Returns the CDMA ERI icon mode,
1888 * 0 - ON
1889 * 1 - FLASHING
1890 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001891 @Override
1892 public int getCdmaEriIconMode(String callingPackage) {
1893 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001894 }
1895
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001897 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1898 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1899 return -1;
1900 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 final Phone phone = getPhone(subId);
1902 if (phone != null) {
1903 return phone.getCdmaEriIconMode();
1904 } else {
1905 return -1;
1906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
1909 /**
1910 * Returns the CDMA ERI text,
1911 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001912 @Override
1913 public String getCdmaEriText(String callingPackage) {
1914 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001915 }
1916
Sanket Padawe356d7632015-06-22 14:03:32 -07001917 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001918 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1919 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1920 return null;
1921 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001922 final Phone phone = getPhone(subId);
1923 if (phone != null) {
1924 return phone.getCdmaEriText();
1925 } else {
1926 return null;
1927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001928 }
1929
1930 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001931 * Returns the CDMA MDN.
1932 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001933 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001934 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001935 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 final Phone phone = getPhone(subId);
1937 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1938 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001939 } else {
1940 return null;
1941 }
1942 }
1943
1944 /**
1945 * Returns the CDMA MIN.
1946 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001948 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001949 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001950 final Phone phone = getPhone(subId);
1951 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1952 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001953 } else {
1954 return null;
1955 }
1956 }
1957
1958 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 * Returns true if CDMA provisioning needs to run.
1960 */
1961 public boolean needsOtaServiceProvisioning() {
1962 return mPhone.needsOtaServiceProvisioning();
1963 }
1964
1965 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001966 * Sets the voice mail number of a given subId.
1967 */
1968 @Override
1969 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001970 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001971 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1972 new Pair<String, String>(alphaTag, number), new Integer(subId));
1973 return success;
1974 }
1975
Ta-wei Yen87c49842016-05-13 21:19:52 -07001976 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07001977 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
1978 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1979 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
1980 if (!TextUtils.equals(callingPackage, systemDialer)) {
1981 throw new SecurityException("caller must be system dialer");
1982 }
1983 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
1984 if (phoneAccountHandle == null){
1985 return null;
1986 }
1987 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
1988 }
1989
1990 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08001991 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08001992 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1993 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
1994 return null;
1995 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08001996 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
1997 }
1998
1999 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002000 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2001 VisualVoicemailSmsFilterSettings settings) {
2002 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002003 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002004 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2005 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002006 }
2007
2008 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002009 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2010 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002011 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002012 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002013 }
2014
2015 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002016 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2017 String callingPackage, int subId) {
2018 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002019 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002020 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002021 }
2022
2023 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002024 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002025 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002026 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002027 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2028 }
2029
2030 @Override
2031 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2032 String number, int port, String text, PendingIntent sentIntent) {
2033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002034 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002035 enforceSendSmsPermission();
2036 // Make the calls as the phone process.
2037 final long identity = Binder.clearCallingIdentity();
2038 try {
2039 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2040 if (port == 0) {
2041 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2042 sentIntent, null, false);
2043 } else {
2044 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2045 smsManager.sendDataMessageWithSelfPermissions(number, null,
2046 (short) port, data, sentIntent, null);
2047 }
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
2050 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002051 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002052 /**
fionaxu0152e512016-11-14 13:36:14 -08002053 * Sets the voice activation state of a given subId.
2054 */
2055 @Override
2056 public void setVoiceActivationState(int subId, int activationState) {
2057 enforceModifyPermissionOrCarrierPrivilege(subId);
2058 final Phone phone = getPhone(subId);
2059 if (phone != null) {
2060 phone.setVoiceActivationState(activationState);
2061 } else {
2062 loge("setVoiceActivationState fails with invalid subId: " + subId);
2063 }
2064 }
2065
2066 /**
2067 * Sets the data activation state of a given subId.
2068 */
2069 @Override
2070 public void setDataActivationState(int subId, int activationState) {
2071 enforceModifyPermissionOrCarrierPrivilege(subId);
2072 final Phone phone = getPhone(subId);
2073 if (phone != null) {
2074 phone.setDataActivationState(activationState);
2075 } else {
2076 loge("setVoiceActivationState fails with invalid subId: " + subId);
2077 }
2078 }
2079
2080 /**
2081 * Returns the voice activation state of a given subId.
2082 */
2083 @Override
2084 public int getVoiceActivationState(int subId, String callingPackage) {
2085 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2086 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2087 }
2088 final Phone phone = getPhone(subId);
2089 if (phone != null) {
2090 return phone.getVoiceActivationState();
2091 } else {
2092 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2093 }
2094 }
2095
2096 /**
2097 * Returns the data activation state of a given subId.
2098 */
2099 @Override
2100 public int getDataActivationState(int subId, String callingPackage) {
2101 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2102 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2103 }
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 return phone.getDataActivationState();
2107 } else {
2108 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2109 }
2110 }
2111
2112 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 * Returns the unread count of voicemails
2114 */
2115 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002116 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002117 }
2118
2119 /**
2120 * Returns the unread count of voicemails for a subId
2121 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002122 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002123 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002124 final Phone phone = getPhone(subId);
2125 if (phone != null) {
2126 return phone.getVoiceMessageCount();
2127 } else {
2128 return 0;
2129 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 }
2131
2132 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002133 * returns true, if the device is in a state where both voice and data
2134 * are supported simultaneously. This can change based on location or network condition.
2135 */
2136 @Override
2137 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2138 final Phone phone = getPhone(subId);
2139 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2140 }
2141
2142 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002143 * Send the dialer code if called from the current default dialer or the caller has
2144 * carrier privilege.
2145 * @param inputCode The dialer code to send
2146 */
2147 @Override
2148 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2150 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2151 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2152 enforceCarrierPrivilege(getDefaultSubscription());
2153 }
2154 mPhone.sendDialerSpecialCode(inputCode);
2155 }
2156
2157 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002158 * Returns the data network type.
2159 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 *
2161 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2162 */
2163 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002164 public int getNetworkType() {
2165 final Phone phone = getPhone(getDefaultSubscription());
2166 if (phone != null) {
2167 return phone.getServiceState().getDataNetworkType();
2168 } else {
2169 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2170 }
Wink Saville36469e72014-06-11 15:17:00 -07002171 }
2172
2173 /**
2174 * Returns the network type for a subId
2175 */
2176 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002177 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2178 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2179 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2180 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002181
Sanket Padawe356d7632015-06-22 14:03:32 -07002182 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002183 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002184 return phone.getServiceState().getDataNetworkType();
2185 } else {
2186 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 }
2189
2190 /**
2191 * Returns the data network type
2192 */
2193 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002194 public int getDataNetworkType(String callingPackage) {
2195 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002196 }
2197
2198 /**
2199 * Returns the data network type for a subId
2200 */
2201 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002202 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2203 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2204 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2205 }
2206
Sanket Padawe356d7632015-06-22 14:03:32 -07002207 final Phone phone = getPhone(subId);
2208 if (phone != null) {
2209 return phone.getServiceState().getDataNetworkType();
2210 } else {
2211 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 }
2214
2215 /**
Wink Saville36469e72014-06-11 15:17:00 -07002216 * Returns the Voice network type for a subId
2217 */
2218 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002219 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2220 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2221 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2222 }
2223
Sanket Padawe356d7632015-06-22 14:03:32 -07002224 final Phone phone = getPhone(subId);
2225 if (phone != null) {
2226 return phone.getServiceState().getVoiceNetworkType();
2227 } else {
2228 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231
2232 /**
2233 * @return true if a ICC card is present
2234 */
2235 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002236 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002237 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2238 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002239 }
2240
2241 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002242 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002243 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002244 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002245 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2246 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002247 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002248 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002249 } else {
2250 return false;
2251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 }
2253
2254 /**
2255 * Return if the current radio is LTE on CDMA. This
2256 * is a tri-state return value as for a period of time
2257 * the mode may be unknown.
2258 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002261 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002263 @Override
2264 public int getLteOnCdmaMode(String callingPackage) {
2265 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002266 }
2267
Sanket Padawe356d7632015-06-22 14:03:32 -07002268 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002269 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2270 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2271 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2272 }
2273
Sanket Padawe356d7632015-06-22 14:03:32 -07002274 final Phone phone = getPhone(subId);
2275 if (phone == null) {
2276 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2277 } else {
2278 return phone.getLteOnCdmaMode();
2279 }
Wink Saville36469e72014-06-11 15:17:00 -07002280 }
2281
2282 public void setPhone(Phone phone) {
2283 mPhone = phone;
2284 }
2285
2286 /**
2287 * {@hide}
2288 * Returns Default subId, 0 in the case of single standby.
2289 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002290 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002291 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002292 }
2293
Shishir Agrawala9f32182016-04-12 12:00:16 -07002294 private int getSlotForDefaultSubscription() {
2295 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2296 }
2297
Wink Savilleb564aae2014-10-23 10:18:09 -07002298 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002299 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002301
2302 /**
2303 * @see android.telephony.TelephonyManager.WifiCallingChoices
2304 */
2305 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002306 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2307 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002308 }
2309
2310 /**
2311 * @see android.telephony.TelephonyManager.WifiCallingChoices
2312 */
2313 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002314 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2315 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2316 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002317 }
2318
Sailesh Nepald1e68152013-12-12 19:08:02 -08002319 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002320 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002321 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002322 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002323
Shishir Agrawal566b7612013-10-28 14:41:00 -07002324 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002325 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2326 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002327 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002328
Derek Tan740e1672017-06-27 14:56:27 -07002329 if (TextUtils.equals(ISDR_AID, aid)) {
2330 // Only allows LPA to open logical channel to ISD-R.
2331 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2332 ComponentInfo bestComponent =
2333 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2334 if (bestComponent == null
2335 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2336 loge("The calling package is not allowed to access ISD-R.");
2337 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2338 }
2339 }
2340
2341 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002342 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002343 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002344 if (DBG) log("iccOpenLogicalChannel: " + response);
2345 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002346 }
2347
2348 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002349 public boolean iccCloseLogicalChannel(int subId, int channel) {
2350 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002351
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002352 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002353 if (channel < 0) {
2354 return false;
2355 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002356 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002357 if (DBG) log("iccCloseLogicalChannel: " + success);
2358 return success;
2359 }
2360
2361 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002362 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002363 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002364 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002365
2366 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002367 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2368 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002369 " data=" + data);
2370 }
2371
2372 if (channel < 0) {
2373 return "";
2374 }
2375
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002376 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002377 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002378 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2379
Shishir Agrawal566b7612013-10-28 14:41:00 -07002380 // Append the returned status code to the end of the response payload.
2381 String s = Integer.toHexString(
2382 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002383 if (response.payload != null) {
2384 s = IccUtils.bytesToHexString(response.payload) + s;
2385 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002386 return s;
2387 }
Jake Hambye994d462014-02-03 13:10:13 -08002388
Evan Charltonc66da362014-05-16 14:06:40 -07002389 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002390 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002391 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002392 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002393
2394 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002395 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2396 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002397 }
2398
2399 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002400 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002401 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2402
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002403 // Append the returned status code to the end of the response payload.
2404 String s = Integer.toHexString(
2405 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002406 if (response.payload != null) {
2407 s = IccUtils.bytesToHexString(response.payload) + s;
2408 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002409 return s;
2410 }
2411
2412 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002413 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002414 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002415 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002416
2417 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002418 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002419 p1 + " " + p2 + " " + p3 + ":" + filePath);
2420 }
2421
2422 IccIoResult response =
2423 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2425 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002426
2427 if (DBG) {
2428 log("Exchange SIM_IO [R]" + response);
2429 }
2430
2431 byte[] result = null;
2432 int length = 2;
2433 if (response.payload != null) {
2434 length = 2 + response.payload.length;
2435 result = new byte[length];
2436 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2437 } else {
2438 result = new byte[length];
2439 }
2440
2441 result[length - 1] = (byte) response.sw2;
2442 result[length - 2] = (byte) response.sw1;
2443 return result;
2444 }
2445
Nathan Haroldb3014052017-01-25 15:57:32 -08002446 /**
2447 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2448 * on a particular subscription
2449 */
2450 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002451 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2452 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002453 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2454 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2455 return null;
2456 }
2457 Object response = sendRequest(
2458 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2459 if (response instanceof String[]) {
2460 return (String[]) response;
2461 }
2462 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2463 return null;
2464 }
2465
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002466 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002467 public String sendEnvelopeWithStatus(int subId, String content) {
2468 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002469
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002470 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002471 if (response.payload == null) {
2472 return "";
2473 }
2474
2475 // Append the returned status code to the end of the response payload.
2476 String s = Integer.toHexString(
2477 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2478 s = IccUtils.bytesToHexString(response.payload) + s;
2479 return s;
2480 }
2481
Jake Hambye994d462014-02-03 13:10:13 -08002482 /**
2483 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2484 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2485 *
2486 * @param itemID the ID of the item to read
2487 * @return the NV item as a String, or null on error.
2488 */
2489 @Override
2490 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002491 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002492 if (DBG) log("nvReadItem: item " + itemID);
2493 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2494 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2495 return value;
2496 }
2497
2498 /**
2499 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2500 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2501 *
2502 * @param itemID the ID of the item to read
2503 * @param itemValue the value to write, as a String
2504 * @return true on success; false on any failure
2505 */
2506 @Override
2507 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002508 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002509 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2510 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2511 new Pair<Integer, String>(itemID, itemValue));
2512 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2513 return success;
2514 }
2515
2516 /**
2517 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2518 * Used for device configuration by some CDMA operators.
2519 *
2520 * @param preferredRoamingList byte array containing the new PRL
2521 * @return true on success; false on any failure
2522 */
2523 @Override
2524 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002525 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002526 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2527 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2528 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2529 return success;
2530 }
2531
2532 /**
2533 * Perform the specified type of NV config reset.
2534 * Used for device configuration by some CDMA operators.
2535 *
2536 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2537 * @return true on success; false on any failure
2538 */
2539 @Override
2540 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002541 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002542 if (DBG) log("nvResetConfig: type " + resetType);
2543 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2544 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2545 return success;
2546 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002547
2548 /**
Wink Saville36469e72014-06-11 15:17:00 -07002549 * {@hide}
2550 * Returns Default sim, 0 in the case of single standby.
2551 */
2552 public int getDefaultSim() {
2553 //TODO Need to get it from Telephony Devcontroller
2554 return 0;
2555 }
2556
Svet Ganovb320e182015-04-16 12:30:10 -07002557 public String[] getPcscfAddress(String apnType, String callingPackage) {
2558 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2559 return new String[0];
2560 }
2561
2562
ram87fca6f2014-07-18 18:58:44 +05302563 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002564 }
2565
Brad Ebinger51f743a2017-01-23 13:50:20 -08002566 /**
Brad Ebinger34bef922017-11-09 10:27:08 -08002567 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2568 * feature or {@link null} if the service is not available. If the feature is available, the
2569 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002570 */
Brad Ebinger34bef922017-11-09 10:27:08 -08002571 public IImsMMTelFeature getMMTelFeatureAndListen(int slotId,
2572 IImsServiceFeatureCallback callback) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002573 enforceModifyPermission();
Brad Ebinger34bef922017-11-09 10:27:08 -08002574 return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback);
2575 }
2576
2577 /**
2578 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2579 * feature during emergency calling or {@link null} if the service is not available. If the
2580 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2581 * listener for feature updates.
2582 */
2583 public IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId,
2584 IImsServiceFeatureCallback callback) {
2585 enforceModifyPermission();
2586 return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback);
2587 }
2588
2589 /**
2590 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2591 * feature during emergency calling or {@link null} if the service is not available. If the
2592 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2593 * listener for feature updates.
2594 */
2595 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2596 enforceModifyPermission();
2597 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002598 }
2599
Brad Ebinger7e934f52017-12-14 14:26:15 -08002600 /**
2601 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2602 * specified.
2603 */
2604 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2605 enforceModifyPermission();
2606 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2607 }
2608
Wink Saville36469e72014-06-11 15:17:00 -07002609 public void setImsRegistrationState(boolean registered) {
2610 enforceModifyPermission();
2611 mPhone.setImsRegistrationState(registered);
2612 }
2613
2614 /**
Stuart Scott54788802015-03-30 13:18:01 -07002615 * Set the network selection mode to automatic.
2616 *
2617 */
2618 @Override
2619 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002620 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002621 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2622 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2623 }
2624
2625 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002626 * Set the network selection mode to manual with the selected carrier.
2627 */
2628 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002629 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002630 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002631 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002632 OperatorInfo operator = new OperatorInfo(
2633 /* operatorAlphaLong */ "",
2634 /* operatorAlphaShort */ "",
2635 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002636 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002637 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2638 persistSelection);
2639 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002640 }
2641
2642 /**
2643 * Scans for available networks.
2644 */
2645 @Override
2646 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002647 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002648 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2649 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2650 CMD_PERFORM_NETWORK_SCAN, null, subId);
2651 return result;
2652 }
2653
2654 /**
yinxub1bed742017-04-17 11:45:04 -07002655 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002656 *
yinxub1bed742017-04-17 11:45:04 -07002657 * @param subId id of the subscription
2658 * @param request contains the radio access networks with bands/channels to scan
2659 * @param messenger callback messenger for scan results or errors
2660 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002661 * @return the id of the requested scan which can be used to stop the scan.
2662 */
2663 @Override
2664 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2665 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002666 enforceModifyPermissionOrCarrierPrivilege(subId);
2667 return mNetworkScanRequestTracker.startNetworkScan(
2668 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002669 }
2670
2671 /**
2672 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002673 *
2674 * @param subId id of the subscription
2675 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002676 */
2677 @Override
2678 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002679 enforceModifyPermissionOrCarrierPrivilege(subId);
2680 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002681 }
2682
2683 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002684 * Get the calculated preferred network type.
2685 * Used for debugging incorrect network type.
2686 *
2687 * @return the preferred network type, defined in RILConstants.java.
2688 */
2689 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002690 public int getCalculatedPreferredNetworkType(String callingPackage) {
2691 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2692 return RILConstants.PREFERRED_NETWORK_MODE;
2693 }
2694
Amit Mahajan43330e02014-11-18 11:54:45 -08002695 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002696 }
2697
2698 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002699 * Get the preferred network type.
2700 * Used for device configuration by some CDMA operators.
2701 *
2702 * @return the preferred network type, defined in RILConstants.java.
2703 */
2704 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002705 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002706 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002707 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002708 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002709 int networkType = (result != null ? result[0] : -1);
2710 if (DBG) log("getPreferredNetworkType: " + networkType);
2711 return networkType;
2712 }
2713
2714 /**
2715 * Set the preferred network type.
2716 * Used for device configuration by some CDMA operators.
2717 *
2718 * @param networkType the preferred network type, defined in RILConstants.java.
2719 * @return true on success; false on any failure.
2720 */
2721 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002722 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002723 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002724 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2725 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002726 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002727 if (success) {
2728 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002729 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002730 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002731 return success;
2732 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002733
2734 /**
Junda Liu475951f2014-11-07 16:45:03 -08002735 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2736 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2737 * tethering.
2738 *
2739 * @return 0: Not required. 1: required. 2: Not set.
2740 * @hide
2741 */
2742 @Override
2743 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002744 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002745 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2746 Settings.Global.TETHER_DUN_REQUIRED, 2);
2747 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2748 // config_tether_apndata.
2749 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2750 dunRequired = 1;
2751 }
2752 return dunRequired;
2753 }
2754
2755 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002756 * Set mobile data enabled
2757 * Used by the user through settings etc to turn on/off mobile data
2758 *
2759 * @param enable {@code true} turn turn data on, else {@code false}
2760 */
2761 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002762 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002763 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002764 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002765 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002766 Phone phone = PhoneFactory.getPhone(phoneId);
2767 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002768 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002769 phone.setDataEnabled(enable);
2770 } else {
2771 loge("setDataEnabled: no phone for subId=" + subId);
2772 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002773 }
2774
2775 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002776 * Get whether mobile data is enabled.
2777 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002778 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002779 *
2780 * @return {@code true} if data is enabled else {@code false}
2781 */
2782 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002783 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002784 try {
2785 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2786 null);
2787 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002788 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002789 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002790 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002791 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002792 Phone phone = PhoneFactory.getPhone(phoneId);
2793 if (phone != null) {
2794 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002795 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002796 return retVal;
2797 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002798 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002799 return false;
2800 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002801 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002802
2803 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002804 public int getCarrierPrivilegeStatus(int subId) {
2805 final Phone phone = getPhone(subId);
2806 if (phone == null) {
2807 loge("getCarrierPrivilegeStatus: Invalid subId");
2808 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2809 }
2810 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002811 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002812 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002813 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2814 }
2815 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002816 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002817 }
Junda Liu29340342014-07-10 15:23:27 -07002818
2819 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002820 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002821 if (TextUtils.isEmpty(pkgName))
2822 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002823 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002824 if (card == null) {
2825 loge("checkCarrierPrivilegesForPackage: No UICC");
2826 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2827 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002828 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2829 }
2830
2831 @Override
2832 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002833 if (TextUtils.isEmpty(pkgName))
2834 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002835 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2836 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2837 UiccCard card = UiccController.getInstance().getUiccCard(i);
2838 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002839 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002840 continue;
2841 }
2842
2843 result = card.getCarrierPrivilegeStatus(
2844 mPhone.getContext().getPackageManager(), pkgName);
2845 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2846 break;
2847 }
2848 }
2849
2850 return result;
Junda Liu29340342014-07-10 15:23:27 -07002851 }
Derek Tan89e89d42014-07-08 17:00:10 -07002852
2853 @Override
Junda Liue64de782015-04-16 17:19:16 -07002854 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2855 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2856 loge("phoneId " + phoneId + " is not valid.");
2857 return null;
2858 }
2859 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002860 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002861 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002862 return null ;
2863 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002864 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002865 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002866 }
2867
Amith Yamasani6e118872016-02-19 12:53:51 -08002868 @Override
2869 public List<String> getPackagesWithCarrierPrivileges() {
2870 PackageManager pm = mPhone.getContext().getPackageManager();
2871 List<String> privilegedPackages = new ArrayList<>();
2872 List<PackageInfo> packages = null;
2873 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2874 UiccCard card = UiccController.getInstance().getUiccCard(i);
2875 if (card == null) {
2876 // No UICC in that slot.
2877 continue;
2878 }
2879 if (card.hasCarrierPrivilegeRules()) {
2880 if (packages == null) {
2881 // Only check packages in user 0 for now
2882 packages = pm.getInstalledPackagesAsUser(
2883 PackageManager.MATCH_DISABLED_COMPONENTS
2884 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2885 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2886 }
2887 for (int p = packages.size() - 1; p >= 0; p--) {
2888 PackageInfo pkgInfo = packages.get(p);
2889 if (pkgInfo != null && pkgInfo.packageName != null
2890 && card.getCarrierPrivilegeStatus(pkgInfo)
2891 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2892 privilegedPackages.add(pkgInfo.packageName);
2893 }
2894 }
2895 }
2896 }
2897 return privilegedPackages;
2898 }
2899
Wink Savilleb564aae2014-10-23 10:18:09 -07002900 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 final Phone phone = getPhone(subId);
2902 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002903 if (card == null) {
2904 loge("getIccId: No UICC");
2905 return null;
2906 }
2907 String iccId = card.getIccId();
2908 if (TextUtils.isEmpty(iccId)) {
2909 loge("getIccId: ICC ID is null or empty.");
2910 return null;
2911 }
2912 return iccId;
2913 }
2914
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002915 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002916 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2917 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002918 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002919
Jeff Sharkey85190e62014-12-05 09:40:12 -08002920 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002921 final Phone phone = getPhone(subId);
2922 if (phone == null) {
2923 return false;
2924 }
2925 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002926
2927 if (DBG_MERGE) {
2928 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2929 + subscriberId + " to " + number);
2930 }
2931
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002932 if (TextUtils.isEmpty(iccId)) {
2933 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002934 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002935
Jeff Sharkey85190e62014-12-05 09:40:12 -08002936 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2937
2938 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002939 if (alphaTag == null) {
2940 editor.remove(alphaTagPrefKey);
2941 } else {
2942 editor.putString(alphaTagPrefKey, alphaTag);
2943 }
2944
Jeff Sharkey85190e62014-12-05 09:40:12 -08002945 // Record both the line number and IMSI for this ICCID, since we need to
2946 // track all merged IMSIs based on line number
2947 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2948 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002949 if (number == null) {
2950 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002951 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002952 } else {
2953 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002954 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002955 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002956
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002957 editor.commit();
2958 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002959 }
2960
2961 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002962 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002963 // This is open to apps with WRITE_SMS.
2964 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002965 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002966 return null;
2967 }
Derek Tan97ebb422014-09-05 16:55:38 -07002968
2969 String iccId = getIccId(subId);
2970 if (iccId != null) {
2971 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002972 if (DBG_MERGE) {
2973 log("getLine1NumberForDisplay returning " +
2974 mTelephonySharedPreferences.getString(numberPrefKey, null));
2975 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002976 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002977 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002978 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002979 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002980 }
2981
2982 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002983 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2984 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2985 return null;
2986 }
Derek Tan97ebb422014-09-05 16:55:38 -07002987
2988 String iccId = getIccId(subId);
2989 if (iccId != null) {
2990 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002991 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002992 }
Derek Tan97ebb422014-09-05 16:55:38 -07002993 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002994 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002995
2996 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002997 public String[] getMergedSubscriberIds(String callingPackage) {
2998 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2999 return null;
3000 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003001 final Context context = mPhone.getContext();
3002 final TelephonyManager tele = TelephonyManager.from(context);
3003 final SubscriptionManager sub = SubscriptionManager.from(context);
3004
3005 // Figure out what subscribers are currently active
3006 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003007 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3008 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 final int[] subIds = sub.getActiveSubscriptionIdList();
3012 for (int subId : subIds) {
3013 activeSubscriberIds.add(tele.getSubscriberId(subId));
3014 }
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003017 }
3018
3019 // First pass, find a number override for an active subscriber
3020 String mergeNumber = null;
3021 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3022 for (String key : prefs.keySet()) {
3023 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3024 final String subscriberId = (String) prefs.get(key);
3025 if (activeSubscriberIds.contains(subscriberId)) {
3026 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3027 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3028 mergeNumber = (String) prefs.get(numberKey);
3029 if (DBG_MERGE) {
3030 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3031 + " for active subscriber " + subscriberId);
3032 }
3033 if (!TextUtils.isEmpty(mergeNumber)) {
3034 break;
3035 }
3036 }
3037 }
3038 }
3039
3040 // Shortcut when no active merged subscribers
3041 if (TextUtils.isEmpty(mergeNumber)) {
3042 return null;
3043 }
3044
3045 // Second pass, find all subscribers under that line override
3046 final ArraySet<String> result = new ArraySet<>();
3047 for (String key : prefs.keySet()) {
3048 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3049 final String number = (String) prefs.get(key);
3050 if (mergeNumber.equals(number)) {
3051 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3052 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3053 final String subscriberId = (String) prefs.get(subscriberKey);
3054 if (!TextUtils.isEmpty(subscriberId)) {
3055 result.add(subscriberId);
3056 }
3057 }
3058 }
3059 }
3060
3061 final String[] resultArray = result.toArray(new String[result.size()]);
3062 Arrays.sort(resultArray);
3063 if (DBG_MERGE) {
3064 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3065 }
3066 return resultArray;
3067 }
3068
3069 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003070 public boolean setOperatorBrandOverride(int subId, String brand) {
3071 enforceCarrierPrivilege(subId);
3072 final Phone phone = getPhone(subId);
3073 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003074 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003075
3076 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003077 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003078 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3079 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003080 enforceCarrierPrivilege(subId);
3081 final Phone phone = getPhone(subId);
3082 if (phone == null) {
3083 return false;
3084 }
3085 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003086 cdmaNonRoamingList);
3087 }
3088
3089 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003090 public void setRadioCapability(RadioAccessFamily[] rafs) {
3091 try {
3092 ProxyController.getInstance().setRadioCapability(rafs);
3093 } catch (RuntimeException e) {
3094 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3095 }
3096 }
3097
3098 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003099 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3100 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3101 return RadioAccessFamily.RAF_UNKNOWN;
3102 }
3103
Wink Saville5d475dd2014-10-17 15:00:58 -07003104 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3105 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003106
3107 @Override
3108 public void enableVideoCalling(boolean enable) {
3109 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003110 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003111 }
3112
3113 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003114 public boolean isVideoCallingEnabled(String callingPackage) {
3115 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3116 return false;
3117 }
3118
Andrew Lee77527ac2014-10-21 16:57:39 -07003119 // Check the user preference and the system-level IMS setting. Even if the user has
3120 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3121 // In the long run, we may instead need to check if there exists a connection service
3122 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003123 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3124 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003125 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003126 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003127
Andrew Leea1239f22015-03-02 17:44:07 -08003128 @Override
3129 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003130 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003131 }
3132
3133 @Override
3134 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003135 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003136 }
3137
Andrew Lee9431b832015-03-09 18:46:45 -07003138 @Override
3139 public boolean isTtyModeSupported() {
3140 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3141 TelephonyManager telephonyManager =
3142 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003143 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003144 }
3145
3146 @Override
3147 public boolean isHearingAidCompatibilitySupported() {
3148 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3149 }
3150
Sanket Padawe7310cc72015-01-14 09:53:20 -08003151 /**
3152 * Returns the unique device ID of phone, for example, the IMEI for
3153 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3154 *
3155 * <p>Requires Permission:
3156 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3157 */
3158 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003159 public String getDeviceId(String callingPackage) {
3160 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3161 return null;
3162 }
3163
Sanket Padawe7310cc72015-01-14 09:53:20 -08003164 final Phone phone = PhoneFactory.getPhone(0);
3165 if (phone != null) {
3166 return phone.getDeviceId();
3167 } else {
3168 return null;
3169 }
3170 }
3171
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003172 /*
3173 * {@hide}
3174 * Returns the IMS Registration Status
3175 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003176 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003177 public boolean isImsRegistered() {
3178 return mPhone.isImsRegistered();
3179 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003180
Ping Sun014fe8e2016-03-02 19:16:45 +08003181 /**
3182 * {@hide}
3183 * Returns the IMS Registration Status on a particular subid
3184 *
3185 * @param subId
3186 */
3187 public boolean isImsRegisteredForSubscriber(int subId) {
3188 Phone phone = getPhone(subId);
3189 if (phone != null) {
3190 return phone.isImsRegistered();
3191 } else {
3192 return false;
3193 }
3194 }
3195
Santos Cordon7a1885b2015-02-03 11:15:19 -08003196 @Override
3197 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3198 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3199 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003200
Nathan Haroldc55097a2015-03-11 18:14:50 -07003201 /*
3202 * {@hide}
3203 * Returns the IMS Registration Status
3204 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003205 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003206 return mPhone.isWifiCallingEnabled();
3207 }
3208
3209 /*
3210 * {@hide}
3211 * Returns the IMS Registration Status
3212 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003213 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003214 return mPhone.isVolteEnabled();
3215 }
Svet Ganovb320e182015-04-16 12:30:10 -07003216
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003217 /*
3218 * {@hide} Returns the IMS Registration Status
3219 */
3220 public boolean isVideoTelephonyAvailable() {
3221 return mPhone.isVideoEnabled();
3222 }
3223
Svet Ganovb320e182015-04-16 12:30:10 -07003224 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003225 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003226 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003227 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3228
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003229 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003230 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003231 } catch (SecurityException e) {
3232 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3233 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003234 }
Svet Ganovb320e182015-04-16 12:30:10 -07003235
3236 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3237 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3238 return false;
3239 }
3240
3241 return true;
3242 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003243
Makoto Onukifee69342015-06-29 14:44:50 -07003244 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003245 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003246 */
3247 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003248 // Default SMS app can always read it.
3249 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3250 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3251 return true;
3252 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003253
Makoto Onukie4072d12015-08-03 15:12:23 -07003254 try {
3255 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003256 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003257 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003258 // Can be read with READ_SMS too.
3259 try {
3260 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3261 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3262 if (opCode != AppOpsManager.OP_NONE) {
3263 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3264 == AppOpsManager.MODE_ALLOWED;
3265 } else {
3266 return true;
3267 }
3268 } catch (SecurityException readSmsSecurityException) {
3269 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003270 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003271 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003272 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003273 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003274 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003275 if (opCode != AppOpsManager.OP_NONE) {
3276 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3277 == AppOpsManager.MODE_ALLOWED;
3278 } else {
3279 return true;
3280 }
3281 } catch (SecurityException readPhoneNumberSecurityException) {
3282 }
3283
3284 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3285 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3286 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003287 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003288 }
3289
Stuart Scott8eef64f2015-04-08 15:13:54 -07003290 @Override
3291 public void factoryReset(int subId) {
3292 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003293 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3294 return;
3295 }
3296
Svet Ganovcc087f82015-05-12 20:35:54 -07003297 final long identity = Binder.clearCallingIdentity();
3298 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003299 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3300 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003301 // Enable data
3302 setDataEnabled(subId, true);
3303 // Set network selection mode to automatic
3304 setNetworkSelectionModeAutomatic(subId);
3305 // Set preferred mobile network type to the best available
3306 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3307 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003308 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003309 }
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003312 }
3313 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003314
3315 @Override
3316 public String getLocaleFromDefaultSim() {
3317 // We query all subscriptions instead of just the active ones, because
3318 // this might be called early on in the provisioning flow when the
3319 // subscriptions potentially aren't active yet.
3320 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3321 if (slist == null || slist.isEmpty()) {
3322 return null;
3323 }
3324
3325 // This function may be called very early, say, from the setup wizard, at
3326 // which point we won't have a default subscription set. If that's the case
3327 // we just choose the first, which will be valid in "most cases".
3328 final int defaultSubId = getDefaultSubscription();
3329 SubscriptionInfo info = null;
3330 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3331 info = slist.get(0);
3332 } else {
3333 for (SubscriptionInfo item : slist) {
3334 if (item.getSubscriptionId() == defaultSubId) {
3335 info = item;
3336 break;
3337 }
3338 }
3339
3340 if (info == null) {
3341 return null;
3342 }
3343 }
3344
3345 // Try and fetch the locale from the carrier properties or from the SIM language
3346 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003347 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003348 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003349 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003350 if (defaultPhone != null) {
3351 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3352 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003353 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003354 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3355 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003356 } else {
3357 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003358 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003359 }
3360 }
3361
Narayan Kamath011676f2015-07-29 12:04:08 +01003362 // The SIM language preferences only store a language (e.g. fr = French), not an
3363 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3364 // the SIM and carrier preferences does not include a country we add the country
3365 // determined from the SIM MCC to provide an exact locale.
3366 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003367 if (mccLocale != null) {
3368 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3369 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003370 }
3371
Tony Hill183b2de2015-06-24 14:53:58 +01003372 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003373 return null;
3374 }
3375
3376 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 return mSubscriptionController.getAllSubInfoList(
3380 mPhone.getContext().getOpPackageName());
3381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
3384 }
3385
3386 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 return mSubscriptionController.getActiveSubscriptionInfoList(
3390 mPhone.getContext().getOpPackageName());
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
3394 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003395
3396 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003397 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3398 * representing the state of the modem.
3399 *
3400 * NOTE: This clears the modem state, so there should only every be one caller.
3401 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003402 */
3403 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003404 public void requestModemActivityInfo(ResultReceiver result) {
3405 enforceModifyPermission();
3406
3407 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3408 Bundle bundle = new Bundle();
3409 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3410 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003411 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003412
3413 /**
3414 * {@hide}
3415 * Returns the service state information on specified subscription.
3416 */
3417 @Override
3418 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3419
3420 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3421 return null;
3422 }
3423
3424 final Phone phone = getPhone(subId);
3425 if (phone == null) {
3426 return null;
3427 }
3428
3429 return phone.getServiceState();
3430 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003431
3432 /**
3433 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3434 *
3435 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3436 * voicemail ringtone.
3437 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3438 * PhoneAccount.
3439 */
3440 @Override
3441 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003442 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003443 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003444 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003445 }
3446
fionaxu7ed723d2017-05-30 18:58:54 -07003447 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003448 }
3449
3450 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003451 * Sets the per-account voicemail ringtone.
3452 *
3453 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3454 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3455 *
3456 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3457 * voicemail ringtone.
3458 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3459 * PhoneAccount.
3460 */
3461 @Override
3462 public void setVoicemailRingtoneUri(String callingPackage,
3463 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3464 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3465 if (!TextUtils.equals(callingPackage,
3466 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3467 enforceModifyPermissionOrCarrierPrivilege(
3468 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3469 }
3470 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3471 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003472 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003473 }
fionaxu7ed723d2017-05-30 18:58:54 -07003474 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003475 }
3476
3477 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003478 * Returns whether vibration is set for voicemail notification in Phone settings.
3479 *
3480 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3481 * voicemail vibration setting.
3482 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3483 */
3484 @Override
3485 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003486 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003487 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003488 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003489 }
3490
fionaxu7ed723d2017-05-30 18:58:54 -07003491 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003492 }
3493
Youhan Wange64578a2016-05-02 15:32:42 -07003494 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003495 * Sets the per-account voicemail vibration.
3496 *
3497 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3498 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3499 *
3500 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3501 * voicemail vibration setting.
3502 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3503 * specific PhoneAccount.
3504 */
3505 @Override
3506 public void setVoicemailVibrationEnabled(String callingPackage,
3507 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3509 if (!TextUtils.equals(callingPackage,
3510 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3511 enforceModifyPermissionOrCarrierPrivilege(
3512 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3513 }
3514
3515 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3516 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003517 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003518 }
fionaxu7ed723d2017-05-30 18:58:54 -07003519 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003520 }
3521
3522 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003523 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3524 *
3525 * @throws SecurityException if the caller does not have the required permission
3526 */
3527 private void enforceReadPrivilegedPermission() {
3528 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3529 null);
3530 }
3531
3532 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003533 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3534 * permission.
3535 *
3536 * @throws SecurityException if the caller does not have the required permission
3537 */
3538 private void enforceSendSmsPermission() {
3539 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3540 }
3541
3542 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003543 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003544 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003545 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003546 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003547 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003548 ComponentName componentName =
3549 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3550 if(componentName == null) {
3551 throw new SecurityException("Caller not current active visual voicemail package[null]");
3552 }
3553 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003554 if (!callingPackage.equals(vvmPackage)) {
3555 throw new SecurityException("Caller not current active visual voicemail package[" +
3556 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003557 }
3558 }
3559
3560 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003561 * Return the application ID for the app type.
3562 *
3563 * @param subId the subscription ID that this request applies to.
3564 * @param appType the uicc app type.
3565 * @return Application ID for specificied app type, or null if no uicc.
3566 */
3567 @Override
3568 public String getAidForAppType(int subId, int appType) {
3569 enforceReadPrivilegedPermission();
3570 Phone phone = getPhone(subId);
3571 if (phone == null) {
3572 return null;
3573 }
3574 String aid = null;
3575 try {
3576 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3577 .getApplicationByType(appType).getAid();
3578 } catch (Exception e) {
3579 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3580 }
3581 return aid;
3582 }
3583
Youhan Wang4001d252016-05-11 10:29:41 -07003584 /**
3585 * Return the Electronic Serial Number.
3586 *
3587 * @param subId the subscription ID that this request applies to.
3588 * @return ESN or null if error.
3589 */
3590 @Override
3591 public String getEsn(int subId) {
3592 enforceReadPrivilegedPermission();
3593 Phone phone = getPhone(subId);
3594 if (phone == null) {
3595 return null;
3596 }
3597 String esn = null;
3598 try {
3599 esn = phone.getEsn();
3600 } catch (Exception e) {
3601 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3602 }
3603 return esn;
3604 }
3605
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003606 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003607 * Return the Preferred Roaming List Version.
3608 *
3609 * @param subId the subscription ID that this request applies to.
3610 * @return PRLVersion or null if error.
3611 */
3612 @Override
3613 public String getCdmaPrlVersion(int subId) {
3614 enforceReadPrivilegedPermission();
3615 Phone phone = getPhone(subId);
3616 if (phone == null) {
3617 return null;
3618 }
3619 String cdmaPrlVersion = null;
3620 try {
3621 cdmaPrlVersion = phone.getCdmaPrlVersion();
3622 } catch (Exception e) {
3623 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3624 }
3625 return cdmaPrlVersion;
3626 }
3627
3628 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003629 * Get snapshot of Telephony histograms
3630 * @return List of Telephony histograms
3631 * @hide
3632 */
3633 @Override
3634 public List<TelephonyHistogram> getTelephonyHistograms() {
3635 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3636 return RIL.getTelephonyRILTimingHistograms();
3637 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003638
3639 /**
3640 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003641 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003642 * Require system privileges. In the future we may add this to carrier APIs.
3643 *
3644 * @return The number of carriers set successfully, should match length of carriers
3645 */
3646 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003647 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003648 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003649
Meng Wang9b7c4e92017-02-17 11:41:27 -08003650 if (carriers == null) {
3651 throw new NullPointerException("carriers cannot be null");
3652 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003653
3654 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003655 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3656 return retVal[0];
3657 }
3658
3659 /**
3660 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003661 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003662 * Require system privileges. In the future we may add this to carrier APIs.
3663 *
3664 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3665 * means all carriers are allowed.
3666 */
3667 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003668 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003669 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003670 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003671 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3672 }
3673
fionaxu59545b42016-05-25 15:53:37 -07003674 /**
3675 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3676 * @param subId the subscription ID that this action applies to.
3677 * @param enabled control enable or disable metered apns.
3678 * {@hide}
3679 */
3680 @Override
3681 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3682 enforceModifyPermission();
3683 final Phone phone = getPhone(subId);
3684 if (phone == null) {
3685 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3686 return;
3687 }
3688 try {
3689 phone.carrierActionSetMeteredApnsEnabled(enabled);
3690 } catch (Exception e) {
3691 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3692 }
3693 }
3694
3695 /**
3696 * Action set from carrier signalling broadcast receivers to enable/disable radio
3697 * @param subId the subscription ID that this action applies to.
3698 * @param enabled control enable or disable radio.
3699 * {@hide}
3700 */
3701 @Override
3702 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3703 enforceModifyPermission();
3704 final Phone phone = getPhone(subId);
3705 if (phone == null) {
3706 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3707 return;
3708 }
3709 try {
3710 phone.carrierActionSetRadioEnabled(enabled);
3711 } catch (Exception e) {
3712 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3713 }
3714 }
3715
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003716 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003717 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3718 * network status based on which carrier apps could apply actions accordingly,
3719 * enable/disable default url handler for example.
3720 *
3721 * @param subId the subscription ID that this action applies to.
3722 * @param report control start/stop reporting the default network status.
3723 * {@hide}
3724 */
3725 @Override
3726 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3727 enforceModifyPermission();
3728 final Phone phone = getPhone(subId);
3729 if (phone == null) {
3730 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3731 return;
3732 }
3733 try {
3734 phone.carrierActionReportDefaultNetworkStatus(report);
3735 } catch (Exception e) {
3736 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3737 }
3738 }
3739
3740 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003741 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3742 * bug report is being generated.
3743 */
3744 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003745 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003746 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3747 != PackageManager.PERMISSION_GRANTED) {
3748 writer.println("Permission Denial: can't dump Phone from pid="
3749 + Binder.getCallingPid()
3750 + ", uid=" + Binder.getCallingUid()
3751 + "without permission "
3752 + android.Manifest.permission.DUMP);
3753 return;
3754 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003755 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003756 }
Jack Yueb89b242016-06-22 13:27:47 -07003757
3758 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003759 * Get aggregated video call data usage since boot.
3760 *
3761 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3762 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003763 * {@hide}
3764 */
3765 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003766 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003767 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3768 null);
3769
Jack Yu84291ec2017-05-26 16:07:50 -07003770 // NetworkStatsService keeps tracking the active network interface and identity. It
3771 // records the delta with the corresponding network identity. We just return the total video
3772 // call data usage snapshot since boot.
3773 Phone phone = getPhone(subId);
3774 if (phone != null) {
3775 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003776 }
Jack Yu84291ec2017-05-26 16:07:50 -07003777 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003778 }
Jack Yu75ab2952016-07-08 14:29:33 -07003779
3780 /**
3781 * Policy control of data connection. Usually used when data limit is passed.
3782 * @param enabled True if enabling the data, otherwise disabling.
3783 * @param subId Subscription index
3784 * {@hide}
3785 */
3786 @Override
3787 public void setPolicyDataEnabled(boolean enabled, int subId) {
3788 enforceModifyPermission();
3789 Phone phone = getPhone(subId);
3790 if (phone != null) {
3791 phone.setPolicyDataEnabled(enabled);
3792 }
3793 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003794
3795 /**
3796 * Get Client request stats
3797 * @return List of Client Request Stats
3798 * @hide
3799 */
3800 @Override
3801 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3802 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3803 return null;
3804 }
3805
3806 Phone phone = getPhone(subId);
3807 if (phone != null) {
3808 return phone.getClientRequestStats();
3809 }
3810
3811 return null;
3812 }
3813
3814 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3815 if (workSource != null) {
3816 return workSource;
3817 }
3818
3819 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3820 workSource = new WorkSource(uid, packageName);
3821 return workSource;
3822 }
Jack Yueb4124c2017-02-16 15:32:43 -08003823
3824 /**
Grace Chen70990072017-03-24 17:21:30 -07003825 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003826 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003827 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003828 * @param state State of SIM (power down, power up, pass through)
3829 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3830 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3831 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003832 *
3833 **/
3834 @Override
Grace Chen70990072017-03-24 17:21:30 -07003835 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003836 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003837 Phone phone = PhoneFactory.getPhone(slotIndex);
3838
Jack Yueb4124c2017-02-16 15:32:43 -08003839 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003840 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003841 }
3842 }
Shuo Qiandd210312017-04-12 22:11:33 +00003843
Tyler Gunn65d45c22017-06-05 11:22:26 -07003844 private boolean isUssdApiAllowed(int subId) {
3845 CarrierConfigManager configManager =
3846 (CarrierConfigManager) mPhone.getContext().getSystemService(
3847 Context.CARRIER_CONFIG_SERVICE);
3848 if (configManager == null) {
3849 return false;
3850 }
3851 PersistableBundle pb = configManager.getConfigForSubId(subId);
3852 if (pb == null) {
3853 return false;
3854 }
3855 return pb.getBoolean(
3856 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3857 }
3858
Shuo Qiandd210312017-04-12 22:11:33 +00003859 /**
3860 * Check if phone is in emergency callback mode
3861 * @return true if phone is in emergency callback mode
3862 * @param subId sub id
3863 */
3864 public boolean getEmergencyCallbackMode(int subId) {
3865 final Phone phone = getPhone(subId);
3866 if (phone != null) {
3867 return phone.isInEcm();
3868 } else {
3869 return false;
3870 }
3871 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003872
3873 /**
3874 * Get the current signal strength information for the given subscription.
3875 * Because this information is not updated when the device is in a low power state
3876 * it should not be relied-upon to be current.
3877 * @param subId Subscription index
3878 * @return the most recent cached signal strength info from the modem
3879 */
3880 @Override
3881 public SignalStrength getSignalStrength(int subId) {
3882 Phone p = getPhone(subId);
3883 if (p == null) {
3884 return null;
3885 }
3886
3887 return p.getSignalStrength();
3888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003889}