blob: 64f621455fb8050375bc25e3882e5fab21e26556 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger7e934f52017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070058import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080059import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070060import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070061import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080064import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070065import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080066import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080067import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070068import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070069import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070071import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080075import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080076import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080077
Andrew Lee312e8172014-10-23 17:01:36 -070078import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080079import com.android.ims.internal.IImsMMTelFeature;
80import com.android.ims.internal.IImsRcsFeature;
Brad Ebinger7e934f52017-12-14 14:26:15 -080081import com.android.ims.internal.IImsRegistration;
Brad Ebinger34bef922017-11-09 10:27:08 -080082import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070083import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070084import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070085import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070086import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080089import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010090import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070091import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070092import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080094import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070095import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070096import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070098import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070099import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800100import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700101import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700102import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700103import com.android.internal.telephony.uicc.IccIoResult;
104import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800105import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700106import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800107import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700108import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700109import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800110import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700111import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800112import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700113import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700114import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800115
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700116import java.io.FileDescriptor;
117import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800118import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800121import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100122import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800123import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124
125/**
126 * Implementation of the ITelephony interface.
127 */
Santos Cordon117fee72014-05-16 17:56:12 -0700128public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129 private static final String LOG_TAG = "PhoneInterfaceManager";
130 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
131 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133
134 // Message codes used with mMainThreadHandler
135 private static final int CMD_HANDLE_PIN_MMI = 1;
136 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
137 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
138 private static final int CMD_ANSWER_RINGING_CALL = 4;
139 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700140 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
141 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142 private static final int CMD_OPEN_CHANNEL = 9;
143 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
144 private static final int CMD_CLOSE_CHANNEL = 11;
145 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800146 private static final int CMD_NV_READ_ITEM = 13;
147 private static final int EVENT_NV_READ_ITEM_DONE = 14;
148 private static final int CMD_NV_WRITE_ITEM = 15;
149 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
150 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
151 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
152 private static final int CMD_NV_RESET_CONFIG = 19;
153 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800154 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
155 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
156 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
157 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800158 private static final int CMD_SEND_ENVELOPE = 25;
159 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700160 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
161 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
162 private static final int CMD_EXCHANGE_SIM_IO = 31;
163 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800164 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
165 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700166 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
167 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700168 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
169 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700170 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
171 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
172 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
173 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700174 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
175 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
176 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
177 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700178 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
180 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182 /** The singleton instance. */
183 private static PhoneInterfaceManager sInstance;
184
Wink Saville3ab207e2014-11-20 13:07:20 -0800185 private PhoneGlobals mApp;
186 private Phone mPhone;
187 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700188 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800189 private AppOpsManager mAppOps;
190 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800191 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800192 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
Derek Tan97ebb422014-09-05 16:55:38 -0700194 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
195 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800196 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700197
Derek Tan740e1672017-06-27 14:56:27 -0700198 // The AID of ISD-R.
199 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
200
yinxub1bed742017-04-17 11:45:04 -0700201 private NetworkScanRequestTracker mNetworkScanRequestTracker;
202
Derek Tan89e89d42014-07-08 17:00:10 -0700203 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204 * A request object to use for transmitting data to an ICC.
205 */
206 private static final class IccAPDUArgument {
207 public int channel, cla, command, p1, p2, p3;
208 public String data;
209
210 public IccAPDUArgument(int channel, int cla, int command,
211 int p1, int p2, int p3, String data) {
212 this.channel = channel;
213 this.cla = cla;
214 this.command = command;
215 this.p1 = p1;
216 this.p2 = p2;
217 this.p3 = p3;
218 this.data = data;
219 }
220 }
221
222 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700223 * A request object to use for transmitting data to an ICC.
224 */
225 private static final class ManualNetworkSelectionArgument {
226 public OperatorInfo operatorInfo;
227 public boolean persistSelection;
228
229 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
230 this.operatorInfo = operatorInfo;
231 this.persistSelection = persistSelection;
232 }
233 }
234
235 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
237 * request after sending. The main thread will notify the request when it is complete.
238 */
239 private static final class MainThreadRequest {
240 /** The argument to use for the request */
241 public Object argument;
242 /** The result of the request that is run on the main thread */
243 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800244 // The subscriber id that this request applies to. Defaults to
245 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
246 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
248 public MainThreadRequest(Object argument) {
249 this.argument = argument;
250 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800251
252 public MainThreadRequest(Object argument, Integer subId) {
253 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800254 if (subId != null) {
255 this.subId = subId;
256 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 }
259
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800260 private static final class IncomingThirdPartyCallArgs {
261 public final ComponentName component;
262 public final String callId;
263 public final String callerDisplayName;
264
265 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
266 String callerDisplayName) {
267 this.component = component;
268 this.callId = callId;
269 this.callerDisplayName = callerDisplayName;
270 }
271 }
272
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 /**
274 * A handler that processes messages on the main thread in the phone process. Since many
275 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
276 * inbound binder threads to the main thread in the phone process. The Binder thread
277 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
278 * on, which will be notified when the operation completes and will contain the result of the
279 * request.
280 *
281 * <p>If a MainThreadRequest object is provided in the msg.obj field,
282 * note that request.result must be set to something non-null for the calling thread to
283 * unblock.
284 */
285 private final class MainThreadHandler extends Handler {
286 @Override
287 public void handleMessage(Message msg) {
288 MainThreadRequest request;
289 Message onCompleted;
290 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800291 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700292 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293
294 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700295 case CMD_HANDLE_USSD_REQUEST: {
296 request = (MainThreadRequest) msg.obj;
297 final Phone phone = getPhoneFromRequest(request);
298 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
299 String ussdRequest = ussdObject.first;
300 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700301
302 if (!isUssdApiAllowed(request.subId)) {
303 // Carrier does not support use of this API, return failure.
304 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
305 UssdResponse response = new UssdResponse(ussdRequest, null);
306 Bundle returnData = new Bundle();
307 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
308 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
309
310 request.result = true;
311 synchronized (request) {
312 request.notifyAll();
313 }
314 return;
315 }
316
Tyler Gunn52dcf772017-04-26 11:30:31 -0700317 try {
318 request.result = phone != null ?
319 phone.handleUssdRequest(ussdRequest, wrappedCallback)
320 : false;
321 } catch (CallStateException cse) {
322 request.result = false;
323 }
pkanwar32d516d2016-10-14 19:37:38 -0700324 // Wake up the requesting thread
325 synchronized (request) {
326 request.notifyAll();
327 }
328 break;
329 }
330
Yorke Lee716f67e2015-06-17 15:39:16 -0700331 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700333 final Phone phone = getPhoneFromRequest(request);
334 request.result = phone != null ?
335 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
336 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 // Wake up the requesting thread
338 synchronized (request) {
339 request.notifyAll();
340 }
341 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
344 case CMD_HANDLE_NEIGHBORING_CELL:
345 request = (MainThreadRequest) msg.obj;
346 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
347 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700348 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 break;
350
351 case EVENT_NEIGHBORING_CELL_DONE:
352 ar = (AsyncResult) msg.obj;
353 request = (MainThreadRequest) ar.userObj;
354 if (ar.exception == null && ar.result != null) {
355 request.result = ar.result;
356 } else {
357 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800358 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 }
360 // Wake up the requesting thread
361 synchronized (request) {
362 request.notifyAll();
363 }
364 break;
365
366 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700367 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800368 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700369 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 break;
371
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 case CMD_END_CALL:
373 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800374 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700375 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700376 Phone phone = getPhone(end_subId);
377 if (phone == null) {
378 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
379 break;
380 }
381 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
383 // CDMA: If the user presses the Power button we treat it as
384 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700385 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
387 // GSM: End the call as per the Phone state
388 hungUp = PhoneUtils.hangup(mCM);
389 } else {
390 throw new IllegalStateException("Unexpected phone type: " + phoneType);
391 }
392 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
393 request.result = hungUp;
394 // Wake up the requesting thread
395 synchronized (request) {
396 request.notifyAll();
397 }
398 break;
399
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700401 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700402 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800403 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700404 if (uiccCard == null) {
405 loge("iccTransmitApduLogicalChannel: No UICC");
406 request.result = new IccIoResult(0x6F, 0, (byte[])null);
407 synchronized (request) {
408 request.notifyAll();
409 }
410 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
412 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700413 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 iccArgument.channel, iccArgument.cla, iccArgument.command,
415 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 break;
419
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700420 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 ar = (AsyncResult) msg.obj;
422 request = (MainThreadRequest) ar.userObj;
423 if (ar.exception == null && ar.result != null) {
424 request.result = ar.result;
425 } else {
426 request.result = new IccIoResult(0x6F, 0, (byte[])null);
427 if (ar.result == null) {
428 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800429 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800431 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 } else {
433 loge("iccTransmitApduLogicalChannel: Unknown exception");
434 }
435 }
436 synchronized (request) {
437 request.notifyAll();
438 }
439 break;
440
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
442 request = (MainThreadRequest) msg.obj;
443 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800444 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 if (uiccCard == null) {
446 loge("iccTransmitApduBasicChannel: No UICC");
447 request.result = new IccIoResult(0x6F, 0, (byte[])null);
448 synchronized (request) {
449 request.notifyAll();
450 }
451 } else {
452 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
453 request);
454 uiccCard.iccTransmitApduBasicChannel(
455 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
456 iccArgument.p3, iccArgument.data, onCompleted);
457 }
458 break;
459
460 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
461 ar = (AsyncResult) msg.obj;
462 request = (MainThreadRequest) ar.userObj;
463 if (ar.exception == null && ar.result != null) {
464 request.result = ar.result;
465 } else {
466 request.result = new IccIoResult(0x6F, 0, (byte[])null);
467 if (ar.result == null) {
468 loge("iccTransmitApduBasicChannel: Empty response");
469 } else if (ar.exception instanceof CommandException) {
470 loge("iccTransmitApduBasicChannel: CommandException: " +
471 ar.exception);
472 } else {
473 loge("iccTransmitApduBasicChannel: Unknown exception");
474 }
475 }
476 synchronized (request) {
477 request.notifyAll();
478 }
479 break;
480
481 case CMD_EXCHANGE_SIM_IO:
482 request = (MainThreadRequest) msg.obj;
483 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800484 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 if (uiccCard == null) {
486 loge("iccExchangeSimIO: No UICC");
487 request.result = new IccIoResult(0x6F, 0, (byte[])null);
488 synchronized (request) {
489 request.notifyAll();
490 }
491 } else {
492 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
493 request);
494 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
495 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
496 iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_EXCHANGE_SIM_IO_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6f, 0, (byte[])null);
507 }
508 synchronized (request) {
509 request.notifyAll();
510 }
511 break;
512
Derek Tan4d5e5c12014-02-04 11:54:58 -0800513 case CMD_SEND_ENVELOPE:
514 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800515 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700516 if (uiccCard == null) {
517 loge("sendEnvelopeWithStatus: No UICC");
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 synchronized (request) {
520 request.notifyAll();
521 }
522 } else {
523 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
524 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
525 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 break;
527
528 case EVENT_SEND_ENVELOPE_DONE:
529 ar = (AsyncResult) msg.obj;
530 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700531 if (ar.exception == null && ar.result != null) {
532 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700534 request.result = new IccIoResult(0x6F, 0, (byte[])null);
535 if (ar.result == null) {
536 loge("sendEnvelopeWithStatus: Empty response");
537 } else if (ar.exception instanceof CommandException) {
538 loge("sendEnvelopeWithStatus: CommandException: " +
539 ar.exception);
540 } else {
541 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
542 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 }
544 synchronized (request) {
545 request.notifyAll();
546 }
547 break;
548
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 case CMD_OPEN_CHANNEL:
550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800552 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800555 request.result = new IccOpenLogicalChannelResponse(-1,
556 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 synchronized (request) {
558 request.notifyAll();
559 }
560 } else {
561 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800562 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
563 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
567 case EVENT_OPEN_CHANNEL_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 int[] result = (int[]) ar.result;
573 int channelId = result[0];
574 byte[] selectResponse = null;
575 if (result.length > 1) {
576 selectResponse = new byte[result.length - 1];
577 for (int i = 1; i < result.length; ++i) {
578 selectResponse[i - 1] = (byte) result[i];
579 }
580 }
581 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700582 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 if (ar.result == null) {
585 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 if (ar.exception != null) {
588 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
589 }
590
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700591 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700592 if (ar.exception instanceof CommandException) {
593 CommandException.Error error =
594 ((CommandException) (ar.exception)).getCommandError();
595 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700597 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700598 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 }
600 }
601 openChannelResp = new IccOpenLogicalChannelResponse(
602 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700604 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 synchronized (request) {
606 request.notifyAll();
607 }
608 break;
609
610 case CMD_CLOSE_CHANNEL:
611 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800612 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700613 if (uiccCard == null) {
614 loge("iccCloseLogicalChannel: No UICC");
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
616 synchronized (request) {
617 request.notifyAll();
618 }
619 } else {
620 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
621 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
622 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
625 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800626 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
627 break;
628
629 case CMD_NV_READ_ITEM:
630 request = (MainThreadRequest) msg.obj;
631 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
632 mPhone.nvReadItem((Integer) request.argument, onCompleted);
633 break;
634
635 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800638 if (ar.exception == null && ar.result != null) {
639 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800641 request.result = "";
642 if (ar.result == null) {
643 loge("nvReadItem: Empty response");
644 } else if (ar.exception instanceof CommandException) {
645 loge("nvReadItem: CommandException: " +
646 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800648 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 }
650 }
651 synchronized (request) {
652 request.notifyAll();
653 }
654 break;
655
Jake Hambye994d462014-02-03 13:10:13 -0800656 case CMD_NV_WRITE_ITEM:
657 request = (MainThreadRequest) msg.obj;
658 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
659 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
660 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
661 break;
662
663 case EVENT_NV_WRITE_ITEM_DONE:
664 handleNullReturnEvent(msg, "nvWriteItem");
665 break;
666
667 case CMD_NV_WRITE_CDMA_PRL:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
670 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
671 break;
672
673 case EVENT_NV_WRITE_CDMA_PRL_DONE:
674 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
675 break;
676
677 case CMD_NV_RESET_CONFIG:
678 request = (MainThreadRequest) msg.obj;
679 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
680 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
681 break;
682
683 case EVENT_NV_RESET_CONFIG_DONE:
684 handleNullReturnEvent(msg, "nvResetConfig");
685 break;
686
Jake Hamby7c27be32014-03-03 13:25:59 -0800687 case CMD_GET_PREFERRED_NETWORK_TYPE:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700690 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800691 break;
692
693 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
694 ar = (AsyncResult) msg.obj;
695 request = (MainThreadRequest) ar.userObj;
696 if (ar.exception == null && ar.result != null) {
697 request.result = ar.result; // Integer
698 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800699 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 if (ar.result == null) {
701 loge("getPreferredNetworkType: Empty response");
702 } else if (ar.exception instanceof CommandException) {
703 loge("getPreferredNetworkType: CommandException: " +
704 ar.exception);
705 } else {
706 loge("getPreferredNetworkType: Unknown exception");
707 }
708 }
709 synchronized (request) {
710 request.notifyAll();
711 }
712 break;
713
714 case CMD_SET_PREFERRED_NETWORK_TYPE:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
717 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700718 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800719 break;
720
721 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
722 handleNullReturnEvent(msg, "setPreferredNetworkType");
723 break;
724
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800725 case CMD_SET_VOICEMAIL_NUMBER:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
728 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800729 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
730 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800731 break;
732
733 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
734 handleNullReturnEvent(msg, "setVoicemailNumber");
735 break;
736
Stuart Scott54788802015-03-30 13:18:01 -0700737 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
740 request);
741 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
742 break;
743
744 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
745 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
746 break;
747
Shishir Agrawal302c8692015-06-19 13:49:39 -0700748 case CMD_PERFORM_NETWORK_SCAN:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
751 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
752 break;
753
754 case EVENT_PERFORM_NETWORK_SCAN_DONE:
755 ar = (AsyncResult) msg.obj;
756 request = (MainThreadRequest) ar.userObj;
757 CellNetworkScanResult cellScanResult;
758 if (ar.exception == null && ar.result != null) {
759 cellScanResult = new CellNetworkScanResult(
760 CellNetworkScanResult.STATUS_SUCCESS,
761 (List<OperatorInfo>) ar.result);
762 } else {
763 if (ar.result == null) {
764 loge("getCellNetworkScanResults: Empty response");
765 }
766 if (ar.exception != null) {
767 loge("getCellNetworkScanResults: Exception: " + ar.exception);
768 }
769 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
770 if (ar.exception instanceof CommandException) {
771 CommandException.Error error =
772 ((CommandException) (ar.exception)).getCommandError();
773 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
774 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
775 } else if (error == CommandException.Error.GENERIC_FAILURE) {
776 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
777 }
778 }
779 cellScanResult = new CellNetworkScanResult(errorCode, null);
780 }
781 request.result = cellScanResult;
782 synchronized (request) {
783 request.notifyAll();
784 }
785 break;
786
787 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
788 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700789 ManualNetworkSelectionArgument selArg =
790 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700791 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
792 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700793 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
794 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 break;
796
797 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
798 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
799 break;
800
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700801 case CMD_GET_MODEM_ACTIVITY_INFO:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700804 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700805 break;
806
807 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
808 ar = (AsyncResult) msg.obj;
809 request = (MainThreadRequest) ar.userObj;
810 if (ar.exception == null && ar.result != null) {
811 request.result = ar.result;
812 } else {
813 if (ar.result == null) {
814 loge("queryModemActivityInfo: Empty response");
815 } else if (ar.exception instanceof CommandException) {
816 loge("queryModemActivityInfo: CommandException: " +
817 ar.exception);
818 } else {
819 loge("queryModemActivityInfo: Unknown exception");
820 }
821 }
Amit Mahajand4766222016-01-28 15:28:28 -0800822 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
823 if (request.result == null) {
824 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
825 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700826 synchronized (request) {
827 request.notifyAll();
828 }
829 break;
830
Meng Wang1a7c35a2016-05-05 20:56:15 -0700831 case CMD_SET_ALLOWED_CARRIERS:
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
834 mPhone.setAllowedCarriers(
835 (List<CarrierIdentifier>) request.argument,
836 onCompleted);
837 break;
838
839 case EVENT_SET_ALLOWED_CARRIERS_DONE:
840 ar = (AsyncResult) msg.obj;
841 request = (MainThreadRequest) ar.userObj;
842 if (ar.exception == null && ar.result != null) {
843 request.result = ar.result;
844 } else {
845 if (ar.result == null) {
846 loge("setAllowedCarriers: Empty response");
847 } else if (ar.exception instanceof CommandException) {
848 loge("setAllowedCarriers: CommandException: " +
849 ar.exception);
850 } else {
851 loge("setAllowedCarriers: Unknown exception");
852 }
853 }
854 // Result cannot be null. Return -1 on error.
855 if (request.result == null) {
856 request.result = new int[]{-1};
857 }
858 synchronized (request) {
859 request.notifyAll();
860 }
861 break;
862
863 case CMD_GET_ALLOWED_CARRIERS:
864 request = (MainThreadRequest) msg.obj;
865 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
866 mPhone.getAllowedCarriers(onCompleted);
867 break;
868
869 case EVENT_GET_ALLOWED_CARRIERS_DONE:
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null && ar.result != null) {
873 request.result = ar.result;
874 } else {
875 if (ar.result == null) {
876 loge("getAllowedCarriers: Empty response");
877 } else if (ar.exception instanceof CommandException) {
878 loge("getAllowedCarriers: CommandException: " +
879 ar.exception);
880 } else {
881 loge("getAllowedCarriers: Unknown exception");
882 }
883 }
884 // Result cannot be null. Return empty list of CarrierIdentifier.
885 if (request.result == null) {
886 request.result = new ArrayList<CarrierIdentifier>(0);
887 }
888 synchronized (request) {
889 request.notifyAll();
890 }
891 break;
892
Nathan Haroldb3014052017-01-25 15:57:32 -0800893 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
899 request.result = new IllegalArgumentException(
900 "Failed to retrieve Forbidden Plmns");
901 if (ar.result == null) {
902 loge("getForbiddenPlmns: Empty response");
903 } else {
904 loge("getForbiddenPlmns: Unknown exception");
905 }
906 }
907 synchronized (request) {
908 request.notifyAll();
909 }
910 break;
911
912 case CMD_GET_FORBIDDEN_PLMNS:
913 request = (MainThreadRequest) msg.obj;
914 uiccCard = getUiccCardFromRequest(request);
915 if (uiccCard == null) {
916 loge("getForbiddenPlmns() UiccCard is null");
917 request.result = new IllegalArgumentException(
918 "getForbiddenPlmns() UiccCard is null");
919 synchronized (request) {
920 request.notifyAll();
921 }
922 break;
923 }
924 Integer appType = (Integer) request.argument;
925 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
926 if (uiccApp == null) {
927 loge("getForbiddenPlmns() no app with specified type -- "
928 + appType);
929 request.result = new IllegalArgumentException("Failed to get UICC App");
930 synchronized (request) {
931 request.notifyAll();
932 }
933 break;
934 } else {
935 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
936 + " specified type -- " + appType);
937 }
938 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
939 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
940 onCompleted);
941 break;
942
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700943 default:
944 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
945 break;
946 }
947 }
Jake Hambye994d462014-02-03 13:10:13 -0800948
949 private void handleNullReturnEvent(Message msg, String command) {
950 AsyncResult ar = (AsyncResult) msg.obj;
951 MainThreadRequest request = (MainThreadRequest) ar.userObj;
952 if (ar.exception == null) {
953 request.result = true;
954 } else {
955 request.result = false;
956 if (ar.exception instanceof CommandException) {
957 loge(command + ": CommandException: " + ar.exception);
958 } else {
959 loge(command + ": Unknown exception");
960 }
961 }
962 synchronized (request) {
963 request.notifyAll();
964 }
965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700966 }
967
968 /**
969 * Posts the specified command to be executed on the main thread,
970 * waits for the request to complete, and returns the result.
971 * @see #sendRequestAsync
972 */
973 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800974 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700975 }
976
977 /**
978 * Posts the specified command to be executed on the main thread,
979 * waits for the request to complete, and returns the result.
980 * @see #sendRequestAsync
981 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800982 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700983 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
984 throw new RuntimeException("This method will deadlock if called from the main thread.");
985 }
986
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800987 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700988 Message msg = mMainThreadHandler.obtainMessage(command, request);
989 msg.sendToTarget();
990
991 // Wait for the request to complete
992 synchronized (request) {
993 while (request.result == null) {
994 try {
995 request.wait();
996 } catch (InterruptedException e) {
997 // Do nothing, go back and wait until the request is complete
998 }
999 }
1000 }
1001 return request.result;
1002 }
1003
1004 /**
1005 * Asynchronous ("fire and forget") version of sendRequest():
1006 * Posts the specified command to be executed on the main thread, and
1007 * returns immediately.
1008 * @see #sendRequest
1009 */
1010 private void sendRequestAsync(int command) {
1011 mMainThreadHandler.sendEmptyMessage(command);
1012 }
1013
1014 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001015 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1016 * @see {@link #sendRequest(int,Object)}
1017 */
1018 private void sendRequestAsync(int command, Object argument) {
1019 MainThreadRequest request = new MainThreadRequest(argument);
1020 Message msg = mMainThreadHandler.obtainMessage(command, request);
1021 msg.sendToTarget();
1022 }
1023
1024 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001025 * Initialize the singleton PhoneInterfaceManager instance.
1026 * This is only done once, at startup, from PhoneApp.onCreate().
1027 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001028 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001029 synchronized (PhoneInterfaceManager.class) {
1030 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001031 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001032 } else {
1033 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1034 }
1035 return sInstance;
1036 }
1037 }
1038
1039 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001040 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001041 mApp = app;
1042 mPhone = phone;
1043 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001044 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1046 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001047 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001048 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001049 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001050 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001051
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001052 publish();
1053 }
1054
1055 private void publish() {
1056 if (DBG) log("publish: " + this);
1057
1058 ServiceManager.addService("phone", this);
1059 }
1060
Stuart Scott584921c2015-01-15 17:10:34 -08001061 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001062 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1063 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001064 }
1065
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001066 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1067 Phone phone = getPhoneFromRequest(request);
1068 return phone == null ? null :
1069 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1070 }
1071
Wink Saville36469e72014-06-11 15:17:00 -07001072 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001073 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001074 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001075 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001076 //
1077 // Implementation of the ITelephony interface.
1078 //
1079
1080 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001081 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001082 }
1083
Wink Savilleb564aae2014-10-23 10:18:09 -07001084 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 if (DBG) log("dial: " + number);
1086 // No permission check needed here: This is just a wrapper around the
1087 // ACTION_DIAL intent, which is available to any app since it puts up
1088 // the UI before it does anything.
1089
1090 String url = createTelUrl(number);
1091 if (url == null) {
1092 return;
1093 }
1094
1095 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001096 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001097 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1098 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1099 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1100 mApp.startActivity(intent);
1101 }
1102 }
1103
1104 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001105 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001106 }
1107
Wink Savilleb564aae2014-10-23 10:18:09 -07001108 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001109 if (DBG) log("call: " + number);
1110
1111 // This is just a wrapper around the ACTION_CALL intent, but we still
1112 // need to do a permission check since we're calling startActivity()
1113 // from the context of the phone app.
1114 enforceCallPermission();
1115
1116 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1117 != AppOpsManager.MODE_ALLOWED) {
1118 return;
1119 }
1120
1121 String url = createTelUrl(number);
1122 if (url == null) {
1123 return;
1124 }
1125
Wink Saville08874612014-08-31 19:19:58 -07001126 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001127 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001128 if (slist != null) {
1129 for (SubscriptionInfo subInfoRecord : slist) {
1130 if (subInfoRecord.getSubscriptionId() == subId) {
1131 isValid = true;
1132 break;
1133 }
Wink Saville08874612014-08-31 19:19:58 -07001134 }
1135 }
1136 if (isValid == false) {
1137 return;
1138 }
1139
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001141 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1143 mApp.startActivity(intent);
1144 }
1145
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001146 /**
1147 * End a call based on call state
1148 * @return true is a call was ended
1149 */
1150 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001151 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001152 }
1153
1154 /**
1155 * End a call based on the call state of the subId
1156 * @return true is a call was ended
1157 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001158 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001159 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001160 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001161 }
1162
1163 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001164 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001165 }
1166
Wink Savilleb564aae2014-10-23 10:18:09 -07001167 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 if (DBG) log("answerRingingCall...");
1169 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1170 // but that can probably wait till the big TelephonyManager API overhaul.
1171 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1172 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001173 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 }
1175
1176 /**
1177 * Make the actual telephony calls to implement answerRingingCall().
1178 * This should only be called from the main thread of the Phone app.
1179 * @see #answerRingingCall
1180 *
1181 * TODO: it would be nice to return true if we answered the call, or
1182 * false if there wasn't actually a ringing incoming call, or some
1183 * other error occurred. (In other words, pass back the return value
1184 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1185 * But that would require calling this method via sendRequest() rather
1186 * than sendRequestAsync(), and right now we don't actually *need* that
1187 * return value, so let's just return void for now.
1188 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001189 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001190 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001192 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1193 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 if (hasActiveCall && hasHoldingCall) {
1195 // Both lines are in use!
1196 // TODO: provide a flag to let the caller specify what
1197 // policy to use if both lines are in use. (The current
1198 // behavior is hardwired to "answer incoming, end ongoing",
1199 // which is how the CALL button is specced to behave.)
1200 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1201 return;
1202 } else {
1203 // answerCall() will automatically hold the current active
1204 // call, if there is one.
1205 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1206 return;
1207 }
1208 } else {
1209 // No call was ringing.
1210 return;
1211 }
1212 }
1213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001215 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001217 public void silenceRinger() {
1218 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 }
1220
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001221 @Override
1222 public boolean isOffhook(String callingPackage) {
1223 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001224 }
1225
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001226 @Override
1227 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1228 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1229 return false;
1230 }
1231
Sanket Padawe356d7632015-06-22 14:03:32 -07001232 final Phone phone = getPhone(subId);
1233 if (phone != null) {
1234 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1235 } else {
1236 return false;
1237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001238 }
1239
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001240 @Override
1241 public boolean isRinging(String callingPackage) {
1242 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001243 }
1244
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001245 @Override
1246 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1247 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1248 return false;
1249 }
1250
Sanket Padawe356d7632015-06-22 14:03:32 -07001251 final Phone phone = getPhone(subId);
1252 if (phone != null) {
1253 return (phone.getState() == PhoneConstants.State.RINGING);
1254 } else {
1255 return false;
1256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 }
1258
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001259 @Override
1260 public boolean isIdle(String callingPackage) {
1261 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001262 }
1263
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001264 @Override
1265 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1266 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1267 return false;
1268 }
1269
Sanket Padawe356d7632015-06-22 14:03:32 -07001270 final Phone phone = getPhone(subId);
1271 if (phone != null) {
1272 return (phone.getState() == PhoneConstants.State.IDLE);
1273 } else {
1274 return false;
1275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 }
1277
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001279 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001280 }
1281
Wink Savilleb564aae2014-10-23 10:18:09 -07001282 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001283 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001284 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1285 }
1286
1287 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001288 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001289 }
1290
Wink Savilleb564aae2014-10-23 10:18:09 -07001291 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001292 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001293 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1294 }
1295
1296 /** {@hide} */
1297 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001298 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001299 }
1300
Wink Savilleb564aae2014-10-23 10:18:09 -07001301 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001303 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 checkSimPin.start();
1305 return checkSimPin.unlockSim(null, pin);
1306 }
1307
Wink Saville9de0f752013-10-22 19:04:03 -07001308 /** {@hide} */
1309 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001310 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001311 }
1312
Wink Savilleb564aae2014-10-23 10:18:09 -07001313 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001315 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 checkSimPuk.start();
1317 return checkSimPuk.unlockSim(puk, pin);
1318 }
1319
1320 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001321 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 * a synchronous one.
1323 */
1324 private static class UnlockSim extends Thread {
1325
1326 private final IccCard mSimCard;
1327
1328 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001329 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1330 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331
1332 // For replies from SimCard interface
1333 private Handler mHandler;
1334
1335 // For async handler to identify request type
1336 private static final int SUPPLY_PIN_COMPLETE = 100;
1337
1338 public UnlockSim(IccCard simCard) {
1339 mSimCard = simCard;
1340 }
1341
1342 @Override
1343 public void run() {
1344 Looper.prepare();
1345 synchronized (UnlockSim.this) {
1346 mHandler = new Handler() {
1347 @Override
1348 public void handleMessage(Message msg) {
1349 AsyncResult ar = (AsyncResult) msg.obj;
1350 switch (msg.what) {
1351 case SUPPLY_PIN_COMPLETE:
1352 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1353 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001354 mRetryCount = msg.arg1;
1355 if (ar.exception != null) {
1356 if (ar.exception instanceof CommandException &&
1357 ((CommandException)(ar.exception)).getCommandError()
1358 == CommandException.Error.PASSWORD_INCORRECT) {
1359 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1360 } else {
1361 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1362 }
1363 } else {
1364 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366 mDone = true;
1367 UnlockSim.this.notifyAll();
1368 }
1369 break;
1370 }
1371 }
1372 };
1373 UnlockSim.this.notifyAll();
1374 }
1375 Looper.loop();
1376 }
1377
1378 /*
1379 * Use PIN or PUK to unlock SIM card
1380 *
1381 * If PUK is null, unlock SIM card with PIN
1382 *
1383 * If PUK is not null, unlock SIM card with PUK and set PIN code
1384 */
Wink Saville9de0f752013-10-22 19:04:03 -07001385 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386
1387 while (mHandler == null) {
1388 try {
1389 wait();
1390 } catch (InterruptedException e) {
1391 Thread.currentThread().interrupt();
1392 }
1393 }
1394 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1395
1396 if (puk == null) {
1397 mSimCard.supplyPin(pin, callback);
1398 } else {
1399 mSimCard.supplyPuk(puk, pin, callback);
1400 }
1401
1402 while (!mDone) {
1403 try {
1404 Log.d(LOG_TAG, "wait for done");
1405 wait();
1406 } catch (InterruptedException e) {
1407 // Restore the interrupted status
1408 Thread.currentThread().interrupt();
1409 }
1410 }
1411 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001412 int[] resultArray = new int[2];
1413 resultArray[0] = mResult;
1414 resultArray[1] = mRetryCount;
1415 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 }
1417 }
1418
1419 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001420 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001421
1422 }
1423
Wink Savilleb564aae2014-10-23 10:18:09 -07001424 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425 // No permission check needed here: this call is harmless, and it's
1426 // needed for the ServiceState.requestStateUpdate() call (which is
1427 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001428 final Phone phone = getPhone(subId);
1429 if (phone != null) {
1430 phone.updateServiceLocation();
1431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432 }
1433
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001434 @Override
1435 public boolean isRadioOn(String callingPackage) {
1436 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001437 }
1438
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001439 @Override
1440 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1441 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1442 return false;
1443 }
1444 return isRadioOnForSubscriber(subId);
1445 }
1446
1447 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001448 final Phone phone = getPhone(subId);
1449 if (phone != null) {
1450 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1451 } else {
1452 return false;
1453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 }
1455
1456 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001457 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001458
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 }
Wink Saville36469e72014-06-11 15:17:00 -07001460
Wink Savilleb564aae2014-10-23 10:18:09 -07001461 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001463 final Phone phone = getPhone(subId);
1464 if (phone != null) {
1465 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1466 }
Wink Saville36469e72014-06-11 15:17:00 -07001467 }
1468
1469 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001470 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001471 }
1472
Wink Savilleb564aae2014-10-23 10:18:09 -07001473 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001474 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001475 final Phone phone = getPhone(subId);
1476 if (phone == null) {
1477 return false;
1478 }
1479 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001480 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001481 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483 return true;
1484 }
Wink Saville36469e72014-06-11 15:17:00 -07001485
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001486 public boolean needMobileRadioShutdown() {
1487 /*
1488 * If any of the Radios are available, it will need to be
1489 * shutdown. So return true if any Radio is available.
1490 */
1491 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1492 Phone phone = PhoneFactory.getPhone(i);
1493 if (phone != null && phone.isRadioAvailable()) return true;
1494 }
1495 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1496 return false;
1497 }
1498
1499 public void shutdownMobileRadios() {
1500 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1501 logv("Shutting down Phone " + i);
1502 shutdownRadioUsingPhoneId(i);
1503 }
1504 }
1505
1506 private void shutdownRadioUsingPhoneId(int phoneId) {
1507 enforceModifyPermission();
1508 Phone phone = PhoneFactory.getPhone(phoneId);
1509 if (phone != null && phone.isRadioAvailable()) {
1510 phone.shutdownRadio();
1511 }
1512 }
1513
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001515 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001516 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1517 if (defaultPhone != null) {
1518 defaultPhone.setRadioPower(turnOn);
1519 return true;
1520 } else {
1521 loge("There's no default phone.");
1522 return false;
1523 }
Wink Saville36469e72014-06-11 15:17:00 -07001524 }
1525
Wink Savilleb564aae2014-10-23 10:18:09 -07001526 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001528 final Phone phone = getPhone(subId);
1529 if (phone != null) {
1530 phone.setRadioPower(turnOn);
1531 return true;
1532 } else {
1533 return false;
1534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 }
1536
Wink Saville36469e72014-06-11 15:17:00 -07001537 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001538 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001539 public boolean enableDataConnectivity() {
1540 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001541 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001542 final Phone phone = getPhone(subId);
1543 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001544 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001545 return true;
1546 } else {
1547 return false;
1548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 }
1550
Wink Saville36469e72014-06-11 15:17:00 -07001551 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001552 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 public boolean disableDataConnectivity() {
1554 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001555 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001556 final Phone phone = getPhone(subId);
1557 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001558 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001559 return true;
1560 } else {
1561 return false;
1562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
1564
Sanket Padawe356d7632015-06-22 14:03:32 -07001565 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001566 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001567 final Phone phone = getPhone(subId);
1568 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001569 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001570 } else {
1571 return false;
1572 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 }
1574
1575 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001576 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001577 }
1578
pkanwarae03a6b2016-11-06 20:37:09 -08001579 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001580 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001581 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1582 return;
1583 }
1584 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1585 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1586 };
1587
Wink Savilleb564aae2014-10-23 10:18:09 -07001588 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1591 return false;
1592 }
Wink Saville36469e72014-06-11 15:17:00 -07001593 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 }
1595
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001597 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001598 }
1599
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001600 public int getCallStateForSlot(int slotIndex) {
1601 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001602 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001603 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001604 }
1605
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001608 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001610 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001612 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001613 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 }
1615
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001618 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 if (phone != null) {
1620 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1621 } else {
1622 return TelephonyManager.DATA_ACTIVITY_NONE;
1623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 }
1625
1626 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001627 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001628 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001629 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001630 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 }
1632
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001633 if (DBG_LOC) log("getCellLocation: is active user");
1634 Bundle data = new Bundle();
1635 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1636 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 return null;
1638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001640 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1641 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1642 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001643 }
1644
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001646 public String getNetworkCountryIsoForPhone(int phoneId) {
1647 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1648 // registered cell info, so return a NULL country instead.
1649 final long identity = Binder.clearCallingIdentity();
1650 try {
1651 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1652 if (TelephonyManager.NETWORK_TYPE_IWLAN
1653 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1654 return "";
1655 }
1656 } finally {
1657 Binder.restoreCallingIdentity(identity);
1658 }
1659 return TelephonyManager.getTelephonyProperty(
1660 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1661 }
1662
1663 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001665 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001666 }
1667
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001669 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 mApp.enforceCallingOrSelfPermission(
1671 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 final Phone phone = getPhone(subId);
1673 if (phone != null) {
1674 phone.enableLocationUpdates();
1675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 }
1677
1678 @Override
1679 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001680 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001681 }
1682
Sanket Padawe356d7632015-06-22 14:03:32 -07001683 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001684 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 mApp.enforceCallingOrSelfPermission(
1686 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001687 final Phone phone = getPhone(subId);
1688 if (phone != null) {
1689 phone.disableLocationUpdates();
1690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 }
1692
1693 @Override
1694 @SuppressWarnings("unchecked")
1695 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001696 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001697 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001698 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 }
1700
1701 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1702 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1703 return null;
1704 }
Svetoslav64fad262015-04-14 14:35:21 -07001705
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001706 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001708 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001710 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1711 try {
1712 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1713 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1714 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1715 } catch (RuntimeException e) {
1716 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001718 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 }
1720
1721
1722 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001723 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001724 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001725 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001726 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 }
1728
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001729 if (DBG_LOC) log("getAllCellInfo: is active user");
1730 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1731 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1732 for (Phone phone : PhoneFactory.getPhones()) {
1733 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1734 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001736 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 }
1738
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001739 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001741 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001742 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1743 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745
Shishir Agrawala9f32182016-04-12 12:00:16 -07001746 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001747 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001748 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1749 return null;
1750 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001751 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001752 return phone == null ? null : phone.getImei();
1753 }
1754
1755 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001756 public String getMeidForSlot(int slotIndex, String callingPackage) {
1757 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1758 return null;
1759 }
1760 Phone phone = PhoneFactory.getPhone(slotIndex);
1761 return phone == null ? null : phone.getMeid();
1762 }
1763
1764 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001765 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001766 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1767 return null;
1768 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001769 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001770 return phone == null ? null : phone.getDeviceSvn();
1771 }
1772
fionaxuf32acdf2017-11-27 22:51:16 -08001773 @Override
1774 public int getSubscriptionCarrierId(int subId) {
1775 final Phone phone = getPhone(subId);
1776 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1777 }
1778
1779 @Override
1780 public String getSubscriptionCarrierName(int subId) {
1781 final Phone phone = getPhone(subId);
1782 return phone == null ? null : phone.getCarrierName();
1783 }
1784
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 //
1786 // Internal helper methods.
1787 //
1788
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001789 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1791 *
1792 * @throws SecurityException if the caller does not have the required permission
1793 */
1794 private void enforceModifyPermission() {
1795 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1796 }
1797
1798 /**
Junda Liua2e36012014-07-09 18:30:01 -07001799 * Make sure either system app or the caller has carrier privilege.
1800 *
1801 * @throws SecurityException if the caller does not have the required permission/privilege
1802 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001803 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001804 int permission = mApp.checkCallingOrSelfPermission(
1805 android.Manifest.permission.MODIFY_PHONE_STATE);
1806 if (permission == PackageManager.PERMISSION_GRANTED) {
1807 return;
1808 }
1809
1810 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001811 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001812 }
1813
1814 /**
1815 * Make sure the caller has carrier privilege.
1816 *
1817 * @throws SecurityException if the caller does not have the required permission
1818 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001819 private void enforceCarrierPrivilege(int subId) {
1820 if (getCarrierPrivilegeStatus(subId) !=
1821 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001822 loge("No Carrier Privilege.");
1823 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001824 }
1825 }
1826
1827 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 * Make sure the caller has the CALL_PHONE permission.
1829 *
1830 * @throws SecurityException if the caller does not have the required permission
1831 */
1832 private void enforceCallPermission() {
1833 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1834 }
1835
Stuart Scott8eef64f2015-04-08 15:13:54 -07001836 private void enforceConnectivityInternalPermission() {
1837 mApp.enforceCallingOrSelfPermission(
1838 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1839 "ConnectivityService");
1840 }
1841
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 private String createTelUrl(String number) {
1843 if (TextUtils.isEmpty(number)) {
1844 return null;
1845 }
1846
Jake Hambye994d462014-02-03 13:10:13 -08001847 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
Ihab Awadf9e92732013-12-05 18:02:52 -08001850 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1852 }
1853
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001854 private static void logv(String msg) {
1855 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1856 }
1857
Ihab Awadf9e92732013-12-05 18:02:52 -08001858 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1860 }
1861
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001862 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001864 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001865 }
1866
Sanket Padawe356d7632015-06-22 14:03:32 -07001867 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001868 public int getActivePhoneTypeForSlot(int slotIndex) {
1869 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001870 if (phone == null) {
1871 return PhoneConstants.PHONE_TYPE_NONE;
1872 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001873 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 }
1876
1877 /**
1878 * Returns the CDMA ERI icon index to display
1879 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001880 @Override
1881 public int getCdmaEriIconIndex(String callingPackage) {
1882 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001883 }
1884
Sanket Padawe356d7632015-06-22 14:03:32 -07001885 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001886 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1887 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1888 return -1;
1889 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001890 final Phone phone = getPhone(subId);
1891 if (phone != null) {
1892 return phone.getCdmaEriIconIndex();
1893 } else {
1894 return -1;
1895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 }
1897
1898 /**
1899 * Returns the CDMA ERI icon mode,
1900 * 0 - ON
1901 * 1 - FLASHING
1902 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001903 @Override
1904 public int getCdmaEriIconMode(String callingPackage) {
1905 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001906 }
1907
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001909 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1910 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1911 return -1;
1912 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 final Phone phone = getPhone(subId);
1914 if (phone != null) {
1915 return phone.getCdmaEriIconMode();
1916 } else {
1917 return -1;
1918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 }
1920
1921 /**
1922 * Returns the CDMA ERI text,
1923 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001924 @Override
1925 public String getCdmaEriText(String callingPackage) {
1926 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001927 }
1928
Sanket Padawe356d7632015-06-22 14:03:32 -07001929 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001930 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1931 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1932 return null;
1933 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001934 final Phone phone = getPhone(subId);
1935 if (phone != null) {
1936 return phone.getCdmaEriText();
1937 } else {
1938 return null;
1939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941
1942 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001943 * Returns the CDMA MDN.
1944 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001946 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001947 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 final Phone phone = getPhone(subId);
1949 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1950 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001951 } else {
1952 return null;
1953 }
1954 }
1955
1956 /**
1957 * Returns the CDMA MIN.
1958 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001960 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001961 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001962 final Phone phone = getPhone(subId);
1963 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1964 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001965 } else {
1966 return null;
1967 }
1968 }
1969
1970 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001971 * Returns true if CDMA provisioning needs to run.
1972 */
1973 public boolean needsOtaServiceProvisioning() {
1974 return mPhone.needsOtaServiceProvisioning();
1975 }
1976
1977 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001978 * Sets the voice mail number of a given subId.
1979 */
1980 @Override
1981 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001982 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001983 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1984 new Pair<String, String>(alphaTag, number), new Integer(subId));
1985 return success;
1986 }
1987
Ta-wei Yen87c49842016-05-13 21:19:52 -07001988 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07001989 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
1990 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1991 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
1992 if (!TextUtils.equals(callingPackage, systemDialer)) {
1993 throw new SecurityException("caller must be system dialer");
1994 }
1995 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
1996 if (phoneAccountHandle == null){
1997 return null;
1998 }
1999 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2000 }
2001
2002 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002003 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002004 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2005 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2006 return null;
2007 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002008 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2009 }
2010
2011 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002012 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2013 VisualVoicemailSmsFilterSettings settings) {
2014 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002015 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002016 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2017 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002018 }
2019
2020 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002021 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2022 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002023 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002024 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002025 }
2026
2027 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002028 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2029 String callingPackage, int subId) {
2030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002031 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002032 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002033 }
2034
2035 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002036 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002037 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002038 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002039 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2040 }
2041
2042 @Override
2043 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2044 String number, int port, String text, PendingIntent sentIntent) {
2045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002046 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002047 enforceSendSmsPermission();
2048 // Make the calls as the phone process.
2049 final long identity = Binder.clearCallingIdentity();
2050 try {
2051 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2052 if (port == 0) {
2053 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2054 sentIntent, null, false);
2055 } else {
2056 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2057 smsManager.sendDataMessageWithSelfPermissions(number, null,
2058 (short) port, data, sentIntent, null);
2059 }
2060 } finally {
2061 Binder.restoreCallingIdentity(identity);
2062 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002063 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002064 /**
fionaxu0152e512016-11-14 13:36:14 -08002065 * Sets the voice activation state of a given subId.
2066 */
2067 @Override
2068 public void setVoiceActivationState(int subId, int activationState) {
2069 enforceModifyPermissionOrCarrierPrivilege(subId);
2070 final Phone phone = getPhone(subId);
2071 if (phone != null) {
2072 phone.setVoiceActivationState(activationState);
2073 } else {
2074 loge("setVoiceActivationState fails with invalid subId: " + subId);
2075 }
2076 }
2077
2078 /**
2079 * Sets the data activation state of a given subId.
2080 */
2081 @Override
2082 public void setDataActivationState(int subId, int activationState) {
2083 enforceModifyPermissionOrCarrierPrivilege(subId);
2084 final Phone phone = getPhone(subId);
2085 if (phone != null) {
2086 phone.setDataActivationState(activationState);
2087 } else {
2088 loge("setVoiceActivationState fails with invalid subId: " + subId);
2089 }
2090 }
2091
2092 /**
2093 * Returns the voice activation state of a given subId.
2094 */
2095 @Override
2096 public int getVoiceActivationState(int subId, String callingPackage) {
2097 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2098 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2099 }
2100 final Phone phone = getPhone(subId);
2101 if (phone != null) {
2102 return phone.getVoiceActivationState();
2103 } else {
2104 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2105 }
2106 }
2107
2108 /**
2109 * Returns the data activation state of a given subId.
2110 */
2111 @Override
2112 public int getDataActivationState(int subId, String callingPackage) {
2113 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2114 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2115 }
2116 final Phone phone = getPhone(subId);
2117 if (phone != null) {
2118 return phone.getDataActivationState();
2119 } else {
2120 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2121 }
2122 }
2123
2124 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 * Returns the unread count of voicemails
2126 */
2127 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002128 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002129 }
2130
2131 /**
2132 * Returns the unread count of voicemails for a subId
2133 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002134 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002135 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002136 final Phone phone = getPhone(subId);
2137 if (phone != null) {
2138 return phone.getVoiceMessageCount();
2139 } else {
2140 return 0;
2141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 }
2143
2144 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002145 * returns true, if the device is in a state where both voice and data
2146 * are supported simultaneously. This can change based on location or network condition.
2147 */
2148 @Override
2149 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2150 final Phone phone = getPhone(subId);
2151 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2152 }
2153
2154 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002155 * Send the dialer code if called from the current default dialer or the caller has
2156 * carrier privilege.
2157 * @param inputCode The dialer code to send
2158 */
2159 @Override
2160 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2161 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2162 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2163 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2164 enforceCarrierPrivilege(getDefaultSubscription());
2165 }
2166 mPhone.sendDialerSpecialCode(inputCode);
2167 }
2168
2169 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002170 * Returns the data network type.
2171 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 *
2173 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2174 */
2175 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002176 public int getNetworkType() {
2177 final Phone phone = getPhone(getDefaultSubscription());
2178 if (phone != null) {
2179 return phone.getServiceState().getDataNetworkType();
2180 } else {
2181 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2182 }
Wink Saville36469e72014-06-11 15:17:00 -07002183 }
2184
2185 /**
2186 * Returns the network type for a subId
2187 */
2188 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002189 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2190 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2191 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2192 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002193
Sanket Padawe356d7632015-06-22 14:03:32 -07002194 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002195 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 return phone.getServiceState().getDataNetworkType();
2197 } else {
2198 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 }
2201
2202 /**
2203 * Returns the data network type
2204 */
2205 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002206 public int getDataNetworkType(String callingPackage) {
2207 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002208 }
2209
2210 /**
2211 * Returns the data network type for a subId
2212 */
2213 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002214 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2215 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2216 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2217 }
2218
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 final Phone phone = getPhone(subId);
2220 if (phone != null) {
2221 return phone.getServiceState().getDataNetworkType();
2222 } else {
2223 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 }
2226
2227 /**
Wink Saville36469e72014-06-11 15:17:00 -07002228 * Returns the Voice network type for a subId
2229 */
2230 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002231 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2232 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2233 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2234 }
2235
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 final Phone phone = getPhone(subId);
2237 if (phone != null) {
2238 return phone.getServiceState().getVoiceNetworkType();
2239 } else {
2240 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 }
2243
2244 /**
2245 * @return true if a ICC card is present
2246 */
2247 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002248 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002249 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2250 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002251 }
2252
2253 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002254 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002255 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002256 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002257 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2258 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002259 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002260 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002261 } else {
2262 return false;
2263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 }
2265
2266 /**
2267 * Return if the current radio is LTE on CDMA. This
2268 * is a tri-state return value as for a period of time
2269 * the mode may be unknown.
2270 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002271 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002273 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002275 @Override
2276 public int getLteOnCdmaMode(String callingPackage) {
2277 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002278 }
2279
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002281 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2282 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2283 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2284 }
2285
Sanket Padawe356d7632015-06-22 14:03:32 -07002286 final Phone phone = getPhone(subId);
2287 if (phone == null) {
2288 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2289 } else {
2290 return phone.getLteOnCdmaMode();
2291 }
Wink Saville36469e72014-06-11 15:17:00 -07002292 }
2293
2294 public void setPhone(Phone phone) {
2295 mPhone = phone;
2296 }
2297
2298 /**
2299 * {@hide}
2300 * Returns Default subId, 0 in the case of single standby.
2301 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002302 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002303 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
Shishir Agrawala9f32182016-04-12 12:00:16 -07002306 private int getSlotForDefaultSubscription() {
2307 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2308 }
2309
Wink Savilleb564aae2014-10-23 10:18:09 -07002310 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002311 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002313
2314 /**
2315 * @see android.telephony.TelephonyManager.WifiCallingChoices
2316 */
2317 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002318 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2319 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002320 }
2321
2322 /**
2323 * @see android.telephony.TelephonyManager.WifiCallingChoices
2324 */
2325 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002326 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2327 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2328 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002329 }
2330
Sailesh Nepald1e68152013-12-12 19:08:02 -08002331 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002332 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002333 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002334 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002335
Shishir Agrawal566b7612013-10-28 14:41:00 -07002336 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002337 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2338 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002339 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002340
Derek Tan740e1672017-06-27 14:56:27 -07002341 if (TextUtils.equals(ISDR_AID, aid)) {
2342 // Only allows LPA to open logical channel to ISD-R.
2343 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2344 ComponentInfo bestComponent =
2345 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2346 if (bestComponent == null
2347 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2348 loge("The calling package is not allowed to access ISD-R.");
2349 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2350 }
2351 }
2352
2353 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002354 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002355 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002356 if (DBG) log("iccOpenLogicalChannel: " + response);
2357 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002358 }
2359
2360 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002361 public boolean iccCloseLogicalChannel(int subId, int channel) {
2362 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002363
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002364 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002365 if (channel < 0) {
2366 return false;
2367 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002368 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002369 if (DBG) log("iccCloseLogicalChannel: " + success);
2370 return success;
2371 }
2372
2373 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002374 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002375 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002376 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002377
2378 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002379 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2380 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002381 " data=" + data);
2382 }
2383
2384 if (channel < 0) {
2385 return "";
2386 }
2387
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002388 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002389 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002390 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2391
Shishir Agrawal566b7612013-10-28 14:41:00 -07002392 // Append the returned status code to the end of the response payload.
2393 String s = Integer.toHexString(
2394 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002395 if (response.payload != null) {
2396 s = IccUtils.bytesToHexString(response.payload) + s;
2397 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002398 return s;
2399 }
Jake Hambye994d462014-02-03 13:10:13 -08002400
Evan Charltonc66da362014-05-16 14:06:40 -07002401 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002402 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002403 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002404 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002405
2406 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002407 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2408 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002409 }
2410
2411 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002412 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002413 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2414
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002415 // Append the returned status code to the end of the response payload.
2416 String s = Integer.toHexString(
2417 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002418 if (response.payload != null) {
2419 s = IccUtils.bytesToHexString(response.payload) + s;
2420 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002421 return s;
2422 }
2423
2424 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002425 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002426 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002427 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002428
2429 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002430 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002431 p1 + " " + p2 + " " + p3 + ":" + filePath);
2432 }
2433
2434 IccIoResult response =
2435 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002436 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2437 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002438
2439 if (DBG) {
2440 log("Exchange SIM_IO [R]" + response);
2441 }
2442
2443 byte[] result = null;
2444 int length = 2;
2445 if (response.payload != null) {
2446 length = 2 + response.payload.length;
2447 result = new byte[length];
2448 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2449 } else {
2450 result = new byte[length];
2451 }
2452
2453 result[length - 1] = (byte) response.sw2;
2454 result[length - 2] = (byte) response.sw1;
2455 return result;
2456 }
2457
Nathan Haroldb3014052017-01-25 15:57:32 -08002458 /**
2459 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2460 * on a particular subscription
2461 */
2462 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002463 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2464 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002465 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2466 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2467 return null;
2468 }
2469 Object response = sendRequest(
2470 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2471 if (response instanceof String[]) {
2472 return (String[]) response;
2473 }
2474 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2475 return null;
2476 }
2477
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002478 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002479 public String sendEnvelopeWithStatus(int subId, String content) {
2480 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002481
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002482 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002483 if (response.payload == null) {
2484 return "";
2485 }
2486
2487 // Append the returned status code to the end of the response payload.
2488 String s = Integer.toHexString(
2489 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2490 s = IccUtils.bytesToHexString(response.payload) + s;
2491 return s;
2492 }
2493
Jake Hambye994d462014-02-03 13:10:13 -08002494 /**
2495 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2496 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2497 *
2498 * @param itemID the ID of the item to read
2499 * @return the NV item as a String, or null on error.
2500 */
2501 @Override
2502 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002503 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002504 if (DBG) log("nvReadItem: item " + itemID);
2505 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2506 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2507 return value;
2508 }
2509
2510 /**
2511 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2512 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2513 *
2514 * @param itemID the ID of the item to read
2515 * @param itemValue the value to write, as a String
2516 * @return true on success; false on any failure
2517 */
2518 @Override
2519 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002520 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002521 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2522 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2523 new Pair<Integer, String>(itemID, itemValue));
2524 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2525 return success;
2526 }
2527
2528 /**
2529 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2530 * Used for device configuration by some CDMA operators.
2531 *
2532 * @param preferredRoamingList byte array containing the new PRL
2533 * @return true on success; false on any failure
2534 */
2535 @Override
2536 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002537 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002538 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2539 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2540 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2541 return success;
2542 }
2543
2544 /**
2545 * Perform the specified type of NV config reset.
2546 * Used for device configuration by some CDMA operators.
2547 *
2548 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2549 * @return true on success; false on any failure
2550 */
2551 @Override
2552 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002553 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002554 if (DBG) log("nvResetConfig: type " + resetType);
2555 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2556 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2557 return success;
2558 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002559
2560 /**
Wink Saville36469e72014-06-11 15:17:00 -07002561 * {@hide}
2562 * Returns Default sim, 0 in the case of single standby.
2563 */
2564 public int getDefaultSim() {
2565 //TODO Need to get it from Telephony Devcontroller
2566 return 0;
2567 }
2568
Svet Ganovb320e182015-04-16 12:30:10 -07002569 public String[] getPcscfAddress(String apnType, String callingPackage) {
2570 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2571 return new String[0];
2572 }
2573
2574
ram87fca6f2014-07-18 18:58:44 +05302575 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002576 }
2577
Brad Ebinger51f743a2017-01-23 13:50:20 -08002578 /**
Brad Ebinger34bef922017-11-09 10:27:08 -08002579 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2580 * feature or {@link null} if the service is not available. If the feature is available, the
2581 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002582 */
Brad Ebinger34bef922017-11-09 10:27:08 -08002583 public IImsMMTelFeature getMMTelFeatureAndListen(int slotId,
2584 IImsServiceFeatureCallback callback) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002585 enforceModifyPermission();
Brad Ebinger34bef922017-11-09 10:27:08 -08002586 return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback);
2587 }
2588
2589 /**
2590 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2591 * feature during emergency calling or {@link null} if the service is not available. If the
2592 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2593 * listener for feature updates.
2594 */
2595 public IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId,
2596 IImsServiceFeatureCallback callback) {
2597 enforceModifyPermission();
2598 return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback);
2599 }
2600
2601 /**
2602 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2603 * feature during emergency calling or {@link null} if the service is not available. If the
2604 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2605 * listener for feature updates.
2606 */
2607 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2608 enforceModifyPermission();
2609 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002610 }
2611
Brad Ebinger7e934f52017-12-14 14:26:15 -08002612 /**
2613 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2614 * specified.
2615 */
2616 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2617 enforceModifyPermission();
2618 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2619 }
2620
Wink Saville36469e72014-06-11 15:17:00 -07002621 public void setImsRegistrationState(boolean registered) {
2622 enforceModifyPermission();
2623 mPhone.setImsRegistrationState(registered);
2624 }
2625
2626 /**
Stuart Scott54788802015-03-30 13:18:01 -07002627 * Set the network selection mode to automatic.
2628 *
2629 */
2630 @Override
2631 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002632 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002633 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2634 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2635 }
2636
2637 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002638 * Set the network selection mode to manual with the selected carrier.
2639 */
2640 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002641 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002642 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002643 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002644 OperatorInfo operator = new OperatorInfo(
2645 /* operatorAlphaLong */ "",
2646 /* operatorAlphaShort */ "",
2647 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002648 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002649 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2650 persistSelection);
2651 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002652 }
2653
2654 /**
2655 * Scans for available networks.
2656 */
2657 @Override
2658 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002659 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002660 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2661 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2662 CMD_PERFORM_NETWORK_SCAN, null, subId);
2663 return result;
2664 }
2665
2666 /**
yinxub1bed742017-04-17 11:45:04 -07002667 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002668 *
yinxub1bed742017-04-17 11:45:04 -07002669 * @param subId id of the subscription
2670 * @param request contains the radio access networks with bands/channels to scan
2671 * @param messenger callback messenger for scan results or errors
2672 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002673 * @return the id of the requested scan which can be used to stop the scan.
2674 */
2675 @Override
2676 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2677 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002678 enforceModifyPermissionOrCarrierPrivilege(subId);
2679 return mNetworkScanRequestTracker.startNetworkScan(
2680 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002681 }
2682
2683 /**
2684 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002685 *
2686 * @param subId id of the subscription
2687 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002688 */
2689 @Override
2690 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002691 enforceModifyPermissionOrCarrierPrivilege(subId);
2692 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002693 }
2694
2695 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002696 * Get the calculated preferred network type.
2697 * Used for debugging incorrect network type.
2698 *
2699 * @return the preferred network type, defined in RILConstants.java.
2700 */
2701 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002702 public int getCalculatedPreferredNetworkType(String callingPackage) {
2703 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2704 return RILConstants.PREFERRED_NETWORK_MODE;
2705 }
2706
Amit Mahajan43330e02014-11-18 11:54:45 -08002707 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002708 }
2709
2710 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002711 * Get the preferred network type.
2712 * Used for device configuration by some CDMA operators.
2713 *
2714 * @return the preferred network type, defined in RILConstants.java.
2715 */
2716 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002717 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002718 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002719 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002720 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002721 int networkType = (result != null ? result[0] : -1);
2722 if (DBG) log("getPreferredNetworkType: " + networkType);
2723 return networkType;
2724 }
2725
2726 /**
2727 * Set the preferred network type.
2728 * Used for device configuration by some CDMA operators.
2729 *
2730 * @param networkType the preferred network type, defined in RILConstants.java.
2731 * @return true on success; false on any failure.
2732 */
2733 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002734 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002735 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002736 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2737 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002738 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002739 if (success) {
2740 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002741 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002742 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002743 return success;
2744 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002745
2746 /**
Junda Liu475951f2014-11-07 16:45:03 -08002747 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2748 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2749 * tethering.
2750 *
2751 * @return 0: Not required. 1: required. 2: Not set.
2752 * @hide
2753 */
2754 @Override
2755 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002756 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002757 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2758 Settings.Global.TETHER_DUN_REQUIRED, 2);
2759 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2760 // config_tether_apndata.
2761 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2762 dunRequired = 1;
2763 }
2764 return dunRequired;
2765 }
2766
2767 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002768 * Set mobile data enabled
2769 * Used by the user through settings etc to turn on/off mobile data
2770 *
2771 * @param enable {@code true} turn turn data on, else {@code false}
2772 */
2773 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002774 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002775 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002776 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002777 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002778 Phone phone = PhoneFactory.getPhone(phoneId);
2779 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002780 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2781 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002782 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002783 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002784 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002785 }
2786
2787 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002788 * Get the user enabled state of Mobile Data.
2789 *
2790 * TODO: remove and use isUserDataEnabled.
2791 * This can't be removed now because some vendor codes
2792 * calls through ITelephony directly while they should
2793 * use TelephonyManager.
2794 *
2795 * @return true on enabled
2796 */
2797 @Override
2798 public boolean getDataEnabled(int subId) {
2799 return isUserDataEnabled(subId);
2800 }
2801
2802 /**
2803 * Get whether mobile data is enabled per user setting.
2804 *
2805 * There are other factors deciding whether mobile data is actually enabled, but they are
2806 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002807 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002808 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002809 *
2810 * @return {@code true} if data is enabled else {@code false}
2811 */
2812 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002813 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002814 try {
2815 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2816 null);
2817 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002818 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002819 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002820 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002821 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002822 Phone phone = PhoneFactory.getPhone(phoneId);
2823 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002824 boolean retVal = phone.isUserDataEnabled();
2825 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002826 return retVal;
2827 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002828 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2829 return false;
2830 }
2831 }
2832
2833 /**
2834 * Get whether mobile data is enabled.
2835 *
2836 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2837 * whether mobile data is actually enabled.
2838 *
2839 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2840 *
2841 * @return {@code true} if data is enabled else {@code false}
2842 */
2843 @Override
2844 public boolean isDataEnabled(int subId) {
2845 try {
2846 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2847 null);
2848 } catch (Exception e) {
2849 enforceModifyPermissionOrCarrierPrivilege(subId);
2850 }
2851 int phoneId = mSubscriptionController.getPhoneId(subId);
2852 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2853 Phone phone = PhoneFactory.getPhone(phoneId);
2854 if (phone != null) {
2855 boolean retVal = phone.isDataEnabled();
2856 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2857 return retVal;
2858 } else {
2859 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002860 return false;
2861 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002862 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002863
2864 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002865 public int getCarrierPrivilegeStatus(int subId) {
2866 final Phone phone = getPhone(subId);
2867 if (phone == null) {
2868 loge("getCarrierPrivilegeStatus: Invalid subId");
2869 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2870 }
2871 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002872 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002873 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2875 }
2876 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002877 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002878 }
Junda Liu29340342014-07-10 15:23:27 -07002879
2880 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002881 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002882 if (TextUtils.isEmpty(pkgName))
2883 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002884 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002885 if (card == null) {
2886 loge("checkCarrierPrivilegesForPackage: No UICC");
2887 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2888 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002889 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2890 }
2891
2892 @Override
2893 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002894 if (TextUtils.isEmpty(pkgName))
2895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002896 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2897 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2898 UiccCard card = UiccController.getInstance().getUiccCard(i);
2899 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002900 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002901 continue;
2902 }
2903
2904 result = card.getCarrierPrivilegeStatus(
2905 mPhone.getContext().getPackageManager(), pkgName);
2906 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2907 break;
2908 }
2909 }
2910
2911 return result;
Junda Liu29340342014-07-10 15:23:27 -07002912 }
Derek Tan89e89d42014-07-08 17:00:10 -07002913
2914 @Override
Junda Liue64de782015-04-16 17:19:16 -07002915 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2916 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2917 loge("phoneId " + phoneId + " is not valid.");
2918 return null;
2919 }
2920 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002921 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002922 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002923 return null ;
2924 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002925 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002926 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002927 }
2928
Amith Yamasani6e118872016-02-19 12:53:51 -08002929 @Override
2930 public List<String> getPackagesWithCarrierPrivileges() {
2931 PackageManager pm = mPhone.getContext().getPackageManager();
2932 List<String> privilegedPackages = new ArrayList<>();
2933 List<PackageInfo> packages = null;
2934 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2935 UiccCard card = UiccController.getInstance().getUiccCard(i);
2936 if (card == null) {
2937 // No UICC in that slot.
2938 continue;
2939 }
2940 if (card.hasCarrierPrivilegeRules()) {
2941 if (packages == null) {
2942 // Only check packages in user 0 for now
2943 packages = pm.getInstalledPackagesAsUser(
2944 PackageManager.MATCH_DISABLED_COMPONENTS
2945 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2946 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2947 }
2948 for (int p = packages.size() - 1; p >= 0; p--) {
2949 PackageInfo pkgInfo = packages.get(p);
2950 if (pkgInfo != null && pkgInfo.packageName != null
2951 && card.getCarrierPrivilegeStatus(pkgInfo)
2952 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2953 privilegedPackages.add(pkgInfo.packageName);
2954 }
2955 }
2956 }
2957 }
2958 return privilegedPackages;
2959 }
2960
Wink Savilleb564aae2014-10-23 10:18:09 -07002961 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002962 final Phone phone = getPhone(subId);
2963 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002964 if (card == null) {
2965 loge("getIccId: No UICC");
2966 return null;
2967 }
2968 String iccId = card.getIccId();
2969 if (TextUtils.isEmpty(iccId)) {
2970 loge("getIccId: ICC ID is null or empty.");
2971 return null;
2972 }
2973 return iccId;
2974 }
2975
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002976 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002977 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2978 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002979 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002980
Jeff Sharkey85190e62014-12-05 09:40:12 -08002981 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002982 final Phone phone = getPhone(subId);
2983 if (phone == null) {
2984 return false;
2985 }
2986 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002987
2988 if (DBG_MERGE) {
2989 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2990 + subscriberId + " to " + number);
2991 }
2992
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002993 if (TextUtils.isEmpty(iccId)) {
2994 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002995 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002996
Jeff Sharkey85190e62014-12-05 09:40:12 -08002997 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2998
2999 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003000 if (alphaTag == null) {
3001 editor.remove(alphaTagPrefKey);
3002 } else {
3003 editor.putString(alphaTagPrefKey, alphaTag);
3004 }
3005
Jeff Sharkey85190e62014-12-05 09:40:12 -08003006 // Record both the line number and IMSI for this ICCID, since we need to
3007 // track all merged IMSIs based on line number
3008 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3009 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003010 if (number == null) {
3011 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003012 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003013 } else {
3014 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003015 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003016 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003017
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003018 editor.commit();
3019 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003020 }
3021
3022 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003023 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003024 // This is open to apps with WRITE_SMS.
3025 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003026 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003027 return null;
3028 }
Derek Tan97ebb422014-09-05 16:55:38 -07003029
3030 String iccId = getIccId(subId);
3031 if (iccId != null) {
3032 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003033 if (DBG_MERGE) {
3034 log("getLine1NumberForDisplay returning " +
3035 mTelephonySharedPreferences.getString(numberPrefKey, null));
3036 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003037 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003038 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003039 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003040 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003041 }
3042
3043 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003044 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3045 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3046 return null;
3047 }
Derek Tan97ebb422014-09-05 16:55:38 -07003048
3049 String iccId = getIccId(subId);
3050 if (iccId != null) {
3051 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003052 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003053 }
Derek Tan97ebb422014-09-05 16:55:38 -07003054 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003055 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003056
3057 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003058 public String[] getMergedSubscriberIds(String callingPackage) {
3059 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3060 return null;
3061 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003062 final Context context = mPhone.getContext();
3063 final TelephonyManager tele = TelephonyManager.from(context);
3064 final SubscriptionManager sub = SubscriptionManager.from(context);
3065
3066 // Figure out what subscribers are currently active
3067 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003068 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3069 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 final int[] subIds = sub.getActiveSubscriptionIdList();
3073 for (int subId : subIds) {
3074 activeSubscriberIds.add(tele.getSubscriberId(subId));
3075 }
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003078 }
3079
3080 // First pass, find a number override for an active subscriber
3081 String mergeNumber = null;
3082 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3083 for (String key : prefs.keySet()) {
3084 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3085 final String subscriberId = (String) prefs.get(key);
3086 if (activeSubscriberIds.contains(subscriberId)) {
3087 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3088 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3089 mergeNumber = (String) prefs.get(numberKey);
3090 if (DBG_MERGE) {
3091 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3092 + " for active subscriber " + subscriberId);
3093 }
3094 if (!TextUtils.isEmpty(mergeNumber)) {
3095 break;
3096 }
3097 }
3098 }
3099 }
3100
3101 // Shortcut when no active merged subscribers
3102 if (TextUtils.isEmpty(mergeNumber)) {
3103 return null;
3104 }
3105
3106 // Second pass, find all subscribers under that line override
3107 final ArraySet<String> result = new ArraySet<>();
3108 for (String key : prefs.keySet()) {
3109 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3110 final String number = (String) prefs.get(key);
3111 if (mergeNumber.equals(number)) {
3112 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3113 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3114 final String subscriberId = (String) prefs.get(subscriberKey);
3115 if (!TextUtils.isEmpty(subscriberId)) {
3116 result.add(subscriberId);
3117 }
3118 }
3119 }
3120 }
3121
3122 final String[] resultArray = result.toArray(new String[result.size()]);
3123 Arrays.sort(resultArray);
3124 if (DBG_MERGE) {
3125 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3126 }
3127 return resultArray;
3128 }
3129
3130 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003131 public boolean setOperatorBrandOverride(int subId, String brand) {
3132 enforceCarrierPrivilege(subId);
3133 final Phone phone = getPhone(subId);
3134 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003135 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003136
3137 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003138 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003139 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3140 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003141 enforceCarrierPrivilege(subId);
3142 final Phone phone = getPhone(subId);
3143 if (phone == null) {
3144 return false;
3145 }
3146 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003147 cdmaNonRoamingList);
3148 }
3149
3150 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003151 public void setRadioCapability(RadioAccessFamily[] rafs) {
3152 try {
3153 ProxyController.getInstance().setRadioCapability(rafs);
3154 } catch (RuntimeException e) {
3155 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3156 }
3157 }
3158
3159 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003160 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3161 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3162 return RadioAccessFamily.RAF_UNKNOWN;
3163 }
3164
Wink Saville5d475dd2014-10-17 15:00:58 -07003165 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3166 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003167
3168 @Override
3169 public void enableVideoCalling(boolean enable) {
3170 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003171 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003172 }
3173
3174 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003175 public boolean isVideoCallingEnabled(String callingPackage) {
3176 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3177 return false;
3178 }
3179
Andrew Lee77527ac2014-10-21 16:57:39 -07003180 // Check the user preference and the system-level IMS setting. Even if the user has
3181 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3182 // In the long run, we may instead need to check if there exists a connection service
3183 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003184 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3185 return imsManager.isVtEnabledByPlatform()
3186 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3187 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003188 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003189
Andrew Leea1239f22015-03-02 17:44:07 -08003190 @Override
3191 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003192 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003193 }
3194
3195 @Override
3196 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003197 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003198 }
3199
Andrew Lee9431b832015-03-09 18:46:45 -07003200 @Override
3201 public boolean isTtyModeSupported() {
3202 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3203 TelephonyManager telephonyManager =
3204 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003205 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003206 }
3207
3208 @Override
3209 public boolean isHearingAidCompatibilitySupported() {
3210 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3211 }
3212
Sanket Padawe7310cc72015-01-14 09:53:20 -08003213 /**
3214 * Returns the unique device ID of phone, for example, the IMEI for
3215 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3216 *
3217 * <p>Requires Permission:
3218 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3219 */
3220 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003221 public String getDeviceId(String callingPackage) {
3222 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3223 return null;
3224 }
3225
Sanket Padawe7310cc72015-01-14 09:53:20 -08003226 final Phone phone = PhoneFactory.getPhone(0);
3227 if (phone != null) {
3228 return phone.getDeviceId();
3229 } else {
3230 return null;
3231 }
3232 }
3233
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003234 /*
3235 * {@hide}
3236 * Returns the IMS Registration Status
3237 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003238 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003239 public boolean isImsRegistered() {
3240 return mPhone.isImsRegistered();
3241 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003242
Ping Sun014fe8e2016-03-02 19:16:45 +08003243 /**
3244 * {@hide}
3245 * Returns the IMS Registration Status on a particular subid
3246 *
3247 * @param subId
3248 */
3249 public boolean isImsRegisteredForSubscriber(int subId) {
3250 Phone phone = getPhone(subId);
3251 if (phone != null) {
3252 return phone.isImsRegistered();
3253 } else {
3254 return false;
3255 }
3256 }
3257
Santos Cordon7a1885b2015-02-03 11:15:19 -08003258 @Override
3259 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3260 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3261 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003262
Nathan Haroldc55097a2015-03-11 18:14:50 -07003263 /*
3264 * {@hide}
3265 * Returns the IMS Registration Status
3266 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003267 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003268 return mPhone.isWifiCallingEnabled();
3269 }
3270
3271 /*
3272 * {@hide}
3273 * Returns the IMS Registration Status
3274 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003275 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003276 return mPhone.isVolteEnabled();
3277 }
Svet Ganovb320e182015-04-16 12:30:10 -07003278
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003279 /*
3280 * {@hide} Returns the IMS Registration Status
3281 */
3282 public boolean isVideoTelephonyAvailable() {
3283 return mPhone.isVideoEnabled();
3284 }
3285
Svet Ganovb320e182015-04-16 12:30:10 -07003286 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003287 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003288 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003289 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3290
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003291 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003292 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003293 } catch (SecurityException e) {
3294 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3295 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003296 }
Svet Ganovb320e182015-04-16 12:30:10 -07003297
3298 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3299 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3300 return false;
3301 }
3302
3303 return true;
3304 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003305
Makoto Onukifee69342015-06-29 14:44:50 -07003306 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003307 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003308 */
3309 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003310 // Default SMS app can always read it.
3311 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3312 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3313 return true;
3314 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003315
Makoto Onukie4072d12015-08-03 15:12:23 -07003316 try {
3317 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003318 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003319 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003320 // Can be read with READ_SMS too.
3321 try {
3322 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3323 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3324 if (opCode != AppOpsManager.OP_NONE) {
3325 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3326 == AppOpsManager.MODE_ALLOWED;
3327 } else {
3328 return true;
3329 }
3330 } catch (SecurityException readSmsSecurityException) {
3331 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003332 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003333 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003334 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003335 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003336 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003337 if (opCode != AppOpsManager.OP_NONE) {
3338 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3339 == AppOpsManager.MODE_ALLOWED;
3340 } else {
3341 return true;
3342 }
3343 } catch (SecurityException readPhoneNumberSecurityException) {
3344 }
3345
3346 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3347 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3348 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003349 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003350 }
3351
Stuart Scott8eef64f2015-04-08 15:13:54 -07003352 @Override
3353 public void factoryReset(int subId) {
3354 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003355 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3356 return;
3357 }
3358
Svet Ganovcc087f82015-05-12 20:35:54 -07003359 final long identity = Binder.clearCallingIdentity();
3360 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003361 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3362 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003363 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003364 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003365 // Set network selection mode to automatic
3366 setNetworkSelectionModeAutomatic(subId);
3367 // Set preferred mobile network type to the best available
3368 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3369 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003370 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003371 }
3372 } finally {
3373 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003374 }
3375 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003376
3377 @Override
3378 public String getLocaleFromDefaultSim() {
3379 // We query all subscriptions instead of just the active ones, because
3380 // this might be called early on in the provisioning flow when the
3381 // subscriptions potentially aren't active yet.
3382 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3383 if (slist == null || slist.isEmpty()) {
3384 return null;
3385 }
3386
3387 // This function may be called very early, say, from the setup wizard, at
3388 // which point we won't have a default subscription set. If that's the case
3389 // we just choose the first, which will be valid in "most cases".
3390 final int defaultSubId = getDefaultSubscription();
3391 SubscriptionInfo info = null;
3392 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3393 info = slist.get(0);
3394 } else {
3395 for (SubscriptionInfo item : slist) {
3396 if (item.getSubscriptionId() == defaultSubId) {
3397 info = item;
3398 break;
3399 }
3400 }
3401
3402 if (info == null) {
3403 return null;
3404 }
3405 }
3406
3407 // Try and fetch the locale from the carrier properties or from the SIM language
3408 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003409 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003410 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003411 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003412 if (defaultPhone != null) {
3413 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3414 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003415 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003416 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3417 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003418 } else {
3419 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003420 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003421 }
3422 }
3423
Narayan Kamath011676f2015-07-29 12:04:08 +01003424 // The SIM language preferences only store a language (e.g. fr = French), not an
3425 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3426 // the SIM and carrier preferences does not include a country we add the country
3427 // determined from the SIM MCC to provide an exact locale.
3428 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003429 if (mccLocale != null) {
3430 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3431 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003432 }
3433
Tony Hill183b2de2015-06-24 14:53:58 +01003434 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003435 return null;
3436 }
3437
3438 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
3441 return mSubscriptionController.getAllSubInfoList(
3442 mPhone.getContext().getOpPackageName());
3443 } finally {
3444 Binder.restoreCallingIdentity(identity);
3445 }
3446 }
3447
3448 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 return mSubscriptionController.getActiveSubscriptionInfoList(
3452 mPhone.getContext().getOpPackageName());
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
3456 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003457
3458 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003459 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3460 * representing the state of the modem.
3461 *
3462 * NOTE: This clears the modem state, so there should only every be one caller.
3463 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003464 */
3465 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003466 public void requestModemActivityInfo(ResultReceiver result) {
3467 enforceModifyPermission();
3468
3469 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3470 Bundle bundle = new Bundle();
3471 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3472 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003473 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003474
3475 /**
3476 * {@hide}
3477 * Returns the service state information on specified subscription.
3478 */
3479 @Override
3480 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3481
3482 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3483 return null;
3484 }
3485
3486 final Phone phone = getPhone(subId);
3487 if (phone == null) {
3488 return null;
3489 }
3490
3491 return phone.getServiceState();
3492 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003493
3494 /**
3495 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3496 *
3497 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3498 * voicemail ringtone.
3499 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3500 * PhoneAccount.
3501 */
3502 @Override
3503 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003504 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003505 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003506 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003507 }
3508
fionaxu7ed723d2017-05-30 18:58:54 -07003509 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003510 }
3511
3512 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003513 * Sets the per-account voicemail ringtone.
3514 *
3515 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3516 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3517 *
3518 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3519 * voicemail ringtone.
3520 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3521 * PhoneAccount.
3522 */
3523 @Override
3524 public void setVoicemailRingtoneUri(String callingPackage,
3525 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3526 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3527 if (!TextUtils.equals(callingPackage,
3528 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3529 enforceModifyPermissionOrCarrierPrivilege(
3530 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3531 }
3532 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3533 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003534 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003535 }
fionaxu7ed723d2017-05-30 18:58:54 -07003536 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003537 }
3538
3539 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003540 * Returns whether vibration is set for voicemail notification in Phone settings.
3541 *
3542 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3543 * voicemail vibration setting.
3544 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3545 */
3546 @Override
3547 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003548 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003549 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003550 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003551 }
3552
fionaxu7ed723d2017-05-30 18:58:54 -07003553 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003554 }
3555
Youhan Wange64578a2016-05-02 15:32:42 -07003556 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003557 * Sets the per-account voicemail vibration.
3558 *
3559 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3560 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3561 *
3562 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3563 * voicemail vibration setting.
3564 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3565 * specific PhoneAccount.
3566 */
3567 @Override
3568 public void setVoicemailVibrationEnabled(String callingPackage,
3569 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3570 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3571 if (!TextUtils.equals(callingPackage,
3572 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3573 enforceModifyPermissionOrCarrierPrivilege(
3574 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3575 }
3576
3577 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3578 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003579 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003580 }
fionaxu7ed723d2017-05-30 18:58:54 -07003581 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003582 }
3583
3584 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003585 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3586 *
3587 * @throws SecurityException if the caller does not have the required permission
3588 */
3589 private void enforceReadPrivilegedPermission() {
3590 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3591 null);
3592 }
3593
3594 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003595 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3596 * permission.
3597 *
3598 * @throws SecurityException if the caller does not have the required permission
3599 */
3600 private void enforceSendSmsPermission() {
3601 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3602 }
3603
3604 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003605 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003606 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003607 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003608 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003609 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003610 ComponentName componentName =
3611 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3612 if(componentName == null) {
3613 throw new SecurityException("Caller not current active visual voicemail package[null]");
3614 }
3615 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003616 if (!callingPackage.equals(vvmPackage)) {
3617 throw new SecurityException("Caller not current active visual voicemail package[" +
3618 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003619 }
3620 }
3621
3622 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003623 * Return the application ID for the app type.
3624 *
3625 * @param subId the subscription ID that this request applies to.
3626 * @param appType the uicc app type.
3627 * @return Application ID for specificied app type, or null if no uicc.
3628 */
3629 @Override
3630 public String getAidForAppType(int subId, int appType) {
3631 enforceReadPrivilegedPermission();
3632 Phone phone = getPhone(subId);
3633 if (phone == null) {
3634 return null;
3635 }
3636 String aid = null;
3637 try {
3638 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3639 .getApplicationByType(appType).getAid();
3640 } catch (Exception e) {
3641 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3642 }
3643 return aid;
3644 }
3645
Youhan Wang4001d252016-05-11 10:29:41 -07003646 /**
3647 * Return the Electronic Serial Number.
3648 *
3649 * @param subId the subscription ID that this request applies to.
3650 * @return ESN or null if error.
3651 */
3652 @Override
3653 public String getEsn(int subId) {
3654 enforceReadPrivilegedPermission();
3655 Phone phone = getPhone(subId);
3656 if (phone == null) {
3657 return null;
3658 }
3659 String esn = null;
3660 try {
3661 esn = phone.getEsn();
3662 } catch (Exception e) {
3663 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3664 }
3665 return esn;
3666 }
3667
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003668 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003669 * Return the Preferred Roaming List Version.
3670 *
3671 * @param subId the subscription ID that this request applies to.
3672 * @return PRLVersion or null if error.
3673 */
3674 @Override
3675 public String getCdmaPrlVersion(int subId) {
3676 enforceReadPrivilegedPermission();
3677 Phone phone = getPhone(subId);
3678 if (phone == null) {
3679 return null;
3680 }
3681 String cdmaPrlVersion = null;
3682 try {
3683 cdmaPrlVersion = phone.getCdmaPrlVersion();
3684 } catch (Exception e) {
3685 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3686 }
3687 return cdmaPrlVersion;
3688 }
3689
3690 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003691 * Get snapshot of Telephony histograms
3692 * @return List of Telephony histograms
3693 * @hide
3694 */
3695 @Override
3696 public List<TelephonyHistogram> getTelephonyHistograms() {
3697 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3698 return RIL.getTelephonyRILTimingHistograms();
3699 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003700
3701 /**
3702 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003703 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003704 * Require system privileges. In the future we may add this to carrier APIs.
3705 *
3706 * @return The number of carriers set successfully, should match length of carriers
3707 */
3708 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003709 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003710 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003711
Meng Wang9b7c4e92017-02-17 11:41:27 -08003712 if (carriers == null) {
3713 throw new NullPointerException("carriers cannot be null");
3714 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003715
3716 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003717 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3718 return retVal[0];
3719 }
3720
3721 /**
3722 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003723 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003724 * Require system privileges. In the future we may add this to carrier APIs.
3725 *
3726 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3727 * means all carriers are allowed.
3728 */
3729 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003730 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003731 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003732 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003733 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3734 }
3735
fionaxu59545b42016-05-25 15:53:37 -07003736 /**
3737 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3738 * @param subId the subscription ID that this action applies to.
3739 * @param enabled control enable or disable metered apns.
3740 * {@hide}
3741 */
3742 @Override
3743 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3744 enforceModifyPermission();
3745 final Phone phone = getPhone(subId);
3746 if (phone == null) {
3747 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3748 return;
3749 }
3750 try {
3751 phone.carrierActionSetMeteredApnsEnabled(enabled);
3752 } catch (Exception e) {
3753 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3754 }
3755 }
3756
3757 /**
3758 * Action set from carrier signalling broadcast receivers to enable/disable radio
3759 * @param subId the subscription ID that this action applies to.
3760 * @param enabled control enable or disable radio.
3761 * {@hide}
3762 */
3763 @Override
3764 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3765 enforceModifyPermission();
3766 final Phone phone = getPhone(subId);
3767 if (phone == null) {
3768 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3769 return;
3770 }
3771 try {
3772 phone.carrierActionSetRadioEnabled(enabled);
3773 } catch (Exception e) {
3774 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3775 }
3776 }
3777
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003778 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003779 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3780 * network status based on which carrier apps could apply actions accordingly,
3781 * enable/disable default url handler for example.
3782 *
3783 * @param subId the subscription ID that this action applies to.
3784 * @param report control start/stop reporting the default network status.
3785 * {@hide}
3786 */
3787 @Override
3788 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3789 enforceModifyPermission();
3790 final Phone phone = getPhone(subId);
3791 if (phone == null) {
3792 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3793 return;
3794 }
3795 try {
3796 phone.carrierActionReportDefaultNetworkStatus(report);
3797 } catch (Exception e) {
3798 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3799 }
3800 }
3801
3802 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003803 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3804 * bug report is being generated.
3805 */
3806 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003807 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003808 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3809 != PackageManager.PERMISSION_GRANTED) {
3810 writer.println("Permission Denial: can't dump Phone from pid="
3811 + Binder.getCallingPid()
3812 + ", uid=" + Binder.getCallingUid()
3813 + "without permission "
3814 + android.Manifest.permission.DUMP);
3815 return;
3816 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003817 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003818 }
Jack Yueb89b242016-06-22 13:27:47 -07003819
3820 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003821 * Get aggregated video call data usage since boot.
3822 *
3823 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3824 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003825 * {@hide}
3826 */
3827 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003828 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003829 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3830 null);
3831
Jack Yu84291ec2017-05-26 16:07:50 -07003832 // NetworkStatsService keeps tracking the active network interface and identity. It
3833 // records the delta with the corresponding network identity. We just return the total video
3834 // call data usage snapshot since boot.
3835 Phone phone = getPhone(subId);
3836 if (phone != null) {
3837 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003838 }
Jack Yu84291ec2017-05-26 16:07:50 -07003839 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003840 }
Jack Yu75ab2952016-07-08 14:29:33 -07003841
3842 /**
3843 * Policy control of data connection. Usually used when data limit is passed.
3844 * @param enabled True if enabling the data, otherwise disabling.
3845 * @param subId Subscription index
3846 * {@hide}
3847 */
3848 @Override
3849 public void setPolicyDataEnabled(boolean enabled, int subId) {
3850 enforceModifyPermission();
3851 Phone phone = getPhone(subId);
3852 if (phone != null) {
3853 phone.setPolicyDataEnabled(enabled);
3854 }
3855 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003856
3857 /**
3858 * Get Client request stats
3859 * @return List of Client Request Stats
3860 * @hide
3861 */
3862 @Override
3863 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3864 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3865 return null;
3866 }
3867
3868 Phone phone = getPhone(subId);
3869 if (phone != null) {
3870 return phone.getClientRequestStats();
3871 }
3872
3873 return null;
3874 }
3875
3876 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3877 if (workSource != null) {
3878 return workSource;
3879 }
3880
3881 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3882 workSource = new WorkSource(uid, packageName);
3883 return workSource;
3884 }
Jack Yueb4124c2017-02-16 15:32:43 -08003885
3886 /**
Grace Chen70990072017-03-24 17:21:30 -07003887 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003888 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003889 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003890 * @param state State of SIM (power down, power up, pass through)
3891 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3892 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3893 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003894 *
3895 **/
3896 @Override
Grace Chen70990072017-03-24 17:21:30 -07003897 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003898 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003899 Phone phone = PhoneFactory.getPhone(slotIndex);
3900
Jack Yueb4124c2017-02-16 15:32:43 -08003901 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003902 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003903 }
3904 }
Shuo Qiandd210312017-04-12 22:11:33 +00003905
Tyler Gunn65d45c22017-06-05 11:22:26 -07003906 private boolean isUssdApiAllowed(int subId) {
3907 CarrierConfigManager configManager =
3908 (CarrierConfigManager) mPhone.getContext().getSystemService(
3909 Context.CARRIER_CONFIG_SERVICE);
3910 if (configManager == null) {
3911 return false;
3912 }
3913 PersistableBundle pb = configManager.getConfigForSubId(subId);
3914 if (pb == null) {
3915 return false;
3916 }
3917 return pb.getBoolean(
3918 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3919 }
3920
Shuo Qiandd210312017-04-12 22:11:33 +00003921 /**
3922 * Check if phone is in emergency callback mode
3923 * @return true if phone is in emergency callback mode
3924 * @param subId sub id
3925 */
3926 public boolean getEmergencyCallbackMode(int subId) {
3927 final Phone phone = getPhone(subId);
3928 if (phone != null) {
3929 return phone.isInEcm();
3930 } else {
3931 return false;
3932 }
3933 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003934
3935 /**
3936 * Get the current signal strength information for the given subscription.
3937 * Because this information is not updated when the device is in a low power state
3938 * it should not be relied-upon to be current.
3939 * @param subId Subscription index
3940 * @return the most recent cached signal strength info from the modem
3941 */
3942 @Override
3943 public SignalStrength getSignalStrength(int subId) {
3944 Phone p = getPhone(subId);
3945 if (p == null) {
3946 return null;
3947 }
3948
3949 return p.getSignalStrength();
3950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003951}