blob: f0d59294b7c87b45a9f496314aac282d14a6bd9a [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 Ebinger34bef922017-11-09 10:27:08 -080042import android.os.Process;
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;
Hall Liubefa7332017-11-22 17:40:08 -080058import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070059import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080060import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070061import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070062import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080065import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070066import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080067import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070069import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070071import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080076import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080077import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080078
Andrew Lee312e8172014-10-23 17:01:36 -070079import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080080import com.android.ims.internal.IImsMMTelFeature;
81import com.android.ims.internal.IImsRcsFeature;
82import 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) {
Hall Liubefa7332017-11-22 17:40:08 -08001628 mPhone.getContext().getSystemService(AppOpsManager.class)
1629 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001630 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liubefa7332017-11-22 17:40:08 -08001631 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001632 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 }
1634
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001635 if (DBG_LOC) log("getCellLocation: is active user");
1636 Bundle data = new Bundle();
1637 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1638 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 return null;
1640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001642 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1643 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1644 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001645 }
1646
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001648 public String getNetworkCountryIsoForPhone(int phoneId) {
1649 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1650 // registered cell info, so return a NULL country instead.
1651 final long identity = Binder.clearCallingIdentity();
1652 try {
1653 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1654 if (TelephonyManager.NETWORK_TYPE_IWLAN
1655 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1656 return "";
1657 }
1658 } finally {
1659 Binder.restoreCallingIdentity(identity);
1660 }
1661 return TelephonyManager.getTelephonyProperty(
1662 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1663 }
1664
1665 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001667 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001668 }
1669
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001671 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 mApp.enforceCallingOrSelfPermission(
1673 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001674 final Phone phone = getPhone(subId);
1675 if (phone != null) {
1676 phone.enableLocationUpdates();
1677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 }
1679
1680 @Override
1681 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001682 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001683 }
1684
Sanket Padawe356d7632015-06-22 14:03:32 -07001685 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001686 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 mApp.enforceCallingOrSelfPermission(
1688 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 final Phone phone = getPhone(subId);
1690 if (phone != null) {
1691 phone.disableLocationUpdates();
1692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 }
1694
1695 @Override
1696 @SuppressWarnings("unchecked")
1697 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liubefa7332017-11-22 17:40:08 -08001698 mPhone.getContext().getSystemService(AppOpsManager.class)
1699 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001700 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liubefa7332017-11-22 17:40:08 -08001701 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001702 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
1705 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1706 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1707 return null;
1708 }
Svetoslav64fad262015-04-14 14:35:21 -07001709
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001710 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001712 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001714 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1715 try {
1716 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1717 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1718 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1719 } catch (RuntimeException e) {
1720 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001722 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 }
1724
1725
1726 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001727 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liubefa7332017-11-22 17:40:08 -08001728 mPhone.getContext().getSystemService(AppOpsManager.class)
1729 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001730 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liubefa7332017-11-22 17:40:08 -08001731 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001732 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 }
1734
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001735 if (DBG_LOC) log("getAllCellInfo: is active user");
1736 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1737 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1738 for (Phone phone : PhoneFactory.getPhones()) {
1739 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1740 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001742 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
1744
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001745 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001747 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001748 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1749 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
1751
Shishir Agrawala9f32182016-04-12 12:00:16 -07001752 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001753 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001754 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1755 return null;
1756 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001757 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001758 return phone == null ? null : phone.getImei();
1759 }
1760
1761 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001762 public String getMeidForSlot(int slotIndex, String callingPackage) {
1763 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1764 return null;
1765 }
1766 Phone phone = PhoneFactory.getPhone(slotIndex);
1767 return phone == null ? null : phone.getMeid();
1768 }
1769
1770 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001771 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001772 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1773 return null;
1774 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001775 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001776 return phone == null ? null : phone.getDeviceSvn();
1777 }
1778
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 //
1780 // Internal helper methods.
1781 //
1782
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001783 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1785 *
1786 * @throws SecurityException if the caller does not have the required permission
1787 */
1788 private void enforceModifyPermission() {
1789 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1790 }
1791
1792 /**
Junda Liua2e36012014-07-09 18:30:01 -07001793 * Make sure either system app or the caller has carrier privilege.
1794 *
1795 * @throws SecurityException if the caller does not have the required permission/privilege
1796 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001797 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001798 int permission = mApp.checkCallingOrSelfPermission(
1799 android.Manifest.permission.MODIFY_PHONE_STATE);
1800 if (permission == PackageManager.PERMISSION_GRANTED) {
1801 return;
1802 }
1803
1804 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001805 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001806 }
1807
1808 /**
1809 * Make sure the caller has carrier privilege.
1810 *
1811 * @throws SecurityException if the caller does not have the required permission
1812 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001813 private void enforceCarrierPrivilege(int subId) {
1814 if (getCarrierPrivilegeStatus(subId) !=
1815 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001816 loge("No Carrier Privilege.");
1817 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001818 }
1819 }
1820
1821 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 * Make sure the caller has the CALL_PHONE permission.
1823 *
1824 * @throws SecurityException if the caller does not have the required permission
1825 */
1826 private void enforceCallPermission() {
1827 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1828 }
1829
Stuart Scott8eef64f2015-04-08 15:13:54 -07001830 private void enforceConnectivityInternalPermission() {
1831 mApp.enforceCallingOrSelfPermission(
1832 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1833 "ConnectivityService");
1834 }
1835
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 private String createTelUrl(String number) {
1837 if (TextUtils.isEmpty(number)) {
1838 return null;
1839 }
1840
Jake Hambye994d462014-02-03 13:10:13 -08001841 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 }
1843
Ihab Awadf9e92732013-12-05 18:02:52 -08001844 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1846 }
1847
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001848 private static void logv(String msg) {
1849 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1850 }
1851
Ihab Awadf9e92732013-12-05 18:02:52 -08001852 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1854 }
1855
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001856 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001858 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001859 }
1860
Sanket Padawe356d7632015-06-22 14:03:32 -07001861 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001862 public int getActivePhoneTypeForSlot(int slotIndex) {
1863 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 if (phone == null) {
1865 return PhoneConstants.PHONE_TYPE_NONE;
1866 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001867 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 }
1870
1871 /**
1872 * Returns the CDMA ERI icon index to display
1873 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001874 @Override
1875 public int getCdmaEriIconIndex(String callingPackage) {
1876 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001877 }
1878
Sanket Padawe356d7632015-06-22 14:03:32 -07001879 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001880 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1881 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1882 return -1;
1883 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 final Phone phone = getPhone(subId);
1885 if (phone != null) {
1886 return phone.getCdmaEriIconIndex();
1887 } else {
1888 return -1;
1889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
1892 /**
1893 * Returns the CDMA ERI icon mode,
1894 * 0 - ON
1895 * 1 - FLASHING
1896 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001897 @Override
1898 public int getCdmaEriIconMode(String callingPackage) {
1899 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001900 }
1901
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001903 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1904 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1905 return -1;
1906 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 final Phone phone = getPhone(subId);
1908 if (phone != null) {
1909 return phone.getCdmaEriIconMode();
1910 } else {
1911 return -1;
1912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
1915 /**
1916 * Returns the CDMA ERI text,
1917 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001918 @Override
1919 public String getCdmaEriText(String callingPackage) {
1920 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001921 }
1922
Sanket Padawe356d7632015-06-22 14:03:32 -07001923 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001924 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1925 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1926 return null;
1927 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001928 final Phone phone = getPhone(subId);
1929 if (phone != null) {
1930 return phone.getCdmaEriText();
1931 } else {
1932 return null;
1933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 }
1935
1936 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001937 * Returns the CDMA MDN.
1938 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001939 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001940 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001941 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 final Phone phone = getPhone(subId);
1943 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1944 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001945 } else {
1946 return null;
1947 }
1948 }
1949
1950 /**
1951 * Returns the CDMA MIN.
1952 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001953 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001954 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001955 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001956 final Phone phone = getPhone(subId);
1957 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1958 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001959 } else {
1960 return null;
1961 }
1962 }
1963
1964 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965 * Returns true if CDMA provisioning needs to run.
1966 */
1967 public boolean needsOtaServiceProvisioning() {
1968 return mPhone.needsOtaServiceProvisioning();
1969 }
1970
1971 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001972 * Sets the voice mail number of a given subId.
1973 */
1974 @Override
1975 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001976 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001977 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1978 new Pair<String, String>(alphaTag, number), new Integer(subId));
1979 return success;
1980 }
1981
Ta-wei Yen87c49842016-05-13 21:19:52 -07001982 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07001983 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
1984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1985 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
1986 if (!TextUtils.equals(callingPackage, systemDialer)) {
1987 throw new SecurityException("caller must be system dialer");
1988 }
1989 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
1990 if (phoneAccountHandle == null){
1991 return null;
1992 }
1993 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
1994 }
1995
1996 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08001997 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08001998 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1999 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2000 return null;
2001 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002002 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2003 }
2004
2005 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002006 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2007 VisualVoicemailSmsFilterSettings settings) {
2008 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002009 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002010 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2011 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002012 }
2013
2014 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002015 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002017 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002018 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002019 }
2020
2021 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002022 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2023 String callingPackage, int subId) {
2024 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002025 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002026 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002027 }
2028
2029 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002030 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002031 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002032 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002033 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2034 }
2035
2036 @Override
2037 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2038 String number, int port, String text, PendingIntent sentIntent) {
2039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002040 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002041 enforceSendSmsPermission();
2042 // Make the calls as the phone process.
2043 final long identity = Binder.clearCallingIdentity();
2044 try {
2045 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2046 if (port == 0) {
2047 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2048 sentIntent, null, false);
2049 } else {
2050 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2051 smsManager.sendDataMessageWithSelfPermissions(number, null,
2052 (short) port, data, sentIntent, null);
2053 }
2054 } finally {
2055 Binder.restoreCallingIdentity(identity);
2056 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002057 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002058 /**
fionaxu0152e512016-11-14 13:36:14 -08002059 * Sets the voice activation state of a given subId.
2060 */
2061 @Override
2062 public void setVoiceActivationState(int subId, int activationState) {
2063 enforceModifyPermissionOrCarrierPrivilege(subId);
2064 final Phone phone = getPhone(subId);
2065 if (phone != null) {
2066 phone.setVoiceActivationState(activationState);
2067 } else {
2068 loge("setVoiceActivationState fails with invalid subId: " + subId);
2069 }
2070 }
2071
2072 /**
2073 * Sets the data activation state of a given subId.
2074 */
2075 @Override
2076 public void setDataActivationState(int subId, int activationState) {
2077 enforceModifyPermissionOrCarrierPrivilege(subId);
2078 final Phone phone = getPhone(subId);
2079 if (phone != null) {
2080 phone.setDataActivationState(activationState);
2081 } else {
2082 loge("setVoiceActivationState fails with invalid subId: " + subId);
2083 }
2084 }
2085
2086 /**
2087 * Returns the voice activation state of a given subId.
2088 */
2089 @Override
2090 public int getVoiceActivationState(int subId, String callingPackage) {
2091 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2092 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2093 }
2094 final Phone phone = getPhone(subId);
2095 if (phone != null) {
2096 return phone.getVoiceActivationState();
2097 } else {
2098 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2099 }
2100 }
2101
2102 /**
2103 * Returns the data activation state of a given subId.
2104 */
2105 @Override
2106 public int getDataActivationState(int subId, String callingPackage) {
2107 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2108 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2109 }
2110 final Phone phone = getPhone(subId);
2111 if (phone != null) {
2112 return phone.getDataActivationState();
2113 } else {
2114 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2115 }
2116 }
2117
2118 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 * Returns the unread count of voicemails
2120 */
2121 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002122 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002123 }
2124
2125 /**
2126 * Returns the unread count of voicemails for a subId
2127 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002128 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002129 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002130 final Phone phone = getPhone(subId);
2131 if (phone != null) {
2132 return phone.getVoiceMessageCount();
2133 } else {
2134 return 0;
2135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 }
2137
2138 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002139 * returns true, if the device is in a state where both voice and data
2140 * are supported simultaneously. This can change based on location or network condition.
2141 */
2142 @Override
2143 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2144 final Phone phone = getPhone(subId);
2145 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2146 }
2147
2148 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002149 * Send the dialer code if called from the current default dialer or the caller has
2150 * carrier privilege.
2151 * @param inputCode The dialer code to send
2152 */
2153 @Override
2154 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2155 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2156 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2157 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2158 enforceCarrierPrivilege(getDefaultSubscription());
2159 }
2160 mPhone.sendDialerSpecialCode(inputCode);
2161 }
2162
2163 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002164 * Returns the data network type.
2165 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 *
2167 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2168 */
2169 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002170 public int getNetworkType() {
2171 final Phone phone = getPhone(getDefaultSubscription());
2172 if (phone != null) {
2173 return phone.getServiceState().getDataNetworkType();
2174 } else {
2175 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2176 }
Wink Saville36469e72014-06-11 15:17:00 -07002177 }
2178
2179 /**
2180 * Returns the network type for a subId
2181 */
2182 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002183 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2184 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2185 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2186 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002187
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002189 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002190 return phone.getServiceState().getDataNetworkType();
2191 } else {
2192 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 }
2195
2196 /**
2197 * Returns the data network type
2198 */
2199 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002200 public int getDataNetworkType(String callingPackage) {
2201 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002202 }
2203
2204 /**
2205 * Returns the data network type for a subId
2206 */
2207 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002208 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2209 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2210 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2211 }
2212
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 final Phone phone = getPhone(subId);
2214 if (phone != null) {
2215 return phone.getServiceState().getDataNetworkType();
2216 } else {
2217 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220
2221 /**
Wink Saville36469e72014-06-11 15:17:00 -07002222 * Returns the Voice network type for a subId
2223 */
2224 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002225 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2226 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2227 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2228 }
2229
Sanket Padawe356d7632015-06-22 14:03:32 -07002230 final Phone phone = getPhone(subId);
2231 if (phone != null) {
2232 return phone.getServiceState().getVoiceNetworkType();
2233 } else {
2234 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 }
2237
2238 /**
2239 * @return true if a ICC card is present
2240 */
2241 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002242 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002243 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2244 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002245 }
2246
2247 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002248 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002249 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002251 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2252 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002253 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002254 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002255 } else {
2256 return false;
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259
2260 /**
2261 * Return if the current radio is LTE on CDMA. This
2262 * is a tri-state return value as for a period of time
2263 * the mode may be unknown.
2264 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002265 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002267 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002269 @Override
2270 public int getLteOnCdmaMode(String callingPackage) {
2271 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002272 }
2273
Sanket Padawe356d7632015-06-22 14:03:32 -07002274 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002275 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2276 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2277 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2278 }
2279
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 final Phone phone = getPhone(subId);
2281 if (phone == null) {
2282 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2283 } else {
2284 return phone.getLteOnCdmaMode();
2285 }
Wink Saville36469e72014-06-11 15:17:00 -07002286 }
2287
2288 public void setPhone(Phone phone) {
2289 mPhone = phone;
2290 }
2291
2292 /**
2293 * {@hide}
2294 * Returns Default subId, 0 in the case of single standby.
2295 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002296 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002297 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002298 }
2299
Shishir Agrawala9f32182016-04-12 12:00:16 -07002300 private int getSlotForDefaultSubscription() {
2301 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2302 }
2303
Wink Savilleb564aae2014-10-23 10:18:09 -07002304 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002305 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002307
2308 /**
2309 * @see android.telephony.TelephonyManager.WifiCallingChoices
2310 */
2311 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002312 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2313 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002314 }
2315
2316 /**
2317 * @see android.telephony.TelephonyManager.WifiCallingChoices
2318 */
2319 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002320 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2321 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2322 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002323 }
2324
Sailesh Nepald1e68152013-12-12 19:08:02 -08002325 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002326 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002327 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002328 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002329
Shishir Agrawal566b7612013-10-28 14:41:00 -07002330 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002331 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2332 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002333 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002334
Derek Tan740e1672017-06-27 14:56:27 -07002335 if (TextUtils.equals(ISDR_AID, aid)) {
2336 // Only allows LPA to open logical channel to ISD-R.
2337 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2338 ComponentInfo bestComponent =
2339 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2340 if (bestComponent == null
2341 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2342 loge("The calling package is not allowed to access ISD-R.");
2343 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2344 }
2345 }
2346
2347 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002348 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002349 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002350 if (DBG) log("iccOpenLogicalChannel: " + response);
2351 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002352 }
2353
2354 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002355 public boolean iccCloseLogicalChannel(int subId, int channel) {
2356 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002357
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002358 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002359 if (channel < 0) {
2360 return false;
2361 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002362 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002363 if (DBG) log("iccCloseLogicalChannel: " + success);
2364 return success;
2365 }
2366
2367 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002368 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002369 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002370 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002371
2372 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002373 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2374 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002375 " data=" + data);
2376 }
2377
2378 if (channel < 0) {
2379 return "";
2380 }
2381
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002382 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002383 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002384 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2385
Shishir Agrawal566b7612013-10-28 14:41:00 -07002386 // Append the returned status code to the end of the response payload.
2387 String s = Integer.toHexString(
2388 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002389 if (response.payload != null) {
2390 s = IccUtils.bytesToHexString(response.payload) + s;
2391 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002392 return s;
2393 }
Jake Hambye994d462014-02-03 13:10:13 -08002394
Evan Charltonc66da362014-05-16 14:06:40 -07002395 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002396 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002397 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002398 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002399
2400 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002401 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2402 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002403 }
2404
2405 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002406 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002407 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2408
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002409 // Append the returned status code to the end of the response payload.
2410 String s = Integer.toHexString(
2411 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002412 if (response.payload != null) {
2413 s = IccUtils.bytesToHexString(response.payload) + s;
2414 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002415 return s;
2416 }
2417
2418 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002419 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002420 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002421 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002422
2423 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002425 p1 + " " + p2 + " " + p3 + ":" + filePath);
2426 }
2427
2428 IccIoResult response =
2429 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002430 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2431 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002432
2433 if (DBG) {
2434 log("Exchange SIM_IO [R]" + response);
2435 }
2436
2437 byte[] result = null;
2438 int length = 2;
2439 if (response.payload != null) {
2440 length = 2 + response.payload.length;
2441 result = new byte[length];
2442 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2443 } else {
2444 result = new byte[length];
2445 }
2446
2447 result[length - 1] = (byte) response.sw2;
2448 result[length - 2] = (byte) response.sw1;
2449 return result;
2450 }
2451
Nathan Haroldb3014052017-01-25 15:57:32 -08002452 /**
2453 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2454 * on a particular subscription
2455 */
2456 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002457 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2458 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002459 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2460 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2461 return null;
2462 }
2463 Object response = sendRequest(
2464 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2465 if (response instanceof String[]) {
2466 return (String[]) response;
2467 }
2468 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2469 return null;
2470 }
2471
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002472 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002473 public String sendEnvelopeWithStatus(int subId, String content) {
2474 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002475
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002476 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002477 if (response.payload == null) {
2478 return "";
2479 }
2480
2481 // Append the returned status code to the end of the response payload.
2482 String s = Integer.toHexString(
2483 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2484 s = IccUtils.bytesToHexString(response.payload) + s;
2485 return s;
2486 }
2487
Jake Hambye994d462014-02-03 13:10:13 -08002488 /**
2489 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2490 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2491 *
2492 * @param itemID the ID of the item to read
2493 * @return the NV item as a String, or null on error.
2494 */
2495 @Override
2496 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002497 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002498 if (DBG) log("nvReadItem: item " + itemID);
2499 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2500 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2501 return value;
2502 }
2503
2504 /**
2505 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2506 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2507 *
2508 * @param itemID the ID of the item to read
2509 * @param itemValue the value to write, as a String
2510 * @return true on success; false on any failure
2511 */
2512 @Override
2513 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002514 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002515 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2516 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2517 new Pair<Integer, String>(itemID, itemValue));
2518 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2519 return success;
2520 }
2521
2522 /**
2523 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2524 * Used for device configuration by some CDMA operators.
2525 *
2526 * @param preferredRoamingList byte array containing the new PRL
2527 * @return true on success; false on any failure
2528 */
2529 @Override
2530 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002531 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002532 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2533 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2534 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2535 return success;
2536 }
2537
2538 /**
2539 * Perform the specified type of NV config reset.
2540 * Used for device configuration by some CDMA operators.
2541 *
2542 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2543 * @return true on success; false on any failure
2544 */
2545 @Override
2546 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002547 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002548 if (DBG) log("nvResetConfig: type " + resetType);
2549 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2550 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2551 return success;
2552 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002553
2554 /**
Wink Saville36469e72014-06-11 15:17:00 -07002555 * {@hide}
2556 * Returns Default sim, 0 in the case of single standby.
2557 */
2558 public int getDefaultSim() {
2559 //TODO Need to get it from Telephony Devcontroller
2560 return 0;
2561 }
2562
Svet Ganovb320e182015-04-16 12:30:10 -07002563 public String[] getPcscfAddress(String apnType, String callingPackage) {
2564 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2565 return new String[0];
2566 }
2567
2568
ram87fca6f2014-07-18 18:58:44 +05302569 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002570 }
2571
Brad Ebinger51f743a2017-01-23 13:50:20 -08002572 /**
Brad Ebinger34bef922017-11-09 10:27:08 -08002573 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2574 * feature or {@link null} if the service is not available. If the feature is available, the
2575 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002576 */
Brad Ebinger34bef922017-11-09 10:27:08 -08002577 public IImsMMTelFeature getMMTelFeatureAndListen(int slotId,
2578 IImsServiceFeatureCallback callback) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002579 enforceModifyPermission();
Brad Ebinger34bef922017-11-09 10:27:08 -08002580 return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback);
2581 }
2582
2583 /**
2584 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2585 * feature during emergency calling or {@link null} if the service is not available. If the
2586 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2587 * listener for feature updates.
2588 */
2589 public IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId,
2590 IImsServiceFeatureCallback callback) {
2591 enforceModifyPermission();
2592 return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback);
2593 }
2594
2595 /**
2596 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2597 * feature during emergency calling or {@link null} if the service is not available. If the
2598 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2599 * listener for feature updates.
2600 */
2601 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2602 enforceModifyPermission();
2603 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002604 }
2605
Wink Saville36469e72014-06-11 15:17:00 -07002606 public void setImsRegistrationState(boolean registered) {
2607 enforceModifyPermission();
2608 mPhone.setImsRegistrationState(registered);
2609 }
2610
2611 /**
Stuart Scott54788802015-03-30 13:18:01 -07002612 * Set the network selection mode to automatic.
2613 *
2614 */
2615 @Override
2616 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002617 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002618 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2619 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2620 }
2621
2622 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002623 * Set the network selection mode to manual with the selected carrier.
2624 */
2625 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002626 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2627 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002628 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002629 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002630 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2631 persistSelection);
2632 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002633 }
2634
2635 /**
2636 * Scans for available networks.
2637 */
2638 @Override
2639 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002640 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002641 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2642 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2643 CMD_PERFORM_NETWORK_SCAN, null, subId);
2644 return result;
2645 }
2646
2647 /**
yinxub1bed742017-04-17 11:45:04 -07002648 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002649 *
yinxub1bed742017-04-17 11:45:04 -07002650 * @param subId id of the subscription
2651 * @param request contains the radio access networks with bands/channels to scan
2652 * @param messenger callback messenger for scan results or errors
2653 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002654 * @return the id of the requested scan which can be used to stop the scan.
2655 */
2656 @Override
2657 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2658 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002659 enforceModifyPermissionOrCarrierPrivilege(subId);
2660 return mNetworkScanRequestTracker.startNetworkScan(
2661 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002662 }
2663
2664 /**
2665 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002666 *
2667 * @param subId id of the subscription
2668 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002669 */
2670 @Override
2671 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002672 enforceModifyPermissionOrCarrierPrivilege(subId);
2673 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002674 }
2675
2676 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002677 * Get the calculated preferred network type.
2678 * Used for debugging incorrect network type.
2679 *
2680 * @return the preferred network type, defined in RILConstants.java.
2681 */
2682 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002683 public int getCalculatedPreferredNetworkType(String callingPackage) {
2684 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2685 return RILConstants.PREFERRED_NETWORK_MODE;
2686 }
2687
Amit Mahajan43330e02014-11-18 11:54:45 -08002688 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002689 }
2690
2691 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002692 * Get the preferred network type.
2693 * Used for device configuration by some CDMA operators.
2694 *
2695 * @return the preferred network type, defined in RILConstants.java.
2696 */
2697 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002698 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002699 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002700 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002701 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002702 int networkType = (result != null ? result[0] : -1);
2703 if (DBG) log("getPreferredNetworkType: " + networkType);
2704 return networkType;
2705 }
2706
2707 /**
2708 * Set the preferred network type.
2709 * Used for device configuration by some CDMA operators.
2710 *
2711 * @param networkType the preferred network type, defined in RILConstants.java.
2712 * @return true on success; false on any failure.
2713 */
2714 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002715 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002716 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002717 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2718 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002719 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002720 if (success) {
2721 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002722 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002723 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002724 return success;
2725 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002726
2727 /**
Junda Liu475951f2014-11-07 16:45:03 -08002728 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2729 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2730 * tethering.
2731 *
2732 * @return 0: Not required. 1: required. 2: Not set.
2733 * @hide
2734 */
2735 @Override
2736 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002737 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002738 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2739 Settings.Global.TETHER_DUN_REQUIRED, 2);
2740 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2741 // config_tether_apndata.
2742 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2743 dunRequired = 1;
2744 }
2745 return dunRequired;
2746 }
2747
2748 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002749 * Set mobile data enabled
2750 * Used by the user through settings etc to turn on/off mobile data
2751 *
2752 * @param enable {@code true} turn turn data on, else {@code false}
2753 */
2754 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002755 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002756 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002757 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002758 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002759 Phone phone = PhoneFactory.getPhone(phoneId);
2760 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002761 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002762 phone.setDataEnabled(enable);
2763 } else {
2764 loge("setDataEnabled: no phone for subId=" + subId);
2765 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002766 }
2767
2768 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002769 * Get whether mobile data is enabled.
2770 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002771 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002772 *
2773 * @return {@code true} if data is enabled else {@code false}
2774 */
2775 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002776 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002777 try {
2778 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2779 null);
2780 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002781 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002782 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002783 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002784 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002785 Phone phone = PhoneFactory.getPhone(phoneId);
2786 if (phone != null) {
2787 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002788 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002789 return retVal;
2790 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002791 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002792 return false;
2793 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002794 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002795
2796 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002797 public int getCarrierPrivilegeStatus(int subId) {
2798 final Phone phone = getPhone(subId);
2799 if (phone == null) {
2800 loge("getCarrierPrivilegeStatus: Invalid subId");
2801 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2802 }
2803 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002804 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002805 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002806 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2807 }
2808 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002809 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002810 }
Junda Liu29340342014-07-10 15:23:27 -07002811
2812 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002813 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002814 if (TextUtils.isEmpty(pkgName))
2815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002816 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002817 if (card == null) {
2818 loge("checkCarrierPrivilegesForPackage: No UICC");
2819 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2820 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002821 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2822 }
2823
2824 @Override
2825 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002826 if (TextUtils.isEmpty(pkgName))
2827 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002828 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2829 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2830 UiccCard card = UiccController.getInstance().getUiccCard(i);
2831 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002832 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002833 continue;
2834 }
2835
2836 result = card.getCarrierPrivilegeStatus(
2837 mPhone.getContext().getPackageManager(), pkgName);
2838 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2839 break;
2840 }
2841 }
2842
2843 return result;
Junda Liu29340342014-07-10 15:23:27 -07002844 }
Derek Tan89e89d42014-07-08 17:00:10 -07002845
2846 @Override
Junda Liue64de782015-04-16 17:19:16 -07002847 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2848 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2849 loge("phoneId " + phoneId + " is not valid.");
2850 return null;
2851 }
2852 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002853 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002854 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002855 return null ;
2856 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002857 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002858 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002859 }
2860
Amith Yamasani6e118872016-02-19 12:53:51 -08002861 @Override
2862 public List<String> getPackagesWithCarrierPrivileges() {
2863 PackageManager pm = mPhone.getContext().getPackageManager();
2864 List<String> privilegedPackages = new ArrayList<>();
2865 List<PackageInfo> packages = null;
2866 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2867 UiccCard card = UiccController.getInstance().getUiccCard(i);
2868 if (card == null) {
2869 // No UICC in that slot.
2870 continue;
2871 }
2872 if (card.hasCarrierPrivilegeRules()) {
2873 if (packages == null) {
2874 // Only check packages in user 0 for now
2875 packages = pm.getInstalledPackagesAsUser(
2876 PackageManager.MATCH_DISABLED_COMPONENTS
2877 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2878 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2879 }
2880 for (int p = packages.size() - 1; p >= 0; p--) {
2881 PackageInfo pkgInfo = packages.get(p);
2882 if (pkgInfo != null && pkgInfo.packageName != null
2883 && card.getCarrierPrivilegeStatus(pkgInfo)
2884 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2885 privilegedPackages.add(pkgInfo.packageName);
2886 }
2887 }
2888 }
2889 }
2890 return privilegedPackages;
2891 }
2892
Wink Savilleb564aae2014-10-23 10:18:09 -07002893 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002894 final Phone phone = getPhone(subId);
2895 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002896 if (card == null) {
2897 loge("getIccId: No UICC");
2898 return null;
2899 }
2900 String iccId = card.getIccId();
2901 if (TextUtils.isEmpty(iccId)) {
2902 loge("getIccId: ICC ID is null or empty.");
2903 return null;
2904 }
2905 return iccId;
2906 }
2907
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002908 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002909 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2910 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002911 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002912
Jeff Sharkey85190e62014-12-05 09:40:12 -08002913 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002914 final Phone phone = getPhone(subId);
2915 if (phone == null) {
2916 return false;
2917 }
2918 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002919
2920 if (DBG_MERGE) {
2921 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2922 + subscriberId + " to " + number);
2923 }
2924
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002925 if (TextUtils.isEmpty(iccId)) {
2926 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002927 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002928
Jeff Sharkey85190e62014-12-05 09:40:12 -08002929 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2930
2931 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002932 if (alphaTag == null) {
2933 editor.remove(alphaTagPrefKey);
2934 } else {
2935 editor.putString(alphaTagPrefKey, alphaTag);
2936 }
2937
Jeff Sharkey85190e62014-12-05 09:40:12 -08002938 // Record both the line number and IMSI for this ICCID, since we need to
2939 // track all merged IMSIs based on line number
2940 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2941 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002942 if (number == null) {
2943 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002944 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002945 } else {
2946 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002947 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002948 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002949
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002950 editor.commit();
2951 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002952 }
2953
2954 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002955 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002956 // This is open to apps with WRITE_SMS.
2957 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002958 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002959 return null;
2960 }
Derek Tan97ebb422014-09-05 16:55:38 -07002961
2962 String iccId = getIccId(subId);
2963 if (iccId != null) {
2964 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002965 if (DBG_MERGE) {
2966 log("getLine1NumberForDisplay returning " +
2967 mTelephonySharedPreferences.getString(numberPrefKey, null));
2968 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002969 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002970 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002971 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002972 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002973 }
2974
2975 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002976 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2977 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2978 return null;
2979 }
Derek Tan97ebb422014-09-05 16:55:38 -07002980
2981 String iccId = getIccId(subId);
2982 if (iccId != null) {
2983 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002984 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002985 }
Derek Tan97ebb422014-09-05 16:55:38 -07002986 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002987 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002988
2989 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002990 public String[] getMergedSubscriberIds(String callingPackage) {
2991 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2992 return null;
2993 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002994 final Context context = mPhone.getContext();
2995 final TelephonyManager tele = TelephonyManager.from(context);
2996 final SubscriptionManager sub = SubscriptionManager.from(context);
2997
2998 // Figure out what subscribers are currently active
2999 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003000 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3001 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 final int[] subIds = sub.getActiveSubscriptionIdList();
3005 for (int subId : subIds) {
3006 activeSubscriberIds.add(tele.getSubscriberId(subId));
3007 }
3008 } finally {
3009 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003010 }
3011
3012 // First pass, find a number override for an active subscriber
3013 String mergeNumber = null;
3014 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3015 for (String key : prefs.keySet()) {
3016 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3017 final String subscriberId = (String) prefs.get(key);
3018 if (activeSubscriberIds.contains(subscriberId)) {
3019 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3020 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3021 mergeNumber = (String) prefs.get(numberKey);
3022 if (DBG_MERGE) {
3023 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3024 + " for active subscriber " + subscriberId);
3025 }
3026 if (!TextUtils.isEmpty(mergeNumber)) {
3027 break;
3028 }
3029 }
3030 }
3031 }
3032
3033 // Shortcut when no active merged subscribers
3034 if (TextUtils.isEmpty(mergeNumber)) {
3035 return null;
3036 }
3037
3038 // Second pass, find all subscribers under that line override
3039 final ArraySet<String> result = new ArraySet<>();
3040 for (String key : prefs.keySet()) {
3041 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3042 final String number = (String) prefs.get(key);
3043 if (mergeNumber.equals(number)) {
3044 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3045 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3046 final String subscriberId = (String) prefs.get(subscriberKey);
3047 if (!TextUtils.isEmpty(subscriberId)) {
3048 result.add(subscriberId);
3049 }
3050 }
3051 }
3052 }
3053
3054 final String[] resultArray = result.toArray(new String[result.size()]);
3055 Arrays.sort(resultArray);
3056 if (DBG_MERGE) {
3057 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3058 }
3059 return resultArray;
3060 }
3061
3062 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003063 public boolean setOperatorBrandOverride(int subId, String brand) {
3064 enforceCarrierPrivilege(subId);
3065 final Phone phone = getPhone(subId);
3066 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003067 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003068
3069 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003070 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003071 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3072 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003073 enforceCarrierPrivilege(subId);
3074 final Phone phone = getPhone(subId);
3075 if (phone == null) {
3076 return false;
3077 }
3078 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003079 cdmaNonRoamingList);
3080 }
3081
3082 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003083 public void setRadioCapability(RadioAccessFamily[] rafs) {
3084 try {
3085 ProxyController.getInstance().setRadioCapability(rafs);
3086 } catch (RuntimeException e) {
3087 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3088 }
3089 }
3090
3091 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003092 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3093 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3094 return RadioAccessFamily.RAF_UNKNOWN;
3095 }
3096
Wink Saville5d475dd2014-10-17 15:00:58 -07003097 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3098 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003099
3100 @Override
3101 public void enableVideoCalling(boolean enable) {
3102 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003103 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003104 }
3105
3106 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003107 public boolean isVideoCallingEnabled(String callingPackage) {
3108 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3109 return false;
3110 }
3111
Andrew Lee77527ac2014-10-21 16:57:39 -07003112 // Check the user preference and the system-level IMS setting. Even if the user has
3113 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3114 // In the long run, we may instead need to check if there exists a connection service
3115 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003116 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3117 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003118 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003119 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003120
Andrew Leea1239f22015-03-02 17:44:07 -08003121 @Override
3122 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003123 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003124 }
3125
3126 @Override
3127 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003128 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003129 }
3130
Andrew Lee9431b832015-03-09 18:46:45 -07003131 @Override
3132 public boolean isTtyModeSupported() {
3133 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3134 TelephonyManager telephonyManager =
3135 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003136 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003137 }
3138
3139 @Override
3140 public boolean isHearingAidCompatibilitySupported() {
3141 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3142 }
3143
Sanket Padawe7310cc72015-01-14 09:53:20 -08003144 /**
3145 * Returns the unique device ID of phone, for example, the IMEI for
3146 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3147 *
3148 * <p>Requires Permission:
3149 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3150 */
3151 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003152 public String getDeviceId(String callingPackage) {
3153 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3154 return null;
3155 }
3156
Sanket Padawe7310cc72015-01-14 09:53:20 -08003157 final Phone phone = PhoneFactory.getPhone(0);
3158 if (phone != null) {
3159 return phone.getDeviceId();
3160 } else {
3161 return null;
3162 }
3163 }
3164
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003165 /*
3166 * {@hide}
3167 * Returns the IMS Registration Status
3168 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003169 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003170 public boolean isImsRegistered() {
3171 return mPhone.isImsRegistered();
3172 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003173
Ping Sun014fe8e2016-03-02 19:16:45 +08003174 /**
3175 * {@hide}
3176 * Returns the IMS Registration Status on a particular subid
3177 *
3178 * @param subId
3179 */
3180 public boolean isImsRegisteredForSubscriber(int subId) {
3181 Phone phone = getPhone(subId);
3182 if (phone != null) {
3183 return phone.isImsRegistered();
3184 } else {
3185 return false;
3186 }
3187 }
3188
Santos Cordon7a1885b2015-02-03 11:15:19 -08003189 @Override
3190 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3191 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3192 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003193
Nathan Haroldc55097a2015-03-11 18:14:50 -07003194 /*
3195 * {@hide}
3196 * Returns the IMS Registration Status
3197 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003198 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003199 return mPhone.isWifiCallingEnabled();
3200 }
3201
3202 /*
3203 * {@hide}
3204 * Returns the IMS Registration Status
3205 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003206 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003207 return mPhone.isVolteEnabled();
3208 }
Svet Ganovb320e182015-04-16 12:30:10 -07003209
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003210 /*
3211 * {@hide} Returns the IMS Registration Status
3212 */
3213 public boolean isVideoTelephonyAvailable() {
3214 return mPhone.isVideoEnabled();
3215 }
3216
Svet Ganovb320e182015-04-16 12:30:10 -07003217 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003218 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003219 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003220 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3221
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003222 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003223 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003224 } catch (SecurityException e) {
3225 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3226 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003227 }
Svet Ganovb320e182015-04-16 12:30:10 -07003228
3229 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3230 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3231 return false;
3232 }
3233
3234 return true;
3235 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003236
Makoto Onukifee69342015-06-29 14:44:50 -07003237 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003238 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003239 */
3240 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003241 // Default SMS app can always read it.
3242 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3243 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3244 return true;
3245 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003246
Makoto Onukie4072d12015-08-03 15:12:23 -07003247 try {
3248 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003249 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003250 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003251 // Can be read with READ_SMS too.
3252 try {
3253 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3254 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3255 if (opCode != AppOpsManager.OP_NONE) {
3256 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3257 == AppOpsManager.MODE_ALLOWED;
3258 } else {
3259 return true;
3260 }
3261 } catch (SecurityException readSmsSecurityException) {
3262 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003263 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003264 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003265 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003266 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003267 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003268 if (opCode != AppOpsManager.OP_NONE) {
3269 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3270 == AppOpsManager.MODE_ALLOWED;
3271 } else {
3272 return true;
3273 }
3274 } catch (SecurityException readPhoneNumberSecurityException) {
3275 }
3276
3277 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3278 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3279 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003280 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003281 }
3282
Stuart Scott8eef64f2015-04-08 15:13:54 -07003283 @Override
3284 public void factoryReset(int subId) {
3285 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003286 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3287 return;
3288 }
3289
Svet Ganovcc087f82015-05-12 20:35:54 -07003290 final long identity = Binder.clearCallingIdentity();
3291 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003292 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3293 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003294 // Enable data
3295 setDataEnabled(subId, true);
3296 // Set network selection mode to automatic
3297 setNetworkSelectionModeAutomatic(subId);
3298 // Set preferred mobile network type to the best available
3299 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3300 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003301 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003302 }
3303 } finally {
3304 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003305 }
3306 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003307
3308 @Override
3309 public String getLocaleFromDefaultSim() {
3310 // We query all subscriptions instead of just the active ones, because
3311 // this might be called early on in the provisioning flow when the
3312 // subscriptions potentially aren't active yet.
3313 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3314 if (slist == null || slist.isEmpty()) {
3315 return null;
3316 }
3317
3318 // This function may be called very early, say, from the setup wizard, at
3319 // which point we won't have a default subscription set. If that's the case
3320 // we just choose the first, which will be valid in "most cases".
3321 final int defaultSubId = getDefaultSubscription();
3322 SubscriptionInfo info = null;
3323 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3324 info = slist.get(0);
3325 } else {
3326 for (SubscriptionInfo item : slist) {
3327 if (item.getSubscriptionId() == defaultSubId) {
3328 info = item;
3329 break;
3330 }
3331 }
3332
3333 if (info == null) {
3334 return null;
3335 }
3336 }
3337
3338 // Try and fetch the locale from the carrier properties or from the SIM language
3339 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003340 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003341 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003342 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003343 if (defaultPhone != null) {
3344 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3345 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003346 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003347 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3348 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003349 } else {
3350 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003351 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003352 }
3353 }
3354
Narayan Kamath011676f2015-07-29 12:04:08 +01003355 // The SIM language preferences only store a language (e.g. fr = French), not an
3356 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3357 // the SIM and carrier preferences does not include a country we add the country
3358 // determined from the SIM MCC to provide an exact locale.
3359 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003360 if (mccLocale != null) {
3361 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3362 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003363 }
3364
Tony Hill183b2de2015-06-24 14:53:58 +01003365 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003366 return null;
3367 }
3368
3369 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3370 final long identity = Binder.clearCallingIdentity();
3371 try {
3372 return mSubscriptionController.getAllSubInfoList(
3373 mPhone.getContext().getOpPackageName());
3374 } finally {
3375 Binder.restoreCallingIdentity(identity);
3376 }
3377 }
3378
3379 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3380 final long identity = Binder.clearCallingIdentity();
3381 try {
3382 return mSubscriptionController.getActiveSubscriptionInfoList(
3383 mPhone.getContext().getOpPackageName());
3384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
3387 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003388
3389 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003390 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3391 * representing the state of the modem.
3392 *
3393 * NOTE: This clears the modem state, so there should only every be one caller.
3394 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003395 */
3396 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003397 public void requestModemActivityInfo(ResultReceiver result) {
3398 enforceModifyPermission();
3399
3400 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3401 Bundle bundle = new Bundle();
3402 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3403 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003404 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003405
3406 /**
3407 * {@hide}
3408 * Returns the service state information on specified subscription.
3409 */
3410 @Override
3411 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3412
3413 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3414 return null;
3415 }
3416
3417 final Phone phone = getPhone(subId);
3418 if (phone == null) {
3419 return null;
3420 }
3421
3422 return phone.getServiceState();
3423 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003424
3425 /**
3426 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3427 *
3428 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3429 * voicemail ringtone.
3430 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3431 * PhoneAccount.
3432 */
3433 @Override
3434 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003435 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003436 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003437 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003438 }
3439
fionaxu7ed723d2017-05-30 18:58:54 -07003440 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003441 }
3442
3443 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003444 * Sets the per-account voicemail ringtone.
3445 *
3446 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3447 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3448 *
3449 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3450 * voicemail ringtone.
3451 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3452 * PhoneAccount.
3453 */
3454 @Override
3455 public void setVoicemailRingtoneUri(String callingPackage,
3456 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3458 if (!TextUtils.equals(callingPackage,
3459 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3460 enforceModifyPermissionOrCarrierPrivilege(
3461 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3462 }
3463 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3464 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003465 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003466 }
fionaxu7ed723d2017-05-30 18:58:54 -07003467 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003468 }
3469
3470 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003471 * Returns whether vibration is set for voicemail notification in Phone settings.
3472 *
3473 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3474 * voicemail vibration setting.
3475 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3476 */
3477 @Override
3478 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003479 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003480 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003481 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003482 }
3483
fionaxu7ed723d2017-05-30 18:58:54 -07003484 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003485 }
3486
Youhan Wange64578a2016-05-02 15:32:42 -07003487 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003488 * Sets the per-account voicemail vibration.
3489 *
3490 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3491 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3492 *
3493 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3494 * voicemail vibration setting.
3495 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3496 * specific PhoneAccount.
3497 */
3498 @Override
3499 public void setVoicemailVibrationEnabled(String callingPackage,
3500 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3502 if (!TextUtils.equals(callingPackage,
3503 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3504 enforceModifyPermissionOrCarrierPrivilege(
3505 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3506 }
3507
3508 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3509 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003510 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003511 }
fionaxu7ed723d2017-05-30 18:58:54 -07003512 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003513 }
3514
3515 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003516 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3517 *
3518 * @throws SecurityException if the caller does not have the required permission
3519 */
3520 private void enforceReadPrivilegedPermission() {
3521 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3522 null);
3523 }
3524
3525 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003526 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3527 * permission.
3528 *
3529 * @throws SecurityException if the caller does not have the required permission
3530 */
3531 private void enforceSendSmsPermission() {
3532 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3533 }
3534
3535 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003536 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003537 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003538 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003539 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003540 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003541 ComponentName componentName =
3542 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3543 if(componentName == null) {
3544 throw new SecurityException("Caller not current active visual voicemail package[null]");
3545 }
3546 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003547 if (!callingPackage.equals(vvmPackage)) {
3548 throw new SecurityException("Caller not current active visual voicemail package[" +
3549 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003550 }
3551 }
3552
3553 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003554 * Return the application ID for the app type.
3555 *
3556 * @param subId the subscription ID that this request applies to.
3557 * @param appType the uicc app type.
3558 * @return Application ID for specificied app type, or null if no uicc.
3559 */
3560 @Override
3561 public String getAidForAppType(int subId, int appType) {
3562 enforceReadPrivilegedPermission();
3563 Phone phone = getPhone(subId);
3564 if (phone == null) {
3565 return null;
3566 }
3567 String aid = null;
3568 try {
3569 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3570 .getApplicationByType(appType).getAid();
3571 } catch (Exception e) {
3572 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3573 }
3574 return aid;
3575 }
3576
Youhan Wang4001d252016-05-11 10:29:41 -07003577 /**
3578 * Return the Electronic Serial Number.
3579 *
3580 * @param subId the subscription ID that this request applies to.
3581 * @return ESN or null if error.
3582 */
3583 @Override
3584 public String getEsn(int subId) {
3585 enforceReadPrivilegedPermission();
3586 Phone phone = getPhone(subId);
3587 if (phone == null) {
3588 return null;
3589 }
3590 String esn = null;
3591 try {
3592 esn = phone.getEsn();
3593 } catch (Exception e) {
3594 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3595 }
3596 return esn;
3597 }
3598
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003599 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003600 * Return the Preferred Roaming List Version.
3601 *
3602 * @param subId the subscription ID that this request applies to.
3603 * @return PRLVersion or null if error.
3604 */
3605 @Override
3606 public String getCdmaPrlVersion(int subId) {
3607 enforceReadPrivilegedPermission();
3608 Phone phone = getPhone(subId);
3609 if (phone == null) {
3610 return null;
3611 }
3612 String cdmaPrlVersion = null;
3613 try {
3614 cdmaPrlVersion = phone.getCdmaPrlVersion();
3615 } catch (Exception e) {
3616 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3617 }
3618 return cdmaPrlVersion;
3619 }
3620
3621 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003622 * Get snapshot of Telephony histograms
3623 * @return List of Telephony histograms
3624 * @hide
3625 */
3626 @Override
3627 public List<TelephonyHistogram> getTelephonyHistograms() {
3628 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3629 return RIL.getTelephonyRILTimingHistograms();
3630 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003631
3632 /**
3633 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003634 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003635 * Require system privileges. In the future we may add this to carrier APIs.
3636 *
3637 * @return The number of carriers set successfully, should match length of carriers
3638 */
3639 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003640 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003641 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003642
Meng Wang9b7c4e92017-02-17 11:41:27 -08003643 if (carriers == null) {
3644 throw new NullPointerException("carriers cannot be null");
3645 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003646
3647 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003648 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3649 return retVal[0];
3650 }
3651
3652 /**
3653 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003654 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003655 * Require system privileges. In the future we may add this to carrier APIs.
3656 *
3657 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3658 * means all carriers are allowed.
3659 */
3660 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003661 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003662 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003663 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003664 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3665 }
3666
fionaxu59545b42016-05-25 15:53:37 -07003667 /**
3668 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3669 * @param subId the subscription ID that this action applies to.
3670 * @param enabled control enable or disable metered apns.
3671 * {@hide}
3672 */
3673 @Override
3674 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3675 enforceModifyPermission();
3676 final Phone phone = getPhone(subId);
3677 if (phone == null) {
3678 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3679 return;
3680 }
3681 try {
3682 phone.carrierActionSetMeteredApnsEnabled(enabled);
3683 } catch (Exception e) {
3684 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3685 }
3686 }
3687
3688 /**
3689 * Action set from carrier signalling broadcast receivers to enable/disable radio
3690 * @param subId the subscription ID that this action applies to.
3691 * @param enabled control enable or disable radio.
3692 * {@hide}
3693 */
3694 @Override
3695 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3696 enforceModifyPermission();
3697 final Phone phone = getPhone(subId);
3698 if (phone == null) {
3699 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3700 return;
3701 }
3702 try {
3703 phone.carrierActionSetRadioEnabled(enabled);
3704 } catch (Exception e) {
3705 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3706 }
3707 }
3708
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003709 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003710 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3711 * network status based on which carrier apps could apply actions accordingly,
3712 * enable/disable default url handler for example.
3713 *
3714 * @param subId the subscription ID that this action applies to.
3715 * @param report control start/stop reporting the default network status.
3716 * {@hide}
3717 */
3718 @Override
3719 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3720 enforceModifyPermission();
3721 final Phone phone = getPhone(subId);
3722 if (phone == null) {
3723 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3724 return;
3725 }
3726 try {
3727 phone.carrierActionReportDefaultNetworkStatus(report);
3728 } catch (Exception e) {
3729 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3730 }
3731 }
3732
3733 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003734 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3735 * bug report is being generated.
3736 */
3737 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003738 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003739 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3740 != PackageManager.PERMISSION_GRANTED) {
3741 writer.println("Permission Denial: can't dump Phone from pid="
3742 + Binder.getCallingPid()
3743 + ", uid=" + Binder.getCallingUid()
3744 + "without permission "
3745 + android.Manifest.permission.DUMP);
3746 return;
3747 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003748 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003749 }
Jack Yueb89b242016-06-22 13:27:47 -07003750
3751 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003752 * Get aggregated video call data usage since boot.
3753 *
3754 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3755 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003756 * {@hide}
3757 */
3758 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003759 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003760 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3761 null);
3762
Jack Yu84291ec2017-05-26 16:07:50 -07003763 // NetworkStatsService keeps tracking the active network interface and identity. It
3764 // records the delta with the corresponding network identity. We just return the total video
3765 // call data usage snapshot since boot.
3766 Phone phone = getPhone(subId);
3767 if (phone != null) {
3768 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003769 }
Jack Yu84291ec2017-05-26 16:07:50 -07003770 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003771 }
Jack Yu75ab2952016-07-08 14:29:33 -07003772
3773 /**
3774 * Policy control of data connection. Usually used when data limit is passed.
3775 * @param enabled True if enabling the data, otherwise disabling.
3776 * @param subId Subscription index
3777 * {@hide}
3778 */
3779 @Override
3780 public void setPolicyDataEnabled(boolean enabled, int subId) {
3781 enforceModifyPermission();
3782 Phone phone = getPhone(subId);
3783 if (phone != null) {
3784 phone.setPolicyDataEnabled(enabled);
3785 }
3786 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003787
3788 /**
3789 * Get Client request stats
3790 * @return List of Client Request Stats
3791 * @hide
3792 */
3793 @Override
3794 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3795 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3796 return null;
3797 }
3798
3799 Phone phone = getPhone(subId);
3800 if (phone != null) {
3801 return phone.getClientRequestStats();
3802 }
3803
3804 return null;
3805 }
3806
3807 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3808 if (workSource != null) {
3809 return workSource;
3810 }
3811
3812 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3813 workSource = new WorkSource(uid, packageName);
3814 return workSource;
3815 }
Jack Yueb4124c2017-02-16 15:32:43 -08003816
3817 /**
Grace Chen70990072017-03-24 17:21:30 -07003818 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003819 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003820 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003821 * @param state State of SIM (power down, power up, pass through)
3822 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3823 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3824 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003825 *
3826 **/
3827 @Override
Grace Chen70990072017-03-24 17:21:30 -07003828 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003829 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003830 Phone phone = PhoneFactory.getPhone(slotIndex);
3831
Jack Yueb4124c2017-02-16 15:32:43 -08003832 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003833 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003834 }
3835 }
Shuo Qiandd210312017-04-12 22:11:33 +00003836
Tyler Gunn65d45c22017-06-05 11:22:26 -07003837 private boolean isUssdApiAllowed(int subId) {
3838 CarrierConfigManager configManager =
3839 (CarrierConfigManager) mPhone.getContext().getSystemService(
3840 Context.CARRIER_CONFIG_SERVICE);
3841 if (configManager == null) {
3842 return false;
3843 }
3844 PersistableBundle pb = configManager.getConfigForSubId(subId);
3845 if (pb == null) {
3846 return false;
3847 }
3848 return pb.getBoolean(
3849 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3850 }
3851
Shuo Qiandd210312017-04-12 22:11:33 +00003852 /**
3853 * Check if phone is in emergency callback mode
3854 * @return true if phone is in emergency callback mode
3855 * @param subId sub id
3856 */
3857 public boolean getEmergencyCallbackMode(int subId) {
3858 final Phone phone = getPhone(subId);
3859 if (phone != null) {
3860 return phone.isInEcm();
3861 } else {
3862 return false;
3863 }
3864 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003865
3866 /**
3867 * Get the current signal strength information for the given subscription.
3868 * Because this information is not updated when the device is in a low power state
3869 * it should not be relied-upon to be current.
3870 * @param subId Subscription index
3871 * @return the most recent cached signal strength info from the modem
3872 */
3873 @Override
3874 public SignalStrength getSignalStrength(int subId) {
3875 Phone p = getPhone(subId);
3876 if (p == null) {
3877 return null;
3878 }
3879
3880 return p.getSignalStrength();
3881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003882}