blob: 3b2ffc6cdd9042e2c98e8e46433fa35f781ad34d [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.ActivityManager;
23import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070025import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.content.Context;
27import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070028import android.content.SharedPreferences;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Process;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070058import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080059import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070060import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070061import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080064import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070065import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080066import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080067import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070068import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070069import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070071import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080075import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080076import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080077
Andrew Lee312e8172014-10-23 17:01:36 -070078import com.android.ims.ImsManager;
Brad Ebinger51f743a2017-01-23 13:50:20 -080079import com.android.ims.internal.IImsServiceController;
80import com.android.ims.internal.IImsServiceFeatureListener;
Shishir Agrawal566b7612013-10-28 14:41:00 -070081import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070082import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070083import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070084import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080087import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010088import com.android.internal.telephony.MccTable;
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;
Shishir Agrawal566b7612013-10-28 14:41:00 -070098import com.android.internal.telephony.uicc.IccIoResult;
99import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800100import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700101import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800102import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700103import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700104import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800105import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700106import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800107import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700108import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700109import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800110
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700111import java.io.FileDescriptor;
112import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800113import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800116import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100117import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119
120/**
121 * Implementation of the ITelephony interface.
122 */
Santos Cordon117fee72014-05-16 17:56:12 -0700123public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124 private static final String LOG_TAG = "PhoneInterfaceManager";
125 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
126 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128
129 // Message codes used with mMainThreadHandler
130 private static final int CMD_HANDLE_PIN_MMI = 1;
131 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
132 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
133 private static final int CMD_ANSWER_RINGING_CALL = 4;
134 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700135 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
136 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700137 private static final int CMD_OPEN_CHANNEL = 9;
138 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
139 private static final int CMD_CLOSE_CHANNEL = 11;
140 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800141 private static final int CMD_NV_READ_ITEM = 13;
142 private static final int EVENT_NV_READ_ITEM_DONE = 14;
143 private static final int CMD_NV_WRITE_ITEM = 15;
144 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
145 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
146 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
147 private static final int CMD_NV_RESET_CONFIG = 19;
148 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800149 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
150 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
151 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
152 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800153 private static final int CMD_SEND_ENVELOPE = 25;
154 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700155 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
156 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
157 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
158 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
159 private static final int CMD_EXCHANGE_SIM_IO = 31;
160 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800161 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
162 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700163 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
164 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700165 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
166 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700167 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
168 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
169 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
170 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700171 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
172 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
173 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
174 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700175 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800176 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
177 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178
179 /** The singleton instance. */
180 private static PhoneInterfaceManager sInstance;
181
Wink Saville3ab207e2014-11-20 13:07:20 -0800182 private PhoneGlobals mApp;
183 private Phone mPhone;
184 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700185 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800186 private AppOpsManager mAppOps;
187 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800188 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800189 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
Derek Tan97ebb422014-09-05 16:55:38 -0700191 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
192 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800193 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700194
195 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196 * A request object to use for transmitting data to an ICC.
197 */
198 private static final class IccAPDUArgument {
199 public int channel, cla, command, p1, p2, p3;
200 public String data;
201
202 public IccAPDUArgument(int channel, int cla, int command,
203 int p1, int p2, int p3, String data) {
204 this.channel = channel;
205 this.cla = cla;
206 this.command = command;
207 this.p1 = p1;
208 this.p2 = p2;
209 this.p3 = p3;
210 this.data = data;
211 }
212 }
213
214 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700215 * A request object to use for transmitting data to an ICC.
216 */
217 private static final class ManualNetworkSelectionArgument {
218 public OperatorInfo operatorInfo;
219 public boolean persistSelection;
220
221 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
222 this.operatorInfo = operatorInfo;
223 this.persistSelection = persistSelection;
224 }
225 }
226
227 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
229 * request after sending. The main thread will notify the request when it is complete.
230 */
231 private static final class MainThreadRequest {
232 /** The argument to use for the request */
233 public Object argument;
234 /** The result of the request that is run on the main thread */
235 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800236 // The subscriber id that this request applies to. Defaults to
237 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
238 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
240 public MainThreadRequest(Object argument) {
241 this.argument = argument;
242 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800243
244 public MainThreadRequest(Object argument, Integer subId) {
245 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800246 if (subId != null) {
247 this.subId = subId;
248 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250 }
251
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800252 private static final class IncomingThirdPartyCallArgs {
253 public final ComponentName component;
254 public final String callId;
255 public final String callerDisplayName;
256
257 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
258 String callerDisplayName) {
259 this.component = component;
260 this.callId = callId;
261 this.callerDisplayName = callerDisplayName;
262 }
263 }
264
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265 /**
266 * A handler that processes messages on the main thread in the phone process. Since many
267 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
268 * inbound binder threads to the main thread in the phone process. The Binder thread
269 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
270 * on, which will be notified when the operation completes and will contain the result of the
271 * request.
272 *
273 * <p>If a MainThreadRequest object is provided in the msg.obj field,
274 * note that request.result must be set to something non-null for the calling thread to
275 * unblock.
276 */
277 private final class MainThreadHandler extends Handler {
278 @Override
279 public void handleMessage(Message msg) {
280 MainThreadRequest request;
281 Message onCompleted;
282 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800283 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700284 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285
286 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700287 case CMD_HANDLE_USSD_REQUEST: {
288 request = (MainThreadRequest) msg.obj;
289 final Phone phone = getPhoneFromRequest(request);
290 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
291 String ussdRequest = ussdObject.first;
292 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700293
294 if (!isUssdApiAllowed(request.subId)) {
295 // Carrier does not support use of this API, return failure.
296 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
297 UssdResponse response = new UssdResponse(ussdRequest, null);
298 Bundle returnData = new Bundle();
299 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
300 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
301
302 request.result = true;
303 synchronized (request) {
304 request.notifyAll();
305 }
306 return;
307 }
308
Tyler Gunn52dcf772017-04-26 11:30:31 -0700309 try {
310 request.result = phone != null ?
311 phone.handleUssdRequest(ussdRequest, wrappedCallback)
312 : false;
313 } catch (CallStateException cse) {
314 request.result = false;
315 }
pkanwar32d516d2016-10-14 19:37:38 -0700316 // Wake up the requesting thread
317 synchronized (request) {
318 request.notifyAll();
319 }
320 break;
321 }
322
Yorke Lee716f67e2015-06-17 15:39:16 -0700323 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700325 final Phone phone = getPhoneFromRequest(request);
326 request.result = phone != null ?
327 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
328 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329 // Wake up the requesting thread
330 synchronized (request) {
331 request.notifyAll();
332 }
333 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335
336 case CMD_HANDLE_NEIGHBORING_CELL:
337 request = (MainThreadRequest) msg.obj;
338 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
339 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700340 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341 break;
342
343 case EVENT_NEIGHBORING_CELL_DONE:
344 ar = (AsyncResult) msg.obj;
345 request = (MainThreadRequest) ar.userObj;
346 if (ar.exception == null && ar.result != null) {
347 request.result = ar.result;
348 } else {
349 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800350 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 }
352 // Wake up the requesting thread
353 synchronized (request) {
354 request.notifyAll();
355 }
356 break;
357
358 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700359 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800360 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700361 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 break;
363
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 case CMD_END_CALL:
365 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800366 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700367 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700368 Phone phone = getPhone(end_subId);
369 if (phone == null) {
370 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
371 break;
372 }
373 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
375 // CDMA: If the user presses the Power button we treat it as
376 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700377 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
379 // GSM: End the call as per the Phone state
380 hungUp = PhoneUtils.hangup(mCM);
381 } else {
382 throw new IllegalStateException("Unexpected phone type: " + phoneType);
383 }
384 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
385 request.result = hungUp;
386 // Wake up the requesting thread
387 synchronized (request) {
388 request.notifyAll();
389 }
390 break;
391
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700392 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700393 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700394 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800395 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700396 if (uiccCard == null) {
397 loge("iccTransmitApduLogicalChannel: No UICC");
398 request.result = new IccIoResult(0x6F, 0, (byte[])null);
399 synchronized (request) {
400 request.notifyAll();
401 }
402 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700403 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
404 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700405 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700406 iccArgument.channel, iccArgument.cla, iccArgument.command,
407 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700408 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700409 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700410 break;
411
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700413 ar = (AsyncResult) msg.obj;
414 request = (MainThreadRequest) ar.userObj;
415 if (ar.exception == null && ar.result != null) {
416 request.result = ar.result;
417 } else {
418 request.result = new IccIoResult(0x6F, 0, (byte[])null);
419 if (ar.result == null) {
420 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800421 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700422 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800423 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700424 } else {
425 loge("iccTransmitApduLogicalChannel: Unknown exception");
426 }
427 }
428 synchronized (request) {
429 request.notifyAll();
430 }
431 break;
432
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
434 request = (MainThreadRequest) msg.obj;
435 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800436 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 if (uiccCard == null) {
438 loge("iccTransmitApduBasicChannel: No UICC");
439 request.result = new IccIoResult(0x6F, 0, (byte[])null);
440 synchronized (request) {
441 request.notifyAll();
442 }
443 } else {
444 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
445 request);
446 uiccCard.iccTransmitApduBasicChannel(
447 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
448 iccArgument.p3, iccArgument.data, onCompleted);
449 }
450 break;
451
452 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
453 ar = (AsyncResult) msg.obj;
454 request = (MainThreadRequest) ar.userObj;
455 if (ar.exception == null && ar.result != null) {
456 request.result = ar.result;
457 } else {
458 request.result = new IccIoResult(0x6F, 0, (byte[])null);
459 if (ar.result == null) {
460 loge("iccTransmitApduBasicChannel: Empty response");
461 } else if (ar.exception instanceof CommandException) {
462 loge("iccTransmitApduBasicChannel: CommandException: " +
463 ar.exception);
464 } else {
465 loge("iccTransmitApduBasicChannel: Unknown exception");
466 }
467 }
468 synchronized (request) {
469 request.notifyAll();
470 }
471 break;
472
473 case CMD_EXCHANGE_SIM_IO:
474 request = (MainThreadRequest) msg.obj;
475 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800476 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 if (uiccCard == null) {
478 loge("iccExchangeSimIO: No UICC");
479 request.result = new IccIoResult(0x6F, 0, (byte[])null);
480 synchronized (request) {
481 request.notifyAll();
482 }
483 } else {
484 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
485 request);
486 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
487 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
488 iccArgument.data, onCompleted);
489 }
490 break;
491
492 case EVENT_EXCHANGE_SIM_IO_DONE:
493 ar = (AsyncResult) msg.obj;
494 request = (MainThreadRequest) ar.userObj;
495 if (ar.exception == null && ar.result != null) {
496 request.result = ar.result;
497 } else {
498 request.result = new IccIoResult(0x6f, 0, (byte[])null);
499 }
500 synchronized (request) {
501 request.notifyAll();
502 }
503 break;
504
Derek Tan4d5e5c12014-02-04 11:54:58 -0800505 case CMD_SEND_ENVELOPE:
506 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800507 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700508 if (uiccCard == null) {
509 loge("sendEnvelopeWithStatus: No UICC");
510 request.result = new IccIoResult(0x6F, 0, (byte[])null);
511 synchronized (request) {
512 request.notifyAll();
513 }
514 } else {
515 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
516 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
517 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800518 break;
519
520 case EVENT_SEND_ENVELOPE_DONE:
521 ar = (AsyncResult) msg.obj;
522 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700523 if (ar.exception == null && ar.result != null) {
524 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800525 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700526 request.result = new IccIoResult(0x6F, 0, (byte[])null);
527 if (ar.result == null) {
528 loge("sendEnvelopeWithStatus: Empty response");
529 } else if (ar.exception instanceof CommandException) {
530 loge("sendEnvelopeWithStatus: CommandException: " +
531 ar.exception);
532 } else {
533 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
534 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 }
536 synchronized (request) {
537 request.notifyAll();
538 }
539 break;
540
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 case CMD_OPEN_CHANNEL:
542 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800543 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800544 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 if (uiccCard == null) {
546 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800547 request.result = new IccOpenLogicalChannelResponse(-1,
548 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700549 synchronized (request) {
550 request.notifyAll();
551 }
552 } else {
553 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800554 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
555 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 break;
558
559 case EVENT_OPEN_CHANNEL_DONE:
560 ar = (AsyncResult) msg.obj;
561 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 int[] result = (int[]) ar.result;
565 int channelId = result[0];
566 byte[] selectResponse = null;
567 if (result.length > 1) {
568 selectResponse = new byte[result.length - 1];
569 for (int i = 1; i < result.length; ++i) {
570 selectResponse[i - 1] = (byte) result[i];
571 }
572 }
573 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700574 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 if (ar.result == null) {
577 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700579 if (ar.exception != null) {
580 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
581 }
582
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700583 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700584 if (ar.exception instanceof CommandException) {
585 CommandException.Error error =
586 ((CommandException) (ar.exception)).getCommandError();
587 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700588 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700589 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700590 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 }
592 }
593 openChannelResp = new IccOpenLogicalChannelResponse(
594 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700596 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 synchronized (request) {
598 request.notifyAll();
599 }
600 break;
601
602 case CMD_CLOSE_CHANNEL:
603 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800604 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 if (uiccCard == null) {
606 loge("iccCloseLogicalChannel: No UICC");
607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
608 synchronized (request) {
609 request.notifyAll();
610 }
611 } else {
612 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
613 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
614 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 break;
616
617 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800618 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
619 break;
620
621 case CMD_NV_READ_ITEM:
622 request = (MainThreadRequest) msg.obj;
623 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
624 mPhone.nvReadItem((Integer) request.argument, onCompleted);
625 break;
626
627 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 ar = (AsyncResult) msg.obj;
629 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800630 if (ar.exception == null && ar.result != null) {
631 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800633 request.result = "";
634 if (ar.result == null) {
635 loge("nvReadItem: Empty response");
636 } else if (ar.exception instanceof CommandException) {
637 loge("nvReadItem: CommandException: " +
638 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800640 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 }
642 }
643 synchronized (request) {
644 request.notifyAll();
645 }
646 break;
647
Jake Hambye994d462014-02-03 13:10:13 -0800648 case CMD_NV_WRITE_ITEM:
649 request = (MainThreadRequest) msg.obj;
650 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
651 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
652 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
653 break;
654
655 case EVENT_NV_WRITE_ITEM_DONE:
656 handleNullReturnEvent(msg, "nvWriteItem");
657 break;
658
659 case CMD_NV_WRITE_CDMA_PRL:
660 request = (MainThreadRequest) msg.obj;
661 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
662 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
663 break;
664
665 case EVENT_NV_WRITE_CDMA_PRL_DONE:
666 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
667 break;
668
669 case CMD_NV_RESET_CONFIG:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
672 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
673 break;
674
675 case EVENT_NV_RESET_CONFIG_DONE:
676 handleNullReturnEvent(msg, "nvResetConfig");
677 break;
678
Jake Hamby7c27be32014-03-03 13:25:59 -0800679 case CMD_GET_PREFERRED_NETWORK_TYPE:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700682 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800683 break;
684
685 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
686 ar = (AsyncResult) msg.obj;
687 request = (MainThreadRequest) ar.userObj;
688 if (ar.exception == null && ar.result != null) {
689 request.result = ar.result; // Integer
690 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800691 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800692 if (ar.result == null) {
693 loge("getPreferredNetworkType: Empty response");
694 } else if (ar.exception instanceof CommandException) {
695 loge("getPreferredNetworkType: CommandException: " +
696 ar.exception);
697 } else {
698 loge("getPreferredNetworkType: Unknown exception");
699 }
700 }
701 synchronized (request) {
702 request.notifyAll();
703 }
704 break;
705
706 case CMD_SET_PREFERRED_NETWORK_TYPE:
707 request = (MainThreadRequest) msg.obj;
708 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
709 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700710 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 break;
712
713 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
714 handleNullReturnEvent(msg, "setPreferredNetworkType");
715 break;
716
Steven Liu4bf01bc2014-07-17 11:05:29 -0500717 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
718 request = (MainThreadRequest)msg.obj;
719 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
720 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
721 break;
722
723 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
724 ar = (AsyncResult)msg.obj;
725 request = (MainThreadRequest)ar.userObj;
726 request.result = ar;
727 synchronized (request) {
728 request.notifyAll();
729 }
730 break;
731
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800732 case CMD_SET_VOICEMAIL_NUMBER:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
735 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800736 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
737 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800738 break;
739
740 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
741 handleNullReturnEvent(msg, "setVoicemailNumber");
742 break;
743
Stuart Scott54788802015-03-30 13:18:01 -0700744 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
745 request = (MainThreadRequest) msg.obj;
746 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
747 request);
748 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
749 break;
750
751 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
752 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
753 break;
754
Shishir Agrawal302c8692015-06-19 13:49:39 -0700755 case CMD_PERFORM_NETWORK_SCAN:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
758 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
759 break;
760
761 case EVENT_PERFORM_NETWORK_SCAN_DONE:
762 ar = (AsyncResult) msg.obj;
763 request = (MainThreadRequest) ar.userObj;
764 CellNetworkScanResult cellScanResult;
765 if (ar.exception == null && ar.result != null) {
766 cellScanResult = new CellNetworkScanResult(
767 CellNetworkScanResult.STATUS_SUCCESS,
768 (List<OperatorInfo>) ar.result);
769 } else {
770 if (ar.result == null) {
771 loge("getCellNetworkScanResults: Empty response");
772 }
773 if (ar.exception != null) {
774 loge("getCellNetworkScanResults: Exception: " + ar.exception);
775 }
776 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
777 if (ar.exception instanceof CommandException) {
778 CommandException.Error error =
779 ((CommandException) (ar.exception)).getCommandError();
780 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
781 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
782 } else if (error == CommandException.Error.GENERIC_FAILURE) {
783 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
784 }
785 }
786 cellScanResult = new CellNetworkScanResult(errorCode, null);
787 }
788 request.result = cellScanResult;
789 synchronized (request) {
790 request.notifyAll();
791 }
792 break;
793
794 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
795 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700796 ManualNetworkSelectionArgument selArg =
797 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700798 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
799 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700800 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
801 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700802 break;
803
804 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
805 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
806 break;
807
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700808 case CMD_GET_MODEM_ACTIVITY_INFO:
809 request = (MainThreadRequest) msg.obj;
810 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700811 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700812 break;
813
814 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
815 ar = (AsyncResult) msg.obj;
816 request = (MainThreadRequest) ar.userObj;
817 if (ar.exception == null && ar.result != null) {
818 request.result = ar.result;
819 } else {
820 if (ar.result == null) {
821 loge("queryModemActivityInfo: Empty response");
822 } else if (ar.exception instanceof CommandException) {
823 loge("queryModemActivityInfo: CommandException: " +
824 ar.exception);
825 } else {
826 loge("queryModemActivityInfo: Unknown exception");
827 }
828 }
Amit Mahajand4766222016-01-28 15:28:28 -0800829 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
830 if (request.result == null) {
831 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
832 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700833 synchronized (request) {
834 request.notifyAll();
835 }
836 break;
837
Meng Wang1a7c35a2016-05-05 20:56:15 -0700838 case CMD_SET_ALLOWED_CARRIERS:
839 request = (MainThreadRequest) msg.obj;
840 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
841 mPhone.setAllowedCarriers(
842 (List<CarrierIdentifier>) request.argument,
843 onCompleted);
844 break;
845
846 case EVENT_SET_ALLOWED_CARRIERS_DONE:
847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null && ar.result != null) {
850 request.result = ar.result;
851 } else {
852 if (ar.result == null) {
853 loge("setAllowedCarriers: Empty response");
854 } else if (ar.exception instanceof CommandException) {
855 loge("setAllowedCarriers: CommandException: " +
856 ar.exception);
857 } else {
858 loge("setAllowedCarriers: Unknown exception");
859 }
860 }
861 // Result cannot be null. Return -1 on error.
862 if (request.result == null) {
863 request.result = new int[]{-1};
864 }
865 synchronized (request) {
866 request.notifyAll();
867 }
868 break;
869
870 case CMD_GET_ALLOWED_CARRIERS:
871 request = (MainThreadRequest) msg.obj;
872 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
873 mPhone.getAllowedCarriers(onCompleted);
874 break;
875
876 case EVENT_GET_ALLOWED_CARRIERS_DONE:
877 ar = (AsyncResult) msg.obj;
878 request = (MainThreadRequest) ar.userObj;
879 if (ar.exception == null && ar.result != null) {
880 request.result = ar.result;
881 } else {
882 if (ar.result == null) {
883 loge("getAllowedCarriers: Empty response");
884 } else if (ar.exception instanceof CommandException) {
885 loge("getAllowedCarriers: CommandException: " +
886 ar.exception);
887 } else {
888 loge("getAllowedCarriers: Unknown exception");
889 }
890 }
891 // Result cannot be null. Return empty list of CarrierIdentifier.
892 if (request.result == null) {
893 request.result = new ArrayList<CarrierIdentifier>(0);
894 }
895 synchronized (request) {
896 request.notifyAll();
897 }
898 break;
899
Nathan Haroldb3014052017-01-25 15:57:32 -0800900 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null && ar.result != null) {
904 request.result = ar.result;
905 } else {
906 request.result = new IllegalArgumentException(
907 "Failed to retrieve Forbidden Plmns");
908 if (ar.result == null) {
909 loge("getForbiddenPlmns: Empty response");
910 } else {
911 loge("getForbiddenPlmns: Unknown exception");
912 }
913 }
914 synchronized (request) {
915 request.notifyAll();
916 }
917 break;
918
919 case CMD_GET_FORBIDDEN_PLMNS:
920 request = (MainThreadRequest) msg.obj;
921 uiccCard = getUiccCardFromRequest(request);
922 if (uiccCard == null) {
923 loge("getForbiddenPlmns() UiccCard is null");
924 request.result = new IllegalArgumentException(
925 "getForbiddenPlmns() UiccCard is null");
926 synchronized (request) {
927 request.notifyAll();
928 }
929 break;
930 }
931 Integer appType = (Integer) request.argument;
932 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
933 if (uiccApp == null) {
934 loge("getForbiddenPlmns() no app with specified type -- "
935 + appType);
936 request.result = new IllegalArgumentException("Failed to get UICC App");
937 synchronized (request) {
938 request.notifyAll();
939 }
940 break;
941 } else {
942 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
943 + " specified type -- " + appType);
944 }
945 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
946 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
947 onCompleted);
948 break;
949
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700950 default:
951 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
952 break;
953 }
954 }
Jake Hambye994d462014-02-03 13:10:13 -0800955
956 private void handleNullReturnEvent(Message msg, String command) {
957 AsyncResult ar = (AsyncResult) msg.obj;
958 MainThreadRequest request = (MainThreadRequest) ar.userObj;
959 if (ar.exception == null) {
960 request.result = true;
961 } else {
962 request.result = false;
963 if (ar.exception instanceof CommandException) {
964 loge(command + ": CommandException: " + ar.exception);
965 } else {
966 loge(command + ": Unknown exception");
967 }
968 }
969 synchronized (request) {
970 request.notifyAll();
971 }
972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700973 }
974
975 /**
976 * Posts the specified command to be executed on the main thread,
977 * waits for the request to complete, and returns the result.
978 * @see #sendRequestAsync
979 */
980 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800981 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700982 }
983
984 /**
985 * Posts the specified command to be executed on the main thread,
986 * waits for the request to complete, and returns the result.
987 * @see #sendRequestAsync
988 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800989 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700990 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
991 throw new RuntimeException("This method will deadlock if called from the main thread.");
992 }
993
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800994 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700995 Message msg = mMainThreadHandler.obtainMessage(command, request);
996 msg.sendToTarget();
997
998 // Wait for the request to complete
999 synchronized (request) {
1000 while (request.result == null) {
1001 try {
1002 request.wait();
1003 } catch (InterruptedException e) {
1004 // Do nothing, go back and wait until the request is complete
1005 }
1006 }
1007 }
1008 return request.result;
1009 }
1010
1011 /**
1012 * Asynchronous ("fire and forget") version of sendRequest():
1013 * Posts the specified command to be executed on the main thread, and
1014 * returns immediately.
1015 * @see #sendRequest
1016 */
1017 private void sendRequestAsync(int command) {
1018 mMainThreadHandler.sendEmptyMessage(command);
1019 }
1020
1021 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001022 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1023 * @see {@link #sendRequest(int,Object)}
1024 */
1025 private void sendRequestAsync(int command, Object argument) {
1026 MainThreadRequest request = new MainThreadRequest(argument);
1027 Message msg = mMainThreadHandler.obtainMessage(command, request);
1028 msg.sendToTarget();
1029 }
1030
1031 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001032 * Initialize the singleton PhoneInterfaceManager instance.
1033 * This is only done once, at startup, from PhoneApp.onCreate().
1034 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001035 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001036 synchronized (PhoneInterfaceManager.class) {
1037 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001038 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001039 } else {
1040 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1041 }
1042 return sInstance;
1043 }
1044 }
1045
1046 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001047 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001048 mApp = app;
1049 mPhone = phone;
1050 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001051 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001052 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1053 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001054 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001055 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001056 mSubscriptionController = SubscriptionController.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001057
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001058 publish();
1059 }
1060
1061 private void publish() {
1062 if (DBG) log("publish: " + this);
1063
1064 ServiceManager.addService("phone", this);
1065 }
1066
Stuart Scott584921c2015-01-15 17:10:34 -08001067 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001068 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1069 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001070 }
1071
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001072 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1073 Phone phone = getPhoneFromRequest(request);
1074 return phone == null ? null :
1075 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1076 }
1077
Wink Saville36469e72014-06-11 15:17:00 -07001078 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001079 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001080 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001082 //
1083 // Implementation of the ITelephony interface.
1084 //
1085
1086 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001087 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001088 }
1089
Wink Savilleb564aae2014-10-23 10:18:09 -07001090 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001091 if (DBG) log("dial: " + number);
1092 // No permission check needed here: This is just a wrapper around the
1093 // ACTION_DIAL intent, which is available to any app since it puts up
1094 // the UI before it does anything.
1095
1096 String url = createTelUrl(number);
1097 if (url == null) {
1098 return;
1099 }
1100
1101 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001102 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1104 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1105 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1106 mApp.startActivity(intent);
1107 }
1108 }
1109
1110 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001111 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001112 }
1113
Wink Savilleb564aae2014-10-23 10:18:09 -07001114 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001115 if (DBG) log("call: " + number);
1116
1117 // This is just a wrapper around the ACTION_CALL intent, but we still
1118 // need to do a permission check since we're calling startActivity()
1119 // from the context of the phone app.
1120 enforceCallPermission();
1121
1122 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1123 != AppOpsManager.MODE_ALLOWED) {
1124 return;
1125 }
1126
1127 String url = createTelUrl(number);
1128 if (url == null) {
1129 return;
1130 }
1131
Wink Saville08874612014-08-31 19:19:58 -07001132 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001133 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001134 if (slist != null) {
1135 for (SubscriptionInfo subInfoRecord : slist) {
1136 if (subInfoRecord.getSubscriptionId() == subId) {
1137 isValid = true;
1138 break;
1139 }
Wink Saville08874612014-08-31 19:19:58 -07001140 }
1141 }
1142 if (isValid == false) {
1143 return;
1144 }
1145
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001146 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001147 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001148 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1149 mApp.startActivity(intent);
1150 }
1151
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001152 /**
1153 * End a call based on call state
1154 * @return true is a call was ended
1155 */
1156 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001157 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001158 }
1159
1160 /**
1161 * End a call based on the call state of the subId
1162 * @return true is a call was ended
1163 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001164 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001166 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001167 }
1168
1169 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001170 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001171 }
1172
Wink Savilleb564aae2014-10-23 10:18:09 -07001173 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 if (DBG) log("answerRingingCall...");
1175 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1176 // but that can probably wait till the big TelephonyManager API overhaul.
1177 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1178 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001179 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001180 }
1181
1182 /**
1183 * Make the actual telephony calls to implement answerRingingCall().
1184 * This should only be called from the main thread of the Phone app.
1185 * @see #answerRingingCall
1186 *
1187 * TODO: it would be nice to return true if we answered the call, or
1188 * false if there wasn't actually a ringing incoming call, or some
1189 * other error occurred. (In other words, pass back the return value
1190 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1191 * But that would require calling this method via sendRequest() rather
1192 * than sendRequestAsync(), and right now we don't actually *need* that
1193 * return value, so let's just return void for now.
1194 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001195 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001196 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001198 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1199 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001200 if (hasActiveCall && hasHoldingCall) {
1201 // Both lines are in use!
1202 // TODO: provide a flag to let the caller specify what
1203 // policy to use if both lines are in use. (The current
1204 // behavior is hardwired to "answer incoming, end ongoing",
1205 // which is how the CALL button is specced to behave.)
1206 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1207 return;
1208 } else {
1209 // answerCall() will automatically hold the current active
1210 // call, if there is one.
1211 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1212 return;
1213 }
1214 } else {
1215 // No call was ringing.
1216 return;
1217 }
1218 }
1219
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001221 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001223 public void silenceRinger() {
1224 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225 }
1226
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001227 @Override
1228 public boolean isOffhook(String callingPackage) {
1229 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001230 }
1231
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001232 @Override
1233 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1234 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1235 return false;
1236 }
1237
Sanket Padawe356d7632015-06-22 14:03:32 -07001238 final Phone phone = getPhone(subId);
1239 if (phone != null) {
1240 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1241 } else {
1242 return false;
1243 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 }
1245
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001246 @Override
1247 public boolean isRinging(String callingPackage) {
1248 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001249 }
1250
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001251 @Override
1252 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1253 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1254 return false;
1255 }
1256
Sanket Padawe356d7632015-06-22 14:03:32 -07001257 final Phone phone = getPhone(subId);
1258 if (phone != null) {
1259 return (phone.getState() == PhoneConstants.State.RINGING);
1260 } else {
1261 return false;
1262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 }
1264
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001265 @Override
1266 public boolean isIdle(String callingPackage) {
1267 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001268 }
1269
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001270 @Override
1271 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1272 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1273 return false;
1274 }
1275
Sanket Padawe356d7632015-06-22 14:03:32 -07001276 final Phone phone = getPhone(subId);
1277 if (phone != null) {
1278 return (phone.getState() == PhoneConstants.State.IDLE);
1279 } else {
1280 return false;
1281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 }
1283
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001285 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001286 }
1287
Wink Savilleb564aae2014-10-23 10:18:09 -07001288 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001289 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001290 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1291 }
1292
1293 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001294 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001295 }
1296
Wink Savilleb564aae2014-10-23 10:18:09 -07001297 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001298 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001299 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1300 }
1301
1302 /** {@hide} */
1303 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001304 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001305 }
1306
Wink Savilleb564aae2014-10-23 10:18:09 -07001307 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001309 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 checkSimPin.start();
1311 return checkSimPin.unlockSim(null, pin);
1312 }
1313
Wink Saville9de0f752013-10-22 19:04:03 -07001314 /** {@hide} */
1315 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001316 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001317 }
1318
Wink Savilleb564aae2014-10-23 10:18:09 -07001319 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001321 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 checkSimPuk.start();
1323 return checkSimPuk.unlockSim(puk, pin);
1324 }
1325
1326 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001327 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 * a synchronous one.
1329 */
1330 private static class UnlockSim extends Thread {
1331
1332 private final IccCard mSimCard;
1333
1334 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001335 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1336 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337
1338 // For replies from SimCard interface
1339 private Handler mHandler;
1340
1341 // For async handler to identify request type
1342 private static final int SUPPLY_PIN_COMPLETE = 100;
1343
1344 public UnlockSim(IccCard simCard) {
1345 mSimCard = simCard;
1346 }
1347
1348 @Override
1349 public void run() {
1350 Looper.prepare();
1351 synchronized (UnlockSim.this) {
1352 mHandler = new Handler() {
1353 @Override
1354 public void handleMessage(Message msg) {
1355 AsyncResult ar = (AsyncResult) msg.obj;
1356 switch (msg.what) {
1357 case SUPPLY_PIN_COMPLETE:
1358 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1359 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001360 mRetryCount = msg.arg1;
1361 if (ar.exception != null) {
1362 if (ar.exception instanceof CommandException &&
1363 ((CommandException)(ar.exception)).getCommandError()
1364 == CommandException.Error.PASSWORD_INCORRECT) {
1365 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1366 } else {
1367 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1368 }
1369 } else {
1370 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372 mDone = true;
1373 UnlockSim.this.notifyAll();
1374 }
1375 break;
1376 }
1377 }
1378 };
1379 UnlockSim.this.notifyAll();
1380 }
1381 Looper.loop();
1382 }
1383
1384 /*
1385 * Use PIN or PUK to unlock SIM card
1386 *
1387 * If PUK is null, unlock SIM card with PIN
1388 *
1389 * If PUK is not null, unlock SIM card with PUK and set PIN code
1390 */
Wink Saville9de0f752013-10-22 19:04:03 -07001391 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392
1393 while (mHandler == null) {
1394 try {
1395 wait();
1396 } catch (InterruptedException e) {
1397 Thread.currentThread().interrupt();
1398 }
1399 }
1400 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1401
1402 if (puk == null) {
1403 mSimCard.supplyPin(pin, callback);
1404 } else {
1405 mSimCard.supplyPuk(puk, pin, callback);
1406 }
1407
1408 while (!mDone) {
1409 try {
1410 Log.d(LOG_TAG, "wait for done");
1411 wait();
1412 } catch (InterruptedException e) {
1413 // Restore the interrupted status
1414 Thread.currentThread().interrupt();
1415 }
1416 }
1417 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001418 int[] resultArray = new int[2];
1419 resultArray[0] = mResult;
1420 resultArray[1] = mRetryCount;
1421 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001422 }
1423 }
1424
1425 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001426 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001427
1428 }
1429
Wink Savilleb564aae2014-10-23 10:18:09 -07001430 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 // No permission check needed here: this call is harmless, and it's
1432 // needed for the ServiceState.requestStateUpdate() call (which is
1433 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001434 final Phone phone = getPhone(subId);
1435 if (phone != null) {
1436 phone.updateServiceLocation();
1437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438 }
1439
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001440 @Override
1441 public boolean isRadioOn(String callingPackage) {
1442 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001443 }
1444
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001445 @Override
1446 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1447 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1448 return false;
1449 }
1450 return isRadioOnForSubscriber(subId);
1451 }
1452
1453 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001454 final Phone phone = getPhone(subId);
1455 if (phone != null) {
1456 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1457 } else {
1458 return false;
1459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 }
1461
1462 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001463 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001464
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 }
Wink Saville36469e72014-06-11 15:17:00 -07001466
Wink Savilleb564aae2014-10-23 10:18:09 -07001467 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001469 final Phone phone = getPhone(subId);
1470 if (phone != null) {
1471 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1472 }
Wink Saville36469e72014-06-11 15:17:00 -07001473 }
1474
1475 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001476 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001477 }
1478
Wink Savilleb564aae2014-10-23 10:18:09 -07001479 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001480 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001481 final Phone phone = getPhone(subId);
1482 if (phone == null) {
1483 return false;
1484 }
1485 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001486 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 }
1489 return true;
1490 }
Wink Saville36469e72014-06-11 15:17:00 -07001491
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001492 public boolean needMobileRadioShutdown() {
1493 /*
1494 * If any of the Radios are available, it will need to be
1495 * shutdown. So return true if any Radio is available.
1496 */
1497 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1498 Phone phone = PhoneFactory.getPhone(i);
1499 if (phone != null && phone.isRadioAvailable()) return true;
1500 }
1501 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1502 return false;
1503 }
1504
1505 public void shutdownMobileRadios() {
1506 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1507 logv("Shutting down Phone " + i);
1508 shutdownRadioUsingPhoneId(i);
1509 }
1510 }
1511
1512 private void shutdownRadioUsingPhoneId(int phoneId) {
1513 enforceModifyPermission();
1514 Phone phone = PhoneFactory.getPhone(phoneId);
1515 if (phone != null && phone.isRadioAvailable()) {
1516 phone.shutdownRadio();
1517 }
1518 }
1519
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001520 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001521 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001522 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1523 if (defaultPhone != null) {
1524 defaultPhone.setRadioPower(turnOn);
1525 return true;
1526 } else {
1527 loge("There's no default phone.");
1528 return false;
1529 }
Wink Saville36469e72014-06-11 15:17:00 -07001530 }
1531
Wink Savilleb564aae2014-10-23 10:18:09 -07001532 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001534 final Phone phone = getPhone(subId);
1535 if (phone != null) {
1536 phone.setRadioPower(turnOn);
1537 return true;
1538 } else {
1539 return false;
1540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 }
1542
Wink Saville36469e72014-06-11 15:17:00 -07001543 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001544 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 public boolean enableDataConnectivity() {
1546 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001547 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001548 final Phone phone = getPhone(subId);
1549 if (phone != null) {
1550 phone.setDataEnabled(true);
1551 return true;
1552 } else {
1553 return false;
1554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 }
1556
Wink Saville36469e72014-06-11 15:17:00 -07001557 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001558 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 public boolean disableDataConnectivity() {
1560 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001561 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001562 final Phone phone = getPhone(subId);
1563 if (phone != null) {
1564 phone.setDataEnabled(false);
1565 return true;
1566 } else {
1567 return false;
1568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
1570
Sanket Padawe356d7632015-06-22 14:03:32 -07001571 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001572 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 final Phone phone = getPhone(subId);
1574 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001575 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 } else {
1577 return false;
1578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 }
1580
1581 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001582 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001583 }
1584
pkanwarae03a6b2016-11-06 20:37:09 -08001585 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001586 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001587 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1588 return;
1589 }
1590 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1591 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1592 };
1593
Wink Savilleb564aae2014-10-23 10:18:09 -07001594 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001596 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1597 return false;
1598 }
Wink Saville36469e72014-06-11 15:17:00 -07001599 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
1601
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001603 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001604 }
1605
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001606 public int getCallStateForSlot(int slotIndex) {
1607 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001608 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001609 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 }
1611
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001614 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001615 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001616 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001618 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Sanket Padawe356d7632015-06-22 14:03:32 -07001622 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001624 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 if (phone != null) {
1626 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1627 } else {
1628 return TelephonyManager.DATA_ACTIVITY_NONE;
1629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 }
1631
1632 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001633 public Bundle getCellLocation(String callingPackage) {
1634 enforceFineOrCoarseLocationPermission("getCellLocation");
1635
1636 // OP_COARSE_LOCATION controls both fine and coarse location.
1637 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1638 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001639 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001640 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 }
1642
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001643 if (checkIfCallerIsSelfOrForegroundUser() ||
1644 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 if (DBG_LOC) log("getCellLocation: is active user");
1646 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001647 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 if (phone == null) {
1649 return null;
1650 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001651
1652 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1653 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 return data;
1655 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001656 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 return null;
1658 }
1659 }
1660
Svetoslav64fad262015-04-14 14:35:21 -07001661 private void enforceFineOrCoarseLocationPermission(String message) {
1662 try {
1663 mApp.enforceCallingOrSelfPermission(
1664 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1665 } catch (SecurityException e) {
1666 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1667 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1668 // is the weaker precondition
1669 mApp.enforceCallingOrSelfPermission(
1670 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1671 }
1672 }
1673
1674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 @Override
1676 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001677 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001678 }
1679
Sanket Padawe356d7632015-06-22 14:03:32 -07001680 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001681 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 mApp.enforceCallingOrSelfPermission(
1683 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 final Phone phone = getPhone(subId);
1685 if (phone != null) {
1686 phone.enableLocationUpdates();
1687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 }
1689
1690 @Override
1691 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001692 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001693 }
1694
Sanket Padawe356d7632015-06-22 14:03:32 -07001695 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001696 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 mApp.enforceCallingOrSelfPermission(
1698 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 final Phone phone = getPhone(subId);
1700 if (phone != null) {
1701 phone.disableLocationUpdates();
1702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
1705 @Override
1706 @SuppressWarnings("unchecked")
1707 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001708 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1709
1710 // OP_COARSE_LOCATION controls both fine and coarse location.
1711 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1712 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1713 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 }
1715
1716 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1717 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1718 return null;
1719 }
Svetoslav64fad262015-04-14 14:35:21 -07001720
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001721 if (checkIfCallerIsSelfOrForegroundUser() ||
1722 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1724
1725 ArrayList<NeighboringCellInfo> cells = null;
1726
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001727 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 try {
1729 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001730 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001731 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001733 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735 return cells;
1736 } else {
1737 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1738 return null;
1739 }
1740 }
1741
1742
1743 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001744 public List<CellInfo> getAllCellInfo(String callingPackage) {
1745 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1746
1747 // OP_COARSE_LOCATION controls both fine and coarse location.
1748 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1749 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1750 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
1752
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001753 if (checkIfCallerIsSelfOrForegroundUser() ||
1754 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001756 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001757 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1758 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001759 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1760 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001761 }
1762 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 } else {
1764 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1765 return null;
1766 }
1767 }
1768
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001769 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001771 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001772 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1773 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
1775
Shishir Agrawala9f32182016-04-12 12:00:16 -07001776 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001777 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001778 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1779 return null;
1780 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001781 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001782 return phone == null ? null : phone.getImei();
1783 }
1784
1785 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001786 public String getMeidForSlot(int slotIndex, String callingPackage) {
1787 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1788 return null;
1789 }
1790 Phone phone = PhoneFactory.getPhone(slotIndex);
1791 return phone == null ? null : phone.getMeid();
1792 }
1793
1794 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001795 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001796 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1797 return null;
1798 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001799 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001800 return phone == null ? null : phone.getDeviceSvn();
1801 }
1802
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 //
1804 // Internal helper methods.
1805 //
1806
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001807 /**
1808 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1809 */
1810 private boolean checkCallerInteractAcrossUsersFull() {
1811 return mPhone.getContext().checkCallingOrSelfPermission(
1812 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1813 == PackageManager.PERMISSION_GRANTED;
1814 }
1815
Jake Hambye994d462014-02-03 13:10:13 -08001816 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 boolean ok;
1818
1819 boolean self = Binder.getCallingUid() == Process.myUid();
1820 if (!self) {
1821 // Get the caller's user id then clear the calling identity
1822 // which will be restored in the finally clause.
1823 int callingUser = UserHandle.getCallingUserId();
1824 long ident = Binder.clearCallingIdentity();
1825
1826 try {
1827 // With calling identity cleared the current user is the foreground user.
1828 int foregroundUser = ActivityManager.getCurrentUser();
1829 ok = (foregroundUser == callingUser);
1830 if (DBG_LOC) {
1831 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1832 + " callingUser=" + callingUser + " ok=" + ok);
1833 }
1834 } catch (Exception ex) {
1835 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1836 ok = false;
1837 } finally {
1838 Binder.restoreCallingIdentity(ident);
1839 }
1840 } else {
1841 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1842 ok = true;
1843 }
1844 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1845 return ok;
1846 }
1847
1848 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1850 *
1851 * @throws SecurityException if the caller does not have the required permission
1852 */
1853 private void enforceModifyPermission() {
1854 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1855 }
1856
1857 /**
Junda Liua2e36012014-07-09 18:30:01 -07001858 * Make sure either system app or the caller has carrier privilege.
1859 *
1860 * @throws SecurityException if the caller does not have the required permission/privilege
1861 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001862 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001863 int permission = mApp.checkCallingOrSelfPermission(
1864 android.Manifest.permission.MODIFY_PHONE_STATE);
1865 if (permission == PackageManager.PERMISSION_GRANTED) {
1866 return;
1867 }
1868
1869 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001870 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001871 }
1872
1873 /**
1874 * Make sure the caller has carrier privilege.
1875 *
1876 * @throws SecurityException if the caller does not have the required permission
1877 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001878 private void enforceCarrierPrivilege(int subId) {
1879 if (getCarrierPrivilegeStatus(subId) !=
1880 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001881 loge("No Carrier Privilege.");
1882 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001883 }
1884 }
1885
1886 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 * Make sure the caller has the CALL_PHONE permission.
1888 *
1889 * @throws SecurityException if the caller does not have the required permission
1890 */
1891 private void enforceCallPermission() {
1892 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1893 }
1894
Stuart Scott8eef64f2015-04-08 15:13:54 -07001895 private void enforceConnectivityInternalPermission() {
1896 mApp.enforceCallingOrSelfPermission(
1897 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1898 "ConnectivityService");
1899 }
1900
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 private String createTelUrl(String number) {
1902 if (TextUtils.isEmpty(number)) {
1903 return null;
1904 }
1905
Jake Hambye994d462014-02-03 13:10:13 -08001906 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 }
1908
Ihab Awadf9e92732013-12-05 18:02:52 -08001909 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1911 }
1912
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001913 private static void logv(String msg) {
1914 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1915 }
1916
Ihab Awadf9e92732013-12-05 18:02:52 -08001917 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1919 }
1920
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001921 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001923 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001924 }
1925
Sanket Padawe356d7632015-06-22 14:03:32 -07001926 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001927 public int getActivePhoneTypeForSlot(int slotIndex) {
1928 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001929 if (phone == null) {
1930 return PhoneConstants.PHONE_TYPE_NONE;
1931 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001932 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 }
1935
1936 /**
1937 * Returns the CDMA ERI icon index to display
1938 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001939 @Override
1940 public int getCdmaEriIconIndex(String callingPackage) {
1941 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001942 }
1943
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001945 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1946 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1947 return -1;
1948 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001949 final Phone phone = getPhone(subId);
1950 if (phone != null) {
1951 return phone.getCdmaEriIconIndex();
1952 } else {
1953 return -1;
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
1957 /**
1958 * Returns the CDMA ERI icon mode,
1959 * 0 - ON
1960 * 1 - FLASHING
1961 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001962 @Override
1963 public int getCdmaEriIconMode(String callingPackage) {
1964 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001965 }
1966
Sanket Padawe356d7632015-06-22 14:03:32 -07001967 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001968 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1969 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1970 return -1;
1971 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001972 final Phone phone = getPhone(subId);
1973 if (phone != null) {
1974 return phone.getCdmaEriIconMode();
1975 } else {
1976 return -1;
1977 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001978 }
1979
1980 /**
1981 * Returns the CDMA ERI text,
1982 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001983 @Override
1984 public String getCdmaEriText(String callingPackage) {
1985 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001986 }
1987
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001989 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1990 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1991 return null;
1992 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 final Phone phone = getPhone(subId);
1994 if (phone != null) {
1995 return phone.getCdmaEriText();
1996 } else {
1997 return null;
1998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000
2001 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002002 * Returns the CDMA MDN.
2003 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002004 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002005 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002006 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002007 final Phone phone = getPhone(subId);
2008 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2009 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002010 } else {
2011 return null;
2012 }
2013 }
2014
2015 /**
2016 * Returns the CDMA MIN.
2017 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002018 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002019 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002020 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002021 final Phone phone = getPhone(subId);
2022 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2023 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002024 } else {
2025 return null;
2026 }
2027 }
2028
2029 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 * Returns true if CDMA provisioning needs to run.
2031 */
2032 public boolean needsOtaServiceProvisioning() {
2033 return mPhone.needsOtaServiceProvisioning();
2034 }
2035
2036 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002037 * Sets the voice mail number of a given subId.
2038 */
2039 @Override
2040 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002041 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002042 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2043 new Pair<String, String>(alphaTag, number), new Integer(subId));
2044 return success;
2045 }
2046
Ta-wei Yen87c49842016-05-13 21:19:52 -07002047 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002048 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2049 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2050 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2051 if (!TextUtils.equals(callingPackage, systemDialer)) {
2052 throw new SecurityException("caller must be system dialer");
2053 }
2054 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2055 if (phoneAccountHandle == null){
2056 return null;
2057 }
2058 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2059 }
2060
2061 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002062 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2064 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2065 return null;
2066 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002067 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2068 }
2069
2070 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002071 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2072 VisualVoicemailSmsFilterSettings settings) {
2073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002074 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002075 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2076 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002077 }
2078
2079 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002080 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2081 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002082 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002083 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002084 }
2085
2086 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002087 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2088 String callingPackage, int subId) {
2089 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002090 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002091 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002092 }
2093
2094 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002095 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002096 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002097 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002098 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2099 }
2100
2101 @Override
2102 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2103 String number, int port, String text, PendingIntent sentIntent) {
2104 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002105 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002106 enforceSendSmsPermission();
2107 // Make the calls as the phone process.
2108 final long identity = Binder.clearCallingIdentity();
2109 try {
2110 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2111 if (port == 0) {
2112 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2113 sentIntent, null, false);
2114 } else {
2115 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2116 smsManager.sendDataMessageWithSelfPermissions(number, null,
2117 (short) port, data, sentIntent, null);
2118 }
2119 } finally {
2120 Binder.restoreCallingIdentity(identity);
2121 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002122 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002123 /**
fionaxu0152e512016-11-14 13:36:14 -08002124 * Sets the voice activation state of a given subId.
2125 */
2126 @Override
2127 public void setVoiceActivationState(int subId, int activationState) {
2128 enforceModifyPermissionOrCarrierPrivilege(subId);
2129 final Phone phone = getPhone(subId);
2130 if (phone != null) {
2131 phone.setVoiceActivationState(activationState);
2132 } else {
2133 loge("setVoiceActivationState fails with invalid subId: " + subId);
2134 }
2135 }
2136
2137 /**
2138 * Sets the data activation state of a given subId.
2139 */
2140 @Override
2141 public void setDataActivationState(int subId, int activationState) {
2142 enforceModifyPermissionOrCarrierPrivilege(subId);
2143 final Phone phone = getPhone(subId);
2144 if (phone != null) {
2145 phone.setDataActivationState(activationState);
2146 } else {
2147 loge("setVoiceActivationState fails with invalid subId: " + subId);
2148 }
2149 }
2150
2151 /**
2152 * Returns the voice activation state of a given subId.
2153 */
2154 @Override
2155 public int getVoiceActivationState(int subId, String callingPackage) {
2156 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2157 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2158 }
2159 final Phone phone = getPhone(subId);
2160 if (phone != null) {
2161 return phone.getVoiceActivationState();
2162 } else {
2163 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2164 }
2165 }
2166
2167 /**
2168 * Returns the data activation state of a given subId.
2169 */
2170 @Override
2171 public int getDataActivationState(int subId, String callingPackage) {
2172 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2173 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2174 }
2175 final Phone phone = getPhone(subId);
2176 if (phone != null) {
2177 return phone.getDataActivationState();
2178 } else {
2179 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2180 }
2181 }
2182
2183 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 * Returns the unread count of voicemails
2185 */
2186 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002187 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002188 }
2189
2190 /**
2191 * Returns the unread count of voicemails for a subId
2192 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002193 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002194 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002195 final Phone phone = getPhone(subId);
2196 if (phone != null) {
2197 return phone.getVoiceMessageCount();
2198 } else {
2199 return 0;
2200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 }
2202
2203 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002204 * returns true, if the device is in a state where both voice and data
2205 * are supported simultaneously. This can change based on location or network condition.
2206 */
2207 @Override
2208 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2209 final Phone phone = getPhone(subId);
2210 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2211 }
2212
2213 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002214 * Send the dialer code if called from the current default dialer or the caller has
2215 * carrier privilege.
2216 * @param inputCode The dialer code to send
2217 */
2218 @Override
2219 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2220 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2221 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2222 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2223 enforceCarrierPrivilege(getDefaultSubscription());
2224 }
2225 mPhone.sendDialerSpecialCode(inputCode);
2226 }
2227
2228 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002229 * Returns the data network type.
2230 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 *
2232 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2233 */
2234 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002235 public int getNetworkType() {
2236 final Phone phone = getPhone(getDefaultSubscription());
2237 if (phone != null) {
2238 return phone.getServiceState().getDataNetworkType();
2239 } else {
2240 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2241 }
Wink Saville36469e72014-06-11 15:17:00 -07002242 }
2243
2244 /**
2245 * Returns the network type for a subId
2246 */
2247 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002248 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2249 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2250 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2251 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002254 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002255 return phone.getServiceState().getDataNetworkType();
2256 } else {
2257 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
2261 /**
2262 * Returns the data network type
2263 */
2264 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002265 public int getDataNetworkType(String callingPackage) {
2266 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002267 }
2268
2269 /**
2270 * Returns the data network type for a subId
2271 */
2272 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002273 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2274 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2275 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2276 }
2277
Sanket Padawe356d7632015-06-22 14:03:32 -07002278 final Phone phone = getPhone(subId);
2279 if (phone != null) {
2280 return phone.getServiceState().getDataNetworkType();
2281 } else {
2282 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 }
2285
2286 /**
Wink Saville36469e72014-06-11 15:17:00 -07002287 * Returns the Voice network type for a subId
2288 */
2289 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002290 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2291 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2292 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2293 }
2294
Sanket Padawe356d7632015-06-22 14:03:32 -07002295 final Phone phone = getPhone(subId);
2296 if (phone != null) {
2297 return phone.getServiceState().getVoiceNetworkType();
2298 } else {
2299 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 /**
2304 * @return true if a ICC card is present
2305 */
2306 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002307 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002308 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2309 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002310 }
2311
2312 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002313 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002314 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002315 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002316 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2317 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002318 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002320 } else {
2321 return false;
2322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 }
2324
2325 /**
2326 * Return if the current radio is LTE on CDMA. This
2327 * is a tri-state return value as for a period of time
2328 * the mode may be unknown.
2329 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002330 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002332 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002334 @Override
2335 public int getLteOnCdmaMode(String callingPackage) {
2336 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002337 }
2338
Sanket Padawe356d7632015-06-22 14:03:32 -07002339 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002340 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2341 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2342 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2343 }
2344
Sanket Padawe356d7632015-06-22 14:03:32 -07002345 final Phone phone = getPhone(subId);
2346 if (phone == null) {
2347 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2348 } else {
2349 return phone.getLteOnCdmaMode();
2350 }
Wink Saville36469e72014-06-11 15:17:00 -07002351 }
2352
2353 public void setPhone(Phone phone) {
2354 mPhone = phone;
2355 }
2356
2357 /**
2358 * {@hide}
2359 * Returns Default subId, 0 in the case of single standby.
2360 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002361 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002362 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002363 }
2364
Shishir Agrawala9f32182016-04-12 12:00:16 -07002365 private int getSlotForDefaultSubscription() {
2366 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2367 }
2368
Wink Savilleb564aae2014-10-23 10:18:09 -07002369 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002370 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002372
2373 /**
2374 * @see android.telephony.TelephonyManager.WifiCallingChoices
2375 */
2376 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002377 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2378 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002379 }
2380
2381 /**
2382 * @see android.telephony.TelephonyManager.WifiCallingChoices
2383 */
2384 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002385 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2386 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2387 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002388 }
2389
Sailesh Nepald1e68152013-12-12 19:08:02 -08002390 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002391 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002392 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002393 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002394
Shishir Agrawal566b7612013-10-28 14:41:00 -07002395 @Override
Ajay Nambid7454d32015-12-03 13:50:00 -08002396 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002397 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002398
Ajay Nambid7454d32015-12-03 13:50:00 -08002399 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + AID + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002400 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Ajay Nambid7454d32015-12-03 13:50:00 -08002401 CMD_OPEN_CHANNEL, new Pair<String, Integer>(AID, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002402 if (DBG) log("iccOpenLogicalChannel: " + response);
2403 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002404 }
2405
2406 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002407 public boolean iccCloseLogicalChannel(int subId, int channel) {
2408 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002409
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002410 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002411 if (channel < 0) {
2412 return false;
2413 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002414 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002415 if (DBG) log("iccCloseLogicalChannel: " + success);
2416 return success;
2417 }
2418
2419 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002420 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002421 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002422 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002423
2424 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002425 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2426 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002427 " data=" + data);
2428 }
2429
2430 if (channel < 0) {
2431 return "";
2432 }
2433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002434 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002435 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002436 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2437
Shishir Agrawal566b7612013-10-28 14:41:00 -07002438 // Append the returned status code to the end of the response payload.
2439 String s = Integer.toHexString(
2440 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002441 if (response.payload != null) {
2442 s = IccUtils.bytesToHexString(response.payload) + s;
2443 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002444 return s;
2445 }
Jake Hambye994d462014-02-03 13:10:13 -08002446
Evan Charltonc66da362014-05-16 14:06:40 -07002447 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002448 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002449 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002450 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002451
2452 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002453 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2454 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002455 }
2456
2457 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002458 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002459 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2460
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002461 // Append the returned status code to the end of the response payload.
2462 String s = Integer.toHexString(
2463 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002464 if (response.payload != null) {
2465 s = IccUtils.bytesToHexString(response.payload) + s;
2466 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002467 return s;
2468 }
2469
2470 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002471 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002472 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002473 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474
2475 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002476 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002477 p1 + " " + p2 + " " + p3 + ":" + filePath);
2478 }
2479
2480 IccIoResult response =
2481 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002482 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2483 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002484
2485 if (DBG) {
2486 log("Exchange SIM_IO [R]" + response);
2487 }
2488
2489 byte[] result = null;
2490 int length = 2;
2491 if (response.payload != null) {
2492 length = 2 + response.payload.length;
2493 result = new byte[length];
2494 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2495 } else {
2496 result = new byte[length];
2497 }
2498
2499 result[length - 1] = (byte) response.sw2;
2500 result[length - 2] = (byte) response.sw1;
2501 return result;
2502 }
2503
Nathan Haroldb3014052017-01-25 15:57:32 -08002504 /**
2505 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2506 * on a particular subscription
2507 */
2508 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002509 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2510 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002511 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2512 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2513 return null;
2514 }
2515 Object response = sendRequest(
2516 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2517 if (response instanceof String[]) {
2518 return (String[]) response;
2519 }
2520 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2521 return null;
2522 }
2523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002524 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002525 public String sendEnvelopeWithStatus(int subId, String content) {
2526 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002527
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002528 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002529 if (response.payload == null) {
2530 return "";
2531 }
2532
2533 // Append the returned status code to the end of the response payload.
2534 String s = Integer.toHexString(
2535 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2536 s = IccUtils.bytesToHexString(response.payload) + s;
2537 return s;
2538 }
2539
Jake Hambye994d462014-02-03 13:10:13 -08002540 /**
2541 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2542 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2543 *
2544 * @param itemID the ID of the item to read
2545 * @return the NV item as a String, or null on error.
2546 */
2547 @Override
2548 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002549 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002550 if (DBG) log("nvReadItem: item " + itemID);
2551 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2552 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2553 return value;
2554 }
2555
2556 /**
2557 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2558 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2559 *
2560 * @param itemID the ID of the item to read
2561 * @param itemValue the value to write, as a String
2562 * @return true on success; false on any failure
2563 */
2564 @Override
2565 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002566 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002567 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2568 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2569 new Pair<Integer, String>(itemID, itemValue));
2570 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2571 return success;
2572 }
2573
2574 /**
2575 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2576 * Used for device configuration by some CDMA operators.
2577 *
2578 * @param preferredRoamingList byte array containing the new PRL
2579 * @return true on success; false on any failure
2580 */
2581 @Override
2582 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002583 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002584 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2585 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2586 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2587 return success;
2588 }
2589
2590 /**
2591 * Perform the specified type of NV config reset.
2592 * Used for device configuration by some CDMA operators.
2593 *
2594 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2595 * @return true on success; false on any failure
2596 */
2597 @Override
2598 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002599 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002600 if (DBG) log("nvResetConfig: type " + resetType);
2601 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2602 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2603 return success;
2604 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002605
2606 /**
Wink Saville36469e72014-06-11 15:17:00 -07002607 * {@hide}
2608 * Returns Default sim, 0 in the case of single standby.
2609 */
2610 public int getDefaultSim() {
2611 //TODO Need to get it from Telephony Devcontroller
2612 return 0;
2613 }
2614
Svet Ganovb320e182015-04-16 12:30:10 -07002615 public String[] getPcscfAddress(String apnType, String callingPackage) {
2616 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2617 return new String[0];
2618 }
2619
2620
ram87fca6f2014-07-18 18:58:44 +05302621 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002622 }
2623
Brad Ebinger51f743a2017-01-23 13:50:20 -08002624 /**
2625 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS
2626 * feature or {@link null} if the service is not available. If an ImsServiceController is
2627 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for
2628 * feature updates.
2629 */
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002630 public IImsServiceController getImsServiceControllerAndListen(int slotIndex, int feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002631 IImsServiceFeatureListener callback) {
2632 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002633 return PhoneFactory.getImsResolver().getImsServiceControllerAndListen(slotIndex, feature,
Brad Ebinger51f743a2017-01-23 13:50:20 -08002634 callback);
2635 }
2636
Wink Saville36469e72014-06-11 15:17:00 -07002637 public void setImsRegistrationState(boolean registered) {
2638 enforceModifyPermission();
2639 mPhone.setImsRegistrationState(registered);
2640 }
2641
2642 /**
Stuart Scott54788802015-03-30 13:18:01 -07002643 * Set the network selection mode to automatic.
2644 *
2645 */
2646 @Override
2647 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002648 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002649 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2650 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2651 }
2652
2653 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002654 * Set the network selection mode to manual with the selected carrier.
2655 */
2656 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002657 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2658 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002659 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002660 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002661 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2662 persistSelection);
2663 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002664 }
2665
2666 /**
2667 * Scans for available networks.
2668 */
2669 @Override
2670 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002671 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002672 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2673 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2674 CMD_PERFORM_NETWORK_SCAN, null, subId);
2675 return result;
2676 }
2677
2678 /**
yinxu504e1392017-04-12 16:03:22 -07002679 * Performs a new network scan and returns the id of this scan.
2680 *
2681 * @return the id of the requested scan which can be used to stop the scan.
2682 */
2683 @Override
2684 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2685 IBinder binder) {
2686 // TODO(yinxu): Implement this method.
2687 throw new UnsupportedOperationException("To be implemented...");
2688 }
2689
2690 /**
2691 * Stops an existing network scan with the given scanId.
2692 */
2693 @Override
2694 public void stopNetworkScan(int subId, int scanId) {
2695 // TODO(yinxu): Implement this method.
2696 throw new UnsupportedOperationException("To be implemented...");
2697 }
2698
2699 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002700 * Get the calculated preferred network type.
2701 * Used for debugging incorrect network type.
2702 *
2703 * @return the preferred network type, defined in RILConstants.java.
2704 */
2705 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002706 public int getCalculatedPreferredNetworkType(String callingPackage) {
2707 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2708 return RILConstants.PREFERRED_NETWORK_MODE;
2709 }
2710
Amit Mahajan43330e02014-11-18 11:54:45 -08002711 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002712 }
2713
2714 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002715 * Get the preferred network type.
2716 * Used for device configuration by some CDMA operators.
2717 *
2718 * @return the preferred network type, defined in RILConstants.java.
2719 */
2720 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002721 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002722 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002723 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002724 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002725 int networkType = (result != null ? result[0] : -1);
2726 if (DBG) log("getPreferredNetworkType: " + networkType);
2727 return networkType;
2728 }
2729
2730 /**
2731 * Set the preferred network type.
2732 * Used for device configuration by some CDMA operators.
2733 *
2734 * @param networkType the preferred network type, defined in RILConstants.java.
2735 * @return true on success; false on any failure.
2736 */
2737 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002738 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002739 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002740 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2741 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002742 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002743 if (success) {
2744 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002745 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002746 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002747 return success;
2748 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002749
2750 /**
Junda Liu475951f2014-11-07 16:45:03 -08002751 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2752 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2753 * tethering.
2754 *
2755 * @return 0: Not required. 1: required. 2: Not set.
2756 * @hide
2757 */
2758 @Override
2759 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002760 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002761 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2762 Settings.Global.TETHER_DUN_REQUIRED, 2);
2763 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2764 // config_tether_apndata.
2765 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2766 dunRequired = 1;
2767 }
2768 return dunRequired;
2769 }
2770
2771 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002772 * Set mobile data enabled
2773 * Used by the user through settings etc to turn on/off mobile data
2774 *
2775 * @param enable {@code true} turn turn data on, else {@code false}
2776 */
2777 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002778 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002779 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002780 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002781 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002782 Phone phone = PhoneFactory.getPhone(phoneId);
2783 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002784 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002785 phone.setDataEnabled(enable);
2786 } else {
2787 loge("setDataEnabled: no phone for subId=" + subId);
2788 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002789 }
2790
2791 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002792 * Get whether mobile data is enabled.
2793 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002794 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002795 *
2796 * @return {@code true} if data is enabled else {@code false}
2797 */
2798 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002799 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002800 try {
2801 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2802 null);
2803 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002804 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002805 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002806 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002807 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002808 Phone phone = PhoneFactory.getPhone(phoneId);
2809 if (phone != null) {
2810 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002811 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002812 return retVal;
2813 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002814 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002815 return false;
2816 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002817 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002818
2819 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002820 public int getCarrierPrivilegeStatus(int subId) {
2821 final Phone phone = getPhone(subId);
2822 if (phone == null) {
2823 loge("getCarrierPrivilegeStatus: Invalid subId");
2824 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2825 }
2826 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002827 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002828 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002829 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2830 }
2831 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002832 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002833 }
Junda Liu29340342014-07-10 15:23:27 -07002834
2835 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002836 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002837 if (TextUtils.isEmpty(pkgName))
2838 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002839 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002840 if (card == null) {
2841 loge("checkCarrierPrivilegesForPackage: No UICC");
2842 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2843 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002844 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2845 }
2846
2847 @Override
2848 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002849 if (TextUtils.isEmpty(pkgName))
2850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002851 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2852 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2853 UiccCard card = UiccController.getInstance().getUiccCard(i);
2854 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002855 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002856 continue;
2857 }
2858
2859 result = card.getCarrierPrivilegeStatus(
2860 mPhone.getContext().getPackageManager(), pkgName);
2861 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2862 break;
2863 }
2864 }
2865
2866 return result;
Junda Liu29340342014-07-10 15:23:27 -07002867 }
Derek Tan89e89d42014-07-08 17:00:10 -07002868
2869 @Override
Junda Liue64de782015-04-16 17:19:16 -07002870 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2871 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2872 loge("phoneId " + phoneId + " is not valid.");
2873 return null;
2874 }
2875 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002876 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002877 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002878 return null ;
2879 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002880 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002881 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002882 }
2883
Amith Yamasani6e118872016-02-19 12:53:51 -08002884 @Override
2885 public List<String> getPackagesWithCarrierPrivileges() {
2886 PackageManager pm = mPhone.getContext().getPackageManager();
2887 List<String> privilegedPackages = new ArrayList<>();
2888 List<PackageInfo> packages = null;
2889 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2890 UiccCard card = UiccController.getInstance().getUiccCard(i);
2891 if (card == null) {
2892 // No UICC in that slot.
2893 continue;
2894 }
2895 if (card.hasCarrierPrivilegeRules()) {
2896 if (packages == null) {
2897 // Only check packages in user 0 for now
2898 packages = pm.getInstalledPackagesAsUser(
2899 PackageManager.MATCH_DISABLED_COMPONENTS
2900 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2901 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2902 }
2903 for (int p = packages.size() - 1; p >= 0; p--) {
2904 PackageInfo pkgInfo = packages.get(p);
2905 if (pkgInfo != null && pkgInfo.packageName != null
2906 && card.getCarrierPrivilegeStatus(pkgInfo)
2907 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2908 privilegedPackages.add(pkgInfo.packageName);
2909 }
2910 }
2911 }
2912 }
2913 return privilegedPackages;
2914 }
2915
Wink Savilleb564aae2014-10-23 10:18:09 -07002916 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002917 final Phone phone = getPhone(subId);
2918 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002919 if (card == null) {
2920 loge("getIccId: No UICC");
2921 return null;
2922 }
2923 String iccId = card.getIccId();
2924 if (TextUtils.isEmpty(iccId)) {
2925 loge("getIccId: ICC ID is null or empty.");
2926 return null;
2927 }
2928 return iccId;
2929 }
2930
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002931 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002932 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2933 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002934 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002935
Jeff Sharkey85190e62014-12-05 09:40:12 -08002936 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002937 final Phone phone = getPhone(subId);
2938 if (phone == null) {
2939 return false;
2940 }
2941 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002942
2943 if (DBG_MERGE) {
2944 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2945 + subscriberId + " to " + number);
2946 }
2947
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002948 if (TextUtils.isEmpty(iccId)) {
2949 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002950 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002951
Jeff Sharkey85190e62014-12-05 09:40:12 -08002952 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2953
2954 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002955 if (alphaTag == null) {
2956 editor.remove(alphaTagPrefKey);
2957 } else {
2958 editor.putString(alphaTagPrefKey, alphaTag);
2959 }
2960
Jeff Sharkey85190e62014-12-05 09:40:12 -08002961 // Record both the line number and IMSI for this ICCID, since we need to
2962 // track all merged IMSIs based on line number
2963 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
2964 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002965 if (number == null) {
2966 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002967 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002968 } else {
2969 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08002970 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002971 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08002972
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002973 editor.commit();
2974 return true;
Derek Tan7226c842014-07-02 17:42:23 -07002975 }
2976
2977 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002978 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07002979 // This is open to apps with WRITE_SMS.
2980 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08002981 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07002982 return null;
2983 }
Derek Tan97ebb422014-09-05 16:55:38 -07002984
2985 String iccId = getIccId(subId);
2986 if (iccId != null) {
2987 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08002988 if (DBG_MERGE) {
2989 log("getLine1NumberForDisplay returning " +
2990 mTelephonySharedPreferences.getString(numberPrefKey, null));
2991 }
Andrew Leedf14ead2014-10-17 14:22:52 -07002992 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07002993 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08002994 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07002995 return null;
Derek Tan7226c842014-07-02 17:42:23 -07002996 }
2997
2998 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002999 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3000 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3001 return null;
3002 }
Derek Tan97ebb422014-09-05 16:55:38 -07003003
3004 String iccId = getIccId(subId);
3005 if (iccId != null) {
3006 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003007 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003008 }
Derek Tan97ebb422014-09-05 16:55:38 -07003009 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003010 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003011
3012 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003013 public String[] getMergedSubscriberIds(String callingPackage) {
3014 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3015 return null;
3016 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003017 final Context context = mPhone.getContext();
3018 final TelephonyManager tele = TelephonyManager.from(context);
3019 final SubscriptionManager sub = SubscriptionManager.from(context);
3020
3021 // Figure out what subscribers are currently active
3022 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003023 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3024 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 final int[] subIds = sub.getActiveSubscriptionIdList();
3028 for (int subId : subIds) {
3029 activeSubscriberIds.add(tele.getSubscriberId(subId));
3030 }
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003033 }
3034
3035 // First pass, find a number override for an active subscriber
3036 String mergeNumber = null;
3037 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3038 for (String key : prefs.keySet()) {
3039 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3040 final String subscriberId = (String) prefs.get(key);
3041 if (activeSubscriberIds.contains(subscriberId)) {
3042 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3043 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3044 mergeNumber = (String) prefs.get(numberKey);
3045 if (DBG_MERGE) {
3046 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3047 + " for active subscriber " + subscriberId);
3048 }
3049 if (!TextUtils.isEmpty(mergeNumber)) {
3050 break;
3051 }
3052 }
3053 }
3054 }
3055
3056 // Shortcut when no active merged subscribers
3057 if (TextUtils.isEmpty(mergeNumber)) {
3058 return null;
3059 }
3060
3061 // Second pass, find all subscribers under that line override
3062 final ArraySet<String> result = new ArraySet<>();
3063 for (String key : prefs.keySet()) {
3064 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3065 final String number = (String) prefs.get(key);
3066 if (mergeNumber.equals(number)) {
3067 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3068 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3069 final String subscriberId = (String) prefs.get(subscriberKey);
3070 if (!TextUtils.isEmpty(subscriberId)) {
3071 result.add(subscriberId);
3072 }
3073 }
3074 }
3075 }
3076
3077 final String[] resultArray = result.toArray(new String[result.size()]);
3078 Arrays.sort(resultArray);
3079 if (DBG_MERGE) {
3080 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3081 }
3082 return resultArray;
3083 }
3084
3085 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003086 public boolean setOperatorBrandOverride(int subId, String brand) {
3087 enforceCarrierPrivilege(subId);
3088 final Phone phone = getPhone(subId);
3089 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003090 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003091
3092 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003093 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003094 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3095 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003096 enforceCarrierPrivilege(subId);
3097 final Phone phone = getPhone(subId);
3098 if (phone == null) {
3099 return false;
3100 }
3101 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003102 cdmaNonRoamingList);
3103 }
3104
3105 @Override
Amit Mahajanf43fe462017-02-23 12:08:31 -08003106 @Deprecated
Steven Liu4bf01bc2014-07-17 11:05:29 -05003107 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3108 enforceModifyPermission();
3109
3110 int returnValue = 0;
3111 try {
3112 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3113 if(result.exception == null) {
3114 if (result.result != null) {
3115 byte[] responseData = (byte[])(result.result);
3116 if(responseData.length > oemResp.length) {
3117 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3118 responseData.length + "bytes. Buffer Size is " +
3119 oemResp.length + "bytes.");
3120 }
3121 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3122 returnValue = responseData.length;
3123 }
3124 } else {
3125 CommandException ex = (CommandException) result.exception;
3126 returnValue = ex.getCommandError().ordinal();
3127 if(returnValue > 0) returnValue *= -1;
3128 }
3129 } catch (RuntimeException e) {
3130 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3131 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3132 if(returnValue > 0) returnValue *= -1;
3133 }
3134
3135 return returnValue;
3136 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003137
3138 @Override
3139 public void setRadioCapability(RadioAccessFamily[] rafs) {
3140 try {
3141 ProxyController.getInstance().setRadioCapability(rafs);
3142 } catch (RuntimeException e) {
3143 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3144 }
3145 }
3146
3147 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003148 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3149 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3150 return RadioAccessFamily.RAF_UNKNOWN;
3151 }
3152
Wink Saville5d475dd2014-10-17 15:00:58 -07003153 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3154 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003155
3156 @Override
3157 public void enableVideoCalling(boolean enable) {
3158 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003159 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003160 }
3161
3162 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003163 public boolean isVideoCallingEnabled(String callingPackage) {
3164 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3165 return false;
3166 }
3167
Andrew Lee77527ac2014-10-21 16:57:39 -07003168 // Check the user preference and the system-level IMS setting. Even if the user has
3169 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3170 // In the long run, we may instead need to check if there exists a connection service
3171 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003172 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3173 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003174 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003175 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003176
Andrew Leea1239f22015-03-02 17:44:07 -08003177 @Override
3178 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003179 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003180 }
3181
3182 @Override
3183 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003184 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003185 }
3186
Andrew Lee9431b832015-03-09 18:46:45 -07003187 @Override
3188 public boolean isTtyModeSupported() {
3189 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3190 TelephonyManager telephonyManager =
3191 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003192 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003193 }
3194
3195 @Override
3196 public boolean isHearingAidCompatibilitySupported() {
3197 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3198 }
3199
Sanket Padawe7310cc72015-01-14 09:53:20 -08003200 /**
3201 * Returns the unique device ID of phone, for example, the IMEI for
3202 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3203 *
3204 * <p>Requires Permission:
3205 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3206 */
3207 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003208 public String getDeviceId(String callingPackage) {
3209 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3210 return null;
3211 }
3212
Sanket Padawe7310cc72015-01-14 09:53:20 -08003213 final Phone phone = PhoneFactory.getPhone(0);
3214 if (phone != null) {
3215 return phone.getDeviceId();
3216 } else {
3217 return null;
3218 }
3219 }
3220
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003221 /*
3222 * {@hide}
3223 * Returns the IMS Registration Status
3224 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003225 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003226 public boolean isImsRegistered() {
3227 return mPhone.isImsRegistered();
3228 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003229
3230 @Override
3231 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3232 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3233 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003234
Nathan Haroldc55097a2015-03-11 18:14:50 -07003235 /*
3236 * {@hide}
3237 * Returns the IMS Registration Status
3238 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003239 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003240 return mPhone.isWifiCallingEnabled();
3241 }
3242
3243 /*
3244 * {@hide}
3245 * Returns the IMS Registration Status
3246 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003247 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003248 return mPhone.isVolteEnabled();
3249 }
Svet Ganovb320e182015-04-16 12:30:10 -07003250
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003251 /*
3252 * {@hide} Returns the IMS Registration Status
3253 */
3254 public boolean isVideoTelephonyAvailable() {
3255 return mPhone.isVideoEnabled();
3256 }
3257
Svet Ganovb320e182015-04-16 12:30:10 -07003258 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003259 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003260 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003261 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3262
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003263 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003264 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003265 } catch (SecurityException e) {
3266 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3267 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003268 }
Svet Ganovb320e182015-04-16 12:30:10 -07003269
3270 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3271 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3272 return false;
3273 }
3274
3275 return true;
3276 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003277
Makoto Onukifee69342015-06-29 14:44:50 -07003278 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003279 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003280 */
3281 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003282 // Default SMS app can always read it.
3283 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3284 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3285 return true;
3286 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003287
Makoto Onukie4072d12015-08-03 15:12:23 -07003288 try {
3289 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003290 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003291 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003292 // Can be read with READ_SMS too.
3293 try {
3294 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3295 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3296 if (opCode != AppOpsManager.OP_NONE) {
3297 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3298 == AppOpsManager.MODE_ALLOWED;
3299 } else {
3300 return true;
3301 }
3302 } catch (SecurityException readSmsSecurityException) {
3303 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003304 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003305 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003306 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003307 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003308 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003309 if (opCode != AppOpsManager.OP_NONE) {
3310 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3311 == AppOpsManager.MODE_ALLOWED;
3312 } else {
3313 return true;
3314 }
3315 } catch (SecurityException readPhoneNumberSecurityException) {
3316 }
3317
3318 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3319 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3320 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003321 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003322 }
3323
Stuart Scott8eef64f2015-04-08 15:13:54 -07003324 @Override
3325 public void factoryReset(int subId) {
3326 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003327 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3328 return;
3329 }
3330
Svet Ganovcc087f82015-05-12 20:35:54 -07003331 final long identity = Binder.clearCallingIdentity();
3332 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003333 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3334 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003335 // Enable data
3336 setDataEnabled(subId, true);
3337 // Set network selection mode to automatic
3338 setNetworkSelectionModeAutomatic(subId);
3339 // Set preferred mobile network type to the best available
3340 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3341 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003342 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003343 }
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003346 }
3347 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003348
3349 @Override
3350 public String getLocaleFromDefaultSim() {
3351 // We query all subscriptions instead of just the active ones, because
3352 // this might be called early on in the provisioning flow when the
3353 // subscriptions potentially aren't active yet.
3354 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3355 if (slist == null || slist.isEmpty()) {
3356 return null;
3357 }
3358
3359 // This function may be called very early, say, from the setup wizard, at
3360 // which point we won't have a default subscription set. If that's the case
3361 // we just choose the first, which will be valid in "most cases".
3362 final int defaultSubId = getDefaultSubscription();
3363 SubscriptionInfo info = null;
3364 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3365 info = slist.get(0);
3366 } else {
3367 for (SubscriptionInfo item : slist) {
3368 if (item.getSubscriptionId() == defaultSubId) {
3369 info = item;
3370 break;
3371 }
3372 }
3373
3374 if (info == null) {
3375 return null;
3376 }
3377 }
3378
3379 // Try and fetch the locale from the carrier properties or from the SIM language
3380 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003381 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003382 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003383 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003384 if (defaultPhone != null) {
3385 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3386 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003387 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003388 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3389 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003390 } else {
3391 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003392 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003393 }
3394 }
3395
Narayan Kamath011676f2015-07-29 12:04:08 +01003396 // The SIM language preferences only store a language (e.g. fr = French), not an
3397 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3398 // the SIM and carrier preferences does not include a country we add the country
3399 // determined from the SIM MCC to provide an exact locale.
3400 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003401 if (mccLocale != null) {
3402 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3403 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003404 }
3405
Tony Hill183b2de2015-06-24 14:53:58 +01003406 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003407 return null;
3408 }
3409
3410 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 return mSubscriptionController.getAllSubInfoList(
3414 mPhone.getContext().getOpPackageName());
3415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
3418 }
3419
3420 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 return mSubscriptionController.getActiveSubscriptionInfoList(
3424 mPhone.getContext().getOpPackageName());
3425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
3428 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003429
3430 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003431 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3432 * representing the state of the modem.
3433 *
3434 * NOTE: This clears the modem state, so there should only every be one caller.
3435 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003436 */
3437 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003438 public void requestModemActivityInfo(ResultReceiver result) {
3439 enforceModifyPermission();
3440
3441 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3442 Bundle bundle = new Bundle();
3443 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3444 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003445 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003446
3447 /**
3448 * {@hide}
3449 * Returns the service state information on specified subscription.
3450 */
3451 @Override
3452 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3453
3454 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3455 return null;
3456 }
3457
3458 final Phone phone = getPhone(subId);
3459 if (phone == null) {
3460 return null;
3461 }
3462
3463 return phone.getServiceState();
3464 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003465
3466 /**
3467 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3468 *
3469 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3470 * voicemail ringtone.
3471 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3472 * PhoneAccount.
3473 */
3474 @Override
3475 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003476 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003477 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003478 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003479 }
3480
fionaxu7ed723d2017-05-30 18:58:54 -07003481 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003482 }
3483
3484 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003485 * Sets the per-account voicemail ringtone.
3486 *
3487 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3488 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3489 *
3490 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3491 * voicemail ringtone.
3492 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3493 * PhoneAccount.
3494 */
3495 @Override
3496 public void setVoicemailRingtoneUri(String callingPackage,
3497 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3498 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3499 if (!TextUtils.equals(callingPackage,
3500 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3501 enforceModifyPermissionOrCarrierPrivilege(
3502 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3503 }
3504 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3505 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003506 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003507 }
fionaxu7ed723d2017-05-30 18:58:54 -07003508 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003509 }
3510
3511 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003512 * Returns whether vibration is set for voicemail notification in Phone settings.
3513 *
3514 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3515 * voicemail vibration setting.
3516 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3517 */
3518 @Override
3519 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003520 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003521 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003522 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003523 }
3524
fionaxu7ed723d2017-05-30 18:58:54 -07003525 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003526 }
3527
Youhan Wange64578a2016-05-02 15:32:42 -07003528 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003529 * Sets the per-account voicemail vibration.
3530 *
3531 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3532 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3533 *
3534 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3535 * voicemail vibration setting.
3536 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3537 * specific PhoneAccount.
3538 */
3539 @Override
3540 public void setVoicemailVibrationEnabled(String callingPackage,
3541 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3543 if (!TextUtils.equals(callingPackage,
3544 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3545 enforceModifyPermissionOrCarrierPrivilege(
3546 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3547 }
3548
3549 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3550 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003551 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003552 }
fionaxu7ed723d2017-05-30 18:58:54 -07003553 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003554 }
3555
3556 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003557 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3558 *
3559 * @throws SecurityException if the caller does not have the required permission
3560 */
3561 private void enforceReadPrivilegedPermission() {
3562 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3563 null);
3564 }
3565
3566 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003567 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3568 * permission.
3569 *
3570 * @throws SecurityException if the caller does not have the required permission
3571 */
3572 private void enforceSendSmsPermission() {
3573 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3574 }
3575
3576 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003577 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003578 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003579 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003580 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003581 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003582 ComponentName componentName =
3583 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3584 if(componentName == null) {
3585 throw new SecurityException("Caller not current active visual voicemail package[null]");
3586 }
3587 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003588 if (!callingPackage.equals(vvmPackage)) {
3589 throw new SecurityException("Caller not current active visual voicemail package[" +
3590 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003591 }
3592 }
3593
3594 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003595 * Return the application ID for the app type.
3596 *
3597 * @param subId the subscription ID that this request applies to.
3598 * @param appType the uicc app type.
3599 * @return Application ID for specificied app type, or null if no uicc.
3600 */
3601 @Override
3602 public String getAidForAppType(int subId, int appType) {
3603 enforceReadPrivilegedPermission();
3604 Phone phone = getPhone(subId);
3605 if (phone == null) {
3606 return null;
3607 }
3608 String aid = null;
3609 try {
3610 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3611 .getApplicationByType(appType).getAid();
3612 } catch (Exception e) {
3613 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3614 }
3615 return aid;
3616 }
3617
Youhan Wang4001d252016-05-11 10:29:41 -07003618 /**
3619 * Return the Electronic Serial Number.
3620 *
3621 * @param subId the subscription ID that this request applies to.
3622 * @return ESN or null if error.
3623 */
3624 @Override
3625 public String getEsn(int subId) {
3626 enforceReadPrivilegedPermission();
3627 Phone phone = getPhone(subId);
3628 if (phone == null) {
3629 return null;
3630 }
3631 String esn = null;
3632 try {
3633 esn = phone.getEsn();
3634 } catch (Exception e) {
3635 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3636 }
3637 return esn;
3638 }
3639
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003640 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003641 * Return the Preferred Roaming List Version.
3642 *
3643 * @param subId the subscription ID that this request applies to.
3644 * @return PRLVersion or null if error.
3645 */
3646 @Override
3647 public String getCdmaPrlVersion(int subId) {
3648 enforceReadPrivilegedPermission();
3649 Phone phone = getPhone(subId);
3650 if (phone == null) {
3651 return null;
3652 }
3653 String cdmaPrlVersion = null;
3654 try {
3655 cdmaPrlVersion = phone.getCdmaPrlVersion();
3656 } catch (Exception e) {
3657 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3658 }
3659 return cdmaPrlVersion;
3660 }
3661
3662 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003663 * Get snapshot of Telephony histograms
3664 * @return List of Telephony histograms
3665 * @hide
3666 */
3667 @Override
3668 public List<TelephonyHistogram> getTelephonyHistograms() {
3669 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3670 return RIL.getTelephonyRILTimingHistograms();
3671 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003672
3673 /**
3674 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003675 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003676 * Require system privileges. In the future we may add this to carrier APIs.
3677 *
3678 * @return The number of carriers set successfully, should match length of carriers
3679 */
3680 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003681 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003682 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003683
Meng Wang9b7c4e92017-02-17 11:41:27 -08003684 if (carriers == null) {
3685 throw new NullPointerException("carriers cannot be null");
3686 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003687
3688 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003689 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3690 return retVal[0];
3691 }
3692
3693 /**
3694 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003695 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003696 * Require system privileges. In the future we may add this to carrier APIs.
3697 *
3698 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3699 * means all carriers are allowed.
3700 */
3701 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003702 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003703 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003704 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003705 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3706 }
3707
fionaxu59545b42016-05-25 15:53:37 -07003708 /**
3709 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3710 * @param subId the subscription ID that this action applies to.
3711 * @param enabled control enable or disable metered apns.
3712 * {@hide}
3713 */
3714 @Override
3715 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3716 enforceModifyPermission();
3717 final Phone phone = getPhone(subId);
3718 if (phone == null) {
3719 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3720 return;
3721 }
3722 try {
3723 phone.carrierActionSetMeteredApnsEnabled(enabled);
3724 } catch (Exception e) {
3725 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3726 }
3727 }
3728
3729 /**
3730 * Action set from carrier signalling broadcast receivers to enable/disable radio
3731 * @param subId the subscription ID that this action applies to.
3732 * @param enabled control enable or disable radio.
3733 * {@hide}
3734 */
3735 @Override
3736 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3737 enforceModifyPermission();
3738 final Phone phone = getPhone(subId);
3739 if (phone == null) {
3740 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3741 return;
3742 }
3743 try {
3744 phone.carrierActionSetRadioEnabled(enabled);
3745 } catch (Exception e) {
3746 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3747 }
3748 }
3749
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003750 /**
3751 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3752 * bug report is being generated.
3753 */
3754 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003755 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003756 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3757 != PackageManager.PERMISSION_GRANTED) {
3758 writer.println("Permission Denial: can't dump Phone from pid="
3759 + Binder.getCallingPid()
3760 + ", uid=" + Binder.getCallingUid()
3761 + "without permission "
3762 + android.Manifest.permission.DUMP);
3763 return;
3764 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003765 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003766 }
Jack Yueb89b242016-06-22 13:27:47 -07003767
3768 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003769 * Get aggregated video call data usage since boot.
3770 *
3771 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3772 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003773 * {@hide}
3774 */
3775 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003776 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003777 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3778 null);
3779
Jack Yu84291ec2017-05-26 16:07:50 -07003780 // NetworkStatsService keeps tracking the active network interface and identity. It
3781 // records the delta with the corresponding network identity. We just return the total video
3782 // call data usage snapshot since boot.
3783 Phone phone = getPhone(subId);
3784 if (phone != null) {
3785 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003786 }
Jack Yu84291ec2017-05-26 16:07:50 -07003787 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003788 }
Jack Yu75ab2952016-07-08 14:29:33 -07003789
3790 /**
3791 * Policy control of data connection. Usually used when data limit is passed.
3792 * @param enabled True if enabling the data, otherwise disabling.
3793 * @param subId Subscription index
3794 * {@hide}
3795 */
3796 @Override
3797 public void setPolicyDataEnabled(boolean enabled, int subId) {
3798 enforceModifyPermission();
3799 Phone phone = getPhone(subId);
3800 if (phone != null) {
3801 phone.setPolicyDataEnabled(enabled);
3802 }
3803 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003804
3805 /**
3806 * Get Client request stats
3807 * @return List of Client Request Stats
3808 * @hide
3809 */
3810 @Override
3811 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3812 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3813 return null;
3814 }
3815
3816 Phone phone = getPhone(subId);
3817 if (phone != null) {
3818 return phone.getClientRequestStats();
3819 }
3820
3821 return null;
3822 }
3823
3824 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3825 if (workSource != null) {
3826 return workSource;
3827 }
3828
3829 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3830 workSource = new WorkSource(uid, packageName);
3831 return workSource;
3832 }
Jack Yueb4124c2017-02-16 15:32:43 -08003833
3834 /**
Grace Chen70990072017-03-24 17:21:30 -07003835 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003836 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003837 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003838 * @param state State of SIM (power down, power up, pass through)
3839 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3840 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3841 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003842 *
3843 **/
3844 @Override
Grace Chen70990072017-03-24 17:21:30 -07003845 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003846 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003847 Phone phone = PhoneFactory.getPhone(slotIndex);
3848
Jack Yueb4124c2017-02-16 15:32:43 -08003849 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003850 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003851 }
3852 }
Shuo Qiandd210312017-04-12 22:11:33 +00003853
Tyler Gunn65d45c22017-06-05 11:22:26 -07003854 private boolean isUssdApiAllowed(int subId) {
3855 CarrierConfigManager configManager =
3856 (CarrierConfigManager) mPhone.getContext().getSystemService(
3857 Context.CARRIER_CONFIG_SERVICE);
3858 if (configManager == null) {
3859 return false;
3860 }
3861 PersistableBundle pb = configManager.getConfigForSubId(subId);
3862 if (pb == null) {
3863 return false;
3864 }
3865 return pb.getBoolean(
3866 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3867 }
3868
Shuo Qiandd210312017-04-12 22:11:33 +00003869 /**
3870 * Check if phone is in emergency callback mode
3871 * @return true if phone is in emergency callback mode
3872 * @param subId sub id
3873 */
3874 public boolean getEmergencyCallbackMode(int subId) {
3875 final Phone phone = getPhone(subId);
3876 if (phone != null) {
3877 return phone.isInEcm();
3878 } else {
3879 return false;
3880 }
3881 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003882
3883 /**
3884 * Get the current signal strength information for the given subscription.
3885 * Because this information is not updated when the device is in a low power state
3886 * it should not be relied-upon to be current.
3887 * @param subId Subscription index
3888 * @return the most recent cached signal strength info from the modem
3889 */
3890 @Override
3891 public SignalStrength getSignalStrength(int subId) {
3892 Phone p = getPhone(subId);
3893 if (p == null) {
3894 return null;
3895 }
3896
3897 return p.getSignalStrength();
3898 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003899}