blob: 808ba82ad04ba178746a306b18ba1127fd5515f6 [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;
Adam Lesinski903a54c2016-04-11 14:49:52 -070042import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.ServiceManager;
44import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070045import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070046import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070047import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080048import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070049import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080050import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080051import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070052import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070053import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070055import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070056import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070057import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080058import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070059import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070060import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070061import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080063import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070064import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080065import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080066import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070067import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070068import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070069import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070071import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080072import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080074import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080075import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080076
Andrew Lee312e8172014-10-23 17:01:36 -070077import com.android.ims.ImsManager;
Brad Ebinger51f743a2017-01-23 13:50:20 -080078import com.android.ims.internal.IImsServiceController;
79import com.android.ims.internal.IImsServiceFeatureListener;
Shishir Agrawal566b7612013-10-28 14:41:00 -070080import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070081import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070082import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070083import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080086import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010087import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070088import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070089import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080091import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070092import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070093import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070094import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070095import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070096import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -080097import com.android.internal.telephony.SubscriptionController;
Jonathan Basseribf5362b2017-07-19 12:22:35 -070098import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -070099import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700100import com.android.internal.telephony.uicc.IccIoResult;
101import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800102import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700103import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800104import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700105import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700106import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800107import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700108import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800109import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700110import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700111import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800112
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700113import java.io.FileDescriptor;
114import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800115import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800118import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100119import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121
122/**
123 * Implementation of the ITelephony interface.
124 */
Santos Cordon117fee72014-05-16 17:56:12 -0700125public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126 private static final String LOG_TAG = "PhoneInterfaceManager";
127 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
128 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800129 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130
131 // Message codes used with mMainThreadHandler
132 private static final int CMD_HANDLE_PIN_MMI = 1;
133 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
134 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
135 private static final int CMD_ANSWER_RINGING_CALL = 4;
136 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700137 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
138 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139 private static final int CMD_OPEN_CHANNEL = 9;
140 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
141 private static final int CMD_CLOSE_CHANNEL = 11;
142 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800143 private static final int CMD_NV_READ_ITEM = 13;
144 private static final int EVENT_NV_READ_ITEM_DONE = 14;
145 private static final int CMD_NV_WRITE_ITEM = 15;
146 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
147 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
148 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
149 private static final int CMD_NV_RESET_CONFIG = 19;
150 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800151 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
152 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
153 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
154 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800155 private static final int CMD_SEND_ENVELOPE = 25;
156 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700157 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
158 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
159 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
160 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
161 private static final int CMD_EXCHANGE_SIM_IO = 31;
162 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800163 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
164 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700165 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
166 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700167 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
168 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700169 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
170 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
171 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
172 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700173 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
174 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
175 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
176 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700177 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800178 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
179 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180
181 /** The singleton instance. */
182 private static PhoneInterfaceManager sInstance;
183
Wink Saville3ab207e2014-11-20 13:07:20 -0800184 private PhoneGlobals mApp;
185 private Phone mPhone;
186 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700187 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800188 private AppOpsManager mAppOps;
189 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800190 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800191 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192
Derek Tan97ebb422014-09-05 16:55:38 -0700193 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
194 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700196
Derek Tan740e1672017-06-27 14:56:27 -0700197 // The AID of ISD-R.
198 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
199
yinxub1bed742017-04-17 11:45:04 -0700200 private NetworkScanRequestTracker mNetworkScanRequestTracker;
201
Derek Tan89e89d42014-07-08 17:00:10 -0700202 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203 * A request object to use for transmitting data to an ICC.
204 */
205 private static final class IccAPDUArgument {
206 public int channel, cla, command, p1, p2, p3;
207 public String data;
208
209 public IccAPDUArgument(int channel, int cla, int command,
210 int p1, int p2, int p3, String data) {
211 this.channel = channel;
212 this.cla = cla;
213 this.command = command;
214 this.p1 = p1;
215 this.p2 = p2;
216 this.p3 = p3;
217 this.data = data;
218 }
219 }
220
221 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700222 * A request object to use for transmitting data to an ICC.
223 */
224 private static final class ManualNetworkSelectionArgument {
225 public OperatorInfo operatorInfo;
226 public boolean persistSelection;
227
228 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
229 this.operatorInfo = operatorInfo;
230 this.persistSelection = persistSelection;
231 }
232 }
233
234 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
236 * request after sending. The main thread will notify the request when it is complete.
237 */
238 private static final class MainThreadRequest {
239 /** The argument to use for the request */
240 public Object argument;
241 /** The result of the request that is run on the main thread */
242 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800243 // The subscriber id that this request applies to. Defaults to
244 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
245 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246
247 public MainThreadRequest(Object argument) {
248 this.argument = argument;
249 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800250
251 public MainThreadRequest(Object argument, Integer subId) {
252 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800253 if (subId != null) {
254 this.subId = subId;
255 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257 }
258
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800259 private static final class IncomingThirdPartyCallArgs {
260 public final ComponentName component;
261 public final String callId;
262 public final String callerDisplayName;
263
264 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
265 String callerDisplayName) {
266 this.component = component;
267 this.callId = callId;
268 this.callerDisplayName = callerDisplayName;
269 }
270 }
271
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 /**
273 * A handler that processes messages on the main thread in the phone process. Since many
274 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
275 * inbound binder threads to the main thread in the phone process. The Binder thread
276 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
277 * on, which will be notified when the operation completes and will contain the result of the
278 * request.
279 *
280 * <p>If a MainThreadRequest object is provided in the msg.obj field,
281 * note that request.result must be set to something non-null for the calling thread to
282 * unblock.
283 */
284 private final class MainThreadHandler extends Handler {
285 @Override
286 public void handleMessage(Message msg) {
287 MainThreadRequest request;
288 Message onCompleted;
289 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800290 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700291 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
293 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700294 case CMD_HANDLE_USSD_REQUEST: {
295 request = (MainThreadRequest) msg.obj;
296 final Phone phone = getPhoneFromRequest(request);
297 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
298 String ussdRequest = ussdObject.first;
299 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700300
301 if (!isUssdApiAllowed(request.subId)) {
302 // Carrier does not support use of this API, return failure.
303 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
304 UssdResponse response = new UssdResponse(ussdRequest, null);
305 Bundle returnData = new Bundle();
306 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
307 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
308
309 request.result = true;
310 synchronized (request) {
311 request.notifyAll();
312 }
313 return;
314 }
315
Tyler Gunn52dcf772017-04-26 11:30:31 -0700316 try {
317 request.result = phone != null ?
318 phone.handleUssdRequest(ussdRequest, wrappedCallback)
319 : false;
320 } catch (CallStateException cse) {
321 request.result = false;
322 }
pkanwar32d516d2016-10-14 19:37:38 -0700323 // Wake up the requesting thread
324 synchronized (request) {
325 request.notifyAll();
326 }
327 break;
328 }
329
Yorke Lee716f67e2015-06-17 15:39:16 -0700330 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700332 final Phone phone = getPhoneFromRequest(request);
333 request.result = phone != null ?
334 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
335 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 // Wake up the requesting thread
337 synchronized (request) {
338 request.notifyAll();
339 }
340 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
343 case CMD_HANDLE_NEIGHBORING_CELL:
344 request = (MainThreadRequest) msg.obj;
345 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
346 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700347 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 break;
349
350 case EVENT_NEIGHBORING_CELL_DONE:
351 ar = (AsyncResult) msg.obj;
352 request = (MainThreadRequest) ar.userObj;
353 if (ar.exception == null && ar.result != null) {
354 request.result = ar.result;
355 } else {
356 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800357 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358 }
359 // Wake up the requesting thread
360 synchronized (request) {
361 request.notifyAll();
362 }
363 break;
364
365 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700366 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800367 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700368 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 break;
370
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 case CMD_END_CALL:
372 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800373 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700374 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700375 Phone phone = getPhone(end_subId);
376 if (phone == null) {
377 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
378 break;
379 }
380 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
382 // CDMA: If the user presses the Power button we treat it as
383 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700384 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
386 // GSM: End the call as per the Phone state
387 hungUp = PhoneUtils.hangup(mCM);
388 } else {
389 throw new IllegalStateException("Unexpected phone type: " + phoneType);
390 }
391 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
392 request.result = hungUp;
393 // Wake up the requesting thread
394 synchronized (request) {
395 request.notifyAll();
396 }
397 break;
398
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700399 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700400 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800402 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700403 if (uiccCard == null) {
404 loge("iccTransmitApduLogicalChannel: No UICC");
405 request.result = new IccIoResult(0x6F, 0, (byte[])null);
406 synchronized (request) {
407 request.notifyAll();
408 }
409 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700410 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
411 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700412 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 iccArgument.channel, iccArgument.cla, iccArgument.command,
414 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700415 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700416 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 break;
418
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700420 ar = (AsyncResult) msg.obj;
421 request = (MainThreadRequest) ar.userObj;
422 if (ar.exception == null && ar.result != null) {
423 request.result = ar.result;
424 } else {
425 request.result = new IccIoResult(0x6F, 0, (byte[])null);
426 if (ar.result == null) {
427 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800428 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800430 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 } else {
432 loge("iccTransmitApduLogicalChannel: Unknown exception");
433 }
434 }
435 synchronized (request) {
436 request.notifyAll();
437 }
438 break;
439
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700440 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
441 request = (MainThreadRequest) msg.obj;
442 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800443 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 if (uiccCard == null) {
445 loge("iccTransmitApduBasicChannel: No UICC");
446 request.result = new IccIoResult(0x6F, 0, (byte[])null);
447 synchronized (request) {
448 request.notifyAll();
449 }
450 } else {
451 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
452 request);
453 uiccCard.iccTransmitApduBasicChannel(
454 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
455 iccArgument.p3, iccArgument.data, onCompleted);
456 }
457 break;
458
459 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
460 ar = (AsyncResult) msg.obj;
461 request = (MainThreadRequest) ar.userObj;
462 if (ar.exception == null && ar.result != null) {
463 request.result = ar.result;
464 } else {
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
466 if (ar.result == null) {
467 loge("iccTransmitApduBasicChannel: Empty response");
468 } else if (ar.exception instanceof CommandException) {
469 loge("iccTransmitApduBasicChannel: CommandException: " +
470 ar.exception);
471 } else {
472 loge("iccTransmitApduBasicChannel: Unknown exception");
473 }
474 }
475 synchronized (request) {
476 request.notifyAll();
477 }
478 break;
479
480 case CMD_EXCHANGE_SIM_IO:
481 request = (MainThreadRequest) msg.obj;
482 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800483 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 if (uiccCard == null) {
485 loge("iccExchangeSimIO: No UICC");
486 request.result = new IccIoResult(0x6F, 0, (byte[])null);
487 synchronized (request) {
488 request.notifyAll();
489 }
490 } else {
491 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
492 request);
493 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
494 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
495 iccArgument.data, onCompleted);
496 }
497 break;
498
499 case EVENT_EXCHANGE_SIM_IO_DONE:
500 ar = (AsyncResult) msg.obj;
501 request = (MainThreadRequest) ar.userObj;
502 if (ar.exception == null && ar.result != null) {
503 request.result = ar.result;
504 } else {
505 request.result = new IccIoResult(0x6f, 0, (byte[])null);
506 }
507 synchronized (request) {
508 request.notifyAll();
509 }
510 break;
511
Derek Tan4d5e5c12014-02-04 11:54:58 -0800512 case CMD_SEND_ENVELOPE:
513 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800514 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700515 if (uiccCard == null) {
516 loge("sendEnvelopeWithStatus: No UICC");
517 request.result = new IccIoResult(0x6F, 0, (byte[])null);
518 synchronized (request) {
519 request.notifyAll();
520 }
521 } else {
522 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
523 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
524 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800525 break;
526
527 case EVENT_SEND_ENVELOPE_DONE:
528 ar = (AsyncResult) msg.obj;
529 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700530 if (ar.exception == null && ar.result != null) {
531 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800532 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700533 request.result = new IccIoResult(0x6F, 0, (byte[])null);
534 if (ar.result == null) {
535 loge("sendEnvelopeWithStatus: Empty response");
536 } else if (ar.exception instanceof CommandException) {
537 loge("sendEnvelopeWithStatus: CommandException: " +
538 ar.exception);
539 } else {
540 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
541 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800542 }
543 synchronized (request) {
544 request.notifyAll();
545 }
546 break;
547
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 case CMD_OPEN_CHANNEL:
549 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800550 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800551 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 if (uiccCard == null) {
553 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800554 request.result = new IccOpenLogicalChannelResponse(-1,
555 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 synchronized (request) {
557 request.notifyAll();
558 }
559 } else {
560 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800561 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
562 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 break;
565
566 case EVENT_OPEN_CHANNEL_DONE:
567 ar = (AsyncResult) msg.obj;
568 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700569 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 int[] result = (int[]) ar.result;
572 int channelId = result[0];
573 byte[] selectResponse = null;
574 if (result.length > 1) {
575 selectResponse = new byte[result.length - 1];
576 for (int i = 1; i < result.length; ++i) {
577 selectResponse[i - 1] = (byte) result[i];
578 }
579 }
580 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700581 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 if (ar.result == null) {
584 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 if (ar.exception != null) {
587 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
588 }
589
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700590 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700591 if (ar.exception instanceof CommandException) {
592 CommandException.Error error =
593 ((CommandException) (ar.exception)).getCommandError();
594 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700596 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700597 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 }
599 }
600 openChannelResp = new IccOpenLogicalChannelResponse(
601 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700603 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 synchronized (request) {
605 request.notifyAll();
606 }
607 break;
608
609 case CMD_CLOSE_CHANNEL:
610 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800611 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 if (uiccCard == null) {
613 loge("iccCloseLogicalChannel: No UICC");
614 request.result = new IccIoResult(0x6F, 0, (byte[])null);
615 synchronized (request) {
616 request.notifyAll();
617 }
618 } else {
619 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
620 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
621 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
624 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800625 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
626 break;
627
628 case CMD_NV_READ_ITEM:
629 request = (MainThreadRequest) msg.obj;
630 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
631 mPhone.nvReadItem((Integer) request.argument, onCompleted);
632 break;
633
634 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 ar = (AsyncResult) msg.obj;
636 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800637 if (ar.exception == null && ar.result != null) {
638 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800640 request.result = "";
641 if (ar.result == null) {
642 loge("nvReadItem: Empty response");
643 } else if (ar.exception instanceof CommandException) {
644 loge("nvReadItem: CommandException: " +
645 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800647 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 }
649 }
650 synchronized (request) {
651 request.notifyAll();
652 }
653 break;
654
Jake Hambye994d462014-02-03 13:10:13 -0800655 case CMD_NV_WRITE_ITEM:
656 request = (MainThreadRequest) msg.obj;
657 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
658 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
659 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
660 break;
661
662 case EVENT_NV_WRITE_ITEM_DONE:
663 handleNullReturnEvent(msg, "nvWriteItem");
664 break;
665
666 case CMD_NV_WRITE_CDMA_PRL:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
669 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
670 break;
671
672 case EVENT_NV_WRITE_CDMA_PRL_DONE:
673 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
674 break;
675
676 case CMD_NV_RESET_CONFIG:
677 request = (MainThreadRequest) msg.obj;
678 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
679 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
680 break;
681
682 case EVENT_NV_RESET_CONFIG_DONE:
683 handleNullReturnEvent(msg, "nvResetConfig");
684 break;
685
Jake Hamby7c27be32014-03-03 13:25:59 -0800686 case CMD_GET_PREFERRED_NETWORK_TYPE:
687 request = (MainThreadRequest) msg.obj;
688 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700689 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800690 break;
691
692 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
693 ar = (AsyncResult) msg.obj;
694 request = (MainThreadRequest) ar.userObj;
695 if (ar.exception == null && ar.result != null) {
696 request.result = ar.result; // Integer
697 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800698 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800699 if (ar.result == null) {
700 loge("getPreferredNetworkType: Empty response");
701 } else if (ar.exception instanceof CommandException) {
702 loge("getPreferredNetworkType: CommandException: " +
703 ar.exception);
704 } else {
705 loge("getPreferredNetworkType: Unknown exception");
706 }
707 }
708 synchronized (request) {
709 request.notifyAll();
710 }
711 break;
712
713 case CMD_SET_PREFERRED_NETWORK_TYPE:
714 request = (MainThreadRequest) msg.obj;
715 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
716 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700717 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 break;
719
720 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
721 handleNullReturnEvent(msg, "setPreferredNetworkType");
722 break;
723
Steven Liu4bf01bc2014-07-17 11:05:29 -0500724 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
725 request = (MainThreadRequest)msg.obj;
726 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
727 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
728 break;
729
730 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
731 ar = (AsyncResult)msg.obj;
732 request = (MainThreadRequest)ar.userObj;
733 request.result = ar;
734 synchronized (request) {
735 request.notifyAll();
736 }
737 break;
738
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800739 case CMD_SET_VOICEMAIL_NUMBER:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
742 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800743 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
744 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800745 break;
746
747 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
748 handleNullReturnEvent(msg, "setVoicemailNumber");
749 break;
750
Stuart Scott54788802015-03-30 13:18:01 -0700751 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
754 request);
755 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
756 break;
757
758 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
759 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
760 break;
761
Shishir Agrawal302c8692015-06-19 13:49:39 -0700762 case CMD_PERFORM_NETWORK_SCAN:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
765 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
766 break;
767
768 case EVENT_PERFORM_NETWORK_SCAN_DONE:
769 ar = (AsyncResult) msg.obj;
770 request = (MainThreadRequest) ar.userObj;
771 CellNetworkScanResult cellScanResult;
772 if (ar.exception == null && ar.result != null) {
773 cellScanResult = new CellNetworkScanResult(
774 CellNetworkScanResult.STATUS_SUCCESS,
775 (List<OperatorInfo>) ar.result);
776 } else {
777 if (ar.result == null) {
778 loge("getCellNetworkScanResults: Empty response");
779 }
780 if (ar.exception != null) {
781 loge("getCellNetworkScanResults: Exception: " + ar.exception);
782 }
783 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
784 if (ar.exception instanceof CommandException) {
785 CommandException.Error error =
786 ((CommandException) (ar.exception)).getCommandError();
787 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
788 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
789 } else if (error == CommandException.Error.GENERIC_FAILURE) {
790 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
791 }
792 }
793 cellScanResult = new CellNetworkScanResult(errorCode, null);
794 }
795 request.result = cellScanResult;
796 synchronized (request) {
797 request.notifyAll();
798 }
799 break;
800
801 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
802 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700803 ManualNetworkSelectionArgument selArg =
804 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700805 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
806 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700807 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
808 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700809 break;
810
811 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
812 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
813 break;
814
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700815 case CMD_GET_MODEM_ACTIVITY_INFO:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700818 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700819 break;
820
821 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null && ar.result != null) {
825 request.result = ar.result;
826 } else {
827 if (ar.result == null) {
828 loge("queryModemActivityInfo: Empty response");
829 } else if (ar.exception instanceof CommandException) {
830 loge("queryModemActivityInfo: CommandException: " +
831 ar.exception);
832 } else {
833 loge("queryModemActivityInfo: Unknown exception");
834 }
835 }
Amit Mahajand4766222016-01-28 15:28:28 -0800836 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
837 if (request.result == null) {
838 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
839 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700840 synchronized (request) {
841 request.notifyAll();
842 }
843 break;
844
Meng Wang1a7c35a2016-05-05 20:56:15 -0700845 case CMD_SET_ALLOWED_CARRIERS:
846 request = (MainThreadRequest) msg.obj;
847 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
848 mPhone.setAllowedCarriers(
849 (List<CarrierIdentifier>) request.argument,
850 onCompleted);
851 break;
852
853 case EVENT_SET_ALLOWED_CARRIERS_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result;
858 } else {
859 if (ar.result == null) {
860 loge("setAllowedCarriers: Empty response");
861 } else if (ar.exception instanceof CommandException) {
862 loge("setAllowedCarriers: CommandException: " +
863 ar.exception);
864 } else {
865 loge("setAllowedCarriers: Unknown exception");
866 }
867 }
868 // Result cannot be null. Return -1 on error.
869 if (request.result == null) {
870 request.result = new int[]{-1};
871 }
872 synchronized (request) {
873 request.notifyAll();
874 }
875 break;
876
877 case CMD_GET_ALLOWED_CARRIERS:
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
880 mPhone.getAllowedCarriers(onCompleted);
881 break;
882
883 case EVENT_GET_ALLOWED_CARRIERS_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
889 if (ar.result == null) {
890 loge("getAllowedCarriers: Empty response");
891 } else if (ar.exception instanceof CommandException) {
892 loge("getAllowedCarriers: CommandException: " +
893 ar.exception);
894 } else {
895 loge("getAllowedCarriers: Unknown exception");
896 }
897 }
898 // Result cannot be null. Return empty list of CarrierIdentifier.
899 if (request.result == null) {
900 request.result = new ArrayList<CarrierIdentifier>(0);
901 }
902 synchronized (request) {
903 request.notifyAll();
904 }
905 break;
906
Nathan Haroldb3014052017-01-25 15:57:32 -0800907 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
908 ar = (AsyncResult) msg.obj;
909 request = (MainThreadRequest) ar.userObj;
910 if (ar.exception == null && ar.result != null) {
911 request.result = ar.result;
912 } else {
913 request.result = new IllegalArgumentException(
914 "Failed to retrieve Forbidden Plmns");
915 if (ar.result == null) {
916 loge("getForbiddenPlmns: Empty response");
917 } else {
918 loge("getForbiddenPlmns: Unknown exception");
919 }
920 }
921 synchronized (request) {
922 request.notifyAll();
923 }
924 break;
925
926 case CMD_GET_FORBIDDEN_PLMNS:
927 request = (MainThreadRequest) msg.obj;
928 uiccCard = getUiccCardFromRequest(request);
929 if (uiccCard == null) {
930 loge("getForbiddenPlmns() UiccCard is null");
931 request.result = new IllegalArgumentException(
932 "getForbiddenPlmns() UiccCard is null");
933 synchronized (request) {
934 request.notifyAll();
935 }
936 break;
937 }
938 Integer appType = (Integer) request.argument;
939 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
940 if (uiccApp == null) {
941 loge("getForbiddenPlmns() no app with specified type -- "
942 + appType);
943 request.result = new IllegalArgumentException("Failed to get UICC App");
944 synchronized (request) {
945 request.notifyAll();
946 }
947 break;
948 } else {
949 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
950 + " specified type -- " + appType);
951 }
952 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
953 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
954 onCompleted);
955 break;
956
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700957 default:
958 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
959 break;
960 }
961 }
Jake Hambye994d462014-02-03 13:10:13 -0800962
963 private void handleNullReturnEvent(Message msg, String command) {
964 AsyncResult ar = (AsyncResult) msg.obj;
965 MainThreadRequest request = (MainThreadRequest) ar.userObj;
966 if (ar.exception == null) {
967 request.result = true;
968 } else {
969 request.result = false;
970 if (ar.exception instanceof CommandException) {
971 loge(command + ": CommandException: " + ar.exception);
972 } else {
973 loge(command + ": Unknown exception");
974 }
975 }
976 synchronized (request) {
977 request.notifyAll();
978 }
979 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700980 }
981
982 /**
983 * Posts the specified command to be executed on the main thread,
984 * waits for the request to complete, and returns the result.
985 * @see #sendRequestAsync
986 */
987 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800988 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700989 }
990
991 /**
992 * Posts the specified command to be executed on the main thread,
993 * waits for the request to complete, and returns the result.
994 * @see #sendRequestAsync
995 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800996 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700997 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
998 throw new RuntimeException("This method will deadlock if called from the main thread.");
999 }
1000
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001001 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001002 Message msg = mMainThreadHandler.obtainMessage(command, request);
1003 msg.sendToTarget();
1004
1005 // Wait for the request to complete
1006 synchronized (request) {
1007 while (request.result == null) {
1008 try {
1009 request.wait();
1010 } catch (InterruptedException e) {
1011 // Do nothing, go back and wait until the request is complete
1012 }
1013 }
1014 }
1015 return request.result;
1016 }
1017
1018 /**
1019 * Asynchronous ("fire and forget") version of sendRequest():
1020 * Posts the specified command to be executed on the main thread, and
1021 * returns immediately.
1022 * @see #sendRequest
1023 */
1024 private void sendRequestAsync(int command) {
1025 mMainThreadHandler.sendEmptyMessage(command);
1026 }
1027
1028 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001029 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1030 * @see {@link #sendRequest(int,Object)}
1031 */
1032 private void sendRequestAsync(int command, Object argument) {
1033 MainThreadRequest request = new MainThreadRequest(argument);
1034 Message msg = mMainThreadHandler.obtainMessage(command, request);
1035 msg.sendToTarget();
1036 }
1037
1038 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001039 * Initialize the singleton PhoneInterfaceManager instance.
1040 * This is only done once, at startup, from PhoneApp.onCreate().
1041 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001042 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001043 synchronized (PhoneInterfaceManager.class) {
1044 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001045 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001046 } else {
1047 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1048 }
1049 return sInstance;
1050 }
1051 }
1052
1053 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001054 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001055 mApp = app;
1056 mPhone = phone;
1057 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001058 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001059 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1060 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001061 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001062 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001063 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001064 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001065
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001066 publish();
1067 }
1068
1069 private void publish() {
1070 if (DBG) log("publish: " + this);
1071
1072 ServiceManager.addService("phone", this);
1073 }
1074
Stuart Scott584921c2015-01-15 17:10:34 -08001075 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001076 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1077 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001078 }
1079
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001080 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1081 Phone phone = getPhoneFromRequest(request);
1082 return phone == null ? null :
1083 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1084 }
1085
Wink Saville36469e72014-06-11 15:17:00 -07001086 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001087 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001088 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 //
1091 // Implementation of the ITelephony interface.
1092 //
1093
1094 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001095 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001096 }
1097
Wink Savilleb564aae2014-10-23 10:18:09 -07001098 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001099 if (DBG) log("dial: " + number);
1100 // No permission check needed here: This is just a wrapper around the
1101 // ACTION_DIAL intent, which is available to any app since it puts up
1102 // the UI before it does anything.
1103
1104 String url = createTelUrl(number);
1105 if (url == null) {
1106 return;
1107 }
1108
1109 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001110 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001111 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1112 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1113 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1114 mApp.startActivity(intent);
1115 }
1116 }
1117
1118 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001119 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001120 }
1121
Wink Savilleb564aae2014-10-23 10:18:09 -07001122 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 if (DBG) log("call: " + number);
1124
1125 // This is just a wrapper around the ACTION_CALL intent, but we still
1126 // need to do a permission check since we're calling startActivity()
1127 // from the context of the phone app.
1128 enforceCallPermission();
1129
1130 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1131 != AppOpsManager.MODE_ALLOWED) {
1132 return;
1133 }
1134
1135 String url = createTelUrl(number);
1136 if (url == null) {
1137 return;
1138 }
1139
Wink Saville08874612014-08-31 19:19:58 -07001140 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001141 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001142 if (slist != null) {
1143 for (SubscriptionInfo subInfoRecord : slist) {
1144 if (subInfoRecord.getSubscriptionId() == subId) {
1145 isValid = true;
1146 break;
1147 }
Wink Saville08874612014-08-31 19:19:58 -07001148 }
1149 }
1150 if (isValid == false) {
1151 return;
1152 }
1153
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001154 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001155 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001156 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1157 mApp.startActivity(intent);
1158 }
1159
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 /**
1161 * End a call based on call state
1162 * @return true is a call was ended
1163 */
1164 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001165 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001166 }
1167
1168 /**
1169 * End a call based on the call state of the subId
1170 * @return true is a call was ended
1171 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001172 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001174 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 }
1176
1177 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001178 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001179 }
1180
Wink Savilleb564aae2014-10-23 10:18:09 -07001181 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001182 if (DBG) log("answerRingingCall...");
1183 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1184 // but that can probably wait till the big TelephonyManager API overhaul.
1185 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1186 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001187 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 }
1189
1190 /**
1191 * Make the actual telephony calls to implement answerRingingCall().
1192 * This should only be called from the main thread of the Phone app.
1193 * @see #answerRingingCall
1194 *
1195 * TODO: it would be nice to return true if we answered the call, or
1196 * false if there wasn't actually a ringing incoming call, or some
1197 * other error occurred. (In other words, pass back the return value
1198 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1199 * But that would require calling this method via sendRequest() rather
1200 * than sendRequestAsync(), and right now we don't actually *need* that
1201 * return value, so let's just return void for now.
1202 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001203 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001204 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001206 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1207 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001208 if (hasActiveCall && hasHoldingCall) {
1209 // Both lines are in use!
1210 // TODO: provide a flag to let the caller specify what
1211 // policy to use if both lines are in use. (The current
1212 // behavior is hardwired to "answer incoming, end ongoing",
1213 // which is how the CALL button is specced to behave.)
1214 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1215 return;
1216 } else {
1217 // answerCall() will automatically hold the current active
1218 // call, if there is one.
1219 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1220 return;
1221 }
1222 } else {
1223 // No call was ringing.
1224 return;
1225 }
1226 }
1227
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001229 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001230 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001231 public void silenceRinger() {
1232 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 }
1234
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001235 @Override
1236 public boolean isOffhook(String callingPackage) {
1237 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001238 }
1239
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001240 @Override
1241 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1242 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1243 return false;
1244 }
1245
Sanket Padawe356d7632015-06-22 14:03:32 -07001246 final Phone phone = getPhone(subId);
1247 if (phone != null) {
1248 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1249 } else {
1250 return false;
1251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 }
1253
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001254 @Override
1255 public boolean isRinging(String callingPackage) {
1256 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001257 }
1258
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001259 @Override
1260 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1261 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1262 return false;
1263 }
1264
Sanket Padawe356d7632015-06-22 14:03:32 -07001265 final Phone phone = getPhone(subId);
1266 if (phone != null) {
1267 return (phone.getState() == PhoneConstants.State.RINGING);
1268 } else {
1269 return false;
1270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271 }
1272
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001273 @Override
1274 public boolean isIdle(String callingPackage) {
1275 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001276 }
1277
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001278 @Override
1279 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1280 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1281 return false;
1282 }
1283
Sanket Padawe356d7632015-06-22 14:03:32 -07001284 final Phone phone = getPhone(subId);
1285 if (phone != null) {
1286 return (phone.getState() == PhoneConstants.State.IDLE);
1287 } else {
1288 return false;
1289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 }
1291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001293 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001294 }
1295
Wink Savilleb564aae2014-10-23 10:18:09 -07001296 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001297 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001298 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1299 }
1300
1301 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001302 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001303 }
1304
Wink Savilleb564aae2014-10-23 10:18:09 -07001305 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001306 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001307 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1308 }
1309
1310 /** {@hide} */
1311 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001312 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001313 }
1314
Wink Savilleb564aae2014-10-23 10:18:09 -07001315 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001317 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 checkSimPin.start();
1319 return checkSimPin.unlockSim(null, pin);
1320 }
1321
Wink Saville9de0f752013-10-22 19:04:03 -07001322 /** {@hide} */
1323 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001324 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001325 }
1326
Wink Savilleb564aae2014-10-23 10:18:09 -07001327 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001329 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 checkSimPuk.start();
1331 return checkSimPuk.unlockSim(puk, pin);
1332 }
1333
1334 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001335 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 * a synchronous one.
1337 */
1338 private static class UnlockSim extends Thread {
1339
1340 private final IccCard mSimCard;
1341
1342 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001343 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1344 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001345
1346 // For replies from SimCard interface
1347 private Handler mHandler;
1348
1349 // For async handler to identify request type
1350 private static final int SUPPLY_PIN_COMPLETE = 100;
1351
1352 public UnlockSim(IccCard simCard) {
1353 mSimCard = simCard;
1354 }
1355
1356 @Override
1357 public void run() {
1358 Looper.prepare();
1359 synchronized (UnlockSim.this) {
1360 mHandler = new Handler() {
1361 @Override
1362 public void handleMessage(Message msg) {
1363 AsyncResult ar = (AsyncResult) msg.obj;
1364 switch (msg.what) {
1365 case SUPPLY_PIN_COMPLETE:
1366 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1367 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001368 mRetryCount = msg.arg1;
1369 if (ar.exception != null) {
1370 if (ar.exception instanceof CommandException &&
1371 ((CommandException)(ar.exception)).getCommandError()
1372 == CommandException.Error.PASSWORD_INCORRECT) {
1373 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1374 } else {
1375 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1376 }
1377 } else {
1378 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 mDone = true;
1381 UnlockSim.this.notifyAll();
1382 }
1383 break;
1384 }
1385 }
1386 };
1387 UnlockSim.this.notifyAll();
1388 }
1389 Looper.loop();
1390 }
1391
1392 /*
1393 * Use PIN or PUK to unlock SIM card
1394 *
1395 * If PUK is null, unlock SIM card with PIN
1396 *
1397 * If PUK is not null, unlock SIM card with PUK and set PIN code
1398 */
Wink Saville9de0f752013-10-22 19:04:03 -07001399 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400
1401 while (mHandler == null) {
1402 try {
1403 wait();
1404 } catch (InterruptedException e) {
1405 Thread.currentThread().interrupt();
1406 }
1407 }
1408 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1409
1410 if (puk == null) {
1411 mSimCard.supplyPin(pin, callback);
1412 } else {
1413 mSimCard.supplyPuk(puk, pin, callback);
1414 }
1415
1416 while (!mDone) {
1417 try {
1418 Log.d(LOG_TAG, "wait for done");
1419 wait();
1420 } catch (InterruptedException e) {
1421 // Restore the interrupted status
1422 Thread.currentThread().interrupt();
1423 }
1424 }
1425 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001426 int[] resultArray = new int[2];
1427 resultArray[0] = mResult;
1428 resultArray[1] = mRetryCount;
1429 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 }
1431 }
1432
1433 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001434 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001435
1436 }
1437
Wink Savilleb564aae2014-10-23 10:18:09 -07001438 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439 // No permission check needed here: this call is harmless, and it's
1440 // needed for the ServiceState.requestStateUpdate() call (which is
1441 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001442 final Phone phone = getPhone(subId);
1443 if (phone != null) {
1444 phone.updateServiceLocation();
1445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 }
1447
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001448 @Override
1449 public boolean isRadioOn(String callingPackage) {
1450 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001451 }
1452
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001453 @Override
1454 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1455 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1456 return false;
1457 }
1458 return isRadioOnForSubscriber(subId);
1459 }
1460
1461 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001462 final Phone phone = getPhone(subId);
1463 if (phone != null) {
1464 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1465 } else {
1466 return false;
1467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 }
1469
1470 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001471 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001472
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 }
Wink Saville36469e72014-06-11 15:17:00 -07001474
Wink Savilleb564aae2014-10-23 10:18:09 -07001475 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001477 final Phone phone = getPhone(subId);
1478 if (phone != null) {
1479 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1480 }
Wink Saville36469e72014-06-11 15:17:00 -07001481 }
1482
1483 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001484 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001485 }
1486
Wink Savilleb564aae2014-10-23 10:18:09 -07001487 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001488 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001489 final Phone phone = getPhone(subId);
1490 if (phone == null) {
1491 return false;
1492 }
1493 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001494 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001495 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 }
1497 return true;
1498 }
Wink Saville36469e72014-06-11 15:17:00 -07001499
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001500 public boolean needMobileRadioShutdown() {
1501 /*
1502 * If any of the Radios are available, it will need to be
1503 * shutdown. So return true if any Radio is available.
1504 */
1505 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1506 Phone phone = PhoneFactory.getPhone(i);
1507 if (phone != null && phone.isRadioAvailable()) return true;
1508 }
1509 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1510 return false;
1511 }
1512
1513 public void shutdownMobileRadios() {
1514 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1515 logv("Shutting down Phone " + i);
1516 shutdownRadioUsingPhoneId(i);
1517 }
1518 }
1519
1520 private void shutdownRadioUsingPhoneId(int phoneId) {
1521 enforceModifyPermission();
1522 Phone phone = PhoneFactory.getPhone(phoneId);
1523 if (phone != null && phone.isRadioAvailable()) {
1524 phone.shutdownRadio();
1525 }
1526 }
1527
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001529 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001530 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1531 if (defaultPhone != null) {
1532 defaultPhone.setRadioPower(turnOn);
1533 return true;
1534 } else {
1535 loge("There's no default phone.");
1536 return false;
1537 }
Wink Saville36469e72014-06-11 15:17:00 -07001538 }
1539
Wink Savilleb564aae2014-10-23 10:18:09 -07001540 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001542 final Phone phone = getPhone(subId);
1543 if (phone != null) {
1544 phone.setRadioPower(turnOn);
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 enableDataConnectivity() {
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(true);
1559 return true;
1560 } else {
1561 return false;
1562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
1564
Wink Saville36469e72014-06-11 15:17:00 -07001565 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001566 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 public boolean disableDataConnectivity() {
1568 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001569 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
1572 phone.setDataEnabled(false);
1573 return true;
1574 } else {
1575 return false;
1576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
Sanket Padawe356d7632015-06-22 14:03:32 -07001579 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001580 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001581 final Phone phone = getPhone(subId);
1582 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001583 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001584 } else {
1585 return false;
1586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 }
1588
1589 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001590 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001591 }
1592
pkanwarae03a6b2016-11-06 20:37:09 -08001593 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001594 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001595 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1596 return;
1597 }
1598 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1599 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1600 };
1601
Wink Savilleb564aae2014-10-23 10:18:09 -07001602 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1605 return false;
1606 }
Wink Saville36469e72014-06-11 15:17:00 -07001607 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 }
1609
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001611 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001612 }
1613
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001614 public int getCallStateForSlot(int slotIndex) {
1615 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001616 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001617 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 }
1619
Sanket Padawe356d7632015-06-22 14:03:32 -07001620 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001622 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001624 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001626 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 }
1629
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001632 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001633 if (phone != null) {
1634 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1635 } else {
1636 return TelephonyManager.DATA_ACTIVITY_NONE;
1637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 }
1639
1640 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001641 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001642 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
1643 callingPackage, Binder.getCallingUid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001644 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 }
1646
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001647 if (DBG_LOC) log("getCellLocation: is active user");
1648 Bundle data = new Bundle();
1649 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1650 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 return null;
1652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001654 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1655 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1656 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001657 }
1658
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001660 public String getNetworkCountryIsoForPhone(int phoneId) {
1661 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1662 // registered cell info, so return a NULL country instead.
1663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1666 if (TelephonyManager.NETWORK_TYPE_IWLAN
1667 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1668 return "";
1669 }
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
1672 }
1673 return TelephonyManager.getTelephonyProperty(
1674 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1675 }
1676
1677 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001679 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001680 }
1681
Sanket Padawe356d7632015-06-22 14:03:32 -07001682 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001683 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 mApp.enforceCallingOrSelfPermission(
1685 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001686 final Phone phone = getPhone(subId);
1687 if (phone != null) {
1688 phone.enableLocationUpdates();
1689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 }
1691
1692 @Override
1693 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001694 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001695 }
1696
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001698 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 mApp.enforceCallingOrSelfPermission(
1700 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 final Phone phone = getPhone(subId);
1702 if (phone != null) {
1703 phone.disableLocationUpdates();
1704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 }
1706
1707 @Override
1708 @SuppressWarnings("unchecked")
1709 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001710 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
1711 callingPackage, Binder.getCallingUid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001712 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 }
1714
1715 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1716 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1717 return null;
1718 }
Svetoslav64fad262015-04-14 14:35:21 -07001719
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001720 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001721
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001722 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001724 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1725 try {
1726 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1727 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1728 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1729 } catch (RuntimeException e) {
1730 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001732 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 }
1734
1735
1736 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001737 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001738 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
1739 callingPackage, Binder.getCallingUid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001740 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
1742
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001743 if (DBG_LOC) log("getAllCellInfo: is active user");
1744 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1745 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1746 for (Phone phone : PhoneFactory.getPhones()) {
1747 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1748 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001750 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
1752
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001753 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001755 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001756 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1757 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759
Shishir Agrawala9f32182016-04-12 12:00:16 -07001760 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001761 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001762 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1763 return null;
1764 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001765 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001766 return phone == null ? null : phone.getImei();
1767 }
1768
1769 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001770 public String getMeidForSlot(int slotIndex, String callingPackage) {
1771 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1772 return null;
1773 }
1774 Phone phone = PhoneFactory.getPhone(slotIndex);
1775 return phone == null ? null : phone.getMeid();
1776 }
1777
1778 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001779 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001780 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1781 return null;
1782 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001783 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001784 return phone == null ? null : phone.getDeviceSvn();
1785 }
1786
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 //
1788 // Internal helper methods.
1789 //
1790
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001791 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1793 *
1794 * @throws SecurityException if the caller does not have the required permission
1795 */
1796 private void enforceModifyPermission() {
1797 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1798 }
1799
1800 /**
Junda Liua2e36012014-07-09 18:30:01 -07001801 * Make sure either system app or the caller has carrier privilege.
1802 *
1803 * @throws SecurityException if the caller does not have the required permission/privilege
1804 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001805 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001806 int permission = mApp.checkCallingOrSelfPermission(
1807 android.Manifest.permission.MODIFY_PHONE_STATE);
1808 if (permission == PackageManager.PERMISSION_GRANTED) {
1809 return;
1810 }
1811
1812 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001813 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001814 }
1815
1816 /**
1817 * Make sure the caller has carrier privilege.
1818 *
1819 * @throws SecurityException if the caller does not have the required permission
1820 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001821 private void enforceCarrierPrivilege(int subId) {
1822 if (getCarrierPrivilegeStatus(subId) !=
1823 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001824 loge("No Carrier Privilege.");
1825 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001826 }
1827 }
1828
1829 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 * Make sure the caller has the CALL_PHONE permission.
1831 *
1832 * @throws SecurityException if the caller does not have the required permission
1833 */
1834 private void enforceCallPermission() {
1835 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1836 }
1837
Stuart Scott8eef64f2015-04-08 15:13:54 -07001838 private void enforceConnectivityInternalPermission() {
1839 mApp.enforceCallingOrSelfPermission(
1840 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1841 "ConnectivityService");
1842 }
1843
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 private String createTelUrl(String number) {
1845 if (TextUtils.isEmpty(number)) {
1846 return null;
1847 }
1848
Jake Hambye994d462014-02-03 13:10:13 -08001849 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 }
1851
Ihab Awadf9e92732013-12-05 18:02:52 -08001852 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1854 }
1855
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001856 private static void logv(String msg) {
1857 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1858 }
1859
Ihab Awadf9e92732013-12-05 18:02:52 -08001860 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1862 }
1863
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001864 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001865 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001866 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001867 }
1868
Sanket Padawe356d7632015-06-22 14:03:32 -07001869 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001870 public int getActivePhoneTypeForSlot(int slotIndex) {
1871 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 if (phone == null) {
1873 return PhoneConstants.PHONE_TYPE_NONE;
1874 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001875 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 }
1878
1879 /**
1880 * Returns the CDMA ERI icon index to display
1881 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001882 @Override
1883 public int getCdmaEriIconIndex(String callingPackage) {
1884 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001885 }
1886
Sanket Padawe356d7632015-06-22 14:03:32 -07001887 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001888 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1889 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1890 return -1;
1891 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 final Phone phone = getPhone(subId);
1893 if (phone != null) {
1894 return phone.getCdmaEriIconIndex();
1895 } else {
1896 return -1;
1897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 }
1899
1900 /**
1901 * Returns the CDMA ERI icon mode,
1902 * 0 - ON
1903 * 1 - FLASHING
1904 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001905 @Override
1906 public int getCdmaEriIconMode(String callingPackage) {
1907 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001908 }
1909
Sanket Padawe356d7632015-06-22 14:03:32 -07001910 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001911 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1912 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1913 return -1;
1914 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001915 final Phone phone = getPhone(subId);
1916 if (phone != null) {
1917 return phone.getCdmaEriIconMode();
1918 } else {
1919 return -1;
1920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
1923 /**
1924 * Returns the CDMA ERI text,
1925 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001926 @Override
1927 public String getCdmaEriText(String callingPackage) {
1928 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001929 }
1930
Sanket Padawe356d7632015-06-22 14:03:32 -07001931 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001932 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1933 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1934 return null;
1935 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 final Phone phone = getPhone(subId);
1937 if (phone != null) {
1938 return phone.getCdmaEriText();
1939 } else {
1940 return null;
1941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
1944 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001945 * Returns the CDMA MDN.
1946 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001948 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001949 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001950 final Phone phone = getPhone(subId);
1951 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1952 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001953 } else {
1954 return null;
1955 }
1956 }
1957
1958 /**
1959 * Returns the CDMA MIN.
1960 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001962 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001963 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001964 final Phone phone = getPhone(subId);
1965 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1966 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001967 } else {
1968 return null;
1969 }
1970 }
1971
1972 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 * Returns true if CDMA provisioning needs to run.
1974 */
1975 public boolean needsOtaServiceProvisioning() {
1976 return mPhone.needsOtaServiceProvisioning();
1977 }
1978
1979 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001980 * Sets the voice mail number of a given subId.
1981 */
1982 @Override
1983 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001984 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001985 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1986 new Pair<String, String>(alphaTag, number), new Integer(subId));
1987 return success;
1988 }
1989
Ta-wei Yen87c49842016-05-13 21:19:52 -07001990 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07001991 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
1992 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1993 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
1994 if (!TextUtils.equals(callingPackage, systemDialer)) {
1995 throw new SecurityException("caller must be system dialer");
1996 }
1997 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
1998 if (phoneAccountHandle == null){
1999 return null;
2000 }
2001 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2002 }
2003
2004 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002005 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002006 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2007 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2008 return null;
2009 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002010 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2011 }
2012
2013 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002014 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2015 VisualVoicemailSmsFilterSettings settings) {
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 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2019 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002020 }
2021
2022 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002023 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2024 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002025 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002026 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002027 }
2028
2029 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002030 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2031 String callingPackage, int subId) {
2032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002033 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002034 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002035 }
2036
2037 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002038 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002039 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002040 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002041 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2042 }
2043
2044 @Override
2045 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2046 String number, int port, String text, PendingIntent sentIntent) {
2047 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002048 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002049 enforceSendSmsPermission();
2050 // Make the calls as the phone process.
2051 final long identity = Binder.clearCallingIdentity();
2052 try {
2053 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2054 if (port == 0) {
2055 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2056 sentIntent, null, false);
2057 } else {
2058 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2059 smsManager.sendDataMessageWithSelfPermissions(number, null,
2060 (short) port, data, sentIntent, null);
2061 }
2062 } finally {
2063 Binder.restoreCallingIdentity(identity);
2064 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002065 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002066 /**
fionaxu0152e512016-11-14 13:36:14 -08002067 * Sets the voice activation state of a given subId.
2068 */
2069 @Override
2070 public void setVoiceActivationState(int subId, int activationState) {
2071 enforceModifyPermissionOrCarrierPrivilege(subId);
2072 final Phone phone = getPhone(subId);
2073 if (phone != null) {
2074 phone.setVoiceActivationState(activationState);
2075 } else {
2076 loge("setVoiceActivationState fails with invalid subId: " + subId);
2077 }
2078 }
2079
2080 /**
2081 * Sets the data activation state of a given subId.
2082 */
2083 @Override
2084 public void setDataActivationState(int subId, int activationState) {
2085 enforceModifyPermissionOrCarrierPrivilege(subId);
2086 final Phone phone = getPhone(subId);
2087 if (phone != null) {
2088 phone.setDataActivationState(activationState);
2089 } else {
2090 loge("setVoiceActivationState fails with invalid subId: " + subId);
2091 }
2092 }
2093
2094 /**
2095 * Returns the voice activation state of a given subId.
2096 */
2097 @Override
2098 public int getVoiceActivationState(int subId, String callingPackage) {
2099 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2100 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2101 }
2102 final Phone phone = getPhone(subId);
2103 if (phone != null) {
2104 return phone.getVoiceActivationState();
2105 } else {
2106 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2107 }
2108 }
2109
2110 /**
2111 * Returns the data activation state of a given subId.
2112 */
2113 @Override
2114 public int getDataActivationState(int subId, String callingPackage) {
2115 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2116 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2117 }
2118 final Phone phone = getPhone(subId);
2119 if (phone != null) {
2120 return phone.getDataActivationState();
2121 } else {
2122 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2123 }
2124 }
2125
2126 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 * Returns the unread count of voicemails
2128 */
2129 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002130 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002131 }
2132
2133 /**
2134 * Returns the unread count of voicemails for a subId
2135 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002136 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002137 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002138 final Phone phone = getPhone(subId);
2139 if (phone != null) {
2140 return phone.getVoiceMessageCount();
2141 } else {
2142 return 0;
2143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 }
2145
2146 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002147 * returns true, if the device is in a state where both voice and data
2148 * are supported simultaneously. This can change based on location or network condition.
2149 */
2150 @Override
2151 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2152 final Phone phone = getPhone(subId);
2153 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2154 }
2155
2156 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002157 * Send the dialer code if called from the current default dialer or the caller has
2158 * carrier privilege.
2159 * @param inputCode The dialer code to send
2160 */
2161 @Override
2162 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2163 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2164 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2165 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2166 enforceCarrierPrivilege(getDefaultSubscription());
2167 }
2168 mPhone.sendDialerSpecialCode(inputCode);
2169 }
2170
2171 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002172 * Returns the data network type.
2173 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 *
2175 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2176 */
2177 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002178 public int getNetworkType() {
2179 final Phone phone = getPhone(getDefaultSubscription());
2180 if (phone != null) {
2181 return phone.getServiceState().getDataNetworkType();
2182 } else {
2183 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2184 }
Wink Saville36469e72014-06-11 15:17:00 -07002185 }
2186
2187 /**
2188 * Returns the network type for a subId
2189 */
2190 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002191 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2192 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2193 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2194 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002195
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002197 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002198 return phone.getServiceState().getDataNetworkType();
2199 } else {
2200 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2201 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 }
2203
2204 /**
2205 * Returns the data network type
2206 */
2207 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002208 public int getDataNetworkType(String callingPackage) {
2209 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002210 }
2211
2212 /**
2213 * Returns the data network type for a subId
2214 */
2215 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002216 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2217 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2218 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2219 }
2220
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 final Phone phone = getPhone(subId);
2222 if (phone != null) {
2223 return phone.getServiceState().getDataNetworkType();
2224 } else {
2225 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 }
2228
2229 /**
Wink Saville36469e72014-06-11 15:17:00 -07002230 * Returns the Voice network type for a subId
2231 */
2232 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002233 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2234 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2235 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2236 }
2237
Sanket Padawe356d7632015-06-22 14:03:32 -07002238 final Phone phone = getPhone(subId);
2239 if (phone != null) {
2240 return phone.getServiceState().getVoiceNetworkType();
2241 } else {
2242 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 }
2245
2246 /**
2247 * @return true if a ICC card is present
2248 */
2249 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002250 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002251 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2252 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002253 }
2254
2255 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002256 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002257 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002258 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002259 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2260 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002261 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002262 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002263 } else {
2264 return false;
2265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
2268 /**
2269 * Return if the current radio is LTE on CDMA. This
2270 * is a tri-state return value as for a period of time
2271 * the mode may be unknown.
2272 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002273 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002275 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002277 @Override
2278 public int getLteOnCdmaMode(String callingPackage) {
2279 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002280 }
2281
Sanket Padawe356d7632015-06-22 14:03:32 -07002282 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002283 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2284 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2285 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2286 }
2287
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 final Phone phone = getPhone(subId);
2289 if (phone == null) {
2290 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2291 } else {
2292 return phone.getLteOnCdmaMode();
2293 }
Wink Saville36469e72014-06-11 15:17:00 -07002294 }
2295
2296 public void setPhone(Phone phone) {
2297 mPhone = phone;
2298 }
2299
2300 /**
2301 * {@hide}
2302 * Returns Default subId, 0 in the case of single standby.
2303 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002304 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002305 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002306 }
2307
Shishir Agrawala9f32182016-04-12 12:00:16 -07002308 private int getSlotForDefaultSubscription() {
2309 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2310 }
2311
Wink Savilleb564aae2014-10-23 10:18:09 -07002312 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002313 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002315
2316 /**
2317 * @see android.telephony.TelephonyManager.WifiCallingChoices
2318 */
2319 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002320 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2321 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002322 }
2323
2324 /**
2325 * @see android.telephony.TelephonyManager.WifiCallingChoices
2326 */
2327 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002328 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2329 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2330 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002331 }
2332
Sailesh Nepald1e68152013-12-12 19:08:02 -08002333 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002334 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002335 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002336 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002337
Shishir Agrawal566b7612013-10-28 14:41:00 -07002338 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002339 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2340 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002341 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002342
Derek Tan740e1672017-06-27 14:56:27 -07002343 if (TextUtils.equals(ISDR_AID, aid)) {
2344 // Only allows LPA to open logical channel to ISD-R.
2345 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2346 ComponentInfo bestComponent =
2347 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2348 if (bestComponent == null
2349 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2350 loge("The calling package is not allowed to access ISD-R.");
2351 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2352 }
2353 }
2354
2355 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002356 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002357 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002358 if (DBG) log("iccOpenLogicalChannel: " + response);
2359 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002360 }
2361
2362 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002363 public boolean iccCloseLogicalChannel(int subId, int channel) {
2364 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002365
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002366 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002367 if (channel < 0) {
2368 return false;
2369 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002370 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002371 if (DBG) log("iccCloseLogicalChannel: " + success);
2372 return success;
2373 }
2374
2375 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002376 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002377 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002378 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002379
2380 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002381 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2382 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002383 " data=" + data);
2384 }
2385
2386 if (channel < 0) {
2387 return "";
2388 }
2389
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002390 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002391 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002392 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2393
Shishir Agrawal566b7612013-10-28 14:41:00 -07002394 // Append the returned status code to the end of the response payload.
2395 String s = Integer.toHexString(
2396 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002397 if (response.payload != null) {
2398 s = IccUtils.bytesToHexString(response.payload) + s;
2399 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002400 return s;
2401 }
Jake Hambye994d462014-02-03 13:10:13 -08002402
Evan Charltonc66da362014-05-16 14:06:40 -07002403 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002404 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002405 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002406 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002407
2408 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002409 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2410 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002411 }
2412
2413 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002414 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002415 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2416
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002417 // Append the returned status code to the end of the response payload.
2418 String s = Integer.toHexString(
2419 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002420 if (response.payload != null) {
2421 s = IccUtils.bytesToHexString(response.payload) + s;
2422 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002423 return s;
2424 }
2425
2426 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002427 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002428 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002429 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002430
2431 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002432 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002433 p1 + " " + p2 + " " + p3 + ":" + filePath);
2434 }
2435
2436 IccIoResult response =
2437 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002438 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2439 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002440
2441 if (DBG) {
2442 log("Exchange SIM_IO [R]" + response);
2443 }
2444
2445 byte[] result = null;
2446 int length = 2;
2447 if (response.payload != null) {
2448 length = 2 + response.payload.length;
2449 result = new byte[length];
2450 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2451 } else {
2452 result = new byte[length];
2453 }
2454
2455 result[length - 1] = (byte) response.sw2;
2456 result[length - 2] = (byte) response.sw1;
2457 return result;
2458 }
2459
Nathan Haroldb3014052017-01-25 15:57:32 -08002460 /**
2461 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2462 * on a particular subscription
2463 */
2464 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002465 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2466 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002467 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2468 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2469 return null;
2470 }
2471 Object response = sendRequest(
2472 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2473 if (response instanceof String[]) {
2474 return (String[]) response;
2475 }
2476 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2477 return null;
2478 }
2479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002480 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002481 public String sendEnvelopeWithStatus(int subId, String content) {
2482 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002483
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002484 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002485 if (response.payload == null) {
2486 return "";
2487 }
2488
2489 // Append the returned status code to the end of the response payload.
2490 String s = Integer.toHexString(
2491 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2492 s = IccUtils.bytesToHexString(response.payload) + s;
2493 return s;
2494 }
2495
Jake Hambye994d462014-02-03 13:10:13 -08002496 /**
2497 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2498 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2499 *
2500 * @param itemID the ID of the item to read
2501 * @return the NV item as a String, or null on error.
2502 */
2503 @Override
2504 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002505 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002506 if (DBG) log("nvReadItem: item " + itemID);
2507 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2508 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2509 return value;
2510 }
2511
2512 /**
2513 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2514 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2515 *
2516 * @param itemID the ID of the item to read
2517 * @param itemValue the value to write, as a String
2518 * @return true on success; false on any failure
2519 */
2520 @Override
2521 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002522 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002523 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2524 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2525 new Pair<Integer, String>(itemID, itemValue));
2526 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2527 return success;
2528 }
2529
2530 /**
2531 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2532 * Used for device configuration by some CDMA operators.
2533 *
2534 * @param preferredRoamingList byte array containing the new PRL
2535 * @return true on success; false on any failure
2536 */
2537 @Override
2538 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002539 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002540 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2541 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2542 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2543 return success;
2544 }
2545
2546 /**
2547 * Perform the specified type of NV config reset.
2548 * Used for device configuration by some CDMA operators.
2549 *
2550 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2551 * @return true on success; false on any failure
2552 */
2553 @Override
2554 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002555 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002556 if (DBG) log("nvResetConfig: type " + resetType);
2557 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2558 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2559 return success;
2560 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002561
2562 /**
Wink Saville36469e72014-06-11 15:17:00 -07002563 * {@hide}
2564 * Returns Default sim, 0 in the case of single standby.
2565 */
2566 public int getDefaultSim() {
2567 //TODO Need to get it from Telephony Devcontroller
2568 return 0;
2569 }
2570
Svet Ganovb320e182015-04-16 12:30:10 -07002571 public String[] getPcscfAddress(String apnType, String callingPackage) {
2572 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2573 return new String[0];
2574 }
2575
2576
ram87fca6f2014-07-18 18:58:44 +05302577 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002578 }
2579
Brad Ebinger51f743a2017-01-23 13:50:20 -08002580 /**
2581 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2582 * feature or {@link null} if the service is not available. If an ImsServiceController is
2583 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2584 * feature updates.
2585 */
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002586 public IImsServiceController getImsServiceControllerAndListen(int slotIndex, int feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002587 IImsServiceFeatureListener callback) {
2588 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002589 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotIndex, feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002590 callback);
2591 }
2592
Wink Saville36469e72014-06-11 15:17:00 -07002593 public void setImsRegistrationState(boolean registered) {
2594 enforceModifyPermission();
2595 mPhone.setImsRegistrationState(registered);
2596 }
2597
2598 /**
Stuart Scott54788802015-03-30 13:18:01 -07002599 * Set the network selection mode to automatic.
2600 *
2601 */
2602 @Override
2603 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002604 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002605 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2606 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2607 }
2608
2609 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002610 * Set the network selection mode to manual with the selected carrier.
2611 */
2612 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002613 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2614 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002615 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002616 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002617 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2618 persistSelection);
2619 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002620 }
2621
2622 /**
2623 * Scans for available networks.
2624 */
2625 @Override
2626 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002627 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002628 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2629 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2630 CMD_PERFORM_NETWORK_SCAN, null, subId);
2631 return result;
2632 }
2633
2634 /**
yinxub1bed742017-04-17 11:45:04 -07002635 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002636 *
yinxub1bed742017-04-17 11:45:04 -07002637 * @param subId id of the subscription
2638 * @param request contains the radio access networks with bands/channels to scan
2639 * @param messenger callback messenger for scan results or errors
2640 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002641 * @return the id of the requested scan which can be used to stop the scan.
2642 */
2643 @Override
2644 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2645 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002646 enforceModifyPermissionOrCarrierPrivilege(subId);
2647 return mNetworkScanRequestTracker.startNetworkScan(
2648 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002649 }
2650
2651 /**
2652 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002653 *
2654 * @param subId id of the subscription
2655 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002656 */
2657 @Override
2658 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002659 enforceModifyPermissionOrCarrierPrivilege(subId);
2660 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002661 }
2662
2663 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002664 * Get the calculated preferred network type.
2665 * Used for debugging incorrect network type.
2666 *
2667 * @return the preferred network type, defined in RILConstants.java.
2668 */
2669 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002670 public int getCalculatedPreferredNetworkType(String callingPackage) {
2671 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2672 return RILConstants.PREFERRED_NETWORK_MODE;
2673 }
2674
Amit Mahajan43330e02014-11-18 11:54:45 -08002675 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002676 }
2677
2678 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002679 * Get the preferred network type.
2680 * Used for device configuration by some CDMA operators.
2681 *
2682 * @return the preferred network type, defined in RILConstants.java.
2683 */
2684 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002685 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002686 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002687 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002688 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002689 int networkType = (result != null ? result[0] : -1);
2690 if (DBG) log("getPreferredNetworkType: " + networkType);
2691 return networkType;
2692 }
2693
2694 /**
2695 * Set the preferred network type.
2696 * Used for device configuration by some CDMA operators.
2697 *
2698 * @param networkType the preferred network type, defined in RILConstants.java.
2699 * @return true on success; false on any failure.
2700 */
2701 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002702 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002703 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002704 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2705 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002706 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002707 if (success) {
2708 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002709 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002710 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002711 return success;
2712 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002713
2714 /**
Junda Liu475951f2014-11-07 16:45:03 -08002715 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2716 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2717 * tethering.
2718 *
2719 * @return 0: Not required. 1: required. 2: Not set.
2720 * @hide
2721 */
2722 @Override
2723 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002724 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002725 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2726 Settings.Global.TETHER_DUN_REQUIRED, 2);
2727 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2728 // config_tether_apndata.
2729 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2730 dunRequired = 1;
2731 }
2732 return dunRequired;
2733 }
2734
2735 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002736 * Set mobile data enabled
2737 * Used by the user through settings etc to turn on/off mobile data
2738 *
2739 * @param enable {@code true} turn turn data on, else {@code false}
2740 */
2741 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002742 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002743 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002744 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002745 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002746 Phone phone = PhoneFactory.getPhone(phoneId);
2747 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002748 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002749 phone.setDataEnabled(enable);
2750 } else {
2751 loge("setDataEnabled: no phone for subId=" + subId);
2752 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002753 }
2754
2755 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002756 * Get whether mobile data is enabled.
2757 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002758 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002759 *
2760 * @return {@code true} if data is enabled else {@code false}
2761 */
2762 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002763 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002764 try {
2765 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2766 null);
2767 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002768 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002769 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002770 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002771 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002772 Phone phone = PhoneFactory.getPhone(phoneId);
2773 if (phone != null) {
2774 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002775 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002776 return retVal;
2777 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002778 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002779 return false;
2780 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002781 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002782
2783 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002784 public int getCarrierPrivilegeStatus(int subId) {
2785 final Phone phone = getPhone(subId);
2786 if (phone == null) {
2787 loge("getCarrierPrivilegeStatus: Invalid subId");
2788 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2789 }
2790 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002791 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002792 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002793 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2794 }
2795 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002796 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002797 }
Junda Liu29340342014-07-10 15:23:27 -07002798
2799 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002800 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002801 if (TextUtils.isEmpty(pkgName))
2802 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002803 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002804 if (card == null) {
2805 loge("checkCarrierPrivilegesForPackage: No UICC");
2806 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2807 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002808 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2809 }
2810
2811 @Override
2812 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002813 if (TextUtils.isEmpty(pkgName))
2814 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002815 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2816 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2817 UiccCard card = UiccController.getInstance().getUiccCard(i);
2818 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002819 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002820 continue;
2821 }
2822
2823 result = card.getCarrierPrivilegeStatus(
2824 mPhone.getContext().getPackageManager(), pkgName);
2825 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2826 break;
2827 }
2828 }
2829
2830 return result;
Junda Liu29340342014-07-10 15:23:27 -07002831 }
Derek Tan89e89d42014-07-08 17:00:10 -07002832
2833 @Override
Junda Liue64de782015-04-16 17:19:16 -07002834 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2835 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2836 loge("phoneId " + phoneId + " is not valid.");
2837 return null;
2838 }
2839 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002840 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002841 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002842 return null ;
2843 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002844 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002845 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002846 }
2847
Amith Yamasani6e118872016-02-19 12:53:51 -08002848 @Override
2849 public List<String> getPackagesWithCarrierPrivileges() {
2850 PackageManager pm = mPhone.getContext().getPackageManager();
2851 List<String> privilegedPackages = new ArrayList<>();
2852 List<PackageInfo> packages = null;
2853 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2854 UiccCard card = UiccController.getInstance().getUiccCard(i);
2855 if (card == null) {
2856 // No UICC in that slot.
2857 continue;
2858 }
2859 if (card.hasCarrierPrivilegeRules()) {
2860 if (packages == null) {
2861 // Only check packages in user 0 for now
2862 packages = pm.getInstalledPackagesAsUser(
2863 PackageManager.MATCH_DISABLED_COMPONENTS
2864 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2865 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2866 }
2867 for (int p = packages.size() - 1; p >= 0; p--) {
2868 PackageInfo pkgInfo = packages.get(p);
2869 if (pkgInfo != null && pkgInfo.packageName != null
2870 && card.getCarrierPrivilegeStatus(pkgInfo)
2871 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2872 privilegedPackages.add(pkgInfo.packageName);
2873 }
2874 }
2875 }
2876 }
2877 return privilegedPackages;
2878 }
2879
Wink Savilleb564aae2014-10-23 10:18:09 -07002880 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 final Phone phone = getPhone(subId);
2882 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002883 if (card == null) {
2884 loge("getIccId: No UICC");
2885 return null;
2886 }
2887 String iccId = card.getIccId();
2888 if (TextUtils.isEmpty(iccId)) {
2889 loge("getIccId: ICC ID is null or empty.");
2890 return null;
2891 }
2892 return iccId;
2893 }
2894
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002895 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002896 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2897 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002898 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002899
Jeff Sharkey85190e62014-12-05 09:40:12 -08002900 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 final Phone phone = getPhone(subId);
2902 if (phone == null) {
2903 return false;
2904 }
2905 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002906
2907 if (DBG_MERGE) {
2908 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2909 + subscriberId + " to " + number);
2910 }
2911
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002912 if (TextUtils.isEmpty(iccId)) {
2913 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002914 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002915
Jeff Sharkey85190e62014-12-05 09:40:12 -08002916 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2917
2918 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002919 if (alphaTag == null) {
2920 editor.remove(alphaTagPrefKey);
2921 } else {
2922 editor.putString(alphaTagPrefKey, alphaTag);
2923 }
2924
Jeff Sharkey85190e62014-12-05 09:40:12 -08002925 // Record both the line number and IMSI for this ICCID, since we need to
2926 // track all merged IMSIs based on line number
2927 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2928 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002929 if (number == null) {
2930 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002931 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002932 } else {
2933 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002934 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002935 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002936
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002937 editor.commit();
2938 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002939 }
2940
2941 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002942 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002943 // This is open to apps with WRITE_SMS.
2944 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002945 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002946 return null;
2947 }
Derek Tan97ebb422014-09-05 16:55:38 -07002948
2949 String iccId = getIccId(subId);
2950 if (iccId != null) {
2951 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002952 if (DBG_MERGE) {
2953 log("getLine1NumberForDisplay returning " +
2954 mTelephonySharedPreferences.getString(numberPrefKey, null));
2955 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002956 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002957 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002958 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002959 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002960 }
2961
2962 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002963 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
2964 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
2965 return null;
2966 }
Derek Tan97ebb422014-09-05 16:55:38 -07002967
2968 String iccId = getIccId(subId);
2969 if (iccId != null) {
2970 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07002971 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002972 }
Derek Tan97ebb422014-09-05 16:55:38 -07002973 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002974 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07002975
2976 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002977 public String[] getMergedSubscriberIds(String callingPackage) {
2978 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
2979 return null;
2980 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002981 final Context context = mPhone.getContext();
2982 final TelephonyManager tele = TelephonyManager.from(context);
2983 final SubscriptionManager sub = SubscriptionManager.from(context);
2984
2985 // Figure out what subscribers are currently active
2986 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07002987 // Clear calling identity, when calling TelephonyManager, because callerUid must be
2988 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
2991 final int[] subIds = sub.getActiveSubscriptionIdList();
2992 for (int subId : subIds) {
2993 activeSubscriberIds.add(tele.getSubscriberId(subId));
2994 }
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002997 }
2998
2999 // First pass, find a number override for an active subscriber
3000 String mergeNumber = null;
3001 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3002 for (String key : prefs.keySet()) {
3003 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3004 final String subscriberId = (String) prefs.get(key);
3005 if (activeSubscriberIds.contains(subscriberId)) {
3006 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3007 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3008 mergeNumber = (String) prefs.get(numberKey);
3009 if (DBG_MERGE) {
3010 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3011 + " for active subscriber " + subscriberId);
3012 }
3013 if (!TextUtils.isEmpty(mergeNumber)) {
3014 break;
3015 }
3016 }
3017 }
3018 }
3019
3020 // Shortcut when no active merged subscribers
3021 if (TextUtils.isEmpty(mergeNumber)) {
3022 return null;
3023 }
3024
3025 // Second pass, find all subscribers under that line override
3026 final ArraySet<String> result = new ArraySet<>();
3027 for (String key : prefs.keySet()) {
3028 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3029 final String number = (String) prefs.get(key);
3030 if (mergeNumber.equals(number)) {
3031 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3032 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3033 final String subscriberId = (String) prefs.get(subscriberKey);
3034 if (!TextUtils.isEmpty(subscriberId)) {
3035 result.add(subscriberId);
3036 }
3037 }
3038 }
3039 }
3040
3041 final String[] resultArray = result.toArray(new String[result.size()]);
3042 Arrays.sort(resultArray);
3043 if (DBG_MERGE) {
3044 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3045 }
3046 return resultArray;
3047 }
3048
3049 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003050 public boolean setOperatorBrandOverride(int subId, String brand) {
3051 enforceCarrierPrivilege(subId);
3052 final Phone phone = getPhone(subId);
3053 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003054 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003055
3056 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003057 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003058 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3059 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003060 enforceCarrierPrivilege(subId);
3061 final Phone phone = getPhone(subId);
3062 if (phone == null) {
3063 return false;
3064 }
3065 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003066 cdmaNonRoamingList);
3067 }
3068
3069 @Override
Amit Mahajanf43fe462017-02-23 12:08:31 -08003070 @Deprecated
Steven Liu4bf01bc2014-07-17 11:05:29 -05003071 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3072 enforceModifyPermission();
3073
3074 int returnValue = 0;
3075 try {
3076 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3077 if(result.exception == null) {
3078 if (result.result != null) {
3079 byte[] responseData = (byte[])(result.result);
3080 if(responseData.length > oemResp.length) {
3081 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3082 responseData.length + "bytes. Buffer Size is " +
3083 oemResp.length + "bytes.");
3084 }
3085 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3086 returnValue = responseData.length;
3087 }
3088 } else {
3089 CommandException ex = (CommandException) result.exception;
3090 returnValue = ex.getCommandError().ordinal();
3091 if(returnValue > 0) returnValue *= -1;
3092 }
3093 } catch (RuntimeException e) {
3094 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3095 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3096 if(returnValue > 0) returnValue *= -1;
3097 }
3098
3099 return returnValue;
3100 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003101
3102 @Override
3103 public void setRadioCapability(RadioAccessFamily[] rafs) {
3104 try {
3105 ProxyController.getInstance().setRadioCapability(rafs);
3106 } catch (RuntimeException e) {
3107 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3108 }
3109 }
3110
3111 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003112 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3113 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3114 return RadioAccessFamily.RAF_UNKNOWN;
3115 }
3116
Wink Saville5d475dd2014-10-17 15:00:58 -07003117 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3118 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003119
3120 @Override
3121 public void enableVideoCalling(boolean enable) {
3122 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003123 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003124 }
3125
3126 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003127 public boolean isVideoCallingEnabled(String callingPackage) {
3128 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3129 return false;
3130 }
3131
Andrew Lee77527ac2014-10-21 16:57:39 -07003132 // Check the user preference and the system-level IMS setting. Even if the user has
3133 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3134 // In the long run, we may instead need to check if there exists a connection service
3135 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003136 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3137 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003138 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003139 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003140
Andrew Leea1239f22015-03-02 17:44:07 -08003141 @Override
3142 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003143 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003144 }
3145
3146 @Override
3147 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003148 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003149 }
3150
Andrew Lee9431b832015-03-09 18:46:45 -07003151 @Override
3152 public boolean isTtyModeSupported() {
3153 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3154 TelephonyManager telephonyManager =
3155 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003156 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003157 }
3158
3159 @Override
3160 public boolean isHearingAidCompatibilitySupported() {
3161 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3162 }
3163
Sanket Padawe7310cc72015-01-14 09:53:20 -08003164 /**
3165 * Returns the unique device ID of phone, for example, the IMEI for
3166 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3167 *
3168 * <p>Requires Permission:
3169 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3170 */
3171 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003172 public String getDeviceId(String callingPackage) {
3173 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3174 return null;
3175 }
3176
Sanket Padawe7310cc72015-01-14 09:53:20 -08003177 final Phone phone = PhoneFactory.getPhone(0);
3178 if (phone != null) {
3179 return phone.getDeviceId();
3180 } else {
3181 return null;
3182 }
3183 }
3184
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003185 /*
3186 * {@hide}
3187 * Returns the IMS Registration Status
3188 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003189 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003190 public boolean isImsRegistered() {
3191 return mPhone.isImsRegistered();
3192 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003193
3194 @Override
3195 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3196 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3197 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003198
Nathan Haroldc55097a2015-03-11 18:14:50 -07003199 /*
3200 * {@hide}
3201 * Returns the IMS Registration Status
3202 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003203 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003204 return mPhone.isWifiCallingEnabled();
3205 }
3206
3207 /*
3208 * {@hide}
3209 * Returns the IMS Registration Status
3210 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003211 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003212 return mPhone.isVolteEnabled();
3213 }
Svet Ganovb320e182015-04-16 12:30:10 -07003214
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003215 /*
3216 * {@hide} Returns the IMS Registration Status
3217 */
3218 public boolean isVideoTelephonyAvailable() {
3219 return mPhone.isVideoEnabled();
3220 }
3221
Svet Ganovb320e182015-04-16 12:30:10 -07003222 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003223 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003224 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003225 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3226
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003227 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003228 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003229 } catch (SecurityException e) {
3230 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3231 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003232 }
Svet Ganovb320e182015-04-16 12:30:10 -07003233
3234 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3235 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3236 return false;
3237 }
3238
3239 return true;
3240 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003241
Makoto Onukifee69342015-06-29 14:44:50 -07003242 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003243 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003244 */
3245 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003246 // Default SMS app can always read it.
3247 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3248 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3249 return true;
3250 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003251
Makoto Onukie4072d12015-08-03 15:12:23 -07003252 try {
3253 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003254 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003255 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003256 // Can be read with READ_SMS too.
3257 try {
3258 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3259 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3260 if (opCode != AppOpsManager.OP_NONE) {
3261 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3262 == AppOpsManager.MODE_ALLOWED;
3263 } else {
3264 return true;
3265 }
3266 } catch (SecurityException readSmsSecurityException) {
3267 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003268 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003269 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003270 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003271 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003272 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003273 if (opCode != AppOpsManager.OP_NONE) {
3274 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3275 == AppOpsManager.MODE_ALLOWED;
3276 } else {
3277 return true;
3278 }
3279 } catch (SecurityException readPhoneNumberSecurityException) {
3280 }
3281
3282 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3283 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3284 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003285 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003286 }
3287
Stuart Scott8eef64f2015-04-08 15:13:54 -07003288 @Override
3289 public void factoryReset(int subId) {
3290 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003291 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3292 return;
3293 }
3294
Svet Ganovcc087f82015-05-12 20:35:54 -07003295 final long identity = Binder.clearCallingIdentity();
3296 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003297 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3298 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003299 // Enable data
3300 setDataEnabled(subId, true);
3301 // Set network selection mode to automatic
3302 setNetworkSelectionModeAutomatic(subId);
3303 // Set preferred mobile network type to the best available
3304 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3305 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003306 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003307 }
3308 } finally {
3309 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003310 }
3311 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003312
3313 @Override
3314 public String getLocaleFromDefaultSim() {
3315 // We query all subscriptions instead of just the active ones, because
3316 // this might be called early on in the provisioning flow when the
3317 // subscriptions potentially aren't active yet.
3318 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3319 if (slist == null || slist.isEmpty()) {
3320 return null;
3321 }
3322
3323 // This function may be called very early, say, from the setup wizard, at
3324 // which point we won't have a default subscription set. If that's the case
3325 // we just choose the first, which will be valid in "most cases".
3326 final int defaultSubId = getDefaultSubscription();
3327 SubscriptionInfo info = null;
3328 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3329 info = slist.get(0);
3330 } else {
3331 for (SubscriptionInfo item : slist) {
3332 if (item.getSubscriptionId() == defaultSubId) {
3333 info = item;
3334 break;
3335 }
3336 }
3337
3338 if (info == null) {
3339 return null;
3340 }
3341 }
3342
3343 // Try and fetch the locale from the carrier properties or from the SIM language
3344 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003345 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003346 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003347 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003348 if (defaultPhone != null) {
3349 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3350 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003351 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003352 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3353 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003354 } else {
3355 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003356 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003357 }
3358 }
3359
Narayan Kamath011676f2015-07-29 12:04:08 +01003360 // The SIM language preferences only store a language (e.g. fr = French), not an
3361 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3362 // the SIM and carrier preferences does not include a country we add the country
3363 // determined from the SIM MCC to provide an exact locale.
3364 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003365 if (mccLocale != null) {
3366 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3367 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003368 }
3369
Tony Hill183b2de2015-06-24 14:53:58 +01003370 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003371 return null;
3372 }
3373
3374 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3375 final long identity = Binder.clearCallingIdentity();
3376 try {
3377 return mSubscriptionController.getAllSubInfoList(
3378 mPhone.getContext().getOpPackageName());
3379 } finally {
3380 Binder.restoreCallingIdentity(identity);
3381 }
3382 }
3383
3384 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 return mSubscriptionController.getActiveSubscriptionInfoList(
3388 mPhone.getContext().getOpPackageName());
3389 } finally {
3390 Binder.restoreCallingIdentity(identity);
3391 }
3392 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003393
3394 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003395 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3396 * representing the state of the modem.
3397 *
3398 * NOTE: This clears the modem state, so there should only every be one caller.
3399 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003400 */
3401 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003402 public void requestModemActivityInfo(ResultReceiver result) {
3403 enforceModifyPermission();
3404
3405 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3406 Bundle bundle = new Bundle();
3407 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3408 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003409 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003410
3411 /**
3412 * {@hide}
3413 * Returns the service state information on specified subscription.
3414 */
3415 @Override
3416 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3417
3418 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3419 return null;
3420 }
3421
3422 final Phone phone = getPhone(subId);
3423 if (phone == null) {
3424 return null;
3425 }
3426
3427 return phone.getServiceState();
3428 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003429
3430 /**
3431 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3432 *
3433 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3434 * voicemail ringtone.
3435 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3436 * PhoneAccount.
3437 */
3438 @Override
3439 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003440 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003441 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003442 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003443 }
3444
fionaxu7ed723d2017-05-30 18:58:54 -07003445 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003446 }
3447
3448 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003449 * Sets the per-account voicemail ringtone.
3450 *
3451 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3452 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3453 *
3454 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3455 * voicemail ringtone.
3456 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3457 * PhoneAccount.
3458 */
3459 @Override
3460 public void setVoicemailRingtoneUri(String callingPackage,
3461 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3462 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3463 if (!TextUtils.equals(callingPackage,
3464 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3465 enforceModifyPermissionOrCarrierPrivilege(
3466 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3467 }
3468 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3469 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003470 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003471 }
fionaxu7ed723d2017-05-30 18:58:54 -07003472 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003473 }
3474
3475 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003476 * Returns whether vibration is set for voicemail notification in Phone settings.
3477 *
3478 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3479 * voicemail vibration setting.
3480 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3481 */
3482 @Override
3483 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003484 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003485 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003486 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003487 }
3488
fionaxu7ed723d2017-05-30 18:58:54 -07003489 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003490 }
3491
Youhan Wange64578a2016-05-02 15:32:42 -07003492 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003493 * Sets the per-account voicemail vibration.
3494 *
3495 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3496 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3497 *
3498 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3499 * voicemail vibration setting.
3500 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3501 * specific PhoneAccount.
3502 */
3503 @Override
3504 public void setVoicemailVibrationEnabled(String callingPackage,
3505 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3506 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3507 if (!TextUtils.equals(callingPackage,
3508 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3509 enforceModifyPermissionOrCarrierPrivilege(
3510 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3511 }
3512
3513 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3514 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003515 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003516 }
fionaxu7ed723d2017-05-30 18:58:54 -07003517 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003518 }
3519
3520 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003521 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3522 *
3523 * @throws SecurityException if the caller does not have the required permission
3524 */
3525 private void enforceReadPrivilegedPermission() {
3526 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3527 null);
3528 }
3529
3530 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003531 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3532 * permission.
3533 *
3534 * @throws SecurityException if the caller does not have the required permission
3535 */
3536 private void enforceSendSmsPermission() {
3537 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3538 }
3539
3540 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003541 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003542 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003543 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003544 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003545 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003546 ComponentName componentName =
3547 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3548 if(componentName == null) {
3549 throw new SecurityException("Caller not current active visual voicemail package[null]");
3550 }
3551 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003552 if (!callingPackage.equals(vvmPackage)) {
3553 throw new SecurityException("Caller not current active visual voicemail package[" +
3554 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003555 }
3556 }
3557
3558 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003559 * Return the application ID for the app type.
3560 *
3561 * @param subId the subscription ID that this request applies to.
3562 * @param appType the uicc app type.
3563 * @return Application ID for specificied app type, or null if no uicc.
3564 */
3565 @Override
3566 public String getAidForAppType(int subId, int appType) {
3567 enforceReadPrivilegedPermission();
3568 Phone phone = getPhone(subId);
3569 if (phone == null) {
3570 return null;
3571 }
3572 String aid = null;
3573 try {
3574 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3575 .getApplicationByType(appType).getAid();
3576 } catch (Exception e) {
3577 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3578 }
3579 return aid;
3580 }
3581
Youhan Wang4001d252016-05-11 10:29:41 -07003582 /**
3583 * Return the Electronic Serial Number.
3584 *
3585 * @param subId the subscription ID that this request applies to.
3586 * @return ESN or null if error.
3587 */
3588 @Override
3589 public String getEsn(int subId) {
3590 enforceReadPrivilegedPermission();
3591 Phone phone = getPhone(subId);
3592 if (phone == null) {
3593 return null;
3594 }
3595 String esn = null;
3596 try {
3597 esn = phone.getEsn();
3598 } catch (Exception e) {
3599 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3600 }
3601 return esn;
3602 }
3603
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003604 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003605 * Return the Preferred Roaming List Version.
3606 *
3607 * @param subId the subscription ID that this request applies to.
3608 * @return PRLVersion or null if error.
3609 */
3610 @Override
3611 public String getCdmaPrlVersion(int subId) {
3612 enforceReadPrivilegedPermission();
3613 Phone phone = getPhone(subId);
3614 if (phone == null) {
3615 return null;
3616 }
3617 String cdmaPrlVersion = null;
3618 try {
3619 cdmaPrlVersion = phone.getCdmaPrlVersion();
3620 } catch (Exception e) {
3621 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3622 }
3623 return cdmaPrlVersion;
3624 }
3625
3626 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003627 * Get snapshot of Telephony histograms
3628 * @return List of Telephony histograms
3629 * @hide
3630 */
3631 @Override
3632 public List<TelephonyHistogram> getTelephonyHistograms() {
3633 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3634 return RIL.getTelephonyRILTimingHistograms();
3635 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003636
3637 /**
3638 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003639 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003640 * Require system privileges. In the future we may add this to carrier APIs.
3641 *
3642 * @return The number of carriers set successfully, should match length of carriers
3643 */
3644 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003645 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003646 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003647
Meng Wang9b7c4e92017-02-17 11:41:27 -08003648 if (carriers == null) {
3649 throw new NullPointerException("carriers cannot be null");
3650 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003651
3652 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003653 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3654 return retVal[0];
3655 }
3656
3657 /**
3658 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003659 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003660 * Require system privileges. In the future we may add this to carrier APIs.
3661 *
3662 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3663 * means all carriers are allowed.
3664 */
3665 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003666 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003667 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003668 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003669 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3670 }
3671
fionaxu59545b42016-05-25 15:53:37 -07003672 /**
3673 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3674 * @param subId the subscription ID that this action applies to.
3675 * @param enabled control enable or disable metered apns.
3676 * {@hide}
3677 */
3678 @Override
3679 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3680 enforceModifyPermission();
3681 final Phone phone = getPhone(subId);
3682 if (phone == null) {
3683 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3684 return;
3685 }
3686 try {
3687 phone.carrierActionSetMeteredApnsEnabled(enabled);
3688 } catch (Exception e) {
3689 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3690 }
3691 }
3692
3693 /**
3694 * Action set from carrier signalling broadcast receivers to enable/disable radio
3695 * @param subId the subscription ID that this action applies to.
3696 * @param enabled control enable or disable radio.
3697 * {@hide}
3698 */
3699 @Override
3700 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3701 enforceModifyPermission();
3702 final Phone phone = getPhone(subId);
3703 if (phone == null) {
3704 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3705 return;
3706 }
3707 try {
3708 phone.carrierActionSetRadioEnabled(enabled);
3709 } catch (Exception e) {
3710 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3711 }
3712 }
3713
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003714 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003715 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3716 * network status based on which carrier apps could apply actions accordingly,
3717 * enable/disable default url handler for example.
3718 *
3719 * @param subId the subscription ID that this action applies to.
3720 * @param report control start/stop reporting the default network status.
3721 * {@hide}
3722 */
3723 @Override
3724 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3725 enforceModifyPermission();
3726 final Phone phone = getPhone(subId);
3727 if (phone == null) {
3728 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3729 return;
3730 }
3731 try {
3732 phone.carrierActionReportDefaultNetworkStatus(report);
3733 } catch (Exception e) {
3734 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3735 }
3736 }
3737
3738 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003739 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3740 * bug report is being generated.
3741 */
3742 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003743 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003744 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3745 != PackageManager.PERMISSION_GRANTED) {
3746 writer.println("Permission Denial: can't dump Phone from pid="
3747 + Binder.getCallingPid()
3748 + ", uid=" + Binder.getCallingUid()
3749 + "without permission "
3750 + android.Manifest.permission.DUMP);
3751 return;
3752 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003753 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003754 }
Jack Yueb89b242016-06-22 13:27:47 -07003755
3756 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003757 * Get aggregated video call data usage since boot.
3758 *
3759 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3760 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003761 * {@hide}
3762 */
3763 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003764 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003765 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3766 null);
3767
Jack Yu84291ec2017-05-26 16:07:50 -07003768 // NetworkStatsService keeps tracking the active network interface and identity. It
3769 // records the delta with the corresponding network identity. We just return the total video
3770 // call data usage snapshot since boot.
3771 Phone phone = getPhone(subId);
3772 if (phone != null) {
3773 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003774 }
Jack Yu84291ec2017-05-26 16:07:50 -07003775 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003776 }
Jack Yu75ab2952016-07-08 14:29:33 -07003777
3778 /**
3779 * Policy control of data connection. Usually used when data limit is passed.
3780 * @param enabled True if enabling the data, otherwise disabling.
3781 * @param subId Subscription index
3782 * {@hide}
3783 */
3784 @Override
3785 public void setPolicyDataEnabled(boolean enabled, int subId) {
3786 enforceModifyPermission();
3787 Phone phone = getPhone(subId);
3788 if (phone != null) {
3789 phone.setPolicyDataEnabled(enabled);
3790 }
3791 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003792
3793 /**
3794 * Get Client request stats
3795 * @return List of Client Request Stats
3796 * @hide
3797 */
3798 @Override
3799 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3800 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3801 return null;
3802 }
3803
3804 Phone phone = getPhone(subId);
3805 if (phone != null) {
3806 return phone.getClientRequestStats();
3807 }
3808
3809 return null;
3810 }
3811
3812 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3813 if (workSource != null) {
3814 return workSource;
3815 }
3816
3817 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3818 workSource = new WorkSource(uid, packageName);
3819 return workSource;
3820 }
Jack Yueb4124c2017-02-16 15:32:43 -08003821
3822 /**
Grace Chen70990072017-03-24 17:21:30 -07003823 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003824 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003825 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003826 * @param state State of SIM (power down, power up, pass through)
3827 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3828 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3829 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003830 *
3831 **/
3832 @Override
Grace Chen70990072017-03-24 17:21:30 -07003833 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003834 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003835 Phone phone = PhoneFactory.getPhone(slotIndex);
3836
Jack Yueb4124c2017-02-16 15:32:43 -08003837 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003838 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003839 }
3840 }
Shuo Qiandd210312017-04-12 22:11:33 +00003841
Tyler Gunn65d45c22017-06-05 11:22:26 -07003842 private boolean isUssdApiAllowed(int subId) {
3843 CarrierConfigManager configManager =
3844 (CarrierConfigManager) mPhone.getContext().getSystemService(
3845 Context.CARRIER_CONFIG_SERVICE);
3846 if (configManager == null) {
3847 return false;
3848 }
3849 PersistableBundle pb = configManager.getConfigForSubId(subId);
3850 if (pb == null) {
3851 return false;
3852 }
3853 return pb.getBoolean(
3854 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3855 }
3856
Shuo Qiandd210312017-04-12 22:11:33 +00003857 /**
3858 * Check if phone is in emergency callback mode
3859 * @return true if phone is in emergency callback mode
3860 * @param subId sub id
3861 */
3862 public boolean getEmergencyCallbackMode(int subId) {
3863 final Phone phone = getPhone(subId);
3864 if (phone != null) {
3865 return phone.isInEcm();
3866 } else {
3867 return false;
3868 }
3869 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003870
3871 /**
3872 * Get the current signal strength information for the given subscription.
3873 * Because this information is not updated when the device is in a low power state
3874 * it should not be relied-upon to be current.
3875 * @param subId Subscription index
3876 * @return the most recent cached signal strength info from the modem
3877 */
3878 @Override
3879 public SignalStrength getSignalStrength(int subId) {
3880 Phone p = getPhone(subId);
3881 if (p == null) {
3882 return null;
3883 }
3884
3885 return p.getSignalStrength();
3886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003887}